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 <htrippaers@schubergphilis.com>
This commit is contained in:
wilderrodrigues 2013-11-14 08:37:02 +01:00 committed by Hugo Trippaers
parent d6298302a1
commit 7a6751aa77
1 changed files with 25 additions and 6 deletions

View File

@ -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);