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

yasith pushed a commit to branch feat/server-collapse
in repository https://gitbox.apache.org/repos/asf/airavata.git

commit ac880848a78009bdf1bb01be7b6fd8768184e355
Author: yasithdev <[email protected]>
AuthorDate: Sat Mar 28 02:03:09 2026 -0500

    refactor: replace remaining Thrift client factories with direct injection
    
    Replace RegistryServiceClientFactory usages in SSHAccountManager,
    AiravataDataMigrator, KeyCloakSecurityManager, GatewayGroupsInitializer,
    OrchestratorServerHandler, and IamAdminServicesHandler with direct
    RegistryServerHandler instantiation. Remove 
SharingRegistryServiceClientFactory
    and update GroupManagerServiceHandler and SharingServiceDBEventHandler 
likewise.
---
 .../service/provisioning/SSHAccountManager.java    | 34 ++--------
 .../security/service/GatewayGroupsInitializer.java | 27 +++-----
 .../security/service/KeyCloakSecurityManager.java  | 21 ++----
 .../handler/SharingServiceDBEventHandler.java      | 13 ++--
 .../SharingServiceDBEventMessagingFactory.java     |  4 +-
 .../sharing/util/AiravataDataMigrator.java         | 27 +++-----
 .../util/SharingRegistryServiceClientFactory.java  | 47 -------------
 .../service/KeyCloakSecurityManagerTest.java       | 27 ++------
 .../thrift/handler/GroupManagerServiceHandler.java | 73 +++++++-------------
 .../thrift/handler/IamAdminServicesHandler.java    | 14 ++--
 .../thrift/handler/OrchestratorServerHandler.java  | 77 ++++++++--------------
 11 files changed, 92 insertions(+), 272 deletions(-)

diff --git 
a/airavata-api/src/main/java/org/apache/airavata/credential/service/provisioning/SSHAccountManager.java
 
b/airavata-api/src/main/java/org/apache/airavata/credential/service/provisioning/SSHAccountManager.java
index 5e59af5880..310ad23e03 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/credential/service/provisioning/SSHAccountManager.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/credential/service/provisioning/SSHAccountManager.java
@@ -24,11 +24,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-import org.apache.airavata.common.config.ServerSettings;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.credential.handler.CredentialStoreServerHandler;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import 
org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription;
 import 
org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface;
 import 
org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol;
@@ -38,7 +36,6 @@ import 
org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResou
 import org.apache.airavata.model.credential.store.PasswordCredential;
 import org.apache.airavata.model.credential.store.SSHCredential;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,7 +69,7 @@ public class SSHAccountManager {
     private static SSHAccountProvisioner getSshAccountProvisioner(String 
gatewayId, String computeResourceId)
             throws InvalidSetupException {
         // get compute resource preferences for the gateway and hostname
-        RegistryService.Client registryServiceClient = 
getRegistryServiceClient();
+        RegistryService.Iface registryServiceClient = 
getRegistryServiceClient();
         ComputeResourcePreference computeResourcePreference = null;
         try {
             computeResourcePreference =
@@ -82,13 +79,6 @@ public class SSHAccountManager {
                     "Failed to get ComputeResourcePreference for [" + 
gatewayId + "] and [" + computeResourceId + "]: "
                             + e.getMessage(),
                     e);
-        } finally {
-            if 
(registryServiceClient.getInputProtocol().getTransport().isOpen()) {
-                
registryServiceClient.getInputProtocol().getTransport().close();
-            }
-            if 
(registryServiceClient.getOutputProtocol().getTransport().isOpen()) {
-                
registryServiceClient.getOutputProtocol().getTransport().close();
-            }
         }
 
         // get the account provisioner and config values for the preferences
@@ -121,7 +111,7 @@ public class SSHAccountManager {
             throws InvalidSetupException, InvalidUsernameException {
 
         // get compute resource preferences for the gateway and hostname
-        RegistryService.Client registryServiceClient = 
getRegistryServiceClient();
+        RegistryService.Iface registryServiceClient = 
getRegistryServiceClient();
         ComputeResourcePreference computeResourcePreference = null;
         ComputeResourceDescription computeResourceDescription = null;
         SSHJobSubmission sshJobSubmission = null;
@@ -143,13 +133,6 @@ public class SSHAccountManager {
                     "Failed to retrieve compute resource information for [" + 
gatewayId + "] and " + "["
                             + computeResourceId + "]: " + e.getMessage(),
                     e);
-        } finally {
-            if 
(registryServiceClient.getInputProtocol().getTransport().isOpen()) {
-                
registryServiceClient.getInputProtocol().getTransport().close();
-            }
-            if 
(registryServiceClient.getOutputProtocol().getTransport().isOpen()) {
-                
registryServiceClient.getOutputProtocol().getTransport().close();
-            }
         }
 
         if (sshJobSubmission == null) {
@@ -299,15 +282,8 @@ public class SSHAccountManager {
         return result;
     }
 
-    private static RegistryService.Client getRegistryServiceClient() {
-
-        try {
-            String registryServerHost = ServerSettings.getRegistryServerHost();
-            int registryServerPort = 
Integer.valueOf(ServerSettings.getRegistryServerPort());
-            return 
RegistryServiceClientFactory.createRegistryClient(registryServerHost, 
registryServerPort);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
-            throw new RuntimeException("Failed to create registry service 
client", e);
-        }
+    private static RegistryService.Iface getRegistryServiceClient() {
+        return new RegistryServerHandler();
     }
 
     private static CredentialStoreService.Iface getCredentialStoreHandler() {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/security/service/GatewayGroupsInitializer.java
 
b/airavata-api/src/main/java/org/apache/airavata/security/service/GatewayGroupsInitializer.java
index f7cbad2c30..cf32de4afc 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/security/service/GatewayGroupsInitializer.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/security/service/GatewayGroupsInitializer.java
@@ -19,18 +19,15 @@
 */
 package org.apache.airavata.security.service;
 
-import org.apache.airavata.common.config.ServerSettings;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.util.AiravataUtils;
-import org.apache.airavata.common.util.ThriftUtils;
 import org.apache.airavata.credential.handler.CredentialStoreServerHandler;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups;
 import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
 import org.apache.airavata.model.credential.store.PasswordCredential;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
+
 import org.apache.airavata.sharing.handler.SharingRegistryServerHandler;
 import org.apache.airavata.sharing.registry.models.*;
 import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
@@ -53,7 +50,7 @@ public class GatewayGroupsInitializer {
         } catch (Exception e) {
             throw new RuntimeException("Failed to create 
SharingRegistryServerHandler", e);
         }
-        RegistryService.Client registryClient = createRegistryClient();
+        RegistryService.Iface registryClient = createRegistryClient();
         CredentialStoreService.Iface credentialStoreHandler = 
createCredentialStoreHandler();
         try {
             GatewayGroupsInitializer gatewayGroupsInitializer =
@@ -61,17 +58,15 @@ public class GatewayGroupsInitializer {
             return gatewayGroupsInitializer.initialize(gatewayId);
         } catch (Exception e) {
             throw new RuntimeException("Failed to initialize a GatewayGroups 
instance for gateway: " + gatewayId, e);
-        } finally {
-            ThriftUtils.close(registryClient);
         }
     }
 
-    private RegistryService.Client registryClient;
+    private RegistryService.Iface registryClient;
     private SharingRegistryService.Iface sharingRegistryClient;
     private CredentialStoreService.Iface credentialStoreClient;
 
     public GatewayGroupsInitializer(
-            RegistryService.Client registryClient,
+            RegistryService.Iface registryClient,
             SharingRegistryService.Iface sharingRegistryClient,
             CredentialStoreService.Iface credentialStoreClient) {
 
@@ -151,7 +146,7 @@ public class GatewayGroupsInitializer {
     }
 
     private String getAdminOwnerUsername(
-            RegistryService.Client registryClient,
+            RegistryService.Iface registryClient,
             CredentialStoreService.Iface credentialStoreClient,
             String gatewayId)
             throws TException {
@@ -163,14 +158,8 @@ public class GatewayGroupsInitializer {
         return adminUsername;
     }
 
-    private static RegistryService.Client createRegistryClient() {
-        try {
-            final int serverPort = 
Integer.parseInt(ServerSettings.getRegistryServerPort());
-            final String serverHost = ServerSettings.getRegistryServerHost();
-            return 
RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
-            throw new RuntimeException("Unable to create registry client...", 
e);
-        }
+    private static RegistryService.Iface createRegistryClient() {
+        return new RegistryServerHandler();
     }
 
     private static CredentialStoreService.Iface createCredentialStoreHandler() 
{
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/security/service/KeyCloakSecurityManager.java
 
b/airavata-api/src/main/java/org/apache/airavata/security/service/KeyCloakSecurityManager.java
index 55f737d255..8c3c292597 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/security/service/KeyCloakSecurityManager.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/security/service/KeyCloakSecurityManager.java
@@ -31,14 +31,13 @@ import java.util.regex.Pattern;
 import org.apache.airavata.common.config.Constants;
 import org.apache.airavata.common.config.ServerSettings;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.util.ThriftUtils;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups;
 import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
 import org.apache.airavata.model.security.AuthzToken;
 import org.apache.airavata.model.workspace.Gateway;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
+
 import org.apache.airavata.security.service.authzcache.*;
 import org.apache.airavata.security.util.AiravataSecurityException;
 import org.apache.airavata.sharing.handler.SharingRegistryServerHandler;
@@ -104,7 +103,7 @@ public class KeyCloakSecurityManager implements 
AiravataSecurityManager {
     private static final String INTERMEDIATE_OUTPUTS_METHODS =
             
"/airavata/fetchIntermediateOutputs|/airavata/getIntermediateOutputProcessStatus";
     private final HashMap<String, String> rolePermissionConfig = new 
HashMap<>();
-    private RegistryService.Client registryServiceClient = null;
+    private RegistryService.Iface registryServiceClient = null;
     private SharingRegistryService.Iface sharingRegistryServiceClient = null;
 
     public KeyCloakSecurityManager() throws AiravataSecurityException, 
ApplicationSettingsException {
@@ -386,19 +385,11 @@ public class KeyCloakSecurityManager implements 
AiravataSecurityManager {
     }
 
     private void closeServiceClients() {
-        if (registryServiceClient != null) {
-            ThriftUtils.close(registryServiceClient);
-        }
+        // No-op: handler is in-process, no transport to close
     }
 
-    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 TException("Unable to create registry client...", e);
-        }
+    private RegistryService.Iface getRegistryServiceClient() {
+        return new RegistryServerHandler();
     }
 
     private static class GatewayGroupMembership {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventHandler.java
 
b/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventHandler.java
index 0b45df4113..afcca2abf1 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventHandler.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventHandler.java
@@ -19,7 +19,6 @@
 */
 package org.apache.airavata.sharing.handler;
 
-import org.apache.airavata.common.config.ServerSettings;
 import org.apache.airavata.common.exception.AiravataException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.util.ThriftUtils;
@@ -35,10 +34,8 @@ import org.apache.airavata.model.workspace.Project;
 import org.apache.airavata.sharing.registry.models.Domain;
 import org.apache.airavata.sharing.registry.models.Entity;
 import org.apache.airavata.sharing.registry.models.PermissionType;
-import org.apache.airavata.sharing.registry.models.SharingRegistryException;
 import org.apache.airavata.sharing.registry.models.User;
 import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
-import org.apache.airavata.sharing.util.SharingRegistryServiceClientFactory;
 import org.apache.airavata.sharing.util.ThriftDataModelConversion;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -51,13 +48,11 @@ public class SharingServiceDBEventHandler implements 
MessageHandler {
 
     private static final Logger log = 
LoggerFactory.getLogger(SharingServiceDBEventHandler.class);
 
-    private final SharingRegistryService.Client sharingRegistryClient;
+    private final SharingRegistryService.Iface sharingRegistryClient;
 
-    SharingServiceDBEventHandler() throws ApplicationSettingsException, 
SharingRegistryException {
-        log.info("Starting sharing registry client.....");
-        sharingRegistryClient = 
SharingRegistryServiceClientFactory.createSharingRegistryClient(
-                ServerSettings.getSetting("sharing.registry.server.host"),
-                
Integer.parseInt(ServerSettings.getSetting("sharing.registry.server.port")));
+    SharingServiceDBEventHandler() throws ApplicationSettingsException, 
TException {
+        log.info("Initializing sharing registry handler.....");
+        sharingRegistryClient = new SharingRegistryServerHandler();
     }
 
     @Override
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventMessagingFactory.java
 
b/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventMessagingFactory.java
index 7f424ca68d..25dc362a45 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventMessagingFactory.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/sharing/handler/SharingServiceDBEventMessagingFactory.java
@@ -32,7 +32,7 @@ import 
org.apache.airavata.model.dbevent.DBEventMessageContext;
 import org.apache.airavata.model.dbevent.DBEventSubscriber;
 import org.apache.airavata.model.dbevent.DBEventType;
 import org.apache.airavata.model.messaging.event.MessageType;
-import org.apache.airavata.sharing.registry.models.SharingRegistryException;
+import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,7 +66,7 @@ public class SharingServiceDBEventMessagingFactory {
         return dbEventPublisher;
     }
 
-    public static Subscriber getDBEventSubscriber() throws AiravataException, 
SharingRegistryException {
+    public static Subscriber getDBEventSubscriber() throws AiravataException, 
TException {
         if (null == sharingServiceDBEventSubscriber) {
             synchronized (SharingServiceDBEventMessagingFactory.class) {
                 if (null == sharingServiceDBEventSubscriber) {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/sharing/util/AiravataDataMigrator.java
 
b/airavata-api/src/main/java/org/apache/airavata/sharing/util/AiravataDataMigrator.java
index a90a36ce18..4a19386f7a 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/sharing/util/AiravataDataMigrator.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/sharing/util/AiravataDataMigrator.java
@@ -30,12 +30,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
-import org.apache.airavata.common.config.ServerSettings;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.util.AiravataUtils;
 import org.apache.airavata.credential.handler.CredentialStoreServerHandler;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import 
org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription;
 import 
org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription;
 import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups;
@@ -55,7 +54,7 @@ import org.apache.airavata.model.security.AuthzToken;
 import org.apache.airavata.model.user.Status;
 import org.apache.airavata.model.user.UserProfile;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
+
 import 
org.apache.airavata.security.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl;
 import org.apache.airavata.security.service.AiravataSecurityManager;
 import org.apache.airavata.security.service.SecurityManagerFactory;
@@ -223,7 +222,7 @@ public class AiravataDataMigrator {
 
         // Creating the gateway groups
         List<Domain> domainList = sharingRegistryServerHandler.getDomains(0, 
-1);
-        final RegistryService.Client registryServiceClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryServiceClient = 
getRegistryServiceClient();
         for (Domain domain : domainList) {
             // If we're only running migration for gatewayId, then skip other 
gateways
             if (gatewayId != null && !gatewayId.equals(domain.getDomainId())) {
@@ -614,7 +613,7 @@ public class AiravataDataMigrator {
             Domain domain,
             String ownerId,
             SharingRegistryServerHandler sharingRegistryServerHandler,
-            RegistryService.Client registryServiceClient)
+            RegistryService.Iface registryServiceClient)
             throws TException, ApplicationSettingsException {
         GatewayGroups gatewayGroups = new GatewayGroups();
         gatewayGroups.setGatewayId(domain.getDomainId());
@@ -662,7 +661,7 @@ public class AiravataDataMigrator {
             Domain domain,
             SharingRegistryServerHandler sharingRegistryServerHandler,
             CredentialStoreService.Iface credentialStoreServiceClient,
-            RegistryService.Client registryServiceClient)
+            RegistryService.Iface registryServiceClient)
             throws TException {
         GatewayResourceProfile gatewayResourceProfile = null;
         try {
@@ -767,7 +766,7 @@ public class AiravataDataMigrator {
     private static boolean needsGroupResourceProfileMigration(
             String gatewayId,
             String domainOwnerId,
-            RegistryService.Client registryServiceClient,
+            RegistryService.Iface registryServiceClient,
             SharingRegistryServerHandler sharingRegistryServerHandler)
             throws TException {
         // Return true if GatewayResourceProfile has at least one 
ComputeResourcePreference and there is no
@@ -790,7 +789,7 @@ public class AiravataDataMigrator {
     }
 
     private static GroupResourceProfile 
migrateGatewayResourceProfileToGroupResourceProfile(
-            String gatewayId, RegistryService.Client registryServiceClient) 
throws TException {
+            String gatewayId, RegistryService.Iface registryServiceClient) 
throws TException {
 
         GroupResourceProfile groupResourceProfile = new GroupResourceProfile();
         groupResourceProfile.setGatewayId(gatewayId);
@@ -873,7 +872,7 @@ public class AiravataDataMigrator {
     }
 
     private static ComputeResourcePolicy createDefaultComputeResourcePolicy(
-            String groupResourceProfileId, String computeResourceId, 
RegistryService.Client registryServiceClient)
+            String groupResourceProfileId, String computeResourceId, 
RegistryService.Iface registryServiceClient)
             throws TException {
         ComputeResourcePolicy computeResourcePolicy = new 
ComputeResourcePolicy();
         computeResourcePolicy.setComputeResourceId(computeResourceId);
@@ -908,14 +907,8 @@ public class AiravataDataMigrator {
         }
     }
 
-    private static 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 TException("Unable to create registry client...", e);
-        }
+    private static RegistryService.Iface getRegistryServiceClient() {
+        return new RegistryServerHandler();
     }
 
 
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/sharing/util/SharingRegistryServiceClientFactory.java
 
b/airavata-api/src/main/java/org/apache/airavata/sharing/util/SharingRegistryServiceClientFactory.java
deleted file mode 100644
index c9fa4c1de4..0000000000
--- 
a/airavata-api/src/main/java/org/apache/airavata/sharing/util/SharingRegistryServiceClientFactory.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.sharing.util;
-
-import org.apache.airavata.sharing.registry.models.SharingRegistryException;
-import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TMultiplexedProtocol;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.transport.TSocket;
-import org.apache.thrift.transport.TTransportException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SharingRegistryServiceClientFactory {
-    private static final Logger logger = 
LoggerFactory.getLogger(SharingRegistryServiceClientFactory.class);
-
-    public static SharingRegistryService.Client 
createSharingRegistryClient(String serverHost, int serverPort)
-            throws SharingRegistryException {
-        try {
-            TSocket socket = new TSocket(serverHost, serverPort);
-            socket.open();
-            TProtocol protocol = new TMultiplexedProtocol(new 
TBinaryProtocol(socket), "SharingRegistry");
-            return new SharingRegistryService.Client(protocol);
-        } catch (TTransportException e) {
-            logger.error("failed to create sharing registry client", e);
-            throw new SharingRegistryException();
-        }
-    }
-}
diff --git 
a/airavata-api/src/test/java/org/apache/airavata/security/service/KeyCloakSecurityManagerTest.java
 
b/airavata-api/src/test/java/org/apache/airavata/security/service/KeyCloakSecurityManagerTest.java
index 9e41b66f2c..0a4a4ebe3a 100644
--- 
a/airavata-api/src/test/java/org/apache/airavata/security/service/KeyCloakSecurityManagerTest.java
+++ 
b/airavata-api/src/test/java/org/apache/airavata/security/service/KeyCloakSecurityManagerTest.java
@@ -35,18 +35,17 @@ import mockit.Mocked;
 import org.apache.airavata.common.config.Constants;
 import org.apache.airavata.common.config.ServerSettings;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups;
 import org.apache.airavata.model.security.AuthzToken;
-import org.apache.airavata.registry.api.RegistryService;
 import org.apache.airavata.security.service.authzcache.AuthzCacheIndex;
 import org.apache.airavata.security.service.authzcache.AuthzCacheManager;
 import 
org.apache.airavata.security.service.authzcache.AuthzCacheManagerFactory;
 import org.apache.airavata.security.service.authzcache.AuthzCachedStatus;
 import org.apache.airavata.security.util.AiravataSecurityException;
+import org.apache.airavata.sharing.handler.SharingRegistryServerHandler;
 import org.apache.airavata.sharing.registry.models.UserGroup;
 import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
-import org.apache.airavata.sharing.util.SharingRegistryServiceClientFactory;
 import org.apache.thrift.TException;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -61,16 +60,10 @@ public class KeyCloakSecurityManagerTest {
     private ServerSettings mockServerSettings;
 
     @Mocked
-    private RegistryServiceClientFactory mockRegistryServiceClientFactory;
+    private RegistryServerHandler mockRegistryServiceClient;
 
     @Mocked
-    private RegistryService.Client mockRegistryServiceClient;
-
-    @Mocked
-    private SharingRegistryServiceClientFactory 
mockSharingRegistryServiceClientFactory;
-
-    @Mocked
-    private SharingRegistryService.Client mockSharingRegistryServiceClient;
+    private SharingRegistryServerHandler mockSharingRegistryServiceClient;
 
     @Mocked
     private AuthzCacheManagerFactory mockAuthzCacheManagerFactory;
@@ -84,18 +77,6 @@ public class KeyCloakSecurityManagerTest {
             {
                 mockServerSettings.isTLSEnabled();
                 result = true;
-                mockServerSettings.getRegistryServerHost();
-                result = "localhost";
-                minTimes = 0;
-                mockServerSettings.getRegistryServerPort();
-                result = "8970";
-                minTimes = 0;
-                mockServerSettings.getSharingRegistryHost();
-                result = "localhost";
-                minTimes = 0;
-                mockServerSettings.getSharingRegistryPort();
-                result = "7878";
-                minTimes = 0;
                 mockServerSettings.getRemoteIDPServiceUrl();
                 result = "https://iam.server/auth";;
                 minTimes = 0;
diff --git 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/GroupManagerServiceHandler.java
 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/GroupManagerServiceHandler.java
index fd6c81e09c..564371e4c6 100644
--- 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/GroupManagerServiceHandler.java
+++ 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/GroupManagerServiceHandler.java
@@ -24,8 +24,6 @@ import java.util.List;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import org.apache.airavata.common.config.Constants;
-import org.apache.airavata.common.config.ServerSettings;
-import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.model.error.AuthorizationException;
 import org.apache.airavata.model.group.GroupModel;
 import org.apache.airavata.model.security.AuthzToken;
@@ -37,11 +35,10 @@ import 
org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManag
 import 
org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
 import org.apache.airavata.sharing.registry.models.GroupCardinality;
 import org.apache.airavata.sharing.registry.models.GroupType;
-import org.apache.airavata.sharing.registry.models.SharingRegistryException;
+import org.apache.airavata.sharing.handler.SharingRegistryServerHandler;
 import org.apache.airavata.sharing.registry.models.User;
 import org.apache.airavata.sharing.registry.models.UserGroup;
 import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
-import org.apache.airavata.sharing.util.SharingRegistryServiceClientFactory;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,8 +50,11 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     private static final Logger logger = 
LoggerFactory.getLogger(GroupManagerServiceHandler.class);
 
     private UserProfileRepository userProfileRepository = new 
UserProfileRepository();
+    private final SharingRegistryService.Iface sharingHandler;
 
-    public GroupManagerServiceHandler() {}
+    public GroupManagerServiceHandler(SharingRegistryServerHandler 
sharingHandler) {
+        this.sharingHandler = sharingHandler;
+    }
 
     @Override
     public String getAPIVersion() throws TException {
@@ -67,7 +67,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
             // TODO Validations for authorization
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
 
             UserGroup sharingUserGroup = new UserGroup();
             sharingUserGroup.setGroupId(UUID.randomUUID().toString());
@@ -97,7 +97,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), 
userId)
@@ -129,7 +129,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean deleteGroup(AuthzToken authzToken, String groupId, String 
ownerId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) {
@@ -152,7 +152,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public GroupModel getGroup(AuthzToken authzToken, String groupId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             final String domainId = getDomainId(authzToken);
             UserGroup userGroup = sharingClient.getGroup(domainId, groupId);
 
@@ -173,20 +173,16 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public List<GroupModel> getGroups(AuthzToken authzToken)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         final String domainId = getDomainId(authzToken);
-        SharingRegistryService.Client sharingClient = null;
         try {
-            sharingClient = getSharingRegistryServiceClient();
-            List<UserGroup> userGroups = sharingClient.getGroups(domainId, 0, 
-1);
+            List<UserGroup> userGroups = sharingHandler.getGroups(domainId, 0, 
-1);
 
-            return convertToGroupModels(userGroups, sharingClient);
+            return convertToGroupModels(userGroups, sharingHandler);
         } catch (Exception e) {
             String msg = "Error Retrieving Groups. Domain ID: " + domainId;
             logger.error(msg, e);
             GroupManagerServiceException exception = new 
GroupManagerServiceException();
             exception.setMessage(msg + " More info : " + e.getMessage());
             throw exception;
-        } finally {
-            closeSharingClient(sharingClient);
         }
     }
 
@@ -195,7 +191,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public List<GroupModel> getAllGroupsUserBelongs(AuthzToken authzToken, 
String userName)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             List<GroupModel> groupModels = new ArrayList<GroupModel>();
             final String domainId = getDomainId(authzToken);
             List<UserGroup> userGroups = 
sharingClient.getAllMemberGroupsForUser(domainId, userName);
@@ -214,7 +210,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean addUsersToGroup(AuthzToken authzToken, List<String> 
userIds, String groupId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId)
@@ -236,7 +232,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean removeUsersFromGroup(AuthzToken authzToken, List<String> 
userIds, String groupId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId)
@@ -258,7 +254,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean transferGroupOwnership(AuthzToken authzToken, String 
groupId, String newOwnerId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) {
@@ -280,7 +276,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean addGroupAdmins(AuthzToken authzToken, String groupId, 
List<String> adminIds)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) {
@@ -301,7 +297,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, 
List<String> adminIds)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             String userId = getUserId(authzToken);
             String domainId = getDomainId(authzToken);
             if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) {
@@ -322,7 +318,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean hasAdminAccess(AuthzToken authzToken, String groupId, 
String adminId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             return sharingClient.hasAdminAccess(getDomainId(authzToken), 
groupId, adminId);
         } catch (Exception e) {
             String msg = "Error Checking Admin Access for the Group. Group ID: 
" + groupId + " Admin ID: " + adminId;
@@ -338,7 +334,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, 
String ownerId)
             throws GroupManagerServiceException, AuthorizationException, 
TException {
         try {
-            SharingRegistryService.Client sharingClient = 
getSharingRegistryServiceClient();
+            SharingRegistryService.Iface sharingClient = sharingHandler;
             return sharingClient.hasOwnerAccess(getDomainId(authzToken), 
groupId, ownerId);
         } catch (Exception e) {
             String msg = "Error Checking Owner Access for the Group. Group ID: 
" + groupId + " Owner ID: " + ownerId;
@@ -349,18 +345,6 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
         }
     }
 
-    // TODO: replace these methods with ThriftClientPool (see AIRAVATA-2607)
-    private SharingRegistryService.Client getSharingRegistryServiceClient()
-            throws TException, ApplicationSettingsException {
-        final int serverPort = 
Integer.parseInt(ServerSettings.getSharingRegistryPort());
-        final String serverHost = ServerSettings.getSharingRegistryHost();
-        try {
-            return 
SharingRegistryServiceClientFactory.createSharingRegistryClient(serverHost, 
serverPort);
-        } catch (SharingRegistryException e) {
-            throw new TException("Unable to create sharing registry 
client...", e);
-        }
-    }
-
     private String getDomainId(AuthzToken authzToken) {
         return authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
     }
@@ -370,7 +354,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
     }
 
     private List<GroupModel> convertToGroupModels(
-            List<UserGroup> userGroups, SharingRegistryService.Client 
sharingClient) throws TException {
+            List<UserGroup> userGroups, SharingRegistryService.Iface 
sharingClient) throws TException {
 
         List<GroupModel> groupModels = new ArrayList<>();
 
@@ -382,7 +366,7 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
         return groupModels;
     }
 
-    private GroupModel convertToGroupModel(UserGroup userGroup, 
SharingRegistryService.Client sharingClient)
+    private GroupModel convertToGroupModel(UserGroup userGroup, 
SharingRegistryService.Iface sharingClient)
             throws TException {
         GroupModel groupModel = new GroupModel();
         groupModel.setId(userGroup.getGroupId());
@@ -399,20 +383,9 @@ public class GroupManagerServiceHandler implements 
GroupManagerService.Iface {
         return groupModel;
     }
 
-    private void closeSharingClient(SharingRegistryService.Client 
sharingClient) {
-        if (sharingClient != null) {
-            if (sharingClient.getInputProtocol().getTransport().isOpen()) {
-                sharingClient.getInputProtocol().getTransport().close();
-            }
-            if (sharingClient.getOutputProtocol().getTransport().isOpen()) {
-                sharingClient.getOutputProtocol().getTransport().close();
-            }
-        }
-    }
-
     private boolean internalAddUsersToGroup(
-            SharingRegistryService.Client sharingClient, String domainId, 
List<String> userIds, String groupId)
-            throws SharingRegistryException, TException {
+            SharingRegistryService.Iface sharingClient, String domainId, 
List<String> userIds, String groupId)
+            throws TException {
 
         // FIXME: workaround for UserProfiles that failed to sync to the 
sharing
         // registry: create any missing users in the sharing registry
diff --git 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/IamAdminServicesHandler.java
 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/IamAdminServicesHandler.java
index bfd2a1704b..aacd330b92 100644
--- 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/IamAdminServicesHandler.java
+++ 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/IamAdminServicesHandler.java
@@ -27,7 +27,7 @@ import 
org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.util.AiravataUtils;
 import org.apache.airavata.credential.handler.CredentialStoreServerHandler;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import org.apache.airavata.messaging.util.DBEventPublisherUtils;
 import org.apache.airavata.messaging.util.DBEventService;
 import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
@@ -39,7 +39,7 @@ import org.apache.airavata.model.security.AuthzToken;
 import org.apache.airavata.model.user.UserProfile;
 import org.apache.airavata.model.workspace.Gateway;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.exception.RegistryServiceException;
+
 import 
org.apache.airavata.security.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl;
 import 
org.apache.airavata.security.profile.user.core.repositories.UserProfileRepository;
 import org.apache.airavata.security.service.interceptor.SecurityCheck;
@@ -346,14 +346,8 @@ public class IamAdminServicesHandler implements 
IamAdminServices.Iface {
         return 
csClient.getPasswordCredential(gwrp.getIdentityServerPwdCredToken(), 
gwrp.getGatewayID());
     }
 
-    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 TException("Unable to create registry client...", e);
-        }
+    private RegistryService.Iface getRegistryServiceClient() {
+        return new RegistryServerHandler();
     }
 
     private CredentialStoreService.Iface getCredentialStoreHandler() throws 
TException {
diff --git 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/OrchestratorServerHandler.java
 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/OrchestratorServerHandler.java
index 359f2c2a8d..4989f289a6 100644
--- 
a/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/OrchestratorServerHandler.java
+++ 
b/airavata-server/thrift/src/main/java/org/apache/airavata/server/thrift/handler/OrchestratorServerHandler.java
@@ -38,7 +38,7 @@ import 
org.apache.airavata.execution.orchestrator.SimpleOrchestratorImpl;
 import org.apache.airavata.execution.scheduler.ProcessScheduler;
 import org.apache.airavata.execution.scheduler.ProcessSchedulerImpl;
 import org.apache.airavata.execution.util.ExperimentModelUtil;
-import org.apache.airavata.execution.util.RegistryServiceClientFactory;
+import org.apache.airavata.execution.handler.RegistryServerHandler;
 import org.apache.airavata.messaging.service.*;
 import org.apache.airavata.messaging.util.*;
 import 
org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription;
@@ -63,7 +63,6 @@ import org.apache.airavata.model.status.*;
 import org.apache.airavata.model.task.TaskTypes;
 import org.apache.airavata.orchestrator.cpi.OrchestratorService;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.RegistryService.Client;
 import org.apache.airavata.registry.api.exception.RegistryServiceException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.curator.RetryPolicy;
@@ -141,7 +140,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
      */
     public boolean launchExperiment(String experimentId, String gatewayId) 
throws TException {
         ExperimentModel experiment = null;
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             // TODO deprecate this approach as we are replacing gfac
             String experimentNodePath = getExperimentNodePath(experimentId);
@@ -308,9 +307,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
             
OrchestratorServerUtils.updateAndPublishExperimentStatus(experimentId, status, 
publisher, gatewayId);
             throw new TException("Experiment '" + experimentId + "' launch 
failed.", e);
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
         return true;
     }
@@ -325,7 +322,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
      * @throws TException
      */
     public boolean validateExperiment(String experimentId) throws TException, 
LaunchValidationException {
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
             return 
orchestrator.validateExperiment(experimentModel).isValidationState();
@@ -333,16 +330,14 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
             log.error(experimentId, "Error while validating experiment", e);
             throw new TException(e);
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
     @Override
     public boolean validateProcess(String experimentId, List<ProcessModel> 
processes)
             throws LaunchValidationException, TException {
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
             for (ProcessModel processModel : processes) {
@@ -366,9 +361,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
             log.error(experimentId, "Error while validating process", e);
             throw new TException(e);
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
@@ -381,7 +374,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
      * @throws TException
      */
     public boolean terminateExperiment(String experimentId, String gatewayId) 
throws TException {
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         log.info(experimentId, "Experiment: {} is cancelling  !!!!!", 
experimentId);
         try {
             return validateStatesAndCancel(registryClient, experimentId, 
gatewayId);
@@ -389,28 +382,24 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
             log.error("expId : " + experimentId + " :- Error while cancelling 
experiment", e);
             return false;
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
     public void fetchIntermediateOutputs(String experimentId, String 
gatewayId, List<String> outputNames)
             throws TException {
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             submitIntermediateOutputsProcess(registryClient, experimentId, 
gatewayId, outputNames);
         } catch (Exception e) {
             log.error("expId : " + experimentId + " :- Error while fetching 
intermediate", e);
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
     private void submitIntermediateOutputsProcess(
-            Client registryClient, String experimentId, String gatewayId, 
List<String> outputNames) throws Exception {
+            RegistryService.Iface registryClient, String experimentId, String 
gatewayId, List<String> outputNames) throws Exception {
 
         ExperimentModel experimentModel = 
registryClient.getExperiment(experimentId);
         ProcessModel processModel = 
ExperimentModelUtil.cloneProcessFromExperiment(experimentModel);
@@ -506,7 +495,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
 
     @Override
     public boolean launchProcess(String processId, String 
airavataCredStoreToken, String gatewayId) throws TException {
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             ProcessStatus processStatus = 
registryClient.getProcessStatus(processId);
 
@@ -547,14 +536,12 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
             log.error(processId, "Error while launching process ", e);
             throw new TException(e);
         } finally {
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
     private ApplicationDeploymentDescription getAppDeployment(
-            RegistryService.Client registryClient, ProcessModel processModel, 
String applicationId)
+            RegistryService.Iface registryClient, ProcessModel processModel, 
String applicationId)
             throws OrchestratorException, ClassNotFoundException, 
ApplicationSettingsException, InstantiationException,
                     IllegalAccessException, TException {
         String selectedModuleId = getModuleId(registryClient, applicationId);
@@ -562,7 +549,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
     }
 
     private ApplicationDeploymentDescription getAppDeploymentForModule(
-            RegistryService.Client registryClient, ProcessModel processModel, 
String selectedModuleId)
+            RegistryService.Iface registryClient, ProcessModel processModel, 
String selectedModuleId)
             throws ClassNotFoundException, ApplicationSettingsException, 
InstantiationException, IllegalAccessException,
                     TException {
 
@@ -587,7 +574,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         return deploymentMap.get(ComputeResourceDescription);
     }
 
-    private String getModuleId(RegistryService.Client registryClient, String 
applicationId)
+    private String getModuleId(RegistryService.Iface registryClient, String 
applicationId)
             throws OrchestratorException, TException {
         ApplicationInterfaceDescription applicationInterface = 
registryClient.getApplicationInterface(applicationId);
         List<String> applicationModules = 
applicationInterface.getApplicationModules();
@@ -600,7 +587,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
     }
 
     private boolean validateStatesAndCancel(
-            RegistryService.Client registryClient, String experimentId, String 
gatewayId) throws Exception {
+            RegistryService.Iface registryClient, String experimentId, String 
gatewayId) throws Exception {
         ExperimentStatus experimentStatus = 
registryClient.getExperimentStatus(experimentId);
         switch (experimentStatus.getState()) {
             case COMPLETED:
@@ -700,7 +687,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         }
 
         private boolean launchSingleAppExperiment() throws TException, 
AiravataException {
-            final RegistryService.Client registryClient = 
getRegistryServiceClient();
+            final RegistryService.Iface registryClient = 
getRegistryServiceClient();
             try {
                 List<String> processIds = 
registryClient.getProcessIds(experimentId);
                 for (String processId : processIds) {
@@ -727,10 +714,6 @@ 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;
         }
@@ -841,7 +824,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
                             status.setState(ExperimentState.SCHEDULED);
                             status.setReason("Job submission failed,  requeued 
to resubmit");
                             List<QueueStatusModel> queueStatusModels = new 
ArrayList<>();
-                            final RegistryService.Client registryClient = 
getRegistryServiceClient();
+                            final RegistryService.Iface registryClient = 
getRegistryServiceClient();
                             ExperimentModel experimentModel =
                                     
registryClient.getExperiment(processIdentity.getExperimentId());
                             UserConfigurationDataModel 
userConfigurationDataModel =
@@ -969,7 +952,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
 
     private void launchExperiment(MessageContext messageContext) {
         ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent();
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         try {
             byte[] bytes = 
ThriftUtils.serializeThriftObject(messageContext.getEvent());
             ThriftUtils.createThriftFromBytes(bytes, expEvent);
@@ -1004,20 +987,12 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
         } finally {
             experimentSubscriber.sendAck(messageContext.getDeliveryTag());
             MDC.clear();
-            if (registryClient != null) {
-                ThriftUtils.close(registryClient);
-            }
+            // No-op: handler is in-process, no transport to close
         }
     }
 
-    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);
-        }
+    private RegistryService.Iface getRegistryServiceClient() {
+        return new RegistryServerHandler();
     }
 
     private void startCurator() throws ApplicationSettingsException {
@@ -1043,7 +1018,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
 
     private void launchQueuedExperiment(String experimentId) throws 
TException, Exception {
         ExperimentModel experiment = null;
-        final RegistryService.Client registryClient = 
getRegistryServiceClient();
+        final RegistryService.Iface registryClient = 
getRegistryServiceClient();
         // TODO deprecate this approach as we are replacing gfac
         experiment = registryClient.getExperiment(experimentId);
         if (experiment == null) {
@@ -1081,7 +1056,7 @@ public class OrchestratorServerHandler implements 
OrchestratorService.Iface {
     }
 
     private void createAndValidateTasks(
-            ExperimentModel experiment, RegistryService.Client registryClient, 
boolean recreateTaskDag)
+            ExperimentModel experiment, RegistryService.Iface registryClient, 
boolean recreateTaskDag)
             throws Exception {
         if (experiment.getUserConfigurationData().isAiravataAutoSchedule()) {
             List<ProcessModel> processModels = 
registryClient.getProcessList(experiment.getExperimentId());

Reply via email to