Search in sources :

Example 6 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference 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 7 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class SSHAccountManager method doesUserHaveSSHAccount.

/**
 * Check if user has an SSH account on the compute resource.
 * @param gatewayId
 * @param computeResourceId
 * @param userId Airavata user id
 * @return
 * @throws InvalidSetupException
 * @throws InvalidUsernameException
 */
public static boolean doesUserHaveSSHAccount(String gatewayId, String computeResourceId, String userId) throws InvalidSetupException, InvalidUsernameException {
    // get compute resource preferences for the gateway and hostname
    RegistryService.Client registryServiceClient = getRegistryServiceClient();
    ComputeResourcePreference computeResourcePreference = null;
    try {
        computeResourcePreference = registryServiceClient.getGatewayComputeResourcePreference(gatewayId, computeResourceId);
    } catch (TException e) {
        throw new RuntimeException("Failed to get ComputeResourcePreference 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();
        }
    }
    // 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.");
    }
    SSHAccountProvisioner sshAccountProvisioner = createSshAccountProvisioner(gatewayId, computeResourcePreference);
    try {
        return sshAccountProvisioner.hasAccount(userId);
    } catch (InvalidUsernameException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("hasAccount call failed for userId [" + userId + "]: " + e.getMessage(), e);
    }
}
Also used : TException(org.apache.thrift.TException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) RegistryService(org.apache.airavata.registry.api.RegistryService) 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)

Example 8 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class DocumentCreatorNew method createLocalHostDocs.

public String createLocalHostDocs() throws AppCatalogException, InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
    // Define compute resource host
    ComputeResourceDescription host = DocumentCreatorUtils.createComputeResourceDescription("localhost", new ArrayList<String>(Arrays.asList(new String[] { "127.0.0.1" })), new ArrayList<String>(Arrays.asList(new String[] { "127.0.0.1" })));
    // host.setIsEmpty(true);
    host.setComputeResourceId(client.registerComputeResource(authzToken, host));
    LOCALSubmission localSubmission = new LOCALSubmission();
    ResourceJobManager resourceJobManager = DocumentCreatorUtils.createResourceJobManager(ResourceJobManagerType.FORK, null, null, null);
    localSubmission.setResourceJobManager(resourceJobManager);
    client.addLocalSubmissionDetails(authzToken, host.getComputeResourceId(), 1, localSubmission);
    LOCALDataMovement localDataMovement = new LOCALDataMovement();
    client.addLocalDataMovementDetails(authzToken, host.getComputeResourceId(), 1, localDataMovement);
    // Define application module
    ApplicationModule module = DocumentCreatorUtils.createApplicationModule("echo", "1.0.0", "Local host echo applications");
    module.setAppModuleId(client.registerApplicationModule(authzToken, DEFAULT_GATEWAY, module));
    // Define application interfaces
    ApplicationInterfaceDescription application = new ApplicationInterfaceDescription();
    // application.setIsEmpty(false);
    application.setApplicationName("SimpleEcho0");
    application.addToApplicationModules(module.getAppModuleId());
    application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("echo_input", "echo_input", "Echo Input Data", null, DataType.STRING));
    application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("echo_output", null, DataType.STRING));
    application.setApplicationInterfaceId(client.registerApplicationInterface(authzToken, DEFAULT_GATEWAY, application));
    // Define application deployment
    ApplicationDeploymentDescription deployment = DocumentCreatorUtils.createApplicationDeployment(host.getComputeResourceId(), module.getAppModuleId(), "/bin/echo", ApplicationParallelismType.SERIAL, "Local echo app depoyment");
    deployment.setAppDeploymentId(client.registerApplicationDeployment(authzToken, DEFAULT_GATEWAY, deployment));
    // Define gateway profile
    ComputeResourcePreference computeResourcePreference = DocumentCreatorUtils.createComputeResourcePreference(host.getComputeResourceId(), "/tmp", null, false, null, null, null);
    gatewayResourceProfile = new GatewayResourceProfile();
    // gatewayResourceProfile.setGatewayID("default");
    gatewayResourceProfile.setGatewayID(DEFAULT_GATEWAY);
    gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
    String gatewayId = client.registerGatewayResourceProfile(authzToken, gatewayResourceProfile);
    gatewayResourceProfile.setGatewayID(gatewayId);
    client.addGatewayComputeResourcePreference(authzToken, gatewayResourceProfile.getGatewayID(), host.getComputeResourceId(), computeResourcePreference);
    return host.getComputeResourceId() + "," + application.getApplicationInterfaceId();
}
Also used : LOCALSubmission(org.apache.airavata.model.appcatalog.computeresource.LOCALSubmission) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) ResourceJobManager(org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) ApplicationModule(org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule)

Example 9 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class DocumentCreatorUtils method createComputeResourcePreference.

public static ComputeResourcePreference createComputeResourcePreference(String computeResourceId, String scratchLocation, String allocationProjectNumber, boolean overridebyAiravata, String preferredBatchQueue, JobSubmissionProtocol preferredJobSubmissionProtocol, DataMovementProtocol preferredDataMovementProtocol) throws AppCatalogException {
    ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
    computeResourcePreference.setComputeResourceId(computeResourceId);
    computeResourcePreference.setOverridebyAiravata(overridebyAiravata);
    computeResourcePreference.setAllocationProjectNumber(allocationProjectNumber);
    computeResourcePreference.setPreferredBatchQueue(preferredBatchQueue);
    computeResourcePreference.setPreferredDataMovementProtocol(preferredDataMovementProtocol);
    computeResourcePreference.setPreferredJobSubmissionProtocol(preferredJobSubmissionProtocol);
    computeResourcePreference.setScratchLocation(scratchLocation);
    return computeResourcePreference;
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)

Example 10 with ComputeResourcePreference

use of org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference in project airavata by apache.

the class AppCatalogThriftConversion method getComputeResourcePreference.

public static ComputeResourcePreference getComputeResourcePreference(ComputeHostPreferenceResource resource) {
    ComputeResourcePreference preference = new ComputeResourcePreference();
    preference.setComputeResourceId(resource.getResourceId());
    preference.setOverridebyAiravata(resource.getOverrideByAiravata());
    if (resource.getPreferredJobProtocol() != null) {
        preference.setPreferredJobSubmissionProtocol(JobSubmissionProtocol.valueOf(resource.getPreferredJobProtocol()));
    }
    if (resource.getPreferedDMProtocol() != null) {
        preference.setPreferredDataMovementProtocol(DataMovementProtocol.valueOf(resource.getPreferedDMProtocol()));
    }
    preference.setPreferredBatchQueue(resource.getBatchQueue());
    preference.setScratchLocation(resource.getScratchLocation());
    preference.setAllocationProjectNumber(resource.getProjectNumber());
    preference.setLoginUserName(resource.getLoginUserName());
    preference.setResourceSpecificCredentialStoreToken(resource.getResourceCSToken());
    if (null != resource.getUsageReportingGatewayId()) {
        preference.setUsageReportingGatewayId(resource.getUsageReportingGatewayId());
    } else {
        preference.setUsageReportingGatewayId(resource.getGatewayId());
    }
    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.setSshAccountProvisioner(resource.getSshAccountProvisioner());
    if (resource.getSshAccountProvisionerConfigurations() != null && !resource.getSshAccountProvisionerConfigurations().isEmpty()) {
        Map<String, String> sshAccountProvisionerConfigCopy = new HashMap<>(resource.getSshAccountProvisionerConfigurations());
        preference.setSshAccountProvisionerConfig(sshAccountProvisionerConfigCopy);
    }
    preference.setSshAccountProvisionerAdditionalInfo(resource.getSshAccountProvisionerAdditionalInfo());
    return preference;
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) HashMap(java.util.HashMap)

Aggregations

ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)30 GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)10 UserComputeResourcePreference (org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference)10 TException (org.apache.thrift.TException)10 AiravataException (org.apache.airavata.common.exception.AiravataException)5 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)5 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)5 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)5 StoragePreference (org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference)4 RegistryService (org.apache.airavata.registry.api.RegistryService)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)3 JobSubmissionInterface (org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface)3 AuthzToken (org.apache.airavata.model.security.AuthzToken)3 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)3 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)2 ApplicationInterfaceDescription (org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription)2 LaunchValidationException (org.apache.airavata.model.error.LaunchValidationException)2 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)2