Merge pull request #116 from IMS94/master

[OODT-1031] Updated filemgr, workflow manager and resource manager starters to use XML RPC by default
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/FileManagerServer.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/FileManagerServer.java
index 0d2d0bf..eae3281 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/FileManagerServer.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/system/FileManagerServer.java
@@ -27,7 +27,11 @@
  *
  */
 public interface FileManagerServer {
-
+    
+    String FILEMGR_PROPERTIES_FILE_SYSTEM_PROPERTY = "org.apache.oodt.cas.filemgr.properties";
+    String FILEMGR_SERVER_SYSTEM_PROPERTY = "filemgr.server";
+    String FILEMGR_CLIENT_SYSTEM_PROPERTY = "filemgr.client";
+    
     /**
      *
      * <p>Preparing and starting up the rpc server.</p>
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/RpcCommunicationFactory.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/RpcCommunicationFactory.java
index 0ea46b2..0ed2bb4 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/RpcCommunicationFactory.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/util/RpcCommunicationFactory.java
@@ -22,6 +22,8 @@
 import org.apache.oodt.cas.filemgr.system.FileManagerServer;
 import org.apache.oodt.cas.filemgr.system.rpc.FileManagerClientFactory;
 import org.apache.oodt.cas.filemgr.system.rpc.FileManagerServerFactory;
+import org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerClientFactory;
+import org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerServerFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -42,11 +44,11 @@
 
     private static Logger LOG = Logger.getLogger(RpcCommunicationFactory.class
             .getName());
-
-    private static String getClientFactoryName(){
-        return System.getProperty("filemgr.client",
-                "org.apache.oodt.cas.filemgr.system.rpc.AvroFileManagerClientFactory");
-   }
+    
+    private static String getClientFactoryName() {
+        return System.getProperty(FileManagerServer.FILEMGR_CLIENT_SYSTEM_PROPERTY,
+                XmlRpcFileManagerClientFactory.class.getName());
+    }
 
     /**
      * Set properties from filemgr.properties file
@@ -54,8 +56,8 @@
      */
     private static void setPror(){
         // set up the configuration, if there is any
-        if (System.getProperty("org.apache.oodt.cas.filemgr.properties") != null) {
-            String configFile = System.getProperty("org.apache.oodt.cas.filemgr.properties");
+        if (System.getProperty(FileManagerServer.FILEMGR_PROPERTIES_FILE_SYSTEM_PROPERTY) != null) {
+            String configFile = System.getProperty(FileManagerServer.FILEMGR_PROPERTIES_FILE_SYSTEM_PROPERTY);
 
             LOG.log(Level.INFO, "Loading File Manager Configuration Properties from: [" + configFile + "]");
 
@@ -126,8 +128,8 @@
     public static FileManagerServer createServer(int port) throws IOException {
         setPror();
 
-        String serverFactory = System.getProperty("filemgr.server",
-                "org.apache.oodt.cas.filemgr.system.rpc.AvroFileManagerServerFactory");
+        String serverFactory = System.getProperty(FileManagerServer.FILEMGR_SERVER_SYSTEM_PROPERTY,
+                XmlRpcFileManagerServerFactory.class.getName());
 
         LOG.log(Level.INFO, "Init. server's factory class: " + serverFactory);
 
diff --git a/filemgr/src/main/resources/filemgr.properties b/filemgr/src/main/resources/filemgr.properties
index 2297555..65c2fca 100644
--- a/filemgr/src/main/resources/filemgr.properties
+++ b/filemgr/src/main/resources/filemgr.properties
@@ -18,8 +18,8 @@
 # rpc configuration, uncomment the avro implementations to use AvroRPC
 #filemgr.server=org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerServerFactory
 #filemgr.client=org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerClientFactory
-filemgr.server=org.apache.oodt.cas.filemgr.system.rpc.AvroFileManagerServerFactory
-filemgr.client=org.apache.oodt.cas.filemgr.system.rpc.AvroFileManagerClientFactory
+filemgr.server=org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerServerFactory
+filemgr.client=org.apache.oodt.cas.filemgr.system.rpc.XmlRpcFileManagerClientFactory
 
 # repository factory
 filemgr.repository.factory=org.apache.oodt.cas.filemgr.repository.XMLRepositoryManagerFactory
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/AvroRpcResourceManager.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/AvroRpcResourceManager.java
index fc3e2ae..73dabde 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/system/AvroRpcResourceManager.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/AvroRpcResourceManager.java
@@ -72,8 +72,8 @@
 
         List<String> propertiesFiles = new ArrayList<>();
         // set up the configuration, if there is any
-        if (System.getProperty("org.apache.oodt.cas.resource.properties") != null) {
-            propertiesFiles.add(System.getProperty("org.apache.oodt.cas.resource.properties"));
+        if (System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY) != null) {
+            propertiesFiles.add(System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY));
         }
 
         configurationManager = ConfigurationManagerFactory
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManager.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManager.java
index c09b299..2210de1 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManager.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/ResourceManager.java
@@ -19,6 +19,11 @@
 
 public interface ResourceManager {
 
+    String RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY = "org.apache.oodt.cas.resource.properties";
+    String RESMGR_SYSTEM_PROPERTY = "resmgr.manager";
+    String RESMGR_CLIENT_SYSTEM_PROPERTY = "resmgr.manager.client";
+    
+    
     void startUp() throws Exception;
 
     boolean isAlive();
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
index 9ee48c8..6c25831 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/XmlRpcResourceManager.java
@@ -77,8 +77,8 @@
         this.port = port;
         List<String> propertiesFiles = new ArrayList<>();
         // set up the configuration, if there is any
-        if (System.getProperty("org.apache.oodt.cas.resource.properties") != null) {
-            propertiesFiles.add(System.getProperty("org.apache.oodt.cas.resource.properties"));
+        if (System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY) != null) {
+            propertiesFiles.add(System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY));
         }
 
         configurationManager = ConfigurationManagerFactory.getConfigurationManager(Component.RESOURCE_MANAGER, propertiesFiles);
diff --git a/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java b/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
index 24f56b9..dd632b6 100644
--- a/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
+++ b/resource/src/main/java/org/apache/oodt/cas/resource/system/rpc/ResourceManagerFactory.java
@@ -19,27 +19,30 @@
 
 import org.apache.oodt.cas.resource.system.ResourceManager;
 import org.apache.oodt.cas.resource.system.ResourceManagerClient;
+import org.apache.oodt.cas.resource.system.XmlRpcResourceManager;
+import org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.net.URL;
 
 public class ResourceManagerFactory {
 
     private static final Logger logger = LoggerFactory.getLogger(ResourceManagerFactory.class);
-
+    
     private static void loadProperties() {
         // set up the configuration, if there is any
-        if (System.getProperty("org.apache.oodt.cas.resource.properties") != null) {
-            String configFile = System.getProperty("org.apache.oodt.cas.resource.properties");
+        if (System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY) != null) {
+            String configFile = System.getProperty(ResourceManager.RESMGR_PROPERTIES_FILE_SYSTEM_PROPERTY);
 
-            logger.info("Loading File Manager Configuration Properties from: [{}]", configFile);
+            logger.info("Loading resource manager configuration properties from: [{}]", configFile);
             try {
                 System.getProperties().load(new FileInputStream(new File(configFile)));
-            } catch (Exception e) {
+            } catch (IOException e) {
                 logger.error("Error loading configuration properties from: [{}]", configFile);
             }
         }
@@ -47,8 +50,8 @@
 
     public static ResourceManager getResourceManager(int port) throws Exception {
         loadProperties();
-        String resourceManagerClass = System.getProperty("resmgr.manager",
-                "org.apache.oodt.cas.resource.system.AvroRpcResourceManager");
+        String resourceManagerClass = System.getProperty(ResourceManager.RESMGR_SYSTEM_PROPERTY,
+                XmlRpcResourceManager.class.getName());
 
         logger.info("Creating resource manager {} at port: {}", resourceManagerClass, port);
 
@@ -66,8 +69,8 @@
 
     public static ResourceManagerClient getResourceManagerClient(URL url) throws Exception {
         loadProperties();
-        String resMgrClientClass = System.getProperty("resmgr.manager.client",
-                "org.apache.oodt.cas.resource.system.AvroRpcResourceManagerClient");
+        String resMgrClientClass = System.getProperty(ResourceManager.RESMGR_CLIENT_SYSTEM_PROPERTY,
+                XmlRpcResourceManagerClient.class.getName());
 
         logger.info("Creating resource manager client {}", resMgrClientClass);
 
diff --git a/resource/src/main/resources/resource.properties b/resource/src/main/resources/resource.properties
index bf6a420..071a13f 100644
--- a/resource/src/main/resources/resource.properties
+++ b/resource/src/main/resources/resource.properties
@@ -17,8 +17,8 @@
 # Properties required to configure the Resource Manager
 
 # Client and server classes to be used as resource managers
-resmgr.manager=org.apache.oodt.cas.resource.system.AvroRpcResourceManager
-resmgr.manager.client=org.apache.oodt.cas.resource.system.AvroRpcResourceManagerClient
+resmgr.manager=org.apache.oodt.cas.resource.system.XmlRpcResourceManager
+resmgr.manager.client=org.apache.oodt.cas.resource.system.XmlRpcResourceManagerClient
 
 # resource spark master
 resource.runner.spark.host = mesos://<ip>:5050
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/AvroRpcWorkflowManager.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/AvroRpcWorkflowManager.java
index 96a46e6..a3ece7f 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/AvroRpcWorkflowManager.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/AvroRpcWorkflowManager.java
@@ -83,7 +83,13 @@
                 port, System.getProperty("user.name", "unknown"));
 
         Preconditions.checkArgument(port > 0, "Must specify a port greater than 0");
-
+    
+        try {
+            loadProperties();
+        } catch (IOException e) {
+            logger.error("Error occurred when loading properties", e);
+        }
+    
         logger.debug("Getting workflow engine");
         engine = getWorkflowEngineFromProperty();
         if(engine == null){
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/WorkflowManager.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/WorkflowManager.java
index eda3027..ddceb40 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/WorkflowManager.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/WorkflowManager.java
@@ -8,7 +8,12 @@
 public interface WorkflowManager {
 
     String PROPERTIES_FILE_PROPERTY = "org.apache.oodt.cas.workflow.properties";
+    String DEFAULT_PROPERTIES_FILE = "workflow.properties";
+    
     String WORKFLOW_ENGINE_FACTORY_PROPERTY = "workflow.engine.factory";
+    String WORKFLOW_SERVER_FACTORY_PROPERTY = "workflow.server.factory";
+    String WORKFLOW_CLIENT_FACTORY_PROPERTY = "workflow.client.factory";
+    
     String ENGINE_RUNNER_FACTORY_PROPERTY = "workflow.engine.runner.factory";
     String WORKFLOW_REPOSITORY_FACTORY_PROPERTY = "workflow.repo.factory";
     int DEFAULT_WEB_SERVER_PORT = 9001;
diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/rpc/RpcCommunicationFactory.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/rpc/RpcCommunicationFactory.java
index 244fe8f..dfc147b 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/rpc/RpcCommunicationFactory.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/rpc/RpcCommunicationFactory.java
@@ -37,34 +37,20 @@
 
     private static final Logger logger = LoggerFactory.getLogger(RpcCommunicationFactory.class);
 
-    private static String getRpcServerClassName() {
-        InputStream prpFileStream = RpcCommunicationFactory.class.getResourceAsStream("/workflow.properties");
-        Properties properties = new Properties();
-        try {
-            properties.load(prpFileStream);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return properties.getProperty("workflow.server.factory",
-                "org.apache.oodt.cas.workflow.system.rpc.AvroRpcWorkflowManagerFactory");
+    private static String getRpcServerFactoryClassName() {
+        return loadProperties().getProperty(WorkflowManager.WORKFLOW_SERVER_FACTORY_PROPERTY,
+                XmlRpcWorkflowManagerFactory.class.getName());
     }
-
-    private static String getRpcClientClassName() {
-        InputStream prpFileStream = RpcCommunicationFactory.class.getResourceAsStream("/workflow.properties");
-        Properties properties = new Properties();
-        try {
-            properties.load(prpFileStream);
-        } catch (IOException e) {
-            logger.error("Unable to load properties", e);
-        }
-        return properties.getProperty("workflow.client.factory",
-                "org.apache.oodt.cas.workflow.system.rpc.AvroRpcWorkflowManagerFactory");
+    
+    private static String getRpcClientFactoryClassName() {
+        return loadProperties().getProperty(WorkflowManager.WORKFLOW_CLIENT_FACTORY_PROPERTY,
+                XmlRpcWorkflowManagerFactory.class.getName());
     }
 
     public static WorkflowManager createServer(int port) {
         try {
             WorkflowManagerFactory workflowManagerFactory =
-                    (WorkflowManagerFactory) Class.forName(getRpcServerClassName()).newInstance();
+                    (WorkflowManagerFactory) Class.forName(getRpcServerFactoryClassName()).newInstance();
             workflowManagerFactory.setPort(port);
             logger.debug("Using workflow manager server factory : {}", workflowManagerFactory.getClass());
             return workflowManagerFactory.createServer();
@@ -77,7 +63,7 @@
     public static WorkflowManagerClient createClient(URL url) {
         try {
             WorkflowManagerFactory workflowManagerFactory =
-                    (WorkflowManagerFactory) Class.forName(getRpcClientClassName()).newInstance();
+                    (WorkflowManagerFactory) Class.forName(getRpcClientFactoryClassName()).newInstance();
             workflowManagerFactory.setUrl(url);
             logger.debug("Using workflow manager client factory : {}", workflowManagerFactory.getClass());
             return workflowManagerFactory.createClient();
@@ -86,4 +72,27 @@
             throw new IllegalStateException("Unable to create client", e);
         }
     }
+    
+    /**
+     * Loads workflow manager properties
+     *
+     * @return
+     */
+    private static Properties loadProperties() {
+        String propertiesFile = System.getProperty(WorkflowManager.PROPERTIES_FILE_PROPERTY, WorkflowManager.DEFAULT_PROPERTIES_FILE);
+        InputStream prpFileStream = RpcCommunicationFactory.class.getResourceAsStream(propertiesFile);
+        Properties properties = new Properties();
+    
+        if (prpFileStream != null) {
+            try {
+                properties.load(prpFileStream);
+            } catch (IOException e) {
+                logger.error("An error occurred when loading properties file: {}", propertiesFile, e);
+            }
+        } else {
+            logger.warn("Properties file: '{}' could not be found. Skipped loading properties", propertiesFile);
+        }
+        
+        return properties;
+    }
 }
diff --git a/workflow/src/main/resources/workflow.properties b/workflow/src/main/resources/workflow.properties
index 328d991..2b92ae4 100644
--- a/workflow/src/main/resources/workflow.properties
+++ b/workflow/src/main/resources/workflow.properties
@@ -16,8 +16,8 @@
 # Properties required to configure the Workflow Manager
 
 #Rpc workflow communication class
-workflow.server.factory = org.apache.oodt.cas.workflow.system.rpc.AvroRpcWorkflowManagerFactory
-workflow.client.factory = org.apache.oodt.cas.workflow.system.rpc.AvroRpcWorkflowManagerFactory
+workflow.server.factory = org.apache.oodt.cas.workflow.system.rpc.XmlRpcWorkflowManagerFactory
+workflow.client.factory = org.apache.oodt.cas.workflow.system.rpc.XmlRpcWorkflowManagerFactory
 
 # workflow repository factory
 workflow.repo.factory = org.apache.oodt.cas.workflow.repository.XMLWorkflowRepositoryFactory