From 0138d06cf2c66a5df3c55951a6f01778035b781d Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 5 May 2011 11:42:07 -0400 Subject: [PATCH] load user specified component specification from enviroment.properties: e.g. cloud-stack-components-specification=components-cloudzone.xml --- .../utils/component/ComponentLocator.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/utils/src/com/cloud/utils/component/ComponentLocator.java b/utils/src/com/cloud/utils/component/ComponentLocator.java index b34e8e107b9..a709a02fa5f 100755 --- a/utils/src/com/cloud/utils/component/ComponentLocator.java +++ b/utils/src/com/cloud/utils/component/ComponentLocator.java @@ -18,6 +18,7 @@ package com.cloud.utils.component; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Constructor; @@ -32,6 +33,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -733,15 +735,26 @@ public class ComponentLocator implements ComponentLocatorMBean { } public static ComponentLocator getLocator(String server) { - Map env = System.getenv(); - String configFile = env.get("cloud-stack-components-specification"); + String configFile = null; + try { + final File propsFile = PropertiesUtil.findConfigFile("environment.properties"); + if (propsFile == null) { + s_logger.debug("environment.properties could not be opened"); + } else { + final FileInputStream finputstream = new FileInputStream(propsFile); + final Properties props = new Properties(); + props.load(finputstream); + finputstream.close(); + configFile = props.getProperty("cloud-stack-components-specification"); + } + } catch (IOException e) { + s_logger.debug("environment.properties could not be loaded:" + e.toString()); + } + if (configFile == null || PropertiesUtil.findConfigFile(configFile) == null) { - configFile = env.get("cloud_stack_components_specification"); - if (configFile == null || PropertiesUtil.findConfigFile(configFile) == null) { - configFile = "components-premium.xml"; - if (PropertiesUtil.findConfigFile(configFile) == null){ - configFile = "components.xml"; - } + configFile = "components-premium.xml"; + if (PropertiesUtil.findConfigFile(configFile) == null){ + configFile = "components.xml"; } } return getLocatorInternal(server, true, configFile, "log4j-cloud");