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/bce873c8 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/bce873c8 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/bce873c8 Branch: refs/heads/develop Commit: bce873c8c6f0d91b489518a89f26d48443e815bc Parents: 9dd4fdb Author: Marcus Christie <[email protected]> Authored: Fri Feb 17 13:14:56 2017 -0500 Committer: Anuj Bhandar <[email protected]> Committed: Tue Feb 28 13:07:17 2017 -0500 ---------------------------------------------------------------------- airavata-api/airavata-api-server/pom.xml | 5 + .../server/handler/AiravataServerHandler.java | 169 +++++++++++++++++++ .../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, 182 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/bce873c8/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/bce873c8/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 a530d97..8415c21 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 @@ -30,7 +30,9 @@ import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; import org.apache.airavata.credential.store.cpi.CredentialStoreService; +import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.messaging.core.MessageContext; import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; @@ -70,18 +72,26 @@ 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; import org.apache.airavata.registry.api.RegistryService; +import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; 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.commons.pool.impl.GenericObjectPool; +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 { @@ -4758,6 +4768,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); @@ -4771,4 +4900,44 @@ public class AiravataServerHandler implements Airavata.Iface { messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); experimentPublisher.publish(messageContext); } + + private CredentialStoreService.Client getCredentialStoreServiceClient() throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); + final String serverHost = ServerSettings.getCredentialStoreServerHost(); + try { + return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); + } catch (CredentialStoreException e) { + throw new TException("Unable to create credential store client...", e); + } + } + + 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 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 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/bce873c8/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/bce873c8/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/bce873c8/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/bce873c8/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/bce873c8/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();
