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;
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations