Search in sources :

Example 1 with UserComputeResourcePreference

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

the class GFacEngineImpl method setUserComputeResourcePreference.

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

Example 2 with UserComputeResourcePreference

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

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

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

the class SSHAccountManager method setupSSHAccount.

/**
 * Add SSH key to compute resource on behalf of user.
 * @param gatewayId
 * @param computeResourceId
 * @param userId Airavata user id
 * @param sshCredential
 * @return a populated but not persisted UserComputeResourcePreference instance
 * @throws InvalidSetupException
 * @throws InvalidUsernameException
 */
public static UserComputeResourcePreference setupSSHAccount(String gatewayId, String computeResourceId, String userId, SSHCredential sshCredential) throws InvalidSetupException, InvalidUsernameException {
    // get compute resource preferences for the gateway and hostname
    RegistryService.Client registryServiceClient = getRegistryServiceClient();
    ComputeResourcePreference computeResourcePreference = null;
    ComputeResourceDescription computeResourceDescription = null;
    SSHJobSubmission sshJobSubmission = null;
    try {
        computeResourcePreference = registryServiceClient.getGatewayComputeResourcePreference(gatewayId, computeResourceId);
        computeResourceDescription = registryServiceClient.getComputeResource(computeResourceId);
        // Find the SSHJobSubmission
        for (JobSubmissionInterface jobSubmissionInterface : computeResourceDescription.getJobSubmissionInterfaces()) {
            if (jobSubmissionInterface.getJobSubmissionProtocol() == JobSubmissionProtocol.SSH) {
                sshJobSubmission = registryServiceClient.getSSHJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
                break;
            }
        }
    } catch (TException e) {
        throw new RuntimeException("Failed to retrieve compute resource information for [" + gatewayId + "] and " + "[" + computeResourceId + "]: " + e.getMessage(), e);
    } finally {
        if (registryServiceClient.getInputProtocol().getTransport().isOpen()) {
            registryServiceClient.getInputProtocol().getTransport().close();
        }
        if (registryServiceClient.getOutputProtocol().getTransport().isOpen()) {
            registryServiceClient.getOutputProtocol().getTransport().close();
        }
    }
    if (sshJobSubmission == null) {
        throw new InvalidSetupException("Compute resource [" + computeResourceId + "] does not have an SSH Job Submission " + "interface.");
    }
    // get the account provisioner and config values for the preferences
    if (!computeResourcePreference.isSetSshAccountProvisioner()) {
        throw new InvalidSetupException("Compute resource [" + computeResourceId + "] does not have an SSH Account Provisioner " + "configured for it.");
    }
    // instantiate and init the account provisioner
    SSHAccountProvisioner sshAccountProvisioner = createSshAccountProvisioner(gatewayId, computeResourcePreference);
    boolean canCreateAccount = SSHAccountProvisionerFactory.canCreateAccount(computeResourcePreference.getSshAccountProvisioner());
    // First check if userId has an account
    boolean hasAccount = false;
    try {
        hasAccount = sshAccountProvisioner.hasAccount(userId);
    } catch (InvalidUsernameException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("hasAccount call failed for userId [" + userId + "]: " + e.getMessage(), e);
    }
    if (!hasAccount && !canCreateAccount) {
        throw new InvalidSetupException("User [" + userId + "] doesn't have account and [" + computeResourceId + "] doesn't " + "have a SSH Account Provisioner that supports creating accounts.");
    }
    // TODO: create account for user if user doesn't have account
    String username = null;
    // Install SSH key
    try {
        username = sshAccountProvisioner.installSSHKey(userId, sshCredential.getPublicKey());
    } catch (InvalidUsernameException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("installSSHKey call failed for userId [" + userId + "]: " + e.getMessage(), e);
    }
    // Verify can authenticate to host
    String sshHostname = getSSHHostname(computeResourceDescription, sshJobSubmission);
    int sshPort = sshJobSubmission.getSshPort();
    boolean validated = false;
    try {
        validated = SSHUtil.validate(sshHostname, sshPort, username, sshCredential);
    } catch (Exception e) {
        throw new RuntimeException("Failed to validate SSH public key installation for account for user [" + username + "] on host [" + sshHostname + "]: " + e.getMessage(), e);
    }
    if (!validated) {
        throw new RuntimeException("Failed to validate installation of key for [" + username + "] on [" + computeResourceDescription.getHostName() + "] using SSH Account Provisioner [" + computeResourcePreference.getSshAccountProvisioner() + "]");
    }
    // create the scratch location on the host
    String scratchLocation = sshAccountProvisioner.getScratchLocation(userId);
    try {
        SSHUtil.execute(sshHostname, sshPort, username, sshCredential, "mkdir -p " + scratchLocation);
    } catch (Exception e) {
        throw new RuntimeException("Failed to create scratch location [" + scratchLocation + "] for user [" + username + "] on host [" + sshHostname + "]: " + e.getMessage(), e);
    }
    UserComputeResourcePreference userComputeResourcePreference = new UserComputeResourcePreference();
    userComputeResourcePreference.setComputeResourceId(computeResourceId);
    userComputeResourcePreference.setLoginUserName(username);
    userComputeResourcePreference.setScratchLocation(scratchLocation);
    userComputeResourcePreference.setValidated(true);
    return userComputeResourcePreference;
}
Also used : TException(org.apache.thrift.TException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) SSHJobSubmission(org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission) TException(org.apache.thrift.TException) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) RegistryService(org.apache.airavata.registry.api.RegistryService)

Example 5 with UserComputeResourcePreference

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

the class AppCatalogThriftConversion method getUserComputeResourcePreference.

public static UserComputeResourcePreference getUserComputeResourcePreference(UserComputeHostPreferenceResource resource) {
    UserComputeResourcePreference preference = new UserComputeResourcePreference();
    preference.setComputeResourceId(resource.getResourceId());
    preference.setPreferredBatchQueue(resource.getBatchQueue());
    preference.setScratchLocation(resource.getScratchLocation());
    preference.setAllocationProjectNumber(resource.getProjectNumber());
    preference.setLoginUserName(resource.getLoginUserName());
    preference.setResourceSpecificCredentialStoreToken(resource.getResourceCSToken());
    preference.setQualityOfService(resource.getQualityOfService());
    preference.setReservation(resource.getReservation());
    if (resource.getReservationStartTime() != null) {
        preference.setReservationStartTime(resource.getReservationStartTime().getTime());
    }
    if (resource.getReservationEndTime() != null) {
        preference.setReservationEndTime(resource.getReservationEndTime().getTime());
    }
    preference.setValidated(resource.isValidated());
    return preference;
}
Also used : UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)

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