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:18 UTC
[airavata] 13/13: Adding GroupManager client sample
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 4ec92a79afbbcf4ed0c92be69c33379065d60ae4
Author: Sachin Kariyattin <sa...@gmail.com>
AuthorDate: Wed Dec 6 01:38:15 2017 -0500
Adding GroupManager client sample
---
.../profile/client/samples/GroupManagerSample.java | 41 ++++++++++++++++++++++
.../client/ProfileServiceClientFactory.java | 15 ++++++++
2 files changed, 56 insertions(+)
diff --git a/airavata-services/profile-service/profile-service-client-sdks/java-client-samples/src/main/java/org/apache/airavata/service/profile/client/samples/GroupManagerSample.java b/airavata-services/profile-service/profile-service-client-sdks/java-client-samples/src/main/java/org/apache/airavata/service/profile/client/samples/GroupManagerSample.java
new file mode 100644
index 0000000..71fdd70
--- /dev/null
+++ b/airavata-services/profile-service/profile-service-client-sdks/java-client-samples/src/main/java/org/apache/airavata/service/profile/client/samples/GroupManagerSample.java
@@ -0,0 +1,41 @@
+package org.apache.airavata.service.profile.client.samples;
+
+import org.apache.airavata.common.utils.Constants;
+import org.apache.airavata.model.security.AuthzToken;
+import org.apache.airavata.service.profile.client.ProfileServiceClientFactory;
+import org.apache.airavata.service.profile.client.util.ProfileServiceClientUtil;
+import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class GroupManagerSample {
+
+ private static final Logger logger = LoggerFactory.getLogger(UserProfileSample.class);
+ private static GroupManagerService.Client groupMangerClient;
+ private static String testGatewayId = "test-gateway-465";
+ private static AuthzToken authzToken = new AuthzToken("empy_token");
+
+ public static void main(String args[]) throws Exception {
+ try {
+ String profileServiceServerHost = ProfileServiceClientUtil.getProfileServiceServerHost();
+ int profileServiceServerPort = ProfileServiceClientUtil.getProfileServiceServerPort();
+
+ groupMangerClient = ProfileServiceClientFactory.createGroupManagerServiceClient(profileServiceServerHost, profileServiceServerPort);
+ Map<String, String> claimsMap = new HashMap<>();
+ claimsMap.put(Constants.GATEWAY_ID,testGatewayId);
+ authzToken.setClaimsMap(claimsMap);
+
+ //NOTE: Only these two methods can be tested as other methods require us to create a group.
+ // createGroup() needs createUser() to be executed. Currently ownerId is set from createUser()
+ // method which requires a sharingServiceClient. Hence, verifying only this method for now.
+ System.out.println("hasAdminAccess() should return [false]: "+ groupMangerClient.hasAdminAccess(authzToken,"test-group-1", "test-user-1"));
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ logger.error("GroupManager client-sample Exception: " + ex, ex);
+ }
+ }
+}
diff --git a/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/client/ProfileServiceClientFactory.java b/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/client/ProfileServiceClientFactory.java
index f41bc77..f447327 100644
--- a/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/client/ProfileServiceClientFactory.java
+++ b/airavata-services/profile-service/profile-service-stubs/src/main/java/org/apache/airavata/service/profile/client/ProfileServiceClientFactory.java
@@ -20,6 +20,9 @@
*/
package org.apache.airavata.service.profile.client;
+import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService;
+import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException;
+import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants;
import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices;
import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException;
import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants;
@@ -75,4 +78,16 @@ public class ProfileServiceClientFactory {
throw new IamAdminServicesException(e.getMessage());
}
}
+
+ public static GroupManagerService.Client createGroupManagerServiceClient(String serverHost, int serverPort) throws GroupManagerServiceException {
+ try {
+ TTransport transport = new TSocket(serverHost, serverPort);
+ transport.open();
+ TProtocol protocol = new TBinaryProtocol(transport);
+ TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, group_manager_cpiConstants.GROUP_MANAGER_CPI_NAME);
+ return new GroupManagerService.Client(multiplexedProtocol);
+ } catch (TTransportException e) {
+ throw new GroupManagerServiceException(e.getMessage());
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@airavata.apache.org" <co...@airavata.apache.org>.