Search in sources :

Example 1 with UserStoragePreference

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

the class AiravataServerHandler method getUserStoragePreference.

@Override
@SecurityCheck
public UserStoragePreference getUserStoragePreference(AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    try {
        UserStoragePreference result = regClient.getUserStoragePreference(userId, gatewayID, userStorageId);
        registryClientPool.returnResource(regClient);
        return result;
    } catch (Exception e) {
        logger.error(userId, "Error while reading user data storage preference...", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while reading user data storage preference. 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) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) 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 UserStoragePreference

use of org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference 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 3 with UserStoragePreference

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

the class RegistryServerHandler method getUserStoragePreference.

/**
 * Fetch a Storage Resource Preference of a registered gateway profile.
 * @param userId identifier for user data model
 * @param gatewayID         The identifier of the gateway profile to request to fetch the particular storage resource preference.
 * @param storageId Identifier of the Storage Preference required to be fetched.
 * @return StoragePreference
 * Returns the StoragePreference object.
 */
@Override
public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) 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!!!");
        }
        UserStoragePreference storagePreference = userProfile.getUserStoragePreference(userId, gatewayID, storageId);
        logger.debug("Airavata retrieved user storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageId);
        return storagePreference;
    } catch (AppCatalogException e) {
        logger.error(gatewayID, "Error while reading gateway data storage preference...", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while reading gateway 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)

Example 4 with UserStoragePreference

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

the class UserResourceProfileTest method userProfileTest.

@Test
public void userProfileTest() throws Exception {
    UsrResourceProfile userProfile = appcatalog.getUserResourceProfile();
    UserResourceProfile uf = new UserResourceProfile();
    ComputeResource computeRs = appcatalog.getComputeResource();
    ComputeResourceDescription cm1 = new ComputeResourceDescription();
    cm1.setHostName("localhost");
    cm1.setResourceDescription("test compute host");
    String hostId1 = computeRs.addComputeResource(cm1);
    ComputeResourceDescription cm2 = new ComputeResourceDescription();
    cm2.setHostName("localhost");
    cm2.setResourceDescription("test compute host");
    String hostId2 = computeRs.addComputeResource(cm2);
    UserComputeResourcePreference preference1 = new UserComputeResourcePreference();
    preference1.setComputeResourceId(hostId1);
    preference1.setPreferredBatchQueue("queue1");
    preference1.setScratchLocation("/tmp");
    preference1.setAllocationProjectNumber("project1");
    UserComputeResourcePreference preference2 = new UserComputeResourcePreference();
    preference2.setComputeResourceId(hostId2);
    preference2.setPreferredBatchQueue("queue2");
    preference2.setScratchLocation("/tmp");
    preference2.setAllocationProjectNumber("project2");
    UserStoragePreference storagePreference = new UserStoragePreference();
    storagePreference.setStorageResourceId("st3");
    storagePreference.setLoginUserName("Anuj");
    storagePreference.setFileSystemRootLocation("/home/Anuj/scratch/");
    List<UserComputeResourcePreference> list = new ArrayList<UserComputeResourcePreference>();
    list.add(preference1);
    list.add(preference2);
    List<UserStoragePreference> stList = new ArrayList<>();
    stList.add(storagePreference);
    uf.setUserComputeResourcePreferences(list);
    uf.setGatewayID("airavataPGA");
    uf.setUserId("Anuj");
    uf.setUserStoragePreferences(stList);
    // Check if UserResourceProfile exists (should not exist)
    // This tests the mechanism that PGA will use to figure out if a user doesn't already have a UserResourceProfile
    UserResourceProfile checkUserResourceProfile = userProfile.getUserResourceProfile(uf.getUserId(), uf.getGatewayID());
    assertNotNull(checkUserResourceProfile.getUserId());
    assertNotNull(checkUserResourceProfile.getGatewayID());
    assertTrue(checkUserResourceProfile.isIsNull());
    String gwId = userProfile.addUserResourceProfile(uf);
    UserResourceProfile retrievedProfile = null;
    // This test is to check whether an existing user can add more compute preferences - AIRAVATA-2245
    System.out.println("*********Start Airavata-2245************");
    ComputeResource computeRs1 = appcatalog.getComputeResource();
    ComputeResourceDescription cm12 = new ComputeResourceDescription();
    cm12.setHostName("localhost123");
    cm12.setResourceDescription("test compute host");
    String hostId12 = computeRs1.addComputeResource(cm12);
    UserComputeResourcePreference preference12 = new UserComputeResourcePreference();
    preference12.setComputeResourceId(hostId12);
    preference12.setPreferredBatchQueue("queue112");
    preference12.setScratchLocation("/tmp21");
    preference12.setAllocationProjectNumber("project12");
    List<UserComputeResourcePreference> list12 = new ArrayList<UserComputeResourcePreference>();
    list12.add(preference12);
    UserResourceProfile uf12 = new UserResourceProfile();
    uf12.setUserComputeResourcePreferences(list12);
    uf12.setGatewayID("airavataPGA");
    uf12.setUserId("Anuj");
    String gwId12 = userProfile.addUserResourceProfile(uf12);
    System.out.println("*******End Airavata-2245******* : success");
    // retrievedProfile = userProfile.getUserResourceProfile("hello",uf.getGatewayID());
    if (userProfile.isUserResourceProfileExists(uf.getUserId(), uf.getGatewayID())) {
        retrievedProfile = userProfile.getUserResourceProfile(uf.getUserId(), uf.getGatewayID());
        assertFalse(retrievedProfile.isIsNull());
        System.out.println("gateway ID :" + retrievedProfile.getGatewayID());
        System.out.println("user ID : " + retrievedProfile.getUserId());
        System.out.println("compute resource size : " + retrievedProfile.getUserComputeResourcePreferencesSize());
    }
    if (retrievedProfile != null) {
        List<UserComputeResourcePreference> preferences = userProfile.getAllUserComputeResourcePreferences(retrievedProfile.getUserId(), retrievedProfile.getGatewayID());
        System.out.println("compute preferences size : " + preferences.size());
        if (preferences != null && !preferences.isEmpty()) {
            for (UserComputeResourcePreference cm : preferences) {
                System.out.println("******** host id ********* : " + cm.getComputeResourceId());
                System.out.println(cm.getPreferredBatchQueue());
                // this statement will remove all the compute resources created
                System.out.println("Compute Preference removed : " + userProfile.removeUserComputeResourcePreferenceFromGateway(retrievedProfile.getUserId(), retrievedProfile.getGatewayID(), cm.getComputeResourceId()));
            }
        }
        List<UserStoragePreference> storagePreferences = userProfile.getAllUserStoragePreferences(retrievedProfile.getUserId(), retrievedProfile.getGatewayID());
        System.out.println("storage preferences size : " + storagePreferences.size());
        if (storagePreferences != null && !storagePreferences.isEmpty()) {
            for (UserStoragePreference cm : storagePreferences) {
                System.out.println("******** storage id ********* : " + cm.getStorageResourceId());
                System.out.println(cm.getFileSystemRootLocation());
                // this statement will remove all the compute resources created
                System.out.println("Storage Preference removed : " + userProfile.removeUserDataStoragePreferenceFromGateway(retrievedProfile.getUserId(), retrievedProfile.getGatewayID(), cm.getStorageResourceId()));
            }
        }
        // remove the user resource profile created.
        System.out.println("User Resource profile removed : " + userProfile.removeUserResourceProfile(retrievedProfile.getUserId(), retrievedProfile.getGatewayID()));
    } else {
        System.out.println("User resource profile is null");
    }
    assertTrue("App interface saved successfully", retrievedProfile != null);
}
Also used : UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) ArrayList(java.util.ArrayList) ComputeResource(org.apache.airavata.registry.cpi.ComputeResource) UsrResourceProfile(org.apache.airavata.registry.cpi.UsrResourceProfile) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile) Test(org.junit.Test)

Example 5 with UserStoragePreference

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

the class UsrResourceProfileImpl method updateUserResourceProfile.

@Override
public void updateUserResourceProfile(String userId, String gatewayId, org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile updatedProfile) throws AppCatalogException {
    try {
        UserResourceProfileResource profileResource = new UserResourceProfileResource();
        CompositeIdentifier ids = new CompositeIdentifier(userId, gatewayId);
        UserResourceProfileResource existingUP = (UserResourceProfileResource) profileResource.get(ids);
        existingUP.setCredentialStoreToken(updatedProfile.getCredentialStoreToken());
        existingUP.setIdentityServerTenant(updatedProfile.getIdentityServerTenant());
        existingUP.setIdentityServerPwdCredToken(updatedProfile.getIdentityServerPwdCredToken());
        existingUP.save();
        List<UserComputeResourcePreference> userComputeResourcePreferences = updatedProfile.getUserComputeResourcePreferences();
        if (userComputeResourcePreferences != null && !userComputeResourcePreferences.isEmpty()) {
            for (UserComputeResourcePreference preference : userComputeResourcePreferences) {
                UserComputeHostPreferenceResource resource = new UserComputeHostPreferenceResource();
                resource.setUserResourceProfileResource(existingUP);
                resource.setResourceId(preference.getComputeResourceId());
                ComputeResourceResource computeHostResource = new ComputeResourceResource();
                resource.setComputeHostResource((ComputeResourceResource) computeHostResource.get(preference.getComputeResourceId()));
                resource.setUserId(userId);
                resource.setGatewayId(gatewayId);
                resource.setLoginUserName(preference.getLoginUserName());
                resource.setBatchQueue(preference.getPreferredBatchQueue());
                resource.setProjectNumber(preference.getAllocationProjectNumber());
                resource.setScratchLocation(preference.getScratchLocation());
                resource.setResourceCSToken(preference.getResourceSpecificCredentialStoreToken());
                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 = updatedProfile.getUserStoragePreferences();
        if (dataStoragePreferences != null && !dataStoragePreferences.isEmpty()) {
            for (UserStoragePreference storagePreference : dataStoragePreferences) {
                UserStoragePreferenceResource resource = new UserStoragePreferenceResource();
                resource.setStorageResourceId(storagePreference.getStorageResourceId());
                resource.setGatewayId(existingUP.getGatewayID());
                resource.setUserId(existingUP.getUserId());
                resource.setFsRootLocation(storagePreference.getFileSystemRootLocation());
                resource.setLoginUserName(storagePreference.getLoginUserName());
                resource.setResourceCSToken(storagePreference.getResourceSpecificCredentialStoreToken());
                resource.setUserResourceProfileResource(existingUP);
                resource.save();
            }
        }
    } catch (Exception e) {
        logger.error("Error while updating User Resource profile...", e);
        throw new AppCatalogException(e);
    }
}
Also used : AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) CompositeIdentifier(org.apache.airavata.registry.cpi.CompositeIdentifier) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Aggregations

UserStoragePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference)9 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)5 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)4 UserResourceProfile (org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile)3 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)3 ArrayList (java.util.ArrayList)2 CompositeIdentifier (org.apache.airavata.registry.cpi.CompositeIdentifier)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 RegistryService (org.apache.airavata.registry.api.RegistryService)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