You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/07 04:33:40 UTC

git commit: load external settings and supporting system properties AIRAVATA-1121

Repository: airavata
Updated Branches:
  refs/heads/master ea57ef58e -> de61d5116


load external settings and supporting system properties AIRAVATA-1121


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

Branch: refs/heads/master
Commit: de61d51162c182db20d54a39eab8bad49b2fad4c
Parents: ea57ef5
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Sun Apr 6 19:29:55 2014 -0700
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Sun Apr 6 19:33:21 2014 -0700

----------------------------------------------------------------------
 .../common/utils/ApplicationSettings.java       | 38 +++++++++++++++++--
 .../client/OrchestratorClientFactoryTest.java   |  1 +
 .../registry/api/util/RegistrySettings.java     | 40 ++++++++++++++++----
 3 files changed, 67 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/de61d511/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
index 39a0455..c27c33b 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
@@ -43,6 +43,9 @@ import org.slf4j.LoggerFactory;
 public class ApplicationSettings {
     public static final String SERVER_PROPERTIES="airavata-server.properties";
     public static final String CLIENT_PROPERTIES="airavata-client.properties";
+    
+	public static String ADDITIONAL_SETTINGS_FILES = "external.settings";
+
 	protected Properties properties = new Properties();
     private Exception propertyLoadException;
 
@@ -69,6 +72,10 @@ public class ApplicationSettings {
 		URL url = getPropertyFileURL();
         try {
             properties.load(url.openStream());
+            URL[] externalSettingsFileURLs = getExternalSettingsFileURLs();
+            for (URL externalSettings : externalSettingsFileURLs) {
+				mergeSettingsImpl(externalSettings.openStream());
+			}
         } catch (Exception e) {
         	propertyLoadException=e;
         }
@@ -84,6 +91,22 @@ public class ApplicationSettings {
 		return url;
 	}
 	
+	protected URL[] getExternalSettingsFileURLs(){
+		try {
+			List<URL> externalSettingsFileURLs=new ArrayList<URL>();
+			String externalSettingsFileNames = getSettingImpl(ADDITIONAL_SETTINGS_FILES);
+			String[] externalSettingFiles = externalSettingsFileNames.split(",");
+			for (String externalSettingFile : externalSettingFiles) {
+				URL externalSettingFileURL = ApplicationSettings.class.getClassLoader().getResource(externalSettingFile);
+				if (externalSettingFileURL!=null){
+					externalSettingsFileURLs.add(externalSettingFileURL);
+				}
+			}
+			return externalSettingsFileURLs.toArray(new URL[]{});
+		} catch (ApplicationSettingsException e) {
+			return new URL[]{};
+		}
+	}
 	protected static ApplicationSettings getInstance(){
 		if (INSTANCE==null){
 			INSTANCE=new ApplicationSettings();
@@ -161,11 +184,18 @@ public class ApplicationSettings {
     }
     
     public String getSettingImpl(String key) throws ApplicationSettingsException{
-    	validateSuccessfulPropertyFileLoad();
-    	if (properties.containsKey(key)){
-    		return deriveAbsoluteValueImpl(properties.getProperty(key));
+    	String rawValue=null;
+    	if (System.getProperties().containsKey(key)){
+    		rawValue=System.getProperties().getProperty(key);
+    	}else{
+    		validateSuccessfulPropertyFileLoad();
+	    	if (properties.containsKey(key)){
+	    		rawValue=properties.getProperty(key);
+	    	}else{
+	    		throw new UnspecifiedApplicationSettingsException(key);		
+	    	}
     	}
-    	throw new UnspecifiedApplicationSettingsException(key);
+    	return deriveAbsoluteValueImpl(rawValue);
     }
     
     public String getSettingImpl(String key, String defaultValue){

http://git-wip-us.apache.org/repos/asf/airavata/blob/de61d511/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
index aafc200..f625489 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/OrchestratorClientFactoryTest.java
@@ -44,6 +44,7 @@ public class OrchestratorClientFactoryTest {
     OrchestratorServer service;
     @Test
     public void setUp() {
+    	AiravataUtils.setExecutionAsServer();
         initialize = new Initialize("registry-derby.sql");
         initialize.initializeDB();
         try {

http://git-wip-us.apache.org/repos/asf/airavata/blob/de61d511/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistrySettings.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistrySettings.java b/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistrySettings.java
index 65c7978..3c2b9a3 100644
--- a/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistrySettings.java
+++ b/modules/registry/registry-api/src/main/java/org/apache/airavata/registry/api/util/RegistrySettings.java
@@ -22,10 +22,15 @@
 package org.apache.airavata.registry.api.util;
 
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Pattern;
 
 import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.common.utils.ApplicationSettings;
+import org.apache.airavata.common.utils.StringUtil;
 import org.apache.airavata.registry.api.exception.RegistrySettingsException;
 import org.apache.airavata.registry.api.exception.RegistrySettingsLoadException;
 
@@ -73,20 +78,39 @@ public class RegistrySettings {
     }
     
     public static String getSetting(String key) throws RegistrySettingsException{
-    	validateSuccessfulPropertyFileLoad();
-    	if (properties.containsKey(key)){
-    		return properties.getProperty(key);
+    	String rawValue=null;
+    	if (System.getProperties().containsKey(key)){
+    		rawValue=System.getProperties().getProperty(key);
+    	}else{
+    		validateSuccessfulPropertyFileLoad();
+	    	if (properties.containsKey(key)){
+	    		rawValue=properties.getProperty(key);
+	    	}else{
+	    		return null;		
+	    	}
     	}
-        return null;
+    	return deriveAbsoluteValueImpl(rawValue);
 //    	throw new UnspecifiedRegistrySettingsException(key);
     }
     
+	private static String deriveAbsoluteValueImpl(String property){
+		if (property!=null){
+			Map<Integer, String> containedParameters = StringUtil.getContainedParameters(property);
+			List<String> parametersAlreadyProcessed=new ArrayList<String>();
+			for (String parameter : containedParameters.values()) {
+				if (!parametersAlreadyProcessed.contains(parameter)) {
+					String parameterName = parameter.substring(2,parameter.length() - 1);
+					String parameterValue = getSetting(parameterName,parameter);
+					property = property.replaceAll(Pattern.quote(parameter), parameterValue);
+					parametersAlreadyProcessed.add(parameter);
+				}
+			}
+		}
+		return property;
+	}
     public static String getSetting(String key, String defaultValue){
     	try {
-			validateSuccessfulPropertyFileLoad();
-			if (properties.containsKey(key)){
-				return properties.getProperty(key);
-			}
+    		return getSetting(key);
 		} catch (RegistrySettingsException e) {
 			//we'll ignore this error since a default value is provided
 		}