You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2017/03/07 22:05:04 UTC
[04/50] [abbrv] airavata git commit: AIRAVATA-2316 Initial
implementation of user profile API methods
AIRAVATA-2316 Initial implementation of user profile API methods
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/de265090
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/de265090
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/de265090
Branch: refs/heads/develop
Commit: de26509047837989ceddd505fe13a96837493928
Parents: 54e0f39
Author: Marcus Christie <ma...@apache.org>
Authored: Fri Feb 17 13:14:56 2017 -0500
Committer: Marcus Christie <ma...@apache.org>
Committed: Fri Feb 17 13:14:56 2017 -0500
----------------------------------------------------------------------
airavata-api/airavata-api-server/pom.xml | 5 +
.../server/handler/AiravataServerHandler.java | 135 +++++++++++++++++++
.../SharingRegistryServiceClientFactory.java | 1 +
.../org/apache/airavata/MigrationManager.java | 2 +-
.../UserProfileAiravataThriftClient.java | 8 +-
.../user/registry/core/utils/JPAConstants.java | 1 +
.../client/UserProfileServiceClientFactory.java | 2 +-
7 files changed, 148 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/airavata-api/airavata-api-server/pom.xml
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/pom.xml b/airavata-api/airavata-api-server/pom.xml
index b60eedb..ce94602 100644
--- a/airavata-api/airavata-api-server/pom.xml
+++ b/airavata-api/airavata-api-server/pom.xml
@@ -151,6 +151,11 @@
<artifactId>registry-api-stubs</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>user-profile-stubs</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index d4479b3..c2bd070 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -71,6 +71,7 @@ import org.apache.airavata.model.status.ExperimentState;
import org.apache.airavata.model.status.ExperimentStatus;
import org.apache.airavata.model.status.JobStatus;
import org.apache.airavata.model.status.QueueStatusModel;
+import org.apache.airavata.model.user.UserProfile;
import org.apache.airavata.model.workspace.Gateway;
import org.apache.airavata.model.workspace.Notification;
import org.apache.airavata.model.workspace.Project;
@@ -80,10 +81,15 @@ import org.apache.airavata.registry.api.exception.RegistryServiceException;
import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory;
import org.apache.airavata.sharing.registry.models.*;
import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
+import org.apache.airavata.userprofile.cpi.UserProfileService;
+import org.apache.airavata.userprofile.cpi.client.UserProfileServiceClientFactory;
+import org.apache.airavata.userprofile.cpi.exception.UserProfileServiceException;
+import org.apache.http.auth.AUTH;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.text.MessageFormat;
import java.util.*;
public class AiravataServerHandler implements Airavata.Iface {
@@ -4077,6 +4083,125 @@ public class AiravataServerHandler implements Airavata.Iface {
}
}
+ @Override
+ @SecurityCheck
+ public String addUserProfile(AuthzToken authzToken, UserProfile userProfile)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that username and gatewayId match authzToken
+ try {
+ return getUserProfileServiceClient().addUserProfile(userProfile);
+ } catch (Exception e) {
+ String msg = "Error adding user profile";
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that username and gatewayId match authzToken
+ try {
+ return getUserProfileServiceClient().updateUserProfile(userProfile);
+ } catch (Exception e) {
+ String msg = "Error updating user profile";
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that username and gatewayId match authzToken
+ try {
+ return getUserProfileServiceClient().getUserProfileById(userId, gatewayId);
+ } catch (Exception e) {
+ String msg = MessageFormat.format("Error getting user profile for [{0}] in [{1}]", userId, gatewayId);
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public boolean deleteUserProfile(AuthzToken authzToken, String userId)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that username match authzToken
+ try {
+ return getUserProfileServiceClient().deleteUserProfile(userId);
+ } catch (Exception e) {
+ String msg = "Error deleting user profile";
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public List<UserProfile> getAllUserProfilesInGateway(AuthzToken authzToken, String gatewayId, int offset, int limit)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that gatewayId match authzToken
+ try {
+ return getUserProfileServiceClient().getAllUserProfilesInGateway(gatewayId, offset, limit);
+ } catch (Exception e) {
+ String msg = MessageFormat.format("Error getting all user profiles for [{0}] with offset={1} and limit={2}", gatewayId, offset, limit);
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public UserProfile getUserProfileByName(AuthzToken authzToken, String userName, String gatewayId)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: check that username and gatewayId match authzToken
+ try {
+ return getUserProfileServiceClient().getUserProfileByName(userName, gatewayId);
+ } catch (Exception e) {
+ String msg = MessageFormat.format("Error getting user profile for [{0}] in [{1}]", userName, gatewayId);
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
+ @Override
+ @SecurityCheck
+ public boolean doesUserProfileExist(AuthzToken authzToken, String userName, String gatewayId)
+ throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+
+ // TODO: verify that authzToken gatewayId matches
+ try {
+ return getUserProfileServiceClient().doesUserExist(userName, gatewayId);
+ } catch (Exception e) {
+ String msg = MessageFormat.format("Error checking if user profile exists for [{0}] in [{1}]", userName, gatewayId);
+ logger.error(msg, e);
+ AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
+ exception.setMessage(msg + " More info : " + e.getMessage());
+ throw exception;
+ }
+ }
+
private void submitExperiment(String gatewayId,String experimentId) throws AiravataException {
ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId);
MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId);
@@ -4120,4 +4245,14 @@ public class AiravataServerHandler implements Airavata.Iface {
throw new TException("Unable to create sharing registry client...", e);
}
}
+
+ private UserProfileService.Client getUserProfileServiceClient() throws TException, ApplicationSettingsException {
+ final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort());
+ final String serverHost = ServerSettings.getUserProfileServerHost();
+ try {
+ return UserProfileServiceClientFactory.createUserProfileServiceClient(serverHost, serverPort);
+ } catch (UserProfileServiceException e) {
+ throw new TException("Unable to create user profile service client...", e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/modules/sharing-registry/sharing-registry-stubs/src/main/java/org/apache/airavata/sharing/registry/client/SharingRegistryServiceClientFactory.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-stubs/src/main/java/org/apache/airavata/sharing/registry/client/SharingRegistryServiceClientFactory.java b/modules/sharing-registry/sharing-registry-stubs/src/main/java/org/apache/airavata/sharing/registry/client/SharingRegistryServiceClientFactory.java
index 407da45..a38958f 100644
--- a/modules/sharing-registry/sharing-registry-stubs/src/main/java/org/apache/airavata/sharing/registry/client/SharingRegistryServiceClientFactory.java
+++ b/modules/sharing-registry/sharing-registry-stubs/src/main/java/org/apache/airavata/sharing/registry/client/SharingRegistryServiceClientFactory.java
@@ -38,6 +38,7 @@ public class SharingRegistryServiceClientFactory {
TBinaryProtocol protocol = new TBinaryProtocol(e);
return new SharingRegistryService.Client(protocol);
} catch (TTransportException var4) {
+ logger.error("failed to create sharing registry client", var4);
throw new SharingRegistryException();
}
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java
----------------------------------------------------------------------
diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java
index 22d770f..ca6e8ca 100644
--- a/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java
+++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/MigrationManager.java
@@ -108,7 +108,7 @@ public class MigrationManager {
private boolean migrateUserProfilesToAiravata(List<UserProfileDAO> ISProfileList) throws TException, ApplicationSettingsException {
System.out.println("Initiating migration to Airavata internal DB ...");
UserProfileAiravataThriftClient objFactory = new UserProfileAiravataThriftClient();
- UserProfileService.Client client = objFactory.getRegistryServiceClient();
+ UserProfileService.Client client = objFactory.getUserProfileServiceClient();
UserProfile airavataUserProfile = new UserProfile();
// Here are the data associations...
for(UserProfileDAO ISProfile : ISProfileList){
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java
----------------------------------------------------------------------
diff --git a/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java
index 7785148..2459739 100644
--- a/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java
+++ b/modules/user-profile-migration/src/main/java/org/apache/airavata/UserProfileAiravataThriftClient.java
@@ -33,12 +33,12 @@ import java.util.List;
public class UserProfileAiravataThriftClient {
- public UserProfileService.Client getRegistryServiceClient() throws TException, ApplicationSettingsException {
+ public UserProfileService.Client getUserProfileServiceClient() throws TException, ApplicationSettingsException {
// Check the server ports before running migration
- final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort());
- final String serverHost = ServerSettings.getRegistryServerHost();
+ final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort());
+ final String serverHost = ServerSettings.getUserProfileServerHost();
try {
- return UserProfileServiceClientFactory.createRegistryClient(serverHost, serverPort);
+ return UserProfileServiceClientFactory.createUserProfileServiceClient(serverHost, serverPort);
} catch (UserProfileServiceException e) {
throw new TException("Unable to create registry client...", e);
}
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java
----------------------------------------------------------------------
diff --git a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java
index 8efb965..65b6135 100644
--- a/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java
+++ b/modules/user-profile/user-profile-core/src/main/java/org/apache/airavata/user/registry/core/utils/JPAConstants.java
@@ -25,6 +25,7 @@ public class JPAConstants {
public static final String KEY_JDBC_USER = "user.profile.catalog.registry.jdbc.user";
public static final String KEY_JDBC_PASSWORD = "user.profile.catalog.registry.jdbc.password";
public static final String KEY_JDBC_DRIVER = "user.profile.catalog.registry.jdbc.driver";
+ // TODO: is this needed?
public static final String KEY_DERBY_START_ENABLE = "user.profile.catalog.start.derby.server.mode";
public static final String VALIDATION_QUERY = "user.profile.catalog.validationQuery";
public static final String JPA_CACHE_SIZE = "user.profile.catalog.jpa.cache.size";
http://git-wip-us.apache.org/repos/asf/airavata/blob/de265090/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/cpi/client/UserProfileServiceClientFactory.java
----------------------------------------------------------------------
diff --git a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/cpi/client/UserProfileServiceClientFactory.java b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/cpi/client/UserProfileServiceClientFactory.java
index dccecce..f2e2a17 100644
--- a/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/cpi/client/UserProfileServiceClientFactory.java
+++ b/modules/user-profile/user-profile-stubs/src/main/java/org/apache/airavata/userprofile/cpi/client/UserProfileServiceClientFactory.java
@@ -30,7 +30,7 @@ import org.apache.thrift.transport.TTransportException;
public class UserProfileServiceClientFactory {
- public static UserProfileService.Client createRegistryClient(String serverHost, int serverPort) throws UserProfileServiceException {
+ public static UserProfileService.Client createUserProfileServiceClient(String serverHost, int serverPort) throws UserProfileServiceException {
try {
TTransport transport = new TSocket(serverHost, serverPort);
transport.open();