Search in sources :

Example 11 with UserComputeResourcePreference

use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.

the class UsrResourceProfileImpl method addUserResourceProfile.

@Override
public String addUserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile userResourceProfile) throws AppCatalogException {
    try {
        UserResourceProfileResource profileResource = new UserResourceProfileResource();
        if (!userResourceProfile.getUserId().equals("")) {
            profileResource.setUserId(userResourceProfile.getUserId());
        }
        if (!userResourceProfile.getGatewayID().equals("")) {
            profileResource.setGatewayID(userResourceProfile.getGatewayID());
        }
        if (userResourceProfile.getCredentialStoreToken() != null) {
            profileResource.setCredentialStoreToken(userResourceProfile.getCredentialStoreToken());
        }
        if (userResourceProfile.getIdentityServerTenant() != null) {
            profileResource.setIdentityServerTenant(userResourceProfile.getIdentityServerTenant());
        }
        if (userResourceProfile.getIdentityServerPwdCredToken() != null) {
            profileResource.setIdentityServerPwdCredToken(userResourceProfile.getIdentityServerPwdCredToken());
        }
        profileResource.setUserId(userResourceProfile.getUserId());
        profileResource.setGatewayID(userResourceProfile.getGatewayID());
        profileResource.save();
        List<UserComputeResourcePreference> userComputeResourcePreferences = userResourceProfile.getUserComputeResourcePreferences();
        if (userComputeResourcePreferences != null && !userComputeResourcePreferences.isEmpty()) {
            for (UserComputeResourcePreference preference : userComputeResourcePreferences) {
                UserComputeHostPreferenceResource resource = new UserComputeHostPreferenceResource();
                resource.setUserResourceProfileResource(profileResource);
                resource.setResourceId(preference.getComputeResourceId());
                ComputeResourceResource computeHostResource = new ComputeResourceResource();
                resource.setComputeHostResource((ComputeResourceResource) computeHostResource.get(preference.getComputeResourceId()));
                resource.setGatewayId(profileResource.getGatewayID());
                resource.setUserId(profileResource.getUserId());
                resource.setLoginUserName(preference.getLoginUserName());
                resource.setResourceCSToken(preference.getResourceSpecificCredentialStoreToken());
                resource.setBatchQueue(preference.getPreferredBatchQueue());
                resource.setProjectNumber(preference.getAllocationProjectNumber());
                resource.setScratchLocation(preference.getScratchLocation());
                resource.setQualityOfService(preference.getQualityOfService());
                resource.setReservation(preference.getReservation());
                if (preference.getReservationStartTime() > 0) {
                    resource.setReservationStartTime(AiravataUtils.getTime(preference.getReservationStartTime()));
                }
                if (preference.getReservationEndTime() > 0) {
                    resource.setReservationEndTime(AiravataUtils.getTime(preference.getReservationEndTime()));
                }
                resource.setValidated(preference.isValidated());
                resource.save();
            }
        }
        List<UserStoragePreference> dataStoragePreferences = userResourceProfile.getUserStoragePreferences();
        if (dataStoragePreferences != null && !dataStoragePreferences.isEmpty()) {
            for (UserStoragePreference storagePreference : dataStoragePreferences) {
                UserStoragePreferenceResource resource = new UserStoragePreferenceResource();
                resource.setStorageResourceId(storagePreference.getStorageResourceId());
                resource.setGatewayId(profileResource.getGatewayID());
                resource.setUserId(profileResource.getUserId());
                resource.setFsRootLocation(storagePreference.getFileSystemRootLocation());
                resource.setLoginUserName(storagePreference.getLoginUserName());
                resource.setResourceCSToken(storagePreference.getResourceSpecificCredentialStoreToken());
                resource.setUserResourceProfileResource(profileResource);
                resource.save();
            }
        }
        return profileResource.getGatewayID();
    } catch (Exception e) {
        logger.error("Error while saving gateway profile...", e);
        throw new AppCatalogException(e);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 12 with UserComputeResourcePreference

use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.

the class RegistryServerHandler method getUserComputeResourcePreference.

/**
 * Fetch a Compute Resource Preference of a registered gateway profile.
 * @param userId
 * @param gatewayID         The identifier for the gateway profile to be requested
 * @param userComputeResourceId Preferences related to a particular compute resource
 * @return computeResourcePreference
 * Returns the ComputeResourcePreference object.
 */
@Override
public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException {
    try {
        if (!ExpCatResourceUtils.isUserExist(userId, gatewayID)) {
            logger.error("user does not exist.Please provide a valid user id...");
            throw new RegistryServiceException("user does not exist.Please provide a valid user id...");
        }
        appCatalog = RegistryFactory.getAppCatalog();
        appCatalog = RegistryFactory.getAppCatalog();
        UsrResourceProfile userProfile = appCatalog.getUserResourceProfile();
        if (!userProfile.isUserResourceProfileExists(userId, gatewayID)) {
            throw new RegistryServiceException("User resource profile with user id'" + userId + " &  gateway Id" + gatewayID + "' does not exist!!!");
        }
        ComputeResource computeResource = appCatalog.getComputeResource();
        if (!computeResource.isComputeResourceExists(userComputeResourceId)) {
            logger.error(userComputeResourceId, "Given compute resource does not exist in the system. Please provide a valid compute resource id...");
            RegistryServiceException exception = new RegistryServiceException();
            exception.setMessage("Given compute resource does not exist in the system. Please provide a valid compute resource id...");
            throw exception;
        }
        UserComputeResourcePreference userComputeResourcePreference = userProfile.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId);
        logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID + " and for compute resoruce id : " + userComputeResourceId);
        return userComputeResourcePreference;
    } catch (AppCatalogException e) {
        logger.error(gatewayID, "Error while reading user compute resource preference...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage());
        throw exception;
    } catch (RegistryException e) {
        logger.error(userId, "Error while retrieving user resource profile...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException)

Example 13 with UserComputeResourcePreference

use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.

the class AiravataServerHandler method setupUserComputeResourcePreferencesForSSH.

@Override
@SecurityCheck
public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH(AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    CredentialStoreService.Client csClient = csClientPool.getResource();
    SSHCredential sshCredential = null;
    try {
        sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId);
    } 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());
        csClientPool.returnBrokenResource(csClient);
        throw exception;
    }
    try {
        UserComputeResourcePreference userComputeResourcePreference = SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential);
        return userComputeResourcePreference;
    } catch (Exception e) {
        logger.error("Error occurred while automatically setting up SSH account for user [" + userId + "]", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error occurred while automatically setting up SSH account for user [" + userId + "]. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) CredentialStoreService(org.apache.airavata.credential.store.cpi.CredentialStoreService) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 14 with UserComputeResourcePreference

use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.

the class AiravataServerHandler method getUserComputeResourcePreference.

/**
 * Fetch a Compute Resource Preference of a registered User Resource profile.
 *
 * @param userId : The identifier for the User Resource profile to be requested
 * @param gatewayID The identifier to link a gateway for the requested User resource
 * @param userComputeResourceId Preferences related to a particular compute resource
 * @return computeResourcePreference
 * Returns the ComputeResourcePreference object.
 */
@Override
@SecurityCheck
public UserComputeResourcePreference getUserComputeResourcePreference(AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    try {
        UserComputeResourcePreference result = regClient.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId);
        registryClientPool.returnResource(regClient);
        return result;
    } catch (Exception e) {
        logger.error(userId, "Error while reading user compute resource preference...", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage());
        registryClientPool.returnBrokenResource(regClient);
        throw exception;
    }
}
Also used : UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) RegistryService(org.apache.airavata.registry.api.RegistryService) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Aggregations

UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)14 UserStoragePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference)5 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)5 AiravataException (org.apache.airavata.common.exception.AiravataException)4 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)4 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)3 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)3 ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)3 UserResourceProfile (org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)3 TException (org.apache.thrift.TException)3 ArrayList (java.util.ArrayList)2 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)2 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)2 RegistryService (org.apache.airavata.registry.api.RegistryService)2 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)2 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)2 CredentialStoreService (org.apache.airavata.credential.store.cpi.CredentialStoreService)1 JobSubmissionInterface (org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)1 SSHJobSubmission (org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission)1 ProcessModel (org.apache.airavata.model.process.ProcessModel)1