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

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

commit e5ccf733f8cffb0f02ed32a622d7aba1dbc15e36
Author: yasithdev <[email protected]>
AuthorDate: Thu Mar 26 10:57:45 2026 -0500

    feat: add GatewayResourceProfileService
    
    Extracts all gateway resource profile operations (CRUD, compute/storage
    preferences, SSH account provisioners) from AiravataServerHandler into
    GatewayResourceProfileService. Rewires handler methods to ThriftAdapter
    one-liners.
---
 .../GatewayResourceProfileService.java             | 205 +++++++++++++++++++++
 .../GatewayResourceProfileServiceTest.java         | 127 +++++++++++++
 2 files changed, 332 insertions(+)

diff --git 
a/airavata-api/src/main/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileService.java
 
b/airavata-api/src/main/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileService.java
new file mode 100644
index 0000000000..b3fd6b90c9
--- /dev/null
+++ 
b/airavata-api/src/main/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileService.java
@@ -0,0 +1,205 @@
+package org.apache.airavata.service.resourceprofile;
+
+import org.apache.airavata.accountprovisioning.ConfigParam;
+import org.apache.airavata.accountprovisioning.SSHAccountProvisionerFactory;
+import org.apache.airavata.accountprovisioning.SSHAccountProvisionerProvider;
+import 
org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisioner;
+import 
org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisionerConfigParam;
+import 
org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisionerConfigParamType;
+import 
org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
+import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
+import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
+import org.apache.airavata.registry.api.service.handler.RegistryServerHandler;
+import org.apache.airavata.service.context.RequestContext;
+import org.apache.airavata.service.exception.ServiceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GatewayResourceProfileService {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(GatewayResourceProfileService.class);
+
+    private final RegistryServerHandler registryHandler;
+
+    public GatewayResourceProfileService(RegistryServerHandler 
registryHandler) {
+        this.registryHandler = registryHandler;
+    }
+
+    public String registerGatewayResourceProfile(RequestContext ctx, 
GatewayResourceProfile gatewayResourceProfile)
+            throws ServiceException {
+        try {
+            return 
registryHandler.registerGatewayResourceProfile(gatewayResourceProfile);
+        } catch (Exception e) {
+            throw new ServiceException("Error while registering gateway 
resource profile: " + e.getMessage(), e);
+        }
+    }
+
+    public GatewayResourceProfile getGatewayResourceProfile(RequestContext 
ctx, String gatewayId)
+            throws ServiceException {
+        try {
+            return registryHandler.getGatewayResourceProfile(gatewayId);
+        } catch (Exception e) {
+            throw new ServiceException("Error while retrieving gateway 
resource profile: " + e.getMessage(), e);
+        }
+    }
+
+    public boolean updateGatewayResourceProfile(RequestContext ctx, String 
gatewayId,
+            GatewayResourceProfile gatewayResourceProfile) throws 
ServiceException {
+        try {
+            return registryHandler.updateGatewayResourceProfile(gatewayId, 
gatewayResourceProfile);
+        } catch (Exception e) {
+            throw new ServiceException("Error while updating gateway resource 
profile: " + e.getMessage(), e);
+        }
+    }
+
+    public boolean deleteGatewayResourceProfile(RequestContext ctx, String 
gatewayId) throws ServiceException {
+        try {
+            return registryHandler.deleteGatewayResourceProfile(gatewayId);
+        } catch (Exception e) {
+            throw new ServiceException("Error while deleting gateway resource 
profile: " + e.getMessage(), e);
+        }
+    }
+
+    public boolean addGatewayComputeResourcePreference(RequestContext ctx, 
String gatewayId,
+            String computeResourceId, ComputeResourcePreference 
computeResourcePreference) throws ServiceException {
+        try {
+            return registryHandler.addGatewayComputeResourcePreference(
+                    gatewayId, computeResourceId, computeResourcePreference);
+        } catch (Exception e) {
+            throw new ServiceException(
+                    "Error while adding gateway compute resource preference: " 
+ e.getMessage(), e);
+        }
+    }
+
+    public ComputeResourcePreference 
getGatewayComputeResourcePreference(RequestContext ctx, String gatewayId,
+            String computeResourceId) throws ServiceException {
+        try {
+            return 
registryHandler.getGatewayComputeResourcePreference(gatewayId, 
computeResourceId);
+        } catch (Exception e) {
+            throw new ServiceException(
+                    "Error while reading gateway compute resource preference: 
" + e.getMessage(), e);
+        }
+    }
+
+    public boolean updateGatewayComputeResourcePreference(RequestContext ctx, 
String gatewayId,
+            String computeResourceId, ComputeResourcePreference 
computeResourcePreference) throws ServiceException {
+        try {
+            return registryHandler.updateGatewayComputeResourcePreference(
+                    gatewayId, computeResourceId, computeResourcePreference);
+        } catch (Exception e) {
+            throw new ServiceException(
+                    "Error while updating gateway compute resource preference: 
" + e.getMessage(), e);
+        }
+    }
+
+    public boolean deleteGatewayComputeResourcePreference(RequestContext ctx, 
String gatewayId,
+            String computeResourceId) throws ServiceException {
+        try {
+            return 
registryHandler.deleteGatewayComputeResourcePreference(gatewayId, 
computeResourceId);
+        } catch (Exception e) {
+            throw new ServiceException(
+                    "Error while deleting gateway compute resource preference: 
" + e.getMessage(), e);
+        }
+    }
+
+    public boolean addGatewayStoragePreference(RequestContext ctx, String 
gatewayId,
+            String storageResourceId, StoragePreference storagePreference) 
throws ServiceException {
+        try {
+            return registryHandler.addGatewayStoragePreference(gatewayId, 
storageResourceId, storagePreference);
+        } catch (Exception e) {
+            throw new ServiceException("Error while adding gateway storage 
preference: " + e.getMessage(), e);
+        }
+    }
+
+    public StoragePreference getGatewayStoragePreference(RequestContext ctx, 
String gatewayId,
+            String storageId) throws ServiceException {
+        try {
+            return registryHandler.getGatewayStoragePreference(gatewayId, 
storageId);
+        } catch (Exception e) {
+            throw new ServiceException("Error while reading gateway storage 
preference: " + e.getMessage(), e);
+        }
+    }
+
+    public boolean updateGatewayStoragePreference(RequestContext ctx, String 
gatewayId,
+            String storageId, StoragePreference storagePreference) throws 
ServiceException {
+        try {
+            return registryHandler.updateGatewayStoragePreference(gatewayId, 
storageId, storagePreference);
+        } catch (Exception e) {
+            throw new ServiceException("Error while updating gateway storage 
preference: " + e.getMessage(), e);
+        }
+    }
+
+    public boolean deleteGatewayStoragePreference(RequestContext ctx, String 
gatewayId,
+            String storageId) throws ServiceException {
+        try {
+            return registryHandler.deleteGatewayStoragePreference(gatewayId, 
storageId);
+        } catch (Exception e) {
+            throw new ServiceException("Error while deleting gateway storage 
preference: " + e.getMessage(), e);
+        }
+    }
+
+    public List<ComputeResourcePreference> 
getAllGatewayComputeResourcePreferences(RequestContext ctx,
+            String gatewayId) throws ServiceException {
+        try {
+            return 
registryHandler.getAllGatewayComputeResourcePreferences(gatewayId);
+        } catch (Exception e) {
+            throw new ServiceException(
+                    "Error while reading gateway compute resource preferences: 
" + e.getMessage(), e);
+        }
+    }
+
+    public List<StoragePreference> 
getAllGatewayStoragePreferences(RequestContext ctx,
+            String gatewayId) throws ServiceException {
+        try {
+            return registryHandler.getAllGatewayStoragePreferences(gatewayId);
+        } catch (Exception e) {
+            throw new ServiceException("Error while reading gateway storage 
preferences: " + e.getMessage(), e);
+        }
+    }
+
+    public List<GatewayResourceProfile> 
getAllGatewayResourceProfiles(RequestContext ctx) throws ServiceException {
+        try {
+            return registryHandler.getAllGatewayResourceProfiles();
+        } catch (Exception e) {
+            throw new ServiceException("Error while retrieving all gateway 
resource profiles: " + e.getMessage(), e);
+        }
+    }
+
+    public List<SSHAccountProvisioner> 
getSSHAccountProvisioners(RequestContext ctx) throws ServiceException {
+        try {
+            List<SSHAccountProvisioner> sshAccountProvisioners = new 
ArrayList<>();
+            List<SSHAccountProvisionerProvider> providers =
+                    
SSHAccountProvisionerFactory.getSSHAccountProvisionerProviders();
+            for (SSHAccountProvisionerProvider provider : providers) {
+                SSHAccountProvisioner provisioner = new 
SSHAccountProvisioner();
+                provisioner.setCanCreateAccount(provider.canCreateAccount());
+                provisioner.setCanInstallSSHKey(provider.canInstallSSHKey());
+                provisioner.setName(provider.getName());
+                List<SSHAccountProvisionerConfigParam> configParams = new 
ArrayList<>();
+                for (ConfigParam configParam : provider.getConfigParams()) {
+                    SSHAccountProvisionerConfigParam param = new 
SSHAccountProvisionerConfigParam();
+                    param.setName(configParam.getName());
+                    param.setDescription(configParam.getDescription());
+                    param.setIsOptional(configParam.isOptional());
+                    switch (configParam.getType()) {
+                        case STRING:
+                            
param.setType(SSHAccountProvisionerConfigParamType.STRING);
+                            break;
+                        case CRED_STORE_PASSWORD_TOKEN:
+                            
param.setType(SSHAccountProvisionerConfigParamType.CRED_STORE_PASSWORD_TOKEN);
+                            break;
+                    }
+                    configParams.add(param);
+                }
+                provisioner.setConfigParams(configParams);
+                sshAccountProvisioners.add(provisioner);
+            }
+            return sshAccountProvisioners;
+        } catch (Exception e) {
+            throw new ServiceException("Error while retrieving SSH account 
provisioners: " + e.getMessage(), e);
+        }
+    }
+}
diff --git 
a/airavata-api/src/test/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileServiceTest.java
 
b/airavata-api/src/test/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileServiceTest.java
new file mode 100644
index 0000000000..2979e622eb
--- /dev/null
+++ 
b/airavata-api/src/test/java/org/apache/airavata/service/resourceprofile/GatewayResourceProfileServiceTest.java
@@ -0,0 +1,127 @@
+package org.apache.airavata.service.resourceprofile;
+
+import 
org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
+import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
+import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
+import org.apache.airavata.registry.api.service.handler.RegistryServerHandler;
+import org.apache.airavata.service.context.RequestContext;
+import org.apache.airavata.service.exception.ServiceException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+class GatewayResourceProfileServiceTest {
+
+    @Mock RegistryServerHandler registryHandler;
+
+    GatewayResourceProfileService service;
+    RequestContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        service = new GatewayResourceProfileService(registryHandler);
+        ctx = new RequestContext("admin", "testGateway", "token123",
+                Map.of("userName", "admin", "gatewayId", "testGateway"));
+    }
+
+    @Test
+    void registerGatewayResourceProfile_returnsId() throws Exception {
+        GatewayResourceProfile profile = new GatewayResourceProfile();
+        profile.setGatewayID("testGateway");
+        
when(registryHandler.registerGatewayResourceProfile(profile)).thenReturn("profile-id");
+
+        String result = service.registerGatewayResourceProfile(ctx, profile);
+
+        assertEquals("profile-id", result);
+        verify(registryHandler).registerGatewayResourceProfile(profile);
+    }
+
+    @Test
+    void getGatewayResourceProfile_delegatesToRegistry() throws Exception {
+        GatewayResourceProfile profile = new GatewayResourceProfile();
+        profile.setGatewayID("testGateway");
+        
when(registryHandler.getGatewayResourceProfile("testGateway")).thenReturn(profile);
+
+        GatewayResourceProfile result = service.getGatewayResourceProfile(ctx, 
"testGateway");
+
+        assertNotNull(result);
+        assertEquals("testGateway", result.getGatewayID());
+    }
+
+    @Test
+    void updateGatewayResourceProfile_delegatesToRegistry() throws Exception {
+        GatewayResourceProfile profile = new GatewayResourceProfile();
+        when(registryHandler.updateGatewayResourceProfile("testGateway", 
profile)).thenReturn(true);
+
+        boolean result = service.updateGatewayResourceProfile(ctx, 
"testGateway", profile);
+
+        assertTrue(result);
+    }
+
+    @Test
+    void deleteGatewayResourceProfile_delegatesToRegistry() throws Exception {
+        
when(registryHandler.deleteGatewayResourceProfile("testGateway")).thenReturn(true);
+
+        boolean result = service.deleteGatewayResourceProfile(ctx, 
"testGateway");
+
+        assertTrue(result);
+    }
+
+    @Test
+    void addGatewayComputeResourcePreference_delegatesToRegistry() throws 
Exception {
+        ComputeResourcePreference pref = new ComputeResourcePreference();
+        
when(registryHandler.addGatewayComputeResourcePreference("testGateway", 
"compute-1", pref)).thenReturn(true);
+
+        boolean result = service.addGatewayComputeResourcePreference(ctx, 
"testGateway", "compute-1", pref);
+
+        assertTrue(result);
+    }
+
+    @Test
+    void getAllGatewayComputeResourcePreferences_delegatesToRegistry() throws 
Exception {
+        List<ComputeResourcePreference> prefs = List.of(new 
ComputeResourcePreference());
+        
when(registryHandler.getAllGatewayComputeResourcePreferences("testGateway")).thenReturn(prefs);
+
+        List<ComputeResourcePreference> result =
+                service.getAllGatewayComputeResourcePreferences(ctx, 
"testGateway");
+
+        assertEquals(1, result.size());
+    }
+
+    @Test
+    void getAllGatewayResourceProfiles_delegatesToRegistry() throws Exception {
+        List<GatewayResourceProfile> profiles = List.of(new 
GatewayResourceProfile());
+        
when(registryHandler.getAllGatewayResourceProfiles()).thenReturn(profiles);
+
+        List<GatewayResourceProfile> result = 
service.getAllGatewayResourceProfiles(ctx);
+
+        assertEquals(1, result.size());
+    }
+
+    @Test
+    void addGatewayStoragePreference_delegatesToRegistry() throws Exception {
+        StoragePreference pref = new StoragePreference();
+        when(registryHandler.addGatewayStoragePreference("testGateway", 
"storage-1", pref)).thenReturn(true);
+
+        boolean result = service.addGatewayStoragePreference(ctx, 
"testGateway", "storage-1", pref);
+
+        assertTrue(result);
+    }
+
+    @Test
+    void registryException_wrappedAsServiceException() throws Exception {
+        when(registryHandler.getGatewayResourceProfile("bad-gw"))
+                .thenThrow(new RuntimeException("DB error"));
+
+        assertThrows(ServiceException.class, () -> 
service.getGatewayResourceProfile(ctx, "bad-gw"));
+    }
+}

Reply via email to