Search in sources :

Example 1 with UserResourceProfile

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

the class AiravataServerHandler method getUserResourceProfile.

/**
 * Fetch the given User Resource Profile.
 *
 * @param userId The identifier for the requested User resource
 *
 * @param gatewayID The identifier to link a gateway for the requested User resource
 *
 * @return userResourceProfile
 * User Resource Profile Object.
 */
@Override
@SecurityCheck
public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    try {
        UserResourceProfile result = regClient.getUserResourceProfile(userId, gatewayID);
        registryClientPool.returnResource(regClient);
        return result;
    } catch (Exception e) {
        logger.error(userId, "Error while retrieving user resource profile...", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage());
        registryClientPool.returnBrokenResource(regClient);
        throw exception;
    }
}
Also used : RegistryService(org.apache.airavata.registry.api.RegistryService) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile) 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 2 with UserResourceProfile

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

the class GFacEngineImpl method setUserResourceProfile.

private void setUserResourceProfile(String gatewayId, ProcessContext processContext) throws AppCatalogException {
    AppCatalog appCatalog = processContext.getAppCatalog();
    ProcessModel processModel = processContext.getProcessModel();
    UserResourceProfile userResourceProfile = appCatalog.getUserResourceProfile().getUserResourceProfile(processModel.getUserName(), gatewayId);
    processContext.setUserResourceProfile(userResourceProfile);
}
Also used : ProcessModel(org.apache.airavata.model.process.ProcessModel) AppCatalog(org.apache.airavata.registry.cpi.AppCatalog) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)

Example 3 with UserResourceProfile

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

the class RegistryServerHandler method updateUserStoragePreference.

/**
 * Update a Storage Resource Preference of a registered user resource profile.
 * @param userId identifier for user data model
 * @param gatewayID         The identifier of the gateway profile to be updated.
 * @param storageId         The Storage resource identifier of the one that you want to update
 * @param userStoragePreference The storagePreference object to be updated to the resource profile.
 * @return status
 * Returns a success/failure of the updation.
 */
@Override
public boolean updateUserStoragePreference(String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) 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();
        UsrResourceProfile userProfile = appCatalog.getUserResourceProfile();
        UserResourceProfile profile = userProfile.getUserResourceProfile(userId, gatewayID);
        List<UserStoragePreference> dataStoragePreferences = profile.getUserStoragePreferences();
        UserStoragePreference preferenceToRemove = null;
        for (UserStoragePreference preference : dataStoragePreferences) {
            if (preference.getStorageResourceId().equals(storageId)) {
                preferenceToRemove = preference;
                break;
            }
        }
        if (preferenceToRemove != null) {
            profile.getUserStoragePreferences().remove(preferenceToRemove);
        }
        profile.getUserStoragePreferences().add(userStoragePreference);
        userProfile.updateUserResourceProfile(userId, gatewayID, profile);
        logger.debug("Airavata updated user storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageId);
        return true;
    } catch (AppCatalogException e) {
        logger.error(gatewayID, "Error while reading user data storage preference...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while updating user data storage 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 : RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)

Example 4 with UserResourceProfile

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

the class RegistryServerHandler method updateUserComputeResourcePreference.

/**
 * Update a Compute Resource Preference to a registered user resource profile.
 * @param userId identifier for user data model
 * @param gatewayID                 The identifier for the gateway profile to be updated.
 * @param computeResourceId         Preferences related to a particular compute resource
 * @param userComputeResourcePreference The ComputeResourcePreference object to be updated to the resource profile.
 * @return status
 * Returns a success/failure of the updation.
 */
@Override
public boolean updateUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) 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();
        UsrResourceProfile userProfile = appCatalog.getUserResourceProfile();
        UserResourceProfile profile = userProfile.getUserResourceProfile(userId, gatewayID);
        List<UserComputeResourcePreference> userComputeResourcePreferences = profile.getUserComputeResourcePreferences();
        UserComputeResourcePreference preferenceToRemove = null;
        for (UserComputeResourcePreference preference : userComputeResourcePreferences) {
            if (preference.getComputeResourceId().equals(computeResourceId)) {
                preferenceToRemove = preference;
                break;
            }
        }
        if (preferenceToRemove != null) {
            profile.getUserComputeResourcePreferences().remove(preferenceToRemove);
        }
        profile.getUserComputeResourcePreferences().add(userComputeResourcePreference);
        userProfile.updateUserResourceProfile(userId, gatewayID, profile);
        logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID + " and for compute resource id : " + computeResourceId);
        return true;
    } catch (AppCatalogException e) {
        logger.error(userId, "Error while reading user compute resource preference...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while updating 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) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)

Example 5 with UserResourceProfile

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

the class RegistryServerHandler method addUserStoragePreference.

/**
 * Add a Storage Resource Preference to a registered gateway profile.
 *
 * @param gatewayID         The identifier of the gateway profile to be added.
 * @param storageResourceId Preferences related to a particular compute resource
 * @param dataStoragePreference
 * @return status
 * Returns a success/failure of the addition. If a profile already exists, this operation will fail.
 * Instead an update should be used.
 */
@Override
public boolean addUserStoragePreference(String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) 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();
        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!!!");
        }
        UserResourceProfile profile = userProfile.getUserResourceProfile(userId, gatewayID);
        // gatewayProfile.removeGatewayResourceProfile(gatewayID);
        dataStoragePreference.setStorageResourceId(storageResourceId);
        profile.addToUserStoragePreferences(dataStoragePreference);
        userProfile.updateUserResourceProfile(userId, gatewayID, profile);
        logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageResourceId);
        return true;
    } catch (AppCatalogException e) {
        logger.error(gatewayID, "Error while registering user resource profile preference...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while registering user resource profile 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 : RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)

Aggregations

UserResourceProfile (org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)11 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)6 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)3 UserStoragePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference)3 ArrayList (java.util.ArrayList)2 AiravataException (org.apache.airavata.common.exception.AiravataException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)1 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)1 ProcessModel (org.apache.airavata.model.process.ProcessModel)1 RegistryService (org.apache.airavata.registry.api.RegistryService)1 AppCatalog (org.apache.airavata.registry.cpi.AppCatalog)1 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)1 ComputeResource (org.apache.airavata.registry.cpi.ComputeResource)1 UsrResourceProfile (org.apache.airavata.registry.cpi.UsrResourceProfile)1 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)1 SharingRegistryService (org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService)1 TException (org.apache.thrift.TException)1 Test (org.junit.Test)1