Repository: cloudstack Updated Branches: refs/heads/master 0f528df22 -> 350ac4c4b
Fixed Resource Leaks Signed-off-by: Santhosh Edukulla <santhosh.eduku...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/350ac4c4 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/350ac4c4 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/350ac4c4 Branch: refs/heads/master Commit: 350ac4c4b0e71156ed27307b2d625f46453500a2 Parents: 0f528df Author: Santhosh Edukulla <santhosh.eduku...@gmail.com> Authored: Mon Oct 13 17:49:07 2014 +0530 Committer: Santhosh Edukulla <santhosh.eduku...@gmail.com> Committed: Mon Oct 13 17:51:02 2014 +0530 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade441to450.java | 169 ++++++++++--------- .../db/test/com/cloud/utils/db/DbTestUtils.java | 39 ++--- .../datastore/util/NexentaNmsClient.java | 11 +- .../storage/datastore/util/SolidFireUtil.java | 13 +- .../cloudstack/region/RegionsApiUtil.java | 16 +- .../resource/NfsSecondaryStorageResource.java | 7 +- .../LocalNfsSecondaryStorageResourceTest.java | 4 +- .../NfsSecondaryStorageResourceTest.java | 6 +- 8 files changed, 132 insertions(+), 133 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java index cde661b..4e2bcad 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade441to450.java @@ -82,126 +82,131 @@ public class Upgrade441to450 implements DbUpgrade { } private void updateSystemVmTemplates(Connection conn) { - PreparedStatement pstmt = null; - ResultSet rs = null; s_logger.debug("Updating System Vm template IDs"); - try{ + try { //Get all hypervisors in use Set<Hypervisor.HypervisorType> hypervisorsListInUse = new HashSet<Hypervisor.HypervisorType>(); - try { - pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); - rs = pstmt.executeQuery(); - while(rs.next()){ - switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { - case XenServer: hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); - break; - case KVM: hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); - break; - case VMware: hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); - break; - case Hyperv: hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); - break; - case LXC: hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); - break; + try (PreparedStatement sel_hyp_type_pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null");) { + try (ResultSet hyp_type_rs = sel_hyp_type_pstmt.executeQuery();) { + while (hyp_type_rs.next()) { + switch (Hypervisor.HypervisorType.getType(hyp_type_rs.getString(1))) { + case XenServer: + hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); + break; + case KVM: + hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); + break; + case VMware: + hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); + break; + case Hyperv: + hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); + break; + case LXC: + hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); + break; + } } + } catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); } } catch (SQLException e) { - throw new CloudRuntimeException("Error while listing hypervisors in use", e); + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); } - - Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>(){ - { put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.5"); + Map<Hypervisor.HypervisorType, String> NewTemplateNameList = new HashMap<Hypervisor.HypervisorType, String>() { + { + put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.5"); put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.5"); put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.5"); put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.5"); put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.5"); } }; - - Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>(){ - { put(Hypervisor.HypervisorType.XenServer, "router.template.xen"); + Map<Hypervisor.HypervisorType, String> routerTemplateConfigurationNames = new HashMap<Hypervisor.HypervisorType, String>() { + { + put(Hypervisor.HypervisorType.XenServer, "router.template.xen"); put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); } }; - - Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>(){ - { put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-xen.vhd.bz2"); + Map<Hypervisor.HypervisorType, String> newTemplateUrl = new HashMap<Hypervisor.HypervisorType, String>() { + { + put(Hypervisor.HypervisorType.XenServer, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-xen.vhd.bz2"); put(Hypervisor.HypervisorType.VMware, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-vmware.ova"); put(Hypervisor.HypervisorType.KVM, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2"); put(Hypervisor.HypervisorType.LXC, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-kvm.qcow2.bz2"); put(Hypervisor.HypervisorType.Hyperv, "http://download.cloud.com/templates/4.5/systemvm64template-4.5-hyperv.vhd.zip"); } }; - - Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>(){ - { put(Hypervisor.HypervisorType.XenServer, "2b15ab4401c2d655264732d3fc600241"); + Map<Hypervisor.HypervisorType, String> newTemplateChecksum = new HashMap<Hypervisor.HypervisorType, String>() { + { + put(Hypervisor.HypervisorType.XenServer, "2b15ab4401c2d655264732d3fc600241"); put(Hypervisor.HypervisorType.VMware, "3106a79a4ce66cd7f6a7c50e93f2db57"); put(Hypervisor.HypervisorType.KVM, "aa9f501fecd3de1daeb9e2f357f6f002"); put(Hypervisor.HypervisorType.LXC, "aa9f501fecd3de1daeb9e2f357f6f002"); put(Hypervisor.HypervisorType.Hyperv, "70bd30ea02ee9ed67d2c6b85c179cee9"); } }; - - for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()){ + for (Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { s_logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); - try { + try (PreparedStatement sel_templ_pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1");) + { //Get 4.5.0 system Vm template Id for corresponding hypervisor - pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null order by id desc limit 1"); - pstmt.setString(1, hypervisorAndTemplateName.getValue()); - rs = pstmt.executeQuery(); - if(rs.next()){ - long templateId = rs.getLong(1); - rs.close(); - pstmt.close(); - pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?"); - pstmt.setLong(1, templateId); - pstmt.executeUpdate(); - pstmt.close(); - // update templete ID of system Vms - pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?"); - pstmt.setLong(1, templateId); - pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); - pstmt.executeUpdate(); - pstmt.close(); - // Change value of global configuration parameter router.template.* for the corresponding hypervisor - pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?"); - pstmt.setString(1, hypervisorAndTemplateName.getValue()); - pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); - pstmt.executeUpdate(); - pstmt.close(); - } else { - if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())){ - throw new CloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); + sel_templ_pstmt.setString(1, hypervisorAndTemplateName.getValue()); + try (ResultSet rs = sel_templ_pstmt.executeQuery();) + { + if (rs.next()) { + long templateId = rs.getLong(1); + try(PreparedStatement update_cloud_templ_pstmt = conn.prepareStatement("update `cloud`.`vm_template` set type='SYSTEM' where id = ?");) + { + update_cloud_templ_pstmt.setLong(1, templateId); + update_cloud_templ_pstmt.executeUpdate(); + // update templete ID of system Vms + }catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); + } + try(PreparedStatement update_instance_pstmt = conn.prepareStatement("update `cloud`.`vm_instance` set vm_template_id = ? where type <> 'User' and hypervisor_type = ?");) { + update_instance_pstmt.setLong(1, templateId); + update_instance_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); + update_instance_pstmt.executeUpdate(); + }catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); + } + // Change value of global configuration parameter router.template.* for the corresponding hypervisor + try(PreparedStatement update_cloud_pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = ?");) + { + update_cloud_pstmt.setString(1, hypervisorAndTemplateName.getValue()); + update_cloud_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); + update_cloud_pstmt.executeUpdate(); + }catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); + } } else { - s_logger.warn("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); - // Update the latest template URLs for corresponding hypervisor - pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1"); - pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); - pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); - pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); - pstmt.executeUpdate(); - pstmt.close(); + if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { + throw new CloudRuntimeException("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); + } else { + s_logger.warn("4.5.0 " + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); + // Update the latest template URLs for corresponding hypervisor + try (PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`vm_template` SET url = ? , checksum = ? WHERE hypervisor_type = ? AND type = 'SYSTEM' AND removed is null order by id desc limit 1");) { + update_pstmt.setString(1, newTemplateUrl.get(hypervisorAndTemplateName.getKey())); + update_pstmt.setString(2, newTemplateChecksum.get(hypervisorAndTemplateName.getKey())); + update_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); + update_pstmt.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); + } + } } + } catch (SQLException e) { + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); } - } catch (SQLException e) { - throw new CloudRuntimeException("Error while updating "+ hypervisorAndTemplateName.getKey() +" systemVm template", e); - } - } - s_logger.debug("Updating System Vm Template IDs Complete"); - } finally { - try { - if (rs != null) { - rs.close(); } - - if (pstmt != null) { - pstmt.close(); - } - } catch (SQLException e) { + s_logger.debug("Updating System Vm Template IDs Complete"); } + }catch(SQLException e){ + throw new CloudRuntimeException("updateSystemVmTemplates:Exception:" + e.getMessage(), e); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/framework/db/test/com/cloud/utils/db/DbTestUtils.java ---------------------------------------------------------------------- diff --git a/framework/db/test/com/cloud/utils/db/DbTestUtils.java b/framework/db/test/com/cloud/utils/db/DbTestUtils.java index 038809f..4d0ecc6 100644 --- a/framework/db/test/com/cloud/utils/db/DbTestUtils.java +++ b/framework/db/test/com/cloud/utils/db/DbTestUtils.java @@ -32,27 +32,17 @@ public class DbTestUtils { if (cleanScript == null) { throw new RuntimeException("Unable to clean the database because I can't find " + file); } - Connection conn = TransactionLegacy.getStandaloneConnection(); - ScriptRunner runner = new ScriptRunner(conn, autoCommit, stopOnError); - FileReader reader; - try { - reader = new FileReader(cleanScript); + try(FileReader reader = new FileReader(cleanScript);) + { + runner.runScript(reader); + conn.close(); } catch (FileNotFoundException e) { throw new RuntimeException("Unable to read " + file, e); - } - try { - runner.runScript(reader); - } catch (IOException e) { + }catch (IOException e) { throw new RuntimeException("Unable to read " + file, e); } catch (SQLException e) { - throw new RuntimeException("Unable to execute " + file, e); - } - - try { - conn.close(); - } catch (SQLException e) { throw new RuntimeException("Unable to close DB connection", e); } } @@ -62,24 +52,15 @@ public class DbTestUtils { if (cleanScript == null) { throw new RuntimeException("Unable to clean the database because I can't find " + file); } - Connection conn = TransactionLegacy.getStandaloneUsageConnection(); - ScriptRunner runner = new ScriptRunner(conn, autoCommit, stopOnError); - FileReader reader; - try { - reader = new FileReader(cleanScript); - } catch (FileNotFoundException e) { - throw new RuntimeException("Unable to read " + file, e); - } - try { + try(FileReader reader = new FileReader(cleanScript);) { runner.runScript(reader); - } catch (IOException e) { - throw new RuntimeException("Unable to read " + file, e); - } catch (SQLException e) { - throw new RuntimeException("Unable to execute " + file, e); + } catch (IOException e){ + throw new RuntimeException("executeUsageScript:Exception:"+e.getMessage(),e); + }catch (SQLException e){ + throw new RuntimeException("executeUsageScript:Exception:"+e.getMessage(),e); } - try { conn.close(); } catch (SQLException e) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/plugins/storage/volume/nexenta/src/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java ---------------------------------------------------------------------- diff --git a/plugins/storage/volume/nexenta/src/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java b/plugins/storage/volume/nexenta/src/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java index ed1a780..beebb44 100644 --- a/plugins/storage/volume/nexenta/src/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java +++ b/plugins/storage/volume/nexenta/src/org/apache/cloudstack/storage/datastore/util/NexentaNmsClient.java @@ -197,10 +197,13 @@ public class NexentaNmsClient { if (!isSuccess(status)) { throw new CloudRuntimeException("Failed on JSON-RPC API call. HTTP error code = " + status); } - BufferedReader buffer = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - String tmp; - while ((tmp = buffer.readLine()) != null) { - sb.append(tmp); + try(BufferedReader buffer = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));) { + String tmp; + while ((tmp = buffer.readLine()) != null) { + sb.append(tmp); + } + }catch (IOException ex) { + throw new CloudRuntimeException(ex.getMessage()); } } catch (ClientProtocolException ex) { throw new CloudRuntimeException(ex.getMessage()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java ---------------------------------------------------------------------- diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java index e3be262..65f3554 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java @@ -1667,12 +1667,13 @@ public class SolidFireUtil { throw new CloudRuntimeException("Failed on JSON-RPC API call. HTTP error code = " + response.getStatusLine().getStatusCode()); } - BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - - String strOutput; - - while ((strOutput = br.readLine()) != null) { - sb.append(strOutput); + try(BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));) { + String strOutput; + while ((strOutput = br.readLine()) != null) { + sb.append(strOutput); + } + }catch (IOException ex) { + throw new CloudRuntimeException(ex.getMessage()); } } catch (UnsupportedEncodingException ex) { throw new CloudRuntimeException(ex.getMessage()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/server/src/org/apache/cloudstack/region/RegionsApiUtil.java ---------------------------------------------------------------------- diff --git a/server/src/org/apache/cloudstack/region/RegionsApiUtil.java b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java index 679f6d8..7894e37 100644 --- a/server/src/org/apache/cloudstack/region/RegionsApiUtil.java +++ b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java @@ -105,8 +105,12 @@ public class RegionsApiUtil { xstream.aliasField("networkdomain", RegionAccount.class, "networkDomain"); xstream.aliasField("id", RegionUser.class, "uuid"); xstream.aliasField("accountId", RegionUser.class, "accountUuid"); - ObjectInputStream in = xstream.createObjectInputStream(is); - return (RegionAccount)in.readObject(); + try(ObjectInputStream in = xstream.createObjectInputStream(is);) { + return (RegionAccount) in.readObject(); + }catch (IOException e) { + s_logger.error(e.getMessage()); + return null; + } } else { return null; } @@ -143,8 +147,12 @@ public class RegionsApiUtil { xstream.aliasField("id", RegionDomain.class, "uuid"); xstream.aliasField("parentdomainid", RegionDomain.class, "parentUuid"); xstream.aliasField("networkdomain", DomainVO.class, "networkDomain"); - ObjectInputStream in = xstream.createObjectInputStream(is); - return (RegionDomain)in.readObject(); + try(ObjectInputStream in = xstream.createObjectInputStream(is);) { + return (RegionDomain) in.readObject(); + }catch (IOException e) { + s_logger.error(e.getMessage()); + return null; + } } else { return null; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java ---------------------------------------------------------------------- diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index c0b4da0..230ef84 100755 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -692,8 +692,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S if (!destFile.createNewFile()) { s_logger.warn("Reusing existing file " + destFile.getPath()); } - FileOutputStream outputStream = new FileOutputStream(destFile); - entity.writeTo(outputStream); + try(FileOutputStream outputStream = new FileOutputStream(destFile);) { + entity.writeTo(outputStream); + }catch (IOException e) { + s_logger.debug("downloadFromUrlToNfs:Exception:"+e.getMessage(),e); + } return new File(destFile.getAbsolutePath()); } catch (IOException e) { s_logger.debug("Faild to get url:" + url + ", due to " + e.toString()); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java ---------------------------------------------------------------------- diff --git a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java index e0fcbae..52bde6a 100644 --- a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java +++ b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/LocalNfsSecondaryStorageResourceTest.java @@ -131,8 +131,8 @@ public class LocalNfsSecondaryStorageResourceTest extends TestCase { s_logger.info("agent.properties found at " + file.getAbsolutePath()); - try { - properties.load(new FileInputStream(file)); + try(FileInputStream fs = new FileInputStream(file);) { + properties.load(fs); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/350ac4c4/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java ---------------------------------------------------------------------- diff --git a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java index e0ae4c5..13ddb35 100644 --- a/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java +++ b/services/secondary-storage/server/test/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResourceTest.java @@ -94,11 +94,9 @@ public class NfsSecondaryStorageResourceTest extends TestCase { if (file == null) { throw new ConfigurationException("Unable to find agent.properties."); } - s_logger.info("agent.properties found at " + file.getAbsolutePath()); - - try { - properties.load(new FileInputStream(file)); + try(FileInputStream fs = new FileInputStream(file);) { + properties.load(fs); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) {