Updated Branches:
  refs/heads/master d6298302a -> 7a6751aa7

Make sure that if the file does not exist an Exception is thrown and that once 
it exists it is also closed after the properties are loaded.

Signed-off-by: Hugo Trippaers <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7a6751aa
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7a6751aa
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7a6751aa

Branch: refs/heads/master
Commit: 7a6751aa770eaf8065864f497bff401012f553ae
Parents: d629830
Author: wilderrodrigues <[email protected]>
Authored: Thu Nov 14 08:37:02 2013 +0100
Committer: Hugo Trippaers <[email protected]>
Committed: Tue Nov 26 08:22:29 2013 +0100

----------------------------------------------------------------------
 .../management/ManagementNetworkGuru.java       | 31 ++++++++++++++++----
 1 file changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7a6751aa/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java
----------------------------------------------------------------------
diff --git 
a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java
 
b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java
index e86e98a..d3d9366 100644
--- 
a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java
+++ 
b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ManagementNetworkGuru.java
@@ -19,6 +19,8 @@ package org.apache.cloudstack.network.contrail.management;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.util.Map;
 import java.util.Properties;
 
@@ -60,12 +62,29 @@ public class ManagementNetworkGuru extends ContrailGuru {
     @Override
     public boolean configure(String name, Map<String, Object> params) throws 
ConfigurationException {
         File configFile = PropertiesUtil.findConfigFile(configuration);
+        FileInputStream inputFile = null;
+
+        try {
+            if (null == configFile) {
+                throw new FileNotFoundException("Configuration file was not 
found!");
+            }
+            inputFile = new FileInputStream(configFile);
+        } catch (FileNotFoundException e) {
+            s_logger.error(e.getMessage());
+            throw new ConfigurationException(e.getMessage());
+        }
+
         final Properties configProps = new Properties();
         try {
-            configProps.load(new FileInputStream(configFile));
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            throw new ConfigurationException(ex.getMessage());
+            configProps.load(inputFile);
+        } catch (IOException e) {
+            s_logger.error(e.getMessage());
+            throw new ConfigurationException(e.getMessage());
+        } finally {
+            try {
+                inputFile.close();
+            } catch (IOException e) {
+            }
         }
         _mgmt_cidr = configProps.getProperty("management.cidr");
         _mgmt_gateway = configProps.getProperty("management.gateway");
@@ -100,8 +119,8 @@ public class ManagementNetworkGuru extends ContrailGuru {
             return null;
         }
         NetworkVO network =
-            new NetworkVO(offering.getTrafficType(), Mode.Dhcp, 
BroadcastDomainType.Lswitch, offering.getId(), Network.State.Allocated, 
plan.getDataCenterId(),
-                plan.getPhysicalNetworkId());
+                new NetworkVO(offering.getTrafficType(), Mode.Dhcp, 
BroadcastDomainType.Lswitch, offering.getId(), Network.State.Allocated, 
plan.getDataCenterId(),
+                        plan.getPhysicalNetworkId());
         if (_mgmt_cidr != null) {
             network.setCidr(_mgmt_cidr);
             network.setGateway(_mgmt_gateway);

Reply via email to