You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2017/12/11 19:56:08 UTC

[airavata] 03/13: Adding API methods GroupManagerServiceHandler

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

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

commit 8810c0461d3eea513192deff7043b6b097ef5259
Author: Sachin Kariyattin <sa...@gmail.com>
AuthorDate: Sun Dec 3 21:16:39 2017 -0500

    Adding API methods GroupManagerServiceHandler
---
 .../profile-service/profile-service-server/pom.xml |   5 +
 .../handlers/GroupManagerServiceHandler.java       | 237 +++++++++++++++++++++
 .../profile/server/ProfileServiceServer.java       |   5 +
 .../cpi/group_manager_cpiConstants.java            |   4 +-
 .../group-manager/group-manager-cpi.thrift         |   4 +-
 5 files changed, 251 insertions(+), 4 deletions(-)

diff --git a/airavata-services/profile-service/profile-service-server/pom.xml b/airavata-services/profile-service/profile-service-server/pom.xml
index 9163929..ba8febe 100644
--- a/airavata-services/profile-service/profile-service-server/pom.xml
+++ b/airavata-services/profile-service/profile-service-server/pom.xml
@@ -54,6 +54,11 @@
             <artifactId>iam-admin-services-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.airavata</groupId>
+            <artifactId>airavata-api-server</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
     
 </project>
\ No newline at end of file
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java
new file mode 100644
index 0000000..7d4b87d
--- /dev/null
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java
@@ -0,0 +1,237 @@
+package org.apache.airavata.service.profile.handlers;
+
+import org.apache.airavata.api.server.util.ThriftClientPool;
+import org.apache.airavata.common.utils.Constants;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.model.error.AuthorizationException;
+import org.apache.airavata.model.group.GroupModel;
+import org.apache.airavata.model.security.AuthzToken;
+import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
+import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException;
+import org.apache.airavata.service.security.interceptor.SecurityCheck;
+import org.apache.airavata.sharing.registry.models.GroupType;
+import org.apache.airavata.sharing.registry.models.UserGroup;
+import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.UUID;
+
+public class GroupManagerServiceHandler implements GroupManagerService.Iface {
+
+    private static final Logger logger = LoggerFactory.getLogger(GroupManagerServiceHandler.class);
+
+    private ThriftClientPool<SharingRegistryService.Client> sharingClientPool;
+
+    public GroupManagerServiceHandler() {
+        GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
+        poolConfig.maxActive = 100;
+        poolConfig.minIdle = 5;
+        poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+        poolConfig.testOnBorrow = true;
+        poolConfig.testWhileIdle = true;
+        poolConfig.numTestsPerEvictionRun = 10;
+        poolConfig.maxWait = 3000;
+
+        sharingClientPool = new ThriftClientPool<>(
+                tProtocol -> new SharingRegistryService.Client(tProtocol), poolConfig, ServerSettings.getSharingRegistryHost(),
+                Integer.parseInt(ServerSettings.getSharingRegistryPort()));
+    }
+
+    @Override
+    @SecurityCheck
+    public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            //TODO Validations for authorization
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+
+            UserGroup sharingUserGroup = new UserGroup();
+            sharingUserGroup.setGroupId(UUID.randomUUID().toString());
+            sharingUserGroup.setName(groupModel.getName());
+            sharingUserGroup.setDescription(groupModel.getDescription());
+            sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP);
+            sharingUserGroup.setDomainId(authzToken.getClaimsMap().get(Constants.GATEWAY_ID));
+
+            String groupId = sharingClient.createGroup(sharingUserGroup);
+            sharingClient.addUsersToGroup(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), groupModel.getMembers(), groupId);
+            return groupId;
+        }
+        catch (Exception e) {
+            String msg = "Error Creating Group" ;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    @SecurityCheck
+    public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            //TODO Validations for authorization
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+
+            UserGroup sharingUserGroup = new UserGroup();
+            sharingUserGroup.setGroupId(groupModel.getId());
+            sharingUserGroup.setName(groupModel.getName());
+            sharingUserGroup.setDescription(groupModel.getDescription());
+            sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP);
+            sharingUserGroup.setDomainId(authzToken.getClaimsMap().get(Constants.GATEWAY_ID));
+
+            //adding and removal of users should be handle separately
+            sharingClient.updateGroup(sharingUserGroup);
+            return true;
+        }
+        catch (Exception e) {
+            String msg = "Error Updating Group" ;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    @SecurityCheck
+    public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            //TODO Validations for authorization
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+
+            sharingClient.deleteGroup(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), groupId);
+            return true;
+        }
+        catch (Exception e) {
+            String msg = "Error Deleting Group. Group ID: " + groupId ;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    @SecurityCheck
+    public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+            UserGroup userGroup = sharingClient.getGroup(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), groupId);
+
+            GroupModel groupModel = new GroupModel();
+            groupModel.setId(userGroup.getGroupId());
+            groupModel.setName(userGroup.getName());
+            groupModel.setDescription(userGroup.getDescription());
+            groupModel.setOwnerId(userGroup.getOwnerId());
+
+            sharingClient.getGroupMembersOfTypeUser(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), groupId, 0, -1).stream().forEach(user->
+                    groupModel.addToMembers(user.getUserId())
+            );
+
+            return groupModel;
+        }
+        catch (Exception e) {
+            String msg = "Error Retreiving Group. Group ID: " + groupId ;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    @SecurityCheck
+    public List<GroupModel> getAllGroupsUserBelongs(AuthzToken authzToken, String userName) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            throw new UnsupportedOperationException("Method not supported yet");
+        }
+        catch (Exception e) {
+            String msg = "Error Retreiving All Groups for User. User ID: " + userName ;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    @SecurityCheck
+    public boolean transferGroupOwnership(AuthzToken authzToken, String domainId, String groupId, String newOwnerId) throws GroupManagerServiceException, AuthorizationException, TException {
+       try{
+           SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+           return sharingClient.transferGroupOwnership(domainId, groupId, newOwnerId);
+       }
+       catch (Exception e) {
+           String msg = "Error Transferring Group Ownership";
+           logger.error(msg, e);
+           GroupManagerServiceException exception = new GroupManagerServiceException();
+           exception.setMessage(msg + " More info : " + e.getMessage());
+           throw exception;
+       }
+
+    }
+
+    @Override
+    @SecurityCheck
+    public boolean addGroupAdmins(AuthzToken authzToken, String domainId, String groupId, List<String> adminIds) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+            return sharingClient.addGroupAdmins(domainId, groupId, adminIds);
+        }
+        catch (Exception e) {
+            String msg = "Error Adding Admins to Group. Group ID: " + groupId;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    public boolean removeGroupAdmins(AuthzToken authzToken, String domainId, String groupId, List<String> adminIds) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+            return sharingClient.removeGroupAdmins(domainId, groupId, adminIds);
+        }
+        catch (Exception e) {
+            String msg = "Error Removing Admins from the Group. Group ID: " + groupId;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    public boolean hasAdminAccess(AuthzToken authzToken, String domainId, String groupId, String adminId) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+            return sharingClient.hasAdminAccess(domainId, groupId, adminId);
+        }
+        catch (Exception e) {
+            String msg = "Error Checking Admin Access for the Group. Group ID: " + groupId + " Admin ID: " + adminId;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+
+    @Override
+    public boolean hasOwnerAccess(AuthzToken authzToken, String domainId, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException {
+        try {
+            SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+            return sharingClient.hasOwnerAccess(domainId, groupId, ownerId);
+        }
+        catch (Exception e) {
+            String msg = "Error Checking Owner Access for the Group. Group ID: " + groupId + " Owner ID: " + ownerId;
+            logger.error(msg, e);
+            GroupManagerServiceException exception = new GroupManagerServiceException();
+            exception.setMessage(msg + " More info : " + e.getMessage());
+            throw exception;
+        }
+    }
+}
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
index 96d6f83..c371173 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
@@ -23,6 +23,9 @@ package org.apache.airavata.service.profile.server;
 
 import org.apache.airavata.common.utils.IServer;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
+import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
+import org.apache.airavata.service.profile.handlers.GroupManagerServiceHandler;
 import org.apache.airavata.service.profile.handlers.IamAdminServicesHandler;
 import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices;
 import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants;
@@ -88,12 +91,14 @@ public class ProfileServiceServer implements IServer {
             UserProfileService.Processor userProfileProcessor = new UserProfileService.Processor(new UserProfileServiceHandler());
             TenantProfileService.Processor teneantProfileProcessor = new TenantProfileService.Processor(new TenantProfileServiceHandler());
             IamAdminServices.Processor iamAdminServicesProcessor = new IamAdminServices.Processor(new IamAdminServicesHandler());
+            GroupManagerService.Processor groupmanagerProcessor = new GroupManagerService.Processor(new GroupManagerServiceHandler());
 
             // create a multiplexed processor
             TMultiplexedProcessor profileServiceProcessor = new TMultiplexedProcessor();
             profileServiceProcessor.registerProcessor(profile_user_cpiConstants.USER_PROFILE_CPI_NAME, userProfileProcessor);
             profileServiceProcessor.registerProcessor(profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME, teneantProfileProcessor);
             profileServiceProcessor.registerProcessor(iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME, iamAdminServicesProcessor);
+            profileServiceProcessor.registerProcessor(group_manager_cpiConstants.GROUP_MANAGER_CPI_NAME, groupmanagerProcessor);
 
             TServerTransport serverTransport;
 
diff --git a/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/groupmanager/cpi/group_manager_cpiConstants.java b/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/groupmanager/cpi/group_manager_cpiConstants.java
index 3b8f5d2..63b69d3 100644
--- a/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/groupmanager/cpi/group_manager_cpiConstants.java
+++ b/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/groupmanager/cpi/group_manager_cpiConstants.java
@@ -25,8 +25,8 @@ package org.apache.airavata.service.profile.groupmanager.cpi;
 @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
 public class group_manager_cpiConstants {
 
-  public static final java.lang.String USER_PROFILE_CPI_VERSION = "0.17";
+  public static final java.lang.String GROUP_MANAGER_CPI_VERSION = "0.17";
 
-  public static final java.lang.String USER_PROFILE_CPI_NAME = "GroupManagerService";
+  public static final java.lang.String GROUP_MANAGER_CPI_NAME = "GroupManagerService";
 
 }
diff --git a/thrift-interface-descriptions/service-cpis/profile-service/group-manager/group-manager-cpi.thrift b/thrift-interface-descriptions/service-cpis/profile-service/group-manager/group-manager-cpi.thrift
index d56760a..a63b5e1 100644
--- a/thrift-interface-descriptions/service-cpis/profile-service/group-manager/group-manager-cpi.thrift
+++ b/thrift-interface-descriptions/service-cpis/profile-service/group-manager/group-manager-cpi.thrift
@@ -31,8 +31,8 @@ include "group_manager_cpi_errors.thrift"
 namespace java org.apache.airavata.service.profile.groupmanager.cpi
 namespace php Airavata.Service.Profile.Groupmanager.CPI
 
-const string USER_PROFILE_CPI_VERSION = "0.17"
-const string USER_PROFILE_CPI_NAME = "GroupManagerService"
+const string GROUP_MANAGER_CPI_VERSION = "0.17"
+const string GROUP_MANAGER_CPI_NAME = "GroupManagerService"
 
 service GroupManagerService {
 

-- 
To stop receiving notification emails like this one, please contact
"commits@airavata.apache.org" <co...@airavata.apache.org>.