This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/develop by this push:
     new 4c80791  AIRAVATA-2664 Thrift client not thread safe; new one for each 
request
4c80791 is described below

commit 4c807911877542c08a5774a9bccb9da51f8162e8
Author: Marcus Christie <[email protected]>
AuthorDate: Thu Feb 1 12:19:27 2018 -0500

    AIRAVATA-2664 Thrift client not thread safe; new one for each request
---
 .../apache/airavata/common/utils/ThriftUtils.java  |  14 +-
 .../airavata/gfac/client/util/Initialize.java      | 100 ----------
 .../core/context/OrchestratorContext.java          |  10 -
 .../orchestrator/core/utils/OrchestratorUtils.java | 182 ++++++++++++-------
 .../cpi/impl/AbstractOrchestrator.java             |  14 --
 .../cpi/impl/SimpleOrchestratorImpl.java           | 201 +++++++++++++--------
 .../orchestrator/core/util/Initialize.java         |  24 ---
 .../server/OrchestratorServerHandler.java          |  63 ++++++-
 .../orchestrator/client/util/Initialize.java       | 131 +-------------
 9 files changed, 303 insertions(+), 436 deletions(-)

diff --git 
a/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftUtils.java
 
b/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftUtils.java
index 9492031..c4a803b 100644
--- 
a/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftUtils.java
+++ 
b/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftUtils.java
@@ -20,10 +20,7 @@
 package org.apache.airavata.common.utils;
 
 import org.apache.airavata.model.task.*;
-import org.apache.thrift.TBase;
-import org.apache.thrift.TDeserializer;
-import org.apache.thrift.TException;
-import org.apache.thrift.TSerializer;
+import org.apache.thrift.*;
 
 public class ThriftUtils {
        public static byte[] serializeThriftObject(TBase object) throws 
TException {
@@ -58,4 +55,13 @@ public class ThriftUtils {
                                return null;
                }
        }
+
+       public static void close(TServiceClient client) {
+               if (client.getOutputProtocol().getTransport().isOpen()) {
+                       client.getOutputProtocol().getTransport().close();
+               }
+               if (client.getInputProtocol().getTransport().isOpen()) {
+                       client.getInputProtocol().getTransport().close();
+               }
+       }
 }
diff --git 
a/modules/gfac/gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
 
b/modules/gfac/gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
index 765e652..64ef144 100644
--- 
a/modules/gfac/gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
+++ 
b/modules/gfac/gfac-service/src/test/java/org/apache/airavata/gfac/client/util/Initialize.java
@@ -19,8 +19,6 @@
  */
 package org.apache.airavata.gfac.client.util;
 
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,7 +27,6 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.InetAddress;
 import java.sql.*;
 import java.util.StringTokenizer;
 
@@ -85,85 +82,6 @@ public class Initialize {
         return false;
     }
 
-    public void initializeDB() throws SQLException{
-        String jdbcUrl = null;
-        String jdbcUser = null;
-        String jdbcPassword = null;
-        try{
-            jdbcUrl = ServerSettings.getSetting("registry.jdbc.url");
-            jdbcUser = ServerSettings.getSetting("registry.jdbc.user");
-            jdbcPassword = ServerSettings.getSetting("registry.jdbc.password");
-            jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + 
jdbcPassword;
-        } catch (ApplicationSettingsException e) {
-            logger.error("Unable to read properties", e);
-        }
-        startDerbyInServerMode();
-        if(!isServerStarted(server, 20)){
-           throw new RuntimeException("Derby server cound not started within 
five seconds...");
-        }
-
-        Connection conn = null;
-        try {
-            Class.forName(Utils.getJDBCDriver()).newInstance();
-            conn = DriverManager.getConnection(jdbcUrl, jdbcUser, 
jdbcPassword);
-            if (!isDatabaseStructureCreated(PERSISTANT_DATA, conn)) {
-                executeSQLScript(conn);
-                logger.info("New Database created for Registry");
-            } else {
-                logger.debug("Database already created for Registry!");
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw new RuntimeException("Database failure", e);
-        } finally {
-            try {
-                if (conn != null){
-                    if (!conn.getAutoCommit()) {
-                        conn.commit();
-                    }
-                    conn.close();
-                }
-            } catch (SQLException e) {
-                logger.error(e.getMessage(), e);
-            }
-        }
-
-        //Commenting this as its not used anywhere and creates dependency on 
registry-cpi and registry-core
-
-//        try{
-//            GatewayResource gatewayResource = new GatewayResource();
-//            
gatewayResource.setGatewayId(ServerSettings.getSetting("default.registry.gateway"));
-//            
gatewayResource.setGatewayName(ServerSettings.getSetting("default.registry.gateway"));
-//            gatewayResource.setDomain("test-domain");
-//            gatewayResource.setEmailAddress("test-email");
-//            gatewayResource.save();
-//
-//            UserResource userResource = new UserResource();
-//            
userResource.setUserName(ServerSettings.getSetting("default.registry.user"));
-//            
userResource.setPassword(ServerSettings.getSetting("default.registry.password"));
-//            userResource.save();
-//
-//            WorkerResource workerResource = (WorkerResource) 
gatewayResource.create(ResourceType.GATEWAY_WORKER);
-//            workerResource.setUser(userResource.getUserName());
-//            workerResource.save();
-//
-//            ProjectResource projectResource = 
(ProjectResource)workerResource.create(ResourceType.PROJECT);
-//            projectResource.setGatewayId(gatewayResource.getGatewayId());
-//            projectResource.setId("default");
-//            projectResource.setName("default");
-//            projectResource.setWorker(workerResource);
-//            projectResource.save();
-//
-//
-//        } catch (ApplicationSettingsException e) {
-//            logger.error("Unable to read properties", e);
-//            throw new SQLException(e.getMessage(), e);
-//        } catch (RegistryException e) {
-//            logger.error("Unable to save data to registry", e);
-//            throw new SQLException(e.getMessage(), e);
-//        }
-    }
-
     public static boolean isDatabaseStructureCreated(String tableName, 
Connection conn) {
         try {
             System.out.println("Running a query to test the database tables 
existence.");
@@ -297,24 +215,6 @@ public class Initialize {
         }
     }
 
-    private void startDerbyInServerMode() {
-        try {
-            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
-            server = new 
NetworkServerControl(InetAddress.getByName(Utils.getHost()),
-                    20000,
-                    Utils.getJDBCUser(), Utils.getJDBCPassword());
-            java.io.PrintWriter consoleWriter = new 
java.io.PrintWriter(System.out, true);
-            server.start(consoleWriter);
-        } catch (IOException e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        } catch (Exception e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        }
-
-    }
-
     public void stopDerbyServer() throws SQLException{
         try {
             server.shutdown();
diff --git 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/context/OrchestratorContext.java
 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/context/OrchestratorContext.java
index 8a62c3d..f61daea 100644
--- 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/context/OrchestratorContext.java
+++ 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/context/OrchestratorContext.java
@@ -21,14 +21,12 @@ package org.apache.airavata.orchestrator.core.context;
 
 import org.apache.airavata.messaging.core.Publisher;
 import org.apache.airavata.orchestrator.core.OrchestratorConfiguration;
-import org.apache.airavata.registry.api.RegistryService;
 
 /**
  * This is the context object used in orchestrator which
  */
 public class OrchestratorContext {
     private OrchestratorConfiguration orchestratorConfiguration;
-    private RegistryService.Client registryClient;
     private Publisher publisher;
     private String gatewayId;
 
@@ -48,14 +46,6 @@ public class OrchestratorContext {
         this.orchestratorConfiguration = orchestratorConfiguration;
     }
 
-    public RegistryService.Client getRegistryClient() {
-        return registryClient;
-    }
-
-    public void setRegistryClient(RegistryService.Client registryClient) {
-        this.registryClient = registryClient;
-    }
-
     public String getGatewayId() {
         return gatewayId;
     }
diff --git 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
index 54f1c33..2ddad85 100644
--- 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
+++ 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/utils/OrchestratorUtils.java
@@ -19,16 +19,12 @@
  */
 package org.apache.airavata.orchestrator.core.utils;
 
-import java.io.IOException;
-import java.util.*;
-
 import org.apache.airavata.common.exception.AiravataException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.common.utils.ThriftUtils;
 import 
org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription;
 import org.apache.airavata.model.appcatalog.computeresource.*;
-import 
org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface;
-import 
org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission;
 import 
org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
 import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
 import 
org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference;
@@ -39,13 +35,17 @@ import 
org.apache.airavata.model.data.movement.SecurityProtocol;
 import org.apache.airavata.model.process.ProcessModel;
 import 
org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel;
 import org.apache.airavata.orchestrator.core.OrchestratorConfiguration;
-import org.apache.airavata.orchestrator.core.context.OrchestratorContext;
 import org.apache.airavata.orchestrator.core.exception.OrchestratorException;
 import org.apache.airavata.registry.api.RegistryService;
+import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
+import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.util.*;
+
 /**
  * This contains orchestrator specific utilities
  */
@@ -73,80 +73,88 @@ public class OrchestratorUtils {
         return orchestratorConfiguration;
     }
 
-    public static JobSubmissionProtocol 
getPreferredJobSubmissionProtocol(OrchestratorContext context,
-                                                                          
ProcessModel model,
+    public static JobSubmissionProtocol 
getPreferredJobSubmissionProtocol(ProcessModel model,
                                                                           
String gatewayId) throws TException, OrchestratorException {
         try {
             String resourceHostId = model.getComputeResourceId();
-            return getComputeResourcePreference(context, gatewayId, 
resourceHostId).getPreferredJobSubmissionProtocol();
+            return getComputeResourcePreference(gatewayId, 
resourceHostId).getPreferredJobSubmissionProtocol();
         } catch (Exception e) {
             logger.error("Error occurred while retrieving job submission", e);
             throw new OrchestratorException("Error occurred while retrieving 
job submission", e);
         }
     }
 
-    public static ComputeResourcePreference 
getComputeResourcePreference(OrchestratorContext context,
-                                                                         
String gatewayId,
+    public static ComputeResourcePreference 
getComputeResourcePreference(String gatewayId,
                                                                          
String resourceHostId)
             throws TException, ApplicationSettingsException {
-        RegistryService.Client registryClient = context.getRegistryClient();
-        return registryClient.getGatewayComputeResourcePreference(gatewayId
-                , resourceHostId);
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        try {
+            return registryClient.getGatewayComputeResourcePreference(gatewayId
+                    , resourceHostId);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
+        }
     }
 
-    public static String getApplicationInterfaceName(OrchestratorContext 
context, ProcessModel model)
+    public static String getApplicationInterfaceName(ProcessModel model)
             throws TException, OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             ApplicationInterfaceDescription appInterface = 
registryClient.getApplicationInterface(model.getApplicationInterfaceId());
             return appInterface.getApplicationName();
         } catch (Exception e) {
             throw new OrchestratorException("Error while retrieving 
application interface", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static DataMovementProtocol 
getPreferredDataMovementProtocol(OrchestratorContext context,
-                                                                        
ProcessModel model,
+    public static DataMovementProtocol 
getPreferredDataMovementProtocol(ProcessModel model,
                                                                         String 
gatewayId) throws TException, OrchestratorException {
         try {
             String resourceHostId = model.getComputeResourceId();
-            return getComputeResourcePreference(context, gatewayId, 
resourceHostId).getPreferredDataMovementProtocol();
+            return getComputeResourcePreference(gatewayId, 
resourceHostId).getPreferredDataMovementProtocol();
         } catch (ApplicationSettingsException e) {
             logger.error("Error occurred while retrieving 
DataMovementProtocol", e);
             throw new OrchestratorException("Error occurred while retrieving 
DataMovementProtocol", e);
         }
     }
 
-    public static ComputeResourcePreference 
getComputeResourcePreference(OrchestratorContext context,
-                                                                         
ProcessModel processModel,
+    public static ComputeResourcePreference 
getComputeResourcePreference(ProcessModel processModel,
                                                                          
String gatewayId) throws TException, OrchestratorException {
         try {
-            return getComputeResourcePreference(context, gatewayId, 
processModel.getComputeResourceId());
+            return getComputeResourcePreference(gatewayId, 
processModel.getComputeResourceId());
         } catch (ApplicationSettingsException e) {
             logger.error("Error occurred while retrieving 
ComputeResourcePreference", e);
             throw new OrchestratorException("Error occurred while retrieving 
ComputeResourcePreference", e);
         }
     }
 
-    public static StoragePreference getStoragePreference(OrchestratorContext 
context,
-                                                         ProcessModel 
processModel,
+    public static StoragePreference getStoragePreference(ProcessModel 
processModel,
                                                          String gatewayId) 
throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             String resourceHostId = processModel.getComputeResourceId();
             return registryClient.getGatewayStoragePreference(gatewayId, 
resourceHostId);
         } catch (Exception e) {
             logger.error("Error occurred while retrieving StoragePreference", 
e);
             throw new OrchestratorException("Error occurred while retrieving 
StoragePreference", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static String getLoginUserName(OrchestratorContext context,
-                                          ProcessModel processModel,
+    public static String getLoginUserName(ProcessModel processModel,
                                           String gatewayId) throws 
AiravataException, TException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
-            ComputeResourcePreference computeResourcePreference = 
getComputeResourcePreference(context, gatewayId,
+            ComputeResourcePreference computeResourcePreference = 
getComputeResourcePreference(gatewayId,
                     processModel.getComputeResourceId());
             ComputationalResourceSchedulingModel processResourceSchedule = 
processModel.getProcessResourceSchedule();
             if (processModel.isUseUserCRPref()) {
@@ -182,15 +190,18 @@ public class OrchestratorUtils {
         } catch (ApplicationSettingsException e) {
             logger.error("Error occurred while initializing app catalog to 
fetch login username", e);
             throw new ApplicationSettingsException("Error occurred while 
initializing app catalog to fetch login username", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static String getScratchLocation(OrchestratorContext context,
-                                            ProcessModel processModel,
+    public static String getScratchLocation(ProcessModel processModel,
                                             String gatewayId) throws  
AiravataException, TException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
-            ComputeResourcePreference computeResourcePreference = 
getComputeResourcePreference(context, gatewayId,
+            ComputeResourcePreference computeResourcePreference = 
getComputeResourcePreference(gatewayId,
                     processModel.getComputeResourceId());
             ComputationalResourceSchedulingModel processResourceSchedule = 
processModel.getProcessResourceSchedule();
             if (processModel.isUseUserCRPref()) {
@@ -226,16 +237,19 @@ public class OrchestratorUtils {
         } catch (AiravataException e) {
             logger.error("Error occurred while initializing app catalog to 
fetch scratch location", e);
             throw new AiravataException("Error occurred while initializing app 
catalog to fetch scratch location", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static JobSubmissionInterface 
getPreferredJobSubmissionInterface(OrchestratorContext context,
-                                                                            
ProcessModel processModel,
+    public static JobSubmissionInterface 
getPreferredJobSubmissionInterface(ProcessModel processModel,
                                                                             
String gatewayId) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             String resourceHostId = processModel.getComputeResourceId();
-            ComputeResourcePreference resourcePreference = 
getComputeResourcePreference(context, processModel, gatewayId);
+            ComputeResourcePreference resourcePreference = 
getComputeResourcePreference(processModel, gatewayId);
             JobSubmissionProtocol preferredJobSubmissionProtocol = 
resourcePreference.getPreferredJobSubmissionProtocol();
             ComputeResourceDescription resourceDescription = 
registryClient.getComputeResource(resourceHostId);
             List<JobSubmissionInterface> jobSubmissionInterfaces = 
resourceDescription.getJobSubmissionInterfaces();
@@ -269,16 +283,19 @@ public class OrchestratorUtils {
             return interfaces.get(0);
         } catch (Exception e) {
             throw new OrchestratorException("Error occurred while retrieving 
data from app catalog", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static DataMovementInterface 
getPrefferredDataMovementInterface(OrchestratorContext context,
-                                                                           
ProcessModel processModel,
+    public static DataMovementInterface 
getPrefferredDataMovementInterface(ProcessModel processModel,
                                                                            
String gatewayId) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             String resourceHostId = processModel.getComputeResourceId();
-            ComputeResourcePreference resourcePreference = 
getComputeResourcePreference(context, processModel, gatewayId);
+            ComputeResourcePreference resourcePreference = 
getComputeResourcePreference(processModel, gatewayId);
             DataMovementProtocol preferredDataMovementProtocol = 
resourcePreference.getPreferredDataMovementProtocol();
             ComputeResourceDescription resourceDescription = 
registryClient.getComputeResource(resourceHostId);
             List<DataMovementInterface> dataMovementInterfaces = 
resourceDescription.getDataMovementInterfaces();
@@ -295,18 +312,21 @@ public class OrchestratorUtils {
             }
         } catch (Exception e) {
             throw new OrchestratorException("Error occurred while retrieving 
data from app catalog", e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
         return null;
     }
 
-    public static int getDataMovementPort(OrchestratorContext context,
-                                          ProcessModel processModel,
+    public static int getDataMovementPort(ProcessModel processModel,
                                           String gatewayId) throws TException, 
ApplicationSettingsException, OrchestratorException {
         try {
-            DataMovementProtocol protocol = 
getPreferredDataMovementProtocol(context, processModel, gatewayId);
-            DataMovementInterface dataMovementInterface = 
getPrefferredDataMovementInterface(context, processModel, gatewayId);
+            DataMovementProtocol protocol = 
getPreferredDataMovementProtocol(processModel, gatewayId);
+            DataMovementInterface dataMovementInterface = 
getPrefferredDataMovementInterface(processModel, gatewayId);
             if (protocol == DataMovementProtocol.SCP ) {
-                SCPDataMovement scpDataMovement = getSCPDataMovement(context, 
dataMovementInterface.getDataMovementInterfaceId());
+                SCPDataMovement scpDataMovement = 
getSCPDataMovement(dataMovementInterface.getDataMovementInterfaceId());
                 if (scpDataMovement != null) {
                     return scpDataMovement.getSshPort();
                 }
@@ -318,29 +338,28 @@ public class OrchestratorUtils {
     }
 
 
-    public static SecurityProtocol getSecurityProtocol(OrchestratorContext 
context,
-                                                       ProcessModel 
processModel,
+    public static SecurityProtocol getSecurityProtocol(ProcessModel 
processModel,
                                                        String gatewayId) 
throws TException, ApplicationSettingsException, OrchestratorException {
         try {
-            JobSubmissionProtocol submissionProtocol = 
getPreferredJobSubmissionProtocol(context, processModel, gatewayId);
-            JobSubmissionInterface jobSubmissionInterface = 
getPreferredJobSubmissionInterface(context, processModel, gatewayId);
+            JobSubmissionProtocol submissionProtocol = 
getPreferredJobSubmissionProtocol(processModel, gatewayId);
+            JobSubmissionInterface jobSubmissionInterface = 
getPreferredJobSubmissionInterface(processModel, gatewayId);
             if (submissionProtocol == JobSubmissionProtocol.SSH ) {
-                SSHJobSubmission sshJobSubmission = 
getSSHJobSubmission(context, 
jobSubmissionInterface.getJobSubmissionInterfaceId());
+                SSHJobSubmission sshJobSubmission = 
getSSHJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
                 if (sshJobSubmission != null) {
                     return sshJobSubmission.getSecurityProtocol();
                 }
             } else if (submissionProtocol == JobSubmissionProtocol.LOCAL) {
-                LOCALSubmission localJobSubmission = 
getLocalJobSubmission(context, 
jobSubmissionInterface.getJobSubmissionInterfaceId());
+                LOCALSubmission localJobSubmission = 
getLocalJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
                 if (localJobSubmission != null) {
                     return localJobSubmission.getSecurityProtocol();
                 }
             } else if (submissionProtocol == JobSubmissionProtocol.SSH_FORK){
-                SSHJobSubmission sshJobSubmission = 
getSSHJobSubmission(context, 
jobSubmissionInterface.getJobSubmissionInterfaceId());
+                SSHJobSubmission sshJobSubmission = 
getSSHJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
                 if (sshJobSubmission != null) {
                     return sshJobSubmission.getSecurityProtocol();
                 }
             } else if (submissionProtocol == JobSubmissionProtocol.CLOUD) {
-                CloudJobSubmission cloudJobSubmission = 
getCloudJobSubmission(context, 
jobSubmissionInterface.getJobSubmissionInterfaceId());
+                CloudJobSubmission cloudJobSubmission = 
getCloudJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
                 if (cloudJobSubmission != null) {
                     return cloudJobSubmission.getSecurityProtocol();
                 }
@@ -351,67 +370,92 @@ public class OrchestratorUtils {
         return null;
     }
 
-    public static LOCALSubmission getLocalJobSubmission(OrchestratorContext 
context,
-                                                        String submissionId) 
throws OrchestratorException {
+    public static LOCALSubmission getLocalJobSubmission(String submissionId) 
throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             return registryClient.getLocalJobSubmission(submissionId);
         } catch (Exception e) {
             String errorMsg = "Error while retrieving local job submission 
with submission id : " + submissionId;
             logger.error(errorMsg, e);
             throw new OrchestratorException(errorMsg, e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static UnicoreJobSubmission 
getUnicoreJobSubmission(OrchestratorContext context,
-                                                               String 
submissionId) throws OrchestratorException {
+    public static UnicoreJobSubmission getUnicoreJobSubmission(String 
submissionId) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             return registryClient.getUnicoreJobSubmission(submissionId);
         } catch (Exception e) {
             String errorMsg = "Error while retrieving UNICORE job submission 
with submission id : " + submissionId;
             logger.error(errorMsg, e);
             throw new OrchestratorException(errorMsg, e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static SSHJobSubmission getSSHJobSubmission(OrchestratorContext 
context,
-                                                       String submissionId) 
throws OrchestratorException {
+    public static SSHJobSubmission getSSHJobSubmission(String submissionId) 
throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             return registryClient.getSSHJobSubmission(submissionId);
         } catch (Exception e) {
             String errorMsg = "Error while retrieving SSH job submission with 
submission id : " + submissionId;
             logger.error(errorMsg, e);
             throw new OrchestratorException(errorMsg, e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static CloudJobSubmission getCloudJobSubmission(OrchestratorContext 
context,
-                                                           String 
submissionId) throws OrchestratorException {
+    public static CloudJobSubmission getCloudJobSubmission(String 
submissionId) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             return registryClient.getCloudJobSubmission(submissionId);
         } catch (Exception e) {
             String errorMsg = "Error while retrieving SSH job submission with 
submission id : " + submissionId;
             logger.error(errorMsg, e);
             throw new OrchestratorException(errorMsg, e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
-    public static SCPDataMovement getSCPDataMovement(OrchestratorContext 
context,
-                                                     String dataMoveId) throws 
OrchestratorException {
+    public static SCPDataMovement getSCPDataMovement(String dataMoveId) throws 
OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
context.getRegistryClient();
             return registryClient.getSCPDataMovement(dataMoveId);
         } catch (Exception e) {
             String errorMsg = "Error while retrieving SCP Data movement with 
submission id : " + dataMoveId;
             logger.error(errorMsg, e);
             throw new OrchestratorException(errorMsg, e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
     private static boolean isValid(String str) {
         return (str != null && !str.trim().isEmpty());
     }
+
+    private static RegistryService.Client getRegistryServiceClient() {
+        try {
+            final int serverPort = 
Integer.parseInt(ServerSettings.getRegistryServerPort());
+            final String serverHost = ServerSettings.getRegistryServerHost();
+            return 
RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort);
+        } catch (RegistryServiceException|ApplicationSettingsException e) {
+            throw new RuntimeException("Unable to create registry client...", 
e);
+        }
+    }
 }
diff --git 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
index fd56909..0778b17 100644
--- 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
+++ 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/AbstractOrchestrator.java
@@ -26,9 +26,6 @@ import 
org.apache.airavata.orchestrator.core.context.OrchestratorContext;
 import org.apache.airavata.orchestrator.core.exception.OrchestratorException;
 import org.apache.airavata.orchestrator.core.utils.OrchestratorUtils;
 import org.apache.airavata.orchestrator.cpi.Orchestrator;
-import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -75,7 +72,6 @@ public abstract class AbstractOrchestrator implements 
Orchestrator {
             setGatewayProperties();
             orchestratorContext = new OrchestratorContext();
             
orchestratorContext.setOrchestratorConfiguration(orchestratorConfiguration);
-            orchestratorContext.setRegistryClient(getRegistryServiceClient());
         }  catch (IOException e) {
             logger.error("Failed to initializing Orchestrator - Error parsing 
configuration files");
             OrchestratorException orchestratorException = new 
OrchestratorException(e);
@@ -95,16 +91,6 @@ public abstract class AbstractOrchestrator implements 
Orchestrator {
         }
     }
 
-    private RegistryService.Client getRegistryServiceClient() throws 
TException, ApplicationSettingsException {
-        final int serverPort = 
Integer.parseInt(ServerSettings.getRegistryServerPort());
-        final String serverHost = ServerSettings.getRegistryServerHost();
-        try {
-            return 
RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort);
-        } catch (RegistryServiceException e) {
-            throw new RuntimeException("Unable to create registry client...", 
e);
-        }
-    }
-
     public OrchestratorContext getOrchestratorContext() {
         return orchestratorContext;
     }
diff --git 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/SimpleOrchestratorImpl.java
 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/SimpleOrchestratorImpl.java
index c5492c3..0d447b8 100644
--- 
a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/SimpleOrchestratorImpl.java
+++ 
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/cpi/impl/SimpleOrchestratorImpl.java
@@ -20,7 +20,9 @@
 package org.apache.airavata.orchestrator.cpi.impl;
 
 import org.apache.airavata.common.exception.AiravataException;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.common.utils.ThriftUtils;
 import org.apache.airavata.gfac.core.task.TaskException;
 import 
org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription;
@@ -34,8 +36,8 @@ import 
org.apache.airavata.model.data.movement.DataMovementProtocol;
 import org.apache.airavata.model.error.LaunchValidationException;
 import org.apache.airavata.model.error.ValidationResults;
 import org.apache.airavata.model.error.ValidatorResult;
+import org.apache.airavata.model.experiment.ExperimentModel;
 import org.apache.airavata.model.process.ProcessModel;
-import org.apache.airavata.model.experiment.*;
 import 
org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel;
 import org.apache.airavata.model.status.TaskState;
 import org.apache.airavata.model.status.TaskStatus;
@@ -49,6 +51,7 @@ import 
org.apache.airavata.orchestrator.core.utils.OrchestratorConstants;
 import org.apache.airavata.orchestrator.core.utils.OrchestratorUtils;
 import org.apache.airavata.orchestrator.core.validator.JobMetadataValidator;
 import org.apache.airavata.registry.api.RegistryService;
+import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
 import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -127,8 +130,15 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
                             ErrorModel details = new ErrorModel();
                             details.setActualErrorMessage(errorMsg);
                             
details.setCreationTime(Calendar.getInstance().getTimeInMillis());
-                            orchestratorContext.getRegistryClient()
-                                    
.addErrors(OrchestratorConstants.EXPERIMENT_ERROR, details, 
experiment.getExperimentId());
+                            final RegistryService.Client registryClient = 
getRegistryServiceClient();
+                            try {
+                                registryClient
+                                        
.addErrors(OrchestratorConstants.EXPERIMENT_ERROR, details, 
experiment.getExperimentId());
+                            } finally {
+                                if (registryClient != null) {
+                                    ThriftUtils.close(registryClient);
+                                }
+                            }
                         } catch (RegistryServiceException e) {
                             logger.error("Error while saving error details to 
registry", e);
                             throw new RuntimeException("Error while saving 
error details to registry", e);
@@ -193,8 +203,15 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
                             ErrorModel details = new ErrorModel();
                             details.setActualErrorMessage(errorMsg);
                             
details.setCreationTime(Calendar.getInstance().getTimeInMillis());
-                            orchestratorContext.getRegistryClient()
-                                    
.addErrors(OrchestratorConstants.PROCESS_ERROR, details, 
processModel.getProcessId());
+                            final RegistryService.Client registryClient = 
getRegistryServiceClient();
+                            try {
+                                registryClient
+                                        
.addErrors(OrchestratorConstants.PROCESS_ERROR, details, 
processModel.getProcessId());
+                            } finally {
+                                if (registryClient != null) {
+                                    ThriftUtils.close(registryClient);
+                                }
+                            }
                         } catch (RegistryServiceException e) {
                             logger.error("Error while saving error details to 
registry", e);
                             throw new RuntimeException("Error while saving 
error details to registry", e);
@@ -259,8 +276,8 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
     }
 
     public List<ProcessModel> createProcesses (String experimentId, String 
gatewayId) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
orchestratorContext.getRegistryClient();
             ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
             List<ProcessModel> processModels = 
registryClient.getProcessList(experimentId);
             if (processModels.equals(null) || processModels.isEmpty()){
@@ -272,13 +289,17 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
             }
         } catch (Exception e) {
             throw new OrchestratorException("Error during creating process", 
e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
         return null;
     }
 
     public String createAndSaveTasks(String gatewayId, ProcessModel 
processModel, boolean autoSchedule) throws OrchestratorException {
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
-            RegistryService.Client registryClient = 
orchestratorContext.getRegistryClient();
             ComputationalResourceSchedulingModel resourceSchedule = 
processModel.getProcessResourceSchedule();
             String userGivenQueueName = resourceSchedule.getQueueName();
             int userGivenWallTime = resourceSchedule.getWallTimeLimit();
@@ -288,16 +309,16 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
             }
             ComputeResourceDescription computeResource = 
registryClient.getComputeResource(resourceHostId);
             JobSubmissionInterface preferredJobSubmissionInterface =
-                    
OrchestratorUtils.getPreferredJobSubmissionInterface(orchestratorContext, 
processModel, gatewayId);
+                    
OrchestratorUtils.getPreferredJobSubmissionInterface(processModel, gatewayId);
             ComputeResourcePreference resourcePreference =
-                    
OrchestratorUtils.getComputeResourcePreference(orchestratorContext, 
processModel, gatewayId);
+                    
OrchestratorUtils.getComputeResourcePreference(processModel, gatewayId);
             List<String> taskIdList = new ArrayList<>();
 
             if (resourcePreference.getPreferredJobSubmissionProtocol() == 
JobSubmissionProtocol.UNICORE) {
                 // TODO - breakdown unicore all in one task to multiple tasks, 
then we don't need to handle UNICORE here.
-                taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, 
preferredJobSubmissionInterface, processModel, userGivenWallTime));
+                taskIdList.addAll(createAndSaveSubmissionTasks(registryClient, 
gatewayId, preferredJobSubmissionInterface, processModel, userGivenWallTime));
             } else {
-                taskIdList.addAll(createAndSaveEnvSetupTask(gatewayId, 
processModel));
+                taskIdList.addAll(createAndSaveEnvSetupTask(registryClient, 
gatewayId, processModel));
                 
taskIdList.addAll(createAndSaveInputDataStagingTasks(processModel, gatewayId));
                 if (autoSchedule) {
                     List<BatchQueue> definedBatchQueues = 
computeResource.getBatchQueues();
@@ -310,21 +331,21 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
                                 int numOfMaxWallTimeJobs = ((int) 
Math.floor(userGivenWallTime / maxRunTime));
                                 for (int i = 1; i <= numOfMaxWallTimeJobs; 
i++) {
                                     taskIdList.addAll(
-                                            
createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, 
processModel, maxRunTime));
+                                            
createAndSaveSubmissionTasks(registryClient, gatewayId, 
preferredJobSubmissionInterface, processModel, maxRunTime));
                                 }
                                 int leftWallTime = userGivenWallTime % 
maxRunTime;
                                 if (leftWallTime != 0) {
                                     taskIdList.addAll(
-                                            
createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, 
processModel, leftWallTime));
+                                            
createAndSaveSubmissionTasks(registryClient, gatewayId, 
preferredJobSubmissionInterface, processModel, leftWallTime));
                                 }
                             } else {
                                 taskIdList.addAll(
-                                        
createAndSaveSubmissionTasks(gatewayId, preferredJobSubmissionInterface, 
processModel, userGivenWallTime));
+                                        
createAndSaveSubmissionTasks(registryClient, gatewayId, 
preferredJobSubmissionInterface, processModel, userGivenWallTime));
                             }
                         }
                     }
                 } else {
-                    taskIdList.addAll(createAndSaveSubmissionTasks(gatewayId, 
preferredJobSubmissionInterface, processModel, userGivenWallTime));
+                    
taskIdList.addAll(createAndSaveSubmissionTasks(registryClient, gatewayId, 
preferredJobSubmissionInterface, processModel, userGivenWallTime));
                 }
                 
taskIdList.addAll(createAndSaveOutputDataStagingTasks(processModel, gatewayId));
             }
@@ -333,6 +354,10 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
             return getTaskDag(taskIdList);
         } catch (Exception e) {
             throw new OrchestratorException("Error during creating process", 
e);
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
+            }
         }
     }
 
@@ -348,7 +373,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         return dag.substring(0, dag.length() - 1); // remove last comma
     }
 
-    private List<String> createAndSaveEnvSetupTask(String gatewayId,
+    private List<String> createAndSaveEnvSetupTask(RegistryService.Client 
registryClient, String gatewayId,
                                                    ProcessModel processModel)
             throws TException, AiravataException, OrchestratorException {
         List<String> envTaskIds = new ArrayList<>();
@@ -359,14 +384,14 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         
envSetupTask.setLastUpdateTime(AiravataUtils.getCurrentTimestamp().getTime());
         envSetupTask.setParentProcessId(processModel.getProcessId());
         EnvironmentSetupTaskModel envSetupSubModel = new 
EnvironmentSetupTaskModel();
-        
envSetupSubModel.setProtocol(OrchestratorUtils.getSecurityProtocol(orchestratorContext,
 processModel, gatewayId));
-        ComputeResourcePreference computeResourcePreference = 
OrchestratorUtils.getComputeResourcePreference(orchestratorContext, 
processModel, gatewayId);
-        String scratchLocation = 
OrchestratorUtils.getScratchLocation(orchestratorContext,processModel, 
gatewayId);
+        
envSetupSubModel.setProtocol(OrchestratorUtils.getSecurityProtocol(processModel,
 gatewayId));
+        ComputeResourcePreference computeResourcePreference = 
OrchestratorUtils.getComputeResourcePreference(processModel, gatewayId);
+        String scratchLocation = 
OrchestratorUtils.getScratchLocation(processModel, gatewayId);
         String workingDir = scratchLocation + File.separator + 
processModel.getProcessId();
         envSetupSubModel.setLocation(workingDir);
         byte[] envSetupSub = 
ThriftUtils.serializeThriftObject(envSetupSubModel);
         envSetupTask.setSubTaskModel(envSetupSub);
-        String envSetupTaskId = (String) 
orchestratorContext.getRegistryClient().addTask(envSetupTask, 
processModel.getProcessId());
+        String envSetupTaskId = (String) registryClient.addTask(envSetupTask, 
processModel.getProcessId());
         envSetupTask.setTaskId(envSetupTaskId);
         envTaskIds.add(envSetupTaskId);
         return envTaskIds;
@@ -389,14 +414,19 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
                         break;
                     case URI:
                     case URI_COLLECTION:
+                        final RegistryService.Client registryClient = 
getRegistryServiceClient();
                         try {
-                            TaskModel inputDataStagingTask = 
getInputDataStagingTask(processModel, processInput, gatewayId);
-                            String taskId = 
orchestratorContext.getRegistryClient()
+                            TaskModel inputDataStagingTask = 
getInputDataStagingTask(registryClient, processModel, processInput, gatewayId);
+                            String taskId = registryClient
                                     .addTask( inputDataStagingTask, 
processModel.getProcessId());
                             inputDataStagingTask.setTaskId(taskId);
                             
dataStagingTaskIds.add(inputDataStagingTask.getTaskId());
                         } catch (TException | TaskException e) {
                             throw new AiravataException("Error while 
serializing data staging sub task model", e);
+                        } finally {
+                            if (registryClient != null) {
+                                ThriftUtils.close(registryClient);
+                            }
                         }
                         break;
                     default:
@@ -411,74 +441,81 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
     public List<String> createAndSaveOutputDataStagingTasks(ProcessModel 
processModel, String gatewayId)
             throws AiravataException, TException, OrchestratorException {
 
+        final RegistryService.Client registryClient = 
getRegistryServiceClient();
         List<String> dataStagingTaskIds = new ArrayList<>();
-        List<OutputDataObjectType> processOutputs = 
processModel.getProcessOutputs();
-        String appName = 
OrchestratorUtils.getApplicationInterfaceName(orchestratorContext, 
processModel);
-        if (processOutputs != null) {
-            for (OutputDataObjectType processOutput : processOutputs) {
-                DataType type = processOutput.getType();
-                switch (type) {
-                    case STDOUT:
-                        if (null == processOutput.getValue() || 
processOutput.getValue().trim().isEmpty()) {
-                            processOutput.setValue(appName + ".stdout");
-                        }
-                        createOutputDataSatagingTasks(processModel, gatewayId, 
dataStagingTaskIds, processOutput);
-                        break;
-                    case STDERR:
-                        if (null == processOutput.getValue() || 
processOutput.getValue().trim().isEmpty()) {
-                            processOutput.setValue(appName + ".stderr");
-                        }
-                        createOutputDataSatagingTasks(processModel, gatewayId, 
dataStagingTaskIds, processOutput);
-                        break;
-                    case URI:
-                        createOutputDataSatagingTasks(processModel, gatewayId, 
dataStagingTaskIds, processOutput);
-                        break;
-                    default:
-                        // nothing to do
-                        break;
+        try {
+            List<OutputDataObjectType> processOutputs = 
processModel.getProcessOutputs();
+            String appName = 
OrchestratorUtils.getApplicationInterfaceName(processModel);
+            if (processOutputs != null) {
+                for (OutputDataObjectType processOutput : processOutputs) {
+                    DataType type = processOutput.getType();
+                    switch (type) {
+                        case STDOUT:
+                            if (null == processOutput.getValue() || 
processOutput.getValue().trim().isEmpty()) {
+                                processOutput.setValue(appName + ".stdout");
+                            }
+                            createOutputDataSatagingTasks(registryClient, 
processModel, gatewayId, dataStagingTaskIds, processOutput);
+                            break;
+                        case STDERR:
+                            if (null == processOutput.getValue() || 
processOutput.getValue().trim().isEmpty()) {
+                                processOutput.setValue(appName + ".stderr");
+                            }
+                            createOutputDataSatagingTasks(registryClient, 
processModel, gatewayId, dataStagingTaskIds, processOutput);
+                            break;
+                        case URI:
+                            createOutputDataSatagingTasks(registryClient, 
processModel, gatewayId, dataStagingTaskIds, processOutput);
+                            break;
+                        default:
+                            // nothing to do
+                            break;
+                    }
                 }
             }
-        }
 
-        try {
-            if (isArchive(processModel, orchestratorContext)) {
-                createArchiveDataStatgingTask(processModel, gatewayId, 
dataStagingTaskIds);
+            try {
+                if (isArchive(registryClient, processModel, 
orchestratorContext)) {
+                    createArchiveDataStatgingTask(registryClient, 
processModel, gatewayId, dataStagingTaskIds);
+                }
+            } catch (Exception e) {
+                throw new AiravataException("Error! Application interface 
retrieval failed", e);
+            }
+        } finally {
+            if (registryClient != null) {
+                ThriftUtils.close(registryClient);
             }
-        } catch (Exception e) {
-            throw new AiravataException("Error! Application interface 
retrieval failed", e);
         }
         return dataStagingTaskIds;
     }
 
-    private boolean isArchive(ProcessModel processModel, OrchestratorContext 
orchestratorContext) throws TException {
-        ApplicationInterfaceDescription appInterface = 
orchestratorContext.getRegistryClient()
+    private boolean isArchive(RegistryService.Client registryClient, 
ProcessModel processModel, OrchestratorContext orchestratorContext) throws 
TException {
+        ApplicationInterfaceDescription appInterface = registryClient
                 
.getApplicationInterface(processModel.getApplicationInterfaceId());
         return appInterface.isArchiveWorkingDirectory();
     }
 
-    private void createArchiveDataStatgingTask(ProcessModel processModel,
+    private void createArchiveDataStatgingTask(RegistryService.Client 
registryClient, ProcessModel processModel,
                                                String gatewayId,
                                                List<String> 
dataStagingTaskIds) throws AiravataException, TException, OrchestratorException 
{
         TaskModel archiveTask = null;
         try {
-            archiveTask = getOutputDataStagingTask(processModel, null, 
gatewayId);
+            archiveTask = getOutputDataStagingTask(registryClient, 
processModel, null, gatewayId);
         } catch (TException e) {
             throw new AiravataException("Error! DataStaging sub task 
serialization failed", e);
         }
-        String taskId = orchestratorContext.getRegistryClient()
+        String taskId = registryClient
                 .addTask(archiveTask, processModel.getProcessId());
         archiveTask.setTaskId(taskId);
         dataStagingTaskIds.add(archiveTask.getTaskId());
 
     }
 
-    private void createOutputDataSatagingTasks(ProcessModel processModel,
+    private void createOutputDataSatagingTasks(RegistryService.Client 
registryClient, ProcessModel processModel,
                                                String gatewayId,
                                                List<String> dataStagingTaskIds,
                                                OutputDataObjectType 
processOutput) throws AiravataException, OrchestratorException {
         try {
-            TaskModel outputDataStagingTask = 
getOutputDataStagingTask(processModel, processOutput, gatewayId);
-            String taskId = orchestratorContext.getRegistryClient()
+            TaskModel outputDataStagingTask = 
getOutputDataStagingTask(registryClient, processModel, processOutput, 
gatewayId);
+            String taskId = registryClient
                     .addTask(outputDataStagingTask, 
processModel.getProcessId());
             outputDataStagingTask.setTaskId(taskId);
             dataStagingTaskIds.add(outputDataStagingTask.getTaskId());
@@ -487,7 +524,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         }
     }
 
-    private List<String> createAndSaveSubmissionTasks(String gatewayId,
+    private List<String> createAndSaveSubmissionTasks(RegistryService.Client 
registryClient, String gatewayId,
                                                       JobSubmissionInterface 
jobSubmissionInterface,
                                                       ProcessModel 
processModel,
                                                       int wallTime)
@@ -496,7 +533,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         JobSubmissionProtocol jobSubmissionProtocol = 
jobSubmissionInterface.getJobSubmissionProtocol();
         MonitorMode monitorMode = null;
         if (jobSubmissionProtocol == JobSubmissionProtocol.SSH || 
jobSubmissionProtocol == JobSubmissionProtocol.SSH_FORK) {
-            SSHJobSubmission sshJobSubmission = 
OrchestratorUtils.getSSHJobSubmission(orchestratorContext, 
jobSubmissionInterface.getJobSubmissionInterfaceId());
+            SSHJobSubmission sshJobSubmission = 
OrchestratorUtils.getSSHJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
             monitorMode = sshJobSubmission.getMonitorMode();
         } else if (jobSubmissionProtocol == JobSubmissionProtocol.UNICORE) {
             monitorMode = MonitorMode.FORK;
@@ -524,8 +561,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         submissionSubTask.setWallTime(wallTime);
         byte[] bytes = ThriftUtils.serializeThriftObject(submissionSubTask);
         taskModel.setSubTaskModel(bytes);
-        String taskId = 
orchestratorContext.getRegistryClient().addTask(taskModel,
-                processModel.getProcessId());
+        String taskId = registryClient.addTask(taskModel, 
processModel.getProcessId());
         taskModel.setTaskId(taskId);
         submissionTaskIds.add(taskModel.getTaskId());
 
@@ -543,7 +579,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
             MonitorTaskModel monitorSubTaskModel = new MonitorTaskModel();
             monitorSubTaskModel.setMonitorMode(monitorMode);
             
monitorTaskModel.setSubTaskModel(ThriftUtils.serializeThriftObject(monitorSubTaskModel));
-            String mTaskId = (String) 
orchestratorContext.getRegistryClient().addTask(monitorTaskModel, 
processModel.getProcessId());
+            String mTaskId = (String) registryClient.addTask(monitorTaskModel, 
processModel.getProcessId());
             monitorTaskModel.setTaskId(mTaskId);
             submissionTaskIds.add(monitorTaskModel.getTaskId());
         }
@@ -560,7 +596,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         });
     }
 
-    private TaskModel getInputDataStagingTask(ProcessModel processModel, 
InputDataObjectType processInput, String gatewayId) throws TException, 
TaskException, AiravataException, OrchestratorException {
+    private TaskModel getInputDataStagingTask(RegistryService.Client 
registryClient, ProcessModel processModel, InputDataObjectType processInput, 
String gatewayId) throws TException, TaskException, AiravataException, 
OrchestratorException {
         // create new task model for this task
         TaskModel taskModel = new TaskModel();
         taskModel.setParentProcessId(processModel.getProcessId());
@@ -572,19 +608,19 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         taskModel.setTaskType(TaskTypes.DATA_STAGING);
         // create data staging sub task model
         DataStagingTaskModel submodel = new DataStagingTaskModel();
-        ComputeResourceDescription computeResource = 
orchestratorContext.getRegistryClient().
+        ComputeResourceDescription computeResource = registryClient.
                 getComputeResource(processModel.getComputeResourceId());
-        String workingDir = 
OrchestratorUtils.getScratchLocation(orchestratorContext,processModel, 
gatewayId) +
+        String workingDir = OrchestratorUtils.getScratchLocation(processModel, 
gatewayId) +
                 File.separator + processModel.getProcessId() + File.separator;
         URI destination = null;
         try {
             DataMovementProtocol dataMovementProtocol =
-                    
OrchestratorUtils.getPreferredDataMovementProtocol(orchestratorContext, 
processModel, gatewayId);
-            String loginUserName = 
OrchestratorUtils.getLoginUserName(orchestratorContext, processModel, 
gatewayId);
+                    
OrchestratorUtils.getPreferredDataMovementProtocol(processModel, gatewayId);
+            String loginUserName = 
OrchestratorUtils.getLoginUserName(processModel, gatewayId);
             destination = new URI(dataMovementProtocol.name(),
                     loginUserName,
                     computeResource.getHostName(),
-                    OrchestratorUtils.getDataMovementPort(orchestratorContext, 
processModel, gatewayId),
+                    OrchestratorUtils.getDataMovementPort(processModel, 
gatewayId),
                     workingDir , null, null);
         } catch (URISyntaxException e) {
             throw new TaskException("Error while constructing destination file 
URI", e);
@@ -597,7 +633,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         return taskModel;
     }
 
-    private TaskModel getOutputDataStagingTask(ProcessModel processModel, 
OutputDataObjectType processOutput, String gatewayId) throws TException, 
AiravataException, OrchestratorException {
+    private TaskModel getOutputDataStagingTask(RegistryService.Client 
registryClient, ProcessModel processModel, OutputDataObjectType processOutput, 
String gatewayId) throws TException, AiravataException, OrchestratorException {
         try {
 
             // create new task model for this task
@@ -609,23 +645,23 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
             
taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
             taskModel.setTaskStatuses(Arrays.asList(taskStatus));
             taskModel.setTaskType(TaskTypes.DATA_STAGING);
-            ComputeResourceDescription computeResource = 
orchestratorContext.getRegistryClient().
+            ComputeResourceDescription computeResource = registryClient.
                     getComputeResource(processModel.getComputeResourceId());
 
-            String workingDir = 
OrchestratorUtils.getScratchLocation(orchestratorContext,processModel, 
gatewayId)
+            String workingDir = 
OrchestratorUtils.getScratchLocation(processModel, gatewayId)
                     + File.separator + processModel.getProcessId() + 
File.separator;
             DataStagingTaskModel submodel = new DataStagingTaskModel();
-            DataMovementProtocol dataMovementProtocol = 
OrchestratorUtils.getPreferredDataMovementProtocol(orchestratorContext, 
processModel, gatewayId);
+            DataMovementProtocol dataMovementProtocol = 
OrchestratorUtils.getPreferredDataMovementProtocol(processModel, gatewayId);
             URI source = null;
             try {
-                String loginUserName = 
OrchestratorUtils.getLoginUserName(orchestratorContext, processModel, 
gatewayId);
+                String loginUserName = 
OrchestratorUtils.getLoginUserName(processModel, gatewayId);
                 if (processOutput != null) {
                     submodel.setType(DataStageType.OUPUT);
                     submodel.setProcessOutput(processOutput);
                     source = new URI(dataMovementProtocol.name(),
                             loginUserName,
                             computeResource.getHostName(),
-                            
OrchestratorUtils.getDataMovementPort(orchestratorContext, processModel, 
gatewayId),
+                            
OrchestratorUtils.getDataMovementPort(processModel, gatewayId),
                             workingDir + processOutput.getValue(), null, null);
                 } else {
                     // archive
@@ -633,7 +669,7 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
                     source = new URI(dataMovementProtocol.name(),
                             loginUserName,
                             computeResource.getHostName(),
-                            
OrchestratorUtils.getDataMovementPort(orchestratorContext, processModel, 
gatewayId),
+                            
OrchestratorUtils.getDataMovementPort(processModel, gatewayId),
                             workingDir, null, null);
                 }
             } catch (URISyntaxException e) {
@@ -652,5 +688,14 @@ public class SimpleOrchestratorImpl extends 
AbstractOrchestrator{
         }
     }
 
+    private RegistryService.Client getRegistryServiceClient() {
+        try {
+            final int serverPort = 
Integer.parseInt(ServerSettings.getRegistryServerPort());
+            final String serverHost = ServerSettings.getRegistryServerHost();
+            return 
RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort);
+        } catch (RegistryServiceException|ApplicationSettingsException e) {
+            throw new RuntimeException("Unable to create registry client...", 
e);
+        }
+    }
 
 }
diff --git 
a/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
 
b/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
index df3e552..09ed114 100644
--- 
a/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
+++ 
b/modules/orchestrator/orchestrator-core/src/test/java/org/apache/airavata/orchestrator/core/util/Initialize.java
@@ -19,11 +19,6 @@
  */
 package org.apache.airavata.orchestrator.core.util;
 
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-//import org.apache.airavata.registry.core.experiment.catalog.ResourceType;
-import org.apache.airavata.registry.core.experiment.catalog.resources.*;
-//import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -32,7 +27,6 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.InetAddress;
 import java.sql.*;
 import java.util.StringTokenizer;
 
@@ -301,24 +295,6 @@ public class Initialize {
         }
     }
 
-    private void startDerbyInServerMode() {
-        try {
-            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
-            server = new 
NetworkServerControl(InetAddress.getByName(Utils.getHost()),
-                    20000,
-                    Utils.getJDBCUser(), Utils.getJDBCPassword());
-            java.io.PrintWriter consoleWriter = new 
java.io.PrintWriter(System.out, true);
-            server.start(consoleWriter);
-        } catch (IOException e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        } catch (Exception e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        }
-
-    }
-
     public void stopDerbyServer() throws SQLException{
         try {
             server.shutdown();
diff --git 
a/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
 
b/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
index b9fdc77..0934d1a 100644
--- 
a/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
+++ 
b/modules/orchestrator/orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
@@ -55,6 +55,7 @@ import 
org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants;
 import 
org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor;
 import org.apache.airavata.orchestrator.util.OrchestratorUtils;
 import org.apache.airavata.registry.api.RegistryService;
+import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
 import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.commons.lang.StringUtils;
 import org.apache.curator.RetryPolicy;
@@ -81,7 +82,6 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
        private final Subscriber statusSubscribe;
        private final Subscriber experimentSubscriber;
        private CuratorFramework curatorClient;
-       private RegistryService.Client registryClient;
 
     /**
         * Query orchestrator server to fetch the CPI version
@@ -97,7 +97,6 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                        // the required properties
                        setAiravataUserName(ServerSettings.getDefaultUser());
                        orchestrator = new SimpleOrchestratorImpl();
-                       registryClient = 
orchestrator.getOrchestratorContext().getRegistryClient();
 
                        publisher = MessagingFactory.getPublisher(Type.STATUS);
                        orchestrator.initialize();
@@ -135,6 +134,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         */
        public boolean launchExperiment(String experimentId, String gatewayId) 
throws TException {
         ExperimentModel experiment = null;
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
             String experimentNodePath = GFacUtils.getExperimentNodePath 
(experimentId);
                        
ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), 
experimentNodePath);
@@ -248,6 +248,10 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                        throw new TException("Experiment '" + experimentId + "' 
launch failed. Experiment failed to validate: " + 
launchValidationException.getErrorMessage(), launchValidationException);
         } catch (Exception e) {
             throw new TException("Experiment '" + experimentId + "' launch 
failed. Unable to figureout execution type for application " + 
experiment.getExecutionId(), e);
+               } finally {
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
         }
         return true;
        }
@@ -262,17 +266,23 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         * @throws TException
         */
        public boolean validateExperiment(String experimentId) throws 
TException, LaunchValidationException {
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
                try {
             ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
             return 
orchestrator.validateExperiment(experimentModel).isValidationState();
                } catch (OrchestratorException e) {
             log.error(experimentId, "Error while validating experiment", e);
                        throw new TException(e);
+               } finally {
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
                }
        }
 
     @Override
     public boolean validateProcess(String experimentId, List<ProcessModel> 
processes) throws LaunchValidationException, TException {
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
         try {
                        ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
                        for (ProcessModel processModel : processes) {
@@ -293,6 +303,10 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         } catch (OrchestratorException e) {
             log.error(experimentId, "Error while validating process", e);
             throw new TException(e);
+               } finally {
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
         }
        }
 
@@ -305,12 +319,17 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         * @throws TException
         */
        public boolean terminateExperiment(String experimentId, String 
gatewayId) throws TException {
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
         log.info(experimentId, "Experiment: {} is cancelling  !!!!!", 
experimentId);
                try {
-                       return validateStatesAndCancel(experimentId, gatewayId);
+                       return validateStatesAndCancel(registryClient, 
experimentId, gatewayId);
                } catch (Exception e) {
                        log.error("expId : " + experimentId + " :- Error while 
cancelling experiment", e);
                        return false;
+               } finally {
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
                }
        }
 
@@ -332,6 +351,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
 
        @Override
        public boolean launchProcess(String processId, String 
airavataCredStoreToken, String gatewayId) throws TException {
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
                try {
                        ProcessModel processModel = 
registryClient.getProcess(processId);
             String applicationId = processModel.getApplicationInterfaceId();
@@ -340,7 +360,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                                throw new OrchestratorException("Error 
executing the job, application interface id shouldn't be null.");
                        }
                        // set application deployment id to process model
-            ApplicationDeploymentDescription applicationDeploymentDescription 
= getAppDeployment(processModel, applicationId);
+            ApplicationDeploymentDescription applicationDeploymentDescription 
= getAppDeployment(registryClient, processModel, applicationId);
             
processModel.setApplicationDeploymentId(applicationDeploymentDescription.getAppDeploymentId());
                        // set compute resource id to process model, default we 
set the same in the user preferred compute host id
                        
processModel.setComputeResourceId(processModel.getProcessResourceSchedule().getResourceHostId());
@@ -349,18 +369,22 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                } catch (Exception e) {
             log.error(processId, "Error while launching process ", e);
             throw new TException(e);
+               } finally {
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
         }
        }
 
-    private ApplicationDeploymentDescription getAppDeployment(ProcessModel 
processModel, String applicationId)
+    private ApplicationDeploymentDescription 
getAppDeployment(RegistryService.Client registryClient, ProcessModel 
processModel, String applicationId)
             throws OrchestratorException,
             ClassNotFoundException, ApplicationSettingsException,
             InstantiationException, IllegalAccessException, TException {
-        String selectedModuleId = getModuleId(applicationId);
-        return getAppDeploymentForModule(processModel, selectedModuleId);
+        String selectedModuleId = getModuleId(registryClient, applicationId);
+        return getAppDeploymentForModule(registryClient, processModel, 
selectedModuleId);
     }
 
-    private ApplicationDeploymentDescription 
getAppDeploymentForModule(ProcessModel processModel, String selectedModuleId)
+    private ApplicationDeploymentDescription 
getAppDeploymentForModule(RegistryService.Client registryClient, ProcessModel 
processModel, String selectedModuleId)
             throws ClassNotFoundException,
             ApplicationSettingsException, InstantiationException,
             IllegalAccessException, TException {
@@ -380,7 +404,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         return deploymentMap.get(ComputeResourceDescription);
     }
 
-       private String getModuleId(String applicationId)
+       private String getModuleId(RegistryService.Client registryClient, 
String applicationId)
             throws OrchestratorException, TException {
                ApplicationInterfaceDescription applicationInterface = 
registryClient.getApplicationInterface(applicationId);
                List<String> applicationModules = 
applicationInterface.getApplicationModules();
@@ -394,7 +418,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                return selectedModuleId;
        }
 
-    private boolean validateStatesAndCancel(String experimentId, String 
gatewayId) throws Exception {
+    private boolean validateStatesAndCancel(RegistryService.Client 
registryClient, String experimentId, String gatewayId) throws Exception {
                ExperimentStatus experimentStatus = 
registryClient.getExperimentStatus(experimentId);
                switch (experimentStatus.getState()) {
                        case COMPLETED: case CANCELED: case FAILED: case 
CANCELING:
@@ -460,6 +484,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         }
 
         private boolean launchSingleAppExperiment() throws TException, 
AiravataException {
+                       final RegistryService.Client registryClient = 
getRegistryServiceClient();
             try {
                 List<String> processIds = 
registryClient.getProcessIds(experimentId);
                 for (String processId : processIds) {
@@ -484,6 +509,10 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                 
messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp());
                 publisher.publish(messageContext);
                    throw new TException(e);
+                       } finally {
+                               if (registryClient != null) {
+                                       ThriftUtils.close(registryClient);
+                               }
             }
             return true;
         }
@@ -633,6 +662,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
 
        private void launchExperiment(MessageContext messageContext) {
                ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent();
+               final RegistryService.Client registryClient = 
getRegistryServiceClient();
                try {
                        byte[] bytes = 
ThriftUtils.serializeThriftObject(messageContext.getEvent());
                        ThriftUtils.createThriftFromBytes(bytes, expEvent);
@@ -657,6 +687,19 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                } finally {
                        
experimentSubscriber.sendAck(messageContext.getDeliveryTag());
                        MDC.clear();
+                       if (registryClient != null) {
+                               ThriftUtils.close(registryClient);
+                       }
+               }
+       }
+
+       private RegistryService.Client getRegistryServiceClient() {
+               try {
+                       final int serverPort = 
Integer.parseInt(ServerSettings.getRegistryServerPort());
+                       final String serverHost = 
ServerSettings.getRegistryServerHost();
+                       return 
RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort);
+               } catch (RegistryServiceException|ApplicationSettingsException 
e) {
+                       throw new RuntimeException("Unable to create registry 
client...", e);
                }
        }
 
diff --git 
a/modules/orchestrator/orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
 
b/modules/orchestrator/orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
index 0c81aee..4ddd441 100644
--- 
a/modules/orchestrator/orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
+++ 
b/modules/orchestrator/orchestrator-service/src/test/java/org/apache/airavata/orchestrator/client/util/Initialize.java
@@ -19,8 +19,6 @@
  */
 package org.apache.airavata.orchestrator.client.util;
 
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.derby.drda.NetworkServerControl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,8 +27,10 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
 import java.util.StringTokenizer;
 
 public class Initialize {
@@ -85,111 +85,6 @@ public class Initialize {
         return false;
     }
 
-    public void initializeDB() throws SQLException{
-        String jdbcUrl = null;
-        String jdbcUser = null;
-        String jdbcPassword = null;
-        try{
-            jdbcUrl = ServerSettings.getSetting("registry.jdbc.url");
-            jdbcUser = ServerSettings.getSetting("registry.jdbc.user");
-            jdbcPassword = ServerSettings.getSetting("registry.jdbc.password");
-            jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + 
jdbcPassword;
-        } catch (ApplicationSettingsException e) {
-            logger.error("Unable to read properties", e);
-        }
-        startDerbyInServerMode();
-        if(!isServerStarted(server, 20)){
-           throw new RuntimeException("Derby server cound not started within 
five seconds...");
-        }
-
-        Connection conn = null;
-        try {
-            Class.forName(Utils.getJDBCDriver()).newInstance();
-            conn = DriverManager.getConnection(jdbcUrl, jdbcUser, 
jdbcPassword);
-            if (!isDatabaseStructureCreated(PERSISTANT_DATA, conn)) {
-                executeSQLScript(conn);
-                logger.info("New Database created for Registry");
-            } else {
-                logger.debug("Database already created for Registry!");
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw new RuntimeException("Database failure", e);
-        } finally {
-            try {
-                if (conn != null){
-                    if (!conn.getAutoCommit()) {
-                        conn.commit();
-                    }
-                    conn.close();
-                }
-            } catch (SQLException e) {
-                logger.error(e.getMessage(), e);
-            }
-        }
-
-        //Commenting this as its not used anywhere and creates dependency on 
registry-cpi and registry-core
-//        try{
-//            GatewayResource gatewayResource = new GatewayResource();
-//            
gatewayResource.setGatewayId(ServerSettings.getSetting("default.registry.gateway"));
-//            
gatewayResource.setGatewayName(ServerSettings.getSetting("default.registry.gateway"));
-//            gatewayResource.setDomain("test-domain");
-//            gatewayResource.setEmailAddress("test-email");
-//            gatewayResource.save();
-//
-//            UserResource userResource = new UserResource();
-//            
userResource.setUserName(ServerSettings.getSetting("default.registry.user"));
-//            
userResource.setPassword(ServerSettings.getSetting("default.registry.password"));
-//            userResource.save();
-//
-//            WorkerResource workerResource = (WorkerResource) 
gatewayResource.create(ResourceType.GATEWAY_WORKER);
-//            workerResource.setUser(userResource.getUserName());
-//            workerResource.save();
-//
-//            ProjectResource projectResource = 
(ProjectResource)workerResource.create(ResourceType.PROJECT);
-//            projectResource.setGatewayId(gatewayResource.getGatewayId());
-//            projectResource.setId("default");
-//            projectResource.setName("default");
-//            projectResource.setWorker(workerResource);
-//            projectResource.save();
-//
-//
-//        } catch (ApplicationSettingsException e) {
-//            logger.error("Unable to read properties", e);
-//            throw new SQLException(e.getMessage(), e);
-//        } catch (RegistryException e) {
-//            logger.error("Unable to save data to registry", e);
-//            throw new SQLException(e.getMessage(), e);
-//        }
-    }
-
-    public static boolean isDatabaseStructureCreated(String tableName, 
Connection conn) {
-        try {
-            System.out.println("Running a query to test the database tables 
existence.");
-            // check whether the tables are already created with a query
-            Statement statement = null;
-            try {
-                statement = conn.createStatement();
-                ResultSet rs = statement.executeQuery("select * from " + 
tableName);
-                if (rs != null) {
-                    rs.close();
-                }
-            } finally {
-                try {
-                    if (statement != null) {
-                        statement.close();
-                    }
-                } catch (SQLException e) {
-                    return false;
-                }
-            }
-        } catch (SQLException e) {
-            return false;
-        }
-
-        return true;
-    }
-
     private void executeSQLScript(Connection conn) throws Exception {
         StringBuffer sql = new StringBuffer();
         BufferedReader reader = null;
@@ -296,24 +191,6 @@ public class Initialize {
         }
     }
 
-    private void startDerbyInServerMode() {
-        try {
-            System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
-            server = new 
NetworkServerControl(InetAddress.getByName(Utils.getHost()),
-                    20000,
-                    Utils.getJDBCUser(), Utils.getJDBCPassword());
-            java.io.PrintWriter consoleWriter = new 
java.io.PrintWriter(System.out, true);
-            server.start(consoleWriter);
-        } catch (IOException e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        } catch (Exception e) {
-            logger.error("Unable to start Apache derby in the server mode! 
Check whether " +
-                    "specified port is available");
-        }
-
-    }
-
     public void stopDerbyServer() throws SQLException{
         try {
             server.shutdown();

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to