http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/d55608f1/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 deleted file mode 100644 index 89be995..0000000 --- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ /dev/null @@ -1,4102 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.airavata.api.server.handler; - -import org.apache.airavata.api.Airavata; -import org.apache.airavata.api.airavata_apiConstants; -import org.apache.airavata.api.server.security.interceptor.SecurityCheck; -import org.apache.airavata.common.exception.AiravataException; -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.datamodel.CredentialOwnerType; -import org.apache.airavata.credential.store.datamodel.PasswordCredential; -import org.apache.airavata.credential.store.datamodel.SSHCredential; -import org.apache.airavata.credential.store.datamodel.SSHCredentialSummary; -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; -import org.apache.airavata.messaging.core.Type; -import org.apache.airavata.model.WorkflowModel; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; -import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; -import org.apache.airavata.model.appcatalog.computeresource.*; -import org.apache.airavata.model.appcatalog.credentialsummary.CredentialSummary; -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.model.appcatalog.storageresource.StorageResourceDescription; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; -import org.apache.airavata.model.application.io.InputDataObjectType; -import org.apache.airavata.model.application.io.OutputDataObjectType; -import org.apache.airavata.model.commons.airavata_commonsConstants; -import org.apache.airavata.model.data.movement.DMType; -import org.apache.airavata.model.data.movement.*; -import org.apache.airavata.model.data.replica.DataProductModel; -import org.apache.airavata.model.data.replica.DataReplicaLocationModel; -import org.apache.airavata.model.error.*; -import org.apache.airavata.model.experiment.*; -import org.apache.airavata.model.group.GroupModel; -import org.apache.airavata.model.group.ResourcePermissionType; -import org.apache.airavata.model.group.ResourceType; -import org.apache.airavata.model.job.JobModel; -import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; -import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; -import org.apache.airavata.model.messaging.event.MessageType; -import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; -import org.apache.airavata.model.security.AuthzToken; -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.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.models.*; -import org.apache.airavata.sharing.registry.server.SharingRegistryServerHandler; -import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; - -public class AiravataServerHandler implements Airavata.Iface { - private static final Logger logger = LoggerFactory.getLogger(AiravataServerHandler.class); - private Publisher statusPublisher; - private Publisher experimentPublisher; - private CredentialStoreService.Client csClient; - - private SharingRegistryServerHandler sharingRegistryServerHandler; - - public AiravataServerHandler() { - try { - statusPublisher = MessagingFactory.getPublisher(Type.STATUS); - experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH); - - sharingRegistryServerHandler = new SharingRegistryServerHandler(); - initSharingRegistry(); - } catch (ApplicationSettingsException e) { - logger.error("Error occured while reading airavata-server properties..", e); - } catch (AiravataException e) { - logger.error("Error occured while reading airavata-server properties..", e); - } catch (TException e) { - logger.error("Error occured while reading airavata-server properties..", e); - } - } - - private void initSharingRegistry() throws ApplicationSettingsException, TException { - if(sharingRegistryServerHandler.getDomain(ServerSettings.getDefaultUserGateway()) == null){ - Domain domain = new Domain(); - domain.setDomainId(ServerSettings.getDefaultUserGateway()); - domain.setName(ServerSettings.getDefaultUserGateway()); - domain.setDescription("Domain entry for " + domain.name); - sharingRegistryServerHandler.createDomain(domain); - - User user = new User(); - user.setDomainId(domain.domainId); - user.setUserId(ServerSettings.getDefaultUser()+"@"+ServerSettings.getDefaultUserGateway()); - user.setUserName(ServerSettings.getDefaultUser()); - sharingRegistryServerHandler.createUser(user); - - //Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":PROJECT"); - entityType.setDomainId(domain.domainId); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":EXPERIMENT"); - entityType.setDomainId(domain.domainId); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":FILE"); - entityType.setDomainId(domain.domainId); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - //Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":READ"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - sharingRegistryServerHandler.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":WRITE"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - sharingRegistryServerHandler.createPermissionType(permissionType); - } - } - - /** - * Query Airavata to fetch the API version - */ - @Override - @SecurityCheck - public String getAPIVersion(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { - - return airavata_apiConstants.AIRAVATA_API_VERSION; - } - - /** - * Verify if User Exists within Airavata. - * - * @param authzToken - * @param gatewayId - * @param userName - * @return true/false - */ - @Override - public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().isUserExists(userName, gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while verifying user", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while verifying user. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public String addGateway(AuthzToken authzToken, Gateway gateway) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - String gatewayId = getRegistryServiceClient().addGateway(gateway); - Domain domain = new Domain(); - domain.setDomainId(gateway.getGatewayId()); - domain.setName(gateway.getGatewayName()); - domain.setDescription("Domain entry for " + domain.name); - sharingRegistryServerHandler.createDomain(domain); - - //Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":PROJECT"); - entityType.setDomainId(domain.domainId); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":EXPERIMENT"); - entityType.setDomainId(domain.domainId); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":FILE"); - entityType.setDomainId(domain.domainId); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - sharingRegistryServerHandler.createEntityType(entityType); - - //Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":READ"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - sharingRegistryServerHandler.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":WRITE"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - sharingRegistryServerHandler.createPermissionType(permissionType); - - return gatewayId; - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while adding gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Get all users in the gateway - * - * @param authzToken - * @param gatewayId The gateway data model. - * @return users - * list of usernames of the users in the gateway - */ - @Override - public List<String> getAllUsersInGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getAllUsersInGateway(gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while retrieving users", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - try { - return getRegistryServiceClient().updateGateway(gatewayId, updatedGateway); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while updating the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating the gateway. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public Gateway getGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - try { - return getRegistryServiceClient().getGateway(gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while getting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the gateway. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean deleteGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().deleteGateway(gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while deleting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public List<Gateway> getAllGateways(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getAllGateways(); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while getting all the gateways", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - try { - return getRegistryServiceClient().isGatewayExist(gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while getting gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * * API methods to retrieve notifications - * * - * - * @param authzToken - * @param notification - */ - @Override - @SecurityCheck - public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().createNotification(notification); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while creating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating notification. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().updateNotification(notification); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while updating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().deleteNotification(gatewayId, notificationId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while deleting notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getNotification(gatewayId, notificationId); - } catch (RegistryServiceException | ApplicationSettingsException e) { - logger.error("Error while retrieving notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retreiving notification. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public List<Notification> getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getAllNotifications(gatewayId); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while getting all notifications", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public String generateAndRegisterSSHKeys(AuthzToken authzToken, String gatewayId, String userName, String description, CredentialOwnerType credentialOwnerType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setUsername(userName); - sshCredential.setGatewayId(gatewayId); - sshCredential.setDescription(description); - if (credentialOwnerType != null) { - sshCredential.setCredentialOwnerType(credentialOwnerType); - } - String key = csClient.addSSHCredential(sshCredential); - logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); - return key; - }catch (Exception e){ - logger.error("Error occurred while registering SSH Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering SSH Credential. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Generate and Register Username PWD Pair with Airavata Credential Store. - * - * @param authzToken - * @param gatewayId The identifier for the requested Gateway. - * @param portalUserName The User for which the credential should be registered. For community accounts, this user is the name of the - * community user name. For computational resources, this user name need not be the same user name on resoruces. - * @param password - * @return airavataCredStoreToken - * An SSH Key pair is generated and stored in the credential store and associated with users or community account - * belonging to a Gateway. - */ - @Override - @SecurityCheck - public String registerPwdCredential(AuthzToken authzToken, String gatewayId, String portalUserName, - String loginUserName, String password, String description) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - PasswordCredential pwdCredential = new PasswordCredential(); - pwdCredential.setPortalUserName(portalUserName); - pwdCredential.setLoginUserName(loginUserName); - pwdCredential.setPassword(password); - pwdCredential.setDescription(description); - pwdCredential.setGatewayId(gatewayId); - String key = csClient.addPasswordCredential(pwdCredential); - logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName); - return key; - }catch (Exception e){ - logger.error("Error occurred while registering PWD Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public String getSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - SSHCredential sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId); - logger.debug("Airavata retrieved SSH pub key for gateway id : " + gatewayId + " and for token : " + airavataCredStoreToken); - return sshCredential.getPublicKey(); - }catch (Exception e){ - logger.error("Error occurred while retrieving SSH credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH credential. More info : " + e.getMessage()); - throw exception; - } - } - - - @Override - @SecurityCheck - public Map<String, String> getAllGatewaySSHPubKeys(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - Map<String, String> allSSHKeysForGateway = csClient.getAllSSHKeysForGateway(gatewayId); - logger.debug("Airavata retrieved all SSH pub keys for gateway Id : " + gatewayId); - return allSSHKeysForGateway; - }catch (Exception e){ - logger.error("Error occurred while retrieving SSH public keys for gateway : " + gatewayId , e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH public keys for gateway : " + gatewayId + ". More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public List<CredentialSummary> getAllGatewaySSHPubKeysSummary(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - List<CredentialSummary> allCredentialSummaries = new ArrayList<>(); - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - List<SSHCredentialSummary> sshSummaryList = csClient.getAllGatewaySSHCredentialSummary(gatewayId); - for(SSHCredentialSummary key : sshSummaryList){ - CredentialSummary summary = new CredentialSummary(); - summary.setGatewayId(key.getGatewayId()); - summary.setUsername(key.getUsername()); - summary.setPublicKey(key.getPublicKey()); - summary.setToken(key.getToken()); - summary.setDescription(key.getDescription()); - summary.setPersistedTime(key.getPersistedTime()); - allCredentialSummaries.add(summary); - } - logger.debug("Airavata retrieved all SSH pub keys summaries for gateway Id : " + gatewayId); - return allCredentialSummaries; - }catch (Exception e){ - logger.error("Error occurred while retrieving SSH public keys summaries for gateway : " + gatewayId , e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH public keys summaries for gateway : " + gatewayId + ". More info : " + e.getMessage()); - throw exception; - } - } - - @Override - public List<CredentialSummary> getAllSSHPubKeysSummaryForUserInGateway(AuthzToken authzToken, String gatewayId, String userId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - List<CredentialSummary> allCredentialSummaries = new ArrayList<>(); - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - List<SSHCredentialSummary> sshSummaryListForUser = csClient.getAllSSHCredentialSummaryForUserInGateway(gatewayId,userId); - for(SSHCredentialSummary key : sshSummaryListForUser){ - CredentialSummary userPubKeySummary = new CredentialSummary(); - userPubKeySummary.setGatewayId(key.getGatewayId()); - userPubKeySummary.setUsername(key.getUsername()); - userPubKeySummary.setPublicKey(key.getPublicKey()); - userPubKeySummary.setToken(key.getToken()); - userPubKeySummary.setDescription(key.getDescription()); - userPubKeySummary.setPersistedTime(key.getPersistedTime()); - allCredentialSummaries.add(userPubKeySummary); - } - logger.debug("Airavata retrieved all SSH pub keys summaries for gateway Id : " + gatewayId + " & user ID : " +userId); - return allCredentialSummaries; - }catch (Exception e){ - logger.error("Error occurred while retrieving SSH public keys summaries for user : " + userId , e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH public keys summaries for user : " + userId + ". More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public Map<String, String> getAllGatewayPWDCredentials(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - Map<String, String> allPwdCredentials = csClient.getAllPWDCredentialsForGateway(gatewayId); - logger.debug("Airavata retrieved all PWD Credentials for gateway Id : " + gatewayId); - return allPwdCredentials; - }catch (Exception e){ - logger.error("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId , e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId + ". More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - return csClient.deleteSSHCredential(airavataCredStoreToken, gatewayId); - }catch (Exception e){ - logger.error("Error occurred while deleting SSH credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting SSH credential. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - if (csClient == null){ - csClient = getCredentialStoreServiceClient(); - } - logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - return csClient.deletePWDCredential(airavataCredStoreToken, gatewayId); - }catch (Exception e){ - logger.error("Error occurred while deleting PWD credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Create a Project - * - * @param project - */ - @Override - @SecurityCheck - public String createProject(AuthzToken authzToken, String gatewayId, Project project) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - try { - String projectId = getRegistryServiceClient().createProject(gatewayId, project); - - if(ServerSettings.isEnableSharing()){ - Entity entity = new Entity(); - entity.setEntityId(projectId); - entity.setDomainId(project.getGatewayId()); - entity.setEntityTypeId(project.getGatewayId()+":"+"PROJECT"); - entity.setOwnerId(project.getOwner() + "@" + project.getGatewayId()); - entity.setName(project.getName()); - entity.setDescription(project.getDescription()); - - sharingRegistryServerHandler.createEntity(entity); - } - - logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); - return projectId; - } catch (Exception e) { - logger.error("Error while creating the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the project. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException { - try { - RegistryService.Client regClient = getRegistryServiceClient(); - Project existingProject = regClient.getProject(projectId); - if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(existingProject.getOwner()) - || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(existingProject.getGatewayId())){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - projectId, gatewayId + ":WRITE")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - if(!updatedProject.getOwner().equals(existingProject.getOwner())){ - throw new InvalidRequestException("Owner of a project cannot be changed"); - } - if(!updatedProject.getGatewayId().equals(existingProject.getGatewayId())){ - throw new InvalidRequestException("Gateway ID of a project cannot be changed"); - } - regClient.updateProject(projectId, updatedProject); - logger.debug("Airavata updated project with project Id : " + projectId ); - } catch (RegistryServiceException | ApplicationSettingsException e) { - logger.error("Error while updating the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating the project. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException { - try { - RegistryService.Client regClient = getRegistryServiceClient(); - Project existingProject = regClient.getProject(projectId); - if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(existingProject.getOwner()) - || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(existingProject.getGatewayId())){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - projectId, gatewayId + ":WRITE")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - boolean ret = regClient.deleteProject(projectId); - logger.debug("Airavata deleted project with project Id : " + projectId ); - return ret; - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while removing the project", e); - ProjectNotFoundException exception = new ProjectNotFoundException(); - exception.setMessage("Error while removing the project. More info : " + e.getMessage()); - throw exception; - } - } - - private boolean validateString(String name){ - boolean valid = true; - if (name == null || name.equals("") || name.trim().length() == 0){ - valid = false; - } - return valid; - } - - /** - * Get a Project by ID - * - * @param projectId - */ - @Override - @SecurityCheck - public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException { - try { - Project project = getRegistryServiceClient().getProject(projectId); - if(authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner()) - && authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(project.getGatewayId())){ - return project; - }else if (ServerSettings.isEnableSharing()){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - projectId, gatewayId + ":READ")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - return project; - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - }else - return null; - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while retrieving the project", e); - ProjectNotFoundException exception = new ProjectNotFoundException(); - exception.setMessage("Error while retrieving the project. More info : " + e.getMessage()); - throw exception; - } - } - - - /** - * Get all Project by user with pagination. Results will be ordered based - * on creation time DESC - * - * @param gatewayId - * The identifier for the requested gateway. - * @param userName - * The identifier of the user - * @param limit - * The amount results to be fetched - * @param offset - * The starting point of the results to be fetched - **/ - @Override - @SecurityCheck - public List<Project> getUserProjects(AuthzToken authzToken, String gatewayId, String userName, - int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - if (ServerSettings.isEnableSharing()){ - // user projects + user accessible projects - List<String> accessibleProjectIds = new ArrayList<>(); - sharingRegistryServerHandler.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName+"@"+gatewayId , gatewayId+":PROJECT", - new ArrayList<>(), offset, limit).stream().forEach(p->accessibleProjectIds.add(p.entityId)); - return getRegistryServiceClient().searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); - }else{ - return getRegistryServiceClient().getUserProjects(gatewayId, userName, limit, offset); - } - - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * - * Search User Projects - * Search and get all Projects for user by project description or/and project name with pagination. - * Results will be ordered based on creation time DESC. - * - * @param gatewayId - * The unique identifier of the gateway making the request. - * - * @param userName - * The identifier of the user. - * - * @param filters - * Map of multiple filter criteria. Currenlt search filters includes Project Name and Project Description - * - * @param limit - * The amount results to be fetched. - * - * @param offset - * The starting point of the results to be fetched. - * - */ - @Override - public List<Project> searchProjects(AuthzToken authzToken, String gatewayId, String userName, Map<ProjectSearchFields, - String> filters, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - List<String> accessibleProjIds = new ArrayList<>(); - - if(ServerSettings.isEnableSharing()) - sharingRegistryServerHandler.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName+"@"+gatewayId, gatewayId+":PROJECT", - new ArrayList<>(), 0, -1).stream().forEach(e->accessibleProjIds.add(e.entityId)); - - return getRegistryServiceClient().searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); - }catch (Exception e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - throw exception; - } - } - - - /** - * Search Experiments by using multiple filter criteria with pagination. Results will be sorted - * based on creation time DESC - * - * @param gatewayId - * Identifier of the requested gateway - * @param userName - * Username of the requested user - * @param filters - * map of multiple filter criteria. - * @param limit - * Amount of results to be fetched - * @param offset - * The starting point of the results to be fetched - */ - @Override - @SecurityCheck - public List<ExperimentSummaryModel> searchExperiments(AuthzToken authzToken, String gatewayId, String userName, Map<ExperimentSearchFields, - String> filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - List<String> accessibleExpIds = new ArrayList<>(); - if(ServerSettings.isEnableSharing()) - sharingRegistryServerHandler.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName+"@"+gatewayId, gatewayId+":EXPERIMENT", - new ArrayList<>(), 0, -1).forEach(e->accessibleExpIds.add(e.entityId)); - return getRegistryServiceClient().searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); - }catch (Exception e) { - logger.error("Error while retrieving experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Get Experiment execution statisitics by sending the gateway id and the time period interested in. - * This method will retrun an ExperimentStatistics object which contains the number of successfully - * completed experiments, failed experiments etc. - * @param gatewayId - * @param fromTime - * @param toTime - * @return - * @throws InvalidRequestException - * @throws AiravataClientException - * @throws AiravataSystemException - * @throws TException - */ - @Override - @SecurityCheck - public ExperimentStatistics getExperimentStatistics(AuthzToken authzToken, String gatewayId, long fromTime, long toTime, - String userName, String applicationName, String resourceHostName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getExperimentStatistics(gatewayId, fromTime, toTime, userName, applicationName, resourceHostName); - }catch (Exception e) { - logger.error("Error while retrieving experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Get Experiments within project with pagination. Results will be sorted - * based on creation time DESC - * - * @param projectId - * Identifier of the project - * @param limit - * Amount of results to be fetched - * @param offset - * The starting point of the results to be fetched - */ - @Override - @SecurityCheck - public List<ExperimentModel> getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, - AuthorizationException, TException { - try { - RegistryService.Client regClient = getRegistryServiceClient(); - Project project = regClient.getProject(projectId); - - if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner()) - || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(project.getGatewayId())){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - projectId, gatewayId + ":READ")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - return regClient.getExperimentsInProject(projectId, limit, offset); - } catch (Exception e) { - logger.error("Error while retrieving the experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Get Experiments by user pagination. Results will be sorted - * based on creation time DESC - * - * @param gatewayId - * Identifier of the requesting gateway - * @param userName - * Username of the requested user - * @param limit - * Amount of results to be fetched - * @param offset - * The starting point of the results to be fetched - */ - @Override - @SecurityCheck - public List<ExperimentModel> getUserExperiments(AuthzToken authzToken, String gatewayId, String userName, int limit, - int offset) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getUserExperiments(gatewayId, userName, limit, offset); - } catch (Exception e) { - logger.error("Error while retrieving the experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Create an experiment for the specified user belonging to the gateway. The gateway identity is not explicitly passed - * but inferred from the authentication header. This experiment is just a persistent place holder. The client - * has to subsequently configure and launch the created experiment. No action is taken on Airavata Server except - * registering the experiment in a persistent store. - * - * @param experiment@return The server-side generated.airavata.registry.core.experiment.globally unique identifier. - * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - * <p/> - * UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - * step, then Airavata Registry will not have a provenance area setup. The client has to follow - * gateway registration steps and retry this request. - * <p/> - * AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - * For now this is a place holder. - * <p/> - * INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - * is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException This exception will be thrown for any Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) throws InvalidRequestException, - AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - String experimentId = getRegistryServiceClient().createExperiment(gatewayId, experiment); - - if(ServerSettings.isEnableSharing()) { - Entity entity = new Entity(); - entity.setEntityId(experimentId); - entity.setDomainId(experiment.getGatewayId()); - entity.setEntityTypeId(experiment.getGatewayId()+":"+"EXPERIMENT"); - entity.setOwnerId(experiment.getUserName() + "@" + experiment.getGatewayId()); - entity.setName(experiment.getExperimentName()); - entity.setDescription(experiment.getDescription()); - entity.setParentEntityId(experiment.getProjectId()); - - sharingRegistryServerHandler.createEntity(entity); - } - - ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, - experimentId, - gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - if(statusPublisher !=null) { - statusPublisher.publish(messageContext); - } - logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); - return experimentId; - } catch (Exception e) { - logger.error("Error while creating the experiment with experiment name {}", experiment.getExperimentName()); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * If the experiment is not already launched experiment can be deleted. - * @param authzToken - * @param experimentId - * @return - * @throws InvalidRequestException - * @throws AiravataClientException - * @throws AiravataSystemException - * @throws AuthorizationException - * @throws TException - */ - @Override - @SecurityCheck - public boolean deleteExperiment(AuthzToken authzToken, String experimentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - RegistryService.Client regClient = getRegistryServiceClient(); - ExperimentModel experimentModel = regClient.getExperiment(experimentId); - - if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName()) - || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - experimentId, gatewayId + ":WRITE")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - - if(!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)){ - logger.error("Error while deleting the experiment"); - throw new RegistryServiceException("Experiment is not in CREATED state. Hence cannot deleted. ID:"+ experimentId); - } - return regClient.deleteExperiment(experimentId); - } catch (Exception e) { - logger.error("Error while deleting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the experiment. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Fetch previously created experiment metadata. - * - * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @return experimentMetada - * This method will return the previously stored experiment metadata. - * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.ExperimentNotFoundException If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. - * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - * <p/> - * UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - * step, then Airavata Registry will not have a provenance area setup. The client has to follow - * gateway registration steps and retry this request. - * <p/> - * AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - * For now this is a place holder. - * <p/> - * INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - * is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException This exception will be thrown for any Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, - ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - ExperimentModel experimentModel = null; - try { - experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId); - if(authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName()) - && authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())){ - return experimentModel; - }else if(ServerSettings.isEnableSharing()){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - airavataExperimentId, gatewayId + ":READ")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - return experimentModel; - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - }else{ - return null; - } - } catch (ApplicationSettingsException e) { - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) - throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - ExperimentModel experimentModel = null; - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId); - if(gatewayId.equals(experimentModel.getGatewayId())){ - return experimentModel; - } else { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (ApplicationSettingsException e) { - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Fetch the completed nested tree structue of previously created experiment metadata which includes processes -> - * tasks -> jobs information. - * - * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @return experimentMetada - * This method will return the previously stored experiment metadata. - * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.ExperimentNotFoundException If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. - * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - * <p/> - * UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - * step, then Airavata Registry will not have a provenance area setup. The client has to follow - * gateway registration steps and retry this request. - * <p/> - * AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - * For now this is a place holder. - * <p/> - * INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - * is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException This exception will be thrown for any Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, - ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getDetailedExperimentTree(airavataExperimentId); - } catch (Exception e) { - logger.error("Error while retrieving the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage()); - throw exception; - } - } - - /** - * Configure a previously created experiment with required inputs, scheduling and other quality of service - * parameters. This method only updates the experiment object within the registry. The experiment has to be launched - * to make it actionable by the server. - * - * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @param experiment - * @return This method call does not have a return value. - * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.ExperimentNotFoundException If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. - * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - * <p/> - * UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - * step, then Airavata Registry will not have a provenance area setup. The client has to follow - * gateway registration steps and retry this request. - * <p/> - * AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - * For now this is a place holder. - * <p/> - * INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - * is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException This exception will be thrown for any Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) - throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, - AuthorizationException, TException { - try { - RegistryService.Client regClient = getRegistryServiceClient(); - ExperimentModel experimentModel = regClient.getExperiment(airavataExperimentId); - if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName()) - || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())){ - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if(!sharingRegistryServerHandler.userHasAccess(gatewayId, userId + "@" + gatewayId, - airavataExperimentId, gatewayId + ":WRITE")){ - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - - regClient.updateExperiment(airavataExperimentId, experiment); - } catch (ApplicationSettingsException | RegistryServiceException e) { - logger.error(airavataExperimentId, "Error while updating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public void updateExperimentConfiguration(AuthzToken authzToken, String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws AuthorizationException, TException { - try { - getRegistryServiceClient().send_updateExperimentConfiguration(airavataExperimentId, userConfiguration); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating user configuration", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user configuration. " + - "Update experiment is only valid for experiments " + - "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + - "experiment is in one of above statuses... " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public void updateResourceScheduleing(AuthzToken authzToken, String airavataExperimentId, - ComputationalResourceSchedulingModel resourceScheduling) throws AuthorizationException, TException { - try { - getRegistryServiceClient().updateResourceScheduleing(airavataExperimentId, resourceScheduling); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating scheduling info", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating scheduling info. " + - "Update experiment is only valid for experiments " + - "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + - "experiment is in one of above statuses... " + e.getMessage()); - throw exception; - } - } - - /** - * * - * * Validate experiment configuration. A true in general indicates, the experiment is ready to be launched. - * * - * * @param experimentID - * * @return sucess/failure - * * - * * - * - * @param airavataExperimentId - */ - @Override - @SecurityCheck - public boolean validateExperiment(AuthzToken authzToken, String airavataExperimentId) throws TException { - // TODO - call validation module and validate experiment -/* try { - ExperimentModel experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId); - if (experimentModel == null) { - logger.error(airavataExperimentId, "Experiment validation failed , experiment {} doesn't exist.", airavataExperimentId); - throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - } catch (RegistryServiceException | ApplicationSettingsException e1) { - logger.error(airavataExperimentId, "Error while retrieving projects", e1); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e1.getMessage()); - throw exception; - } - - Client orchestratorClient = getOrchestratorClient(); - try{ - if (orchestratorClient.validateExperiment(airavataExperimentId)) { - logger.debug(airavataExperimentId, "Experiment validation succeed."); - return true; - } else { - logger.debug(airavataExperimentId, "Experiment validation failed."); - return false; - }}catch (TException e){ - throw e; - }finally { - orchestratorClient.getOutputProtocol().getTransport().close(); - orchestratorClient.getInputProtocol().getTransport().close(); - }*/ - - return true; - } - - /** - * Fetch the previously configured experiment configuration information. - * - * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @return This method returns the previously configured experiment configuration data. - * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.ExperimentNotFoundException If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. - * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - *<p/> - *UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - *step, then Airavata Registry will not have a provenance area setup. The client has to follow - *gateway registration steps and retry this request. - *<p/> - *AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - *For now this is a place holder. - *<p/> - *INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - *is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException This exception will be thrown for any - * Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) throws TException { - try { - return getRegistryServiceClient().getExperimentStatus(airavataExperimentId); - } catch (ApplicationSettingsException e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setMessage(e.getMessage()); - throw exception; - } - } - - - @Override - @SecurityCheck - public List<OutputDataObjectType> getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException, TException { - try { - return getRegistryServiceClient().getExperimentOutputs(airavataExperimentId); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public List<OutputDataObjectType> getIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, - ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - return null; - } - - @SecurityCheck - public Map<String, JobStatus> getJobStatuses(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException, TException { - try { - return getRegistryServiceClient().getJobStatuses(airavataExperimentId); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public List<JobModel> getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, - ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - return getRegistryServiceClient().getJobDetails(airavataExperimentId); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job details", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); - throw exception; - } - } - - - /** - * Launch a previously created and configured experiment. Airavata Server will then start processing the request and appropriate - * notifications and intermediate and output data will be subsequently available for this experiment. - * - * - * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @return This method call does not have a return value. - * @throws org.apache.airavata.model.error.InvalidRequestException - * For any incorrect forming of the request itself. - * @throws org.apache.airavata.model.error.ExperimentNotFoundException - * If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. - * @throws org.apache.airavata.model.error.AiravataClientException - * The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: - * <p/> - * UNKNOWN_GATEWAY_ID - If a Gateway is not registered with Airavata as a one time administrative - * step, then Airavata Registry will not have a provenance area setup. The client has to follow - * gateway registration steps and retry this request. - * <p/> - * AUTHENTICATION_FAILURE - How Authentication will be implemented is yet to be determined. - * For now this is a place holder. - * <p/> - * INVALID_AUTHORIZATION - This will throw an authorization exception. When a more robust security hand-shake - * is implemented, the authorization will be more substantial. - * @throws org.apache.airavata.model.error.AiravataSystemException - * This exception will be thrown for any Airavata Server side issues and if the problem cannot be corrected by the client - * rather an Airavata Administrator will be notified to take corrective action. - */ - @Override - @SecurityCheck - public void launchExperiment(AuthzToken authzToken, final String airavataExperimentId, String gatewayId) - throws TException { - try { - ExperimentModel experiment = getRegistryServiceClient().getExperiment(airavataExperimentId); - if (experiment == null) { - logger.error(airavataExperimentId, "Error while launching experiment, experiment {} doesn't exist.", airavataExperimentId); - throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - submitExperiment(gatewayId, airavataExperimentId); - } catch (RegistryServiceException | ApplicationSettingsException e1) { - logger.error(airavataExperimentId, "Error while instantiate the registry instance", e1); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while instantiate the registry instance. More info : " + e1.getMessage()); - throw exception; - } catch (AiravataException ex) { - logger.error("Experiment publish event fails", ex); - - } - } - - - -// private OrchestratorService.Client getOrchestratorClient() throws TException { -// try { -// final String serverHost = ServerSettings.getOrchestratorServerHost(); -// final int serverPort = ServerSettings.getOrchestratorServerPort(); -// return OrchestratorClientFactory.createOrchestratorClient(serverHost, serverPort); -// } catch (AiravataException e) { -// throw new TException(e); -// } -// } - - /** - * Clone an specified experiment with a new name. A copy of the experiment configuration is made and is persisted with new metadata. - * The client has to subsequently update this configuration if
<TRUNCATED>
