use of org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission 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.computeresource.SSHJobSubmission in project airavata by apache.
the class DocumentCreatorNew method createStampedeAmberDocs.
public String createStampedeAmberDocs() throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException, AppCatalogException {
ComputeResourceDescription host = DocumentCreatorUtils.createComputeResourceDescription(stampedeHostAddress, null, null);
host.addToHostAliases(stampedeHostAddress);
host.addToIpAddresses(stampedeHostAddress);
host.setComputeResourceId(client.registerComputeResource(authzToken, host));
ResourceJobManager resourceJobManager = DocumentCreatorUtils.createResourceJobManager(ResourceJobManagerType.SLURM, "/usr/bin/", null, "push");
SSHJobSubmission sshJobSubmission = new SSHJobSubmission();
sshJobSubmission.setResourceJobManager(resourceJobManager);
sshJobSubmission.setSecurityProtocol(SecurityProtocol.GSI);
sshJobSubmission.setSshPort(2222);
client.addSSHJobSubmissionDetails(authzToken, host.getComputeResourceId(), 1, sshJobSubmission);
SCPDataMovement scpDataMovement = new SCPDataMovement();
scpDataMovement.setSecurityProtocol(SecurityProtocol.GSI);
scpDataMovement.setSshPort(22);
client.addSCPDataMovementDetails(authzToken, host.getComputeResourceId(), 1, scpDataMovement);
ApplicationModule amodule = DocumentCreatorUtils.createApplicationModule("Amber", "12.0", null);
amodule.setAppModuleId(client.registerApplicationModule(authzToken, DEFAULT_GATEWAY, amodule));
ApplicationInterfaceDescription application = new ApplicationInterfaceDescription();
application.setApplicationName("AmberBR2");
application.addToApplicationModules(amodule.getAppModuleId());
application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("AMBER_HEAT_RST", "AMBER_HEAT_RST", null, null, DataType.URI));
application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("AMBER_PROD_IN", "AMBER_PROD_IN", null, null, DataType.URI));
application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("AMBER_PRMTOP", "AMBER_PRMTOP", null, null, DataType.URI));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("AMBER_Prod.info", null, DataType.URI));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("AMBER_Prod.mdcrd", null, DataType.URI));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("AMBER_Prod.out", null, DataType.URI));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("AMBER_Prod.rst", null, DataType.URI));
application.setApplicationInterfaceId(client.registerApplicationInterface(authzToken, DEFAULT_GATEWAY, application));
ApplicationDeploymentDescription deployment = DocumentCreatorUtils.createApplicationDeployment(host.getComputeResourceId(), amodule.getAppModuleId(), "/home1/01437/ogce/production/app_wrappers/amber_wrapper.sh", ApplicationParallelismType.SERIAL, "AmberStampede");
deployment.setAppDeploymentId(client.registerApplicationDeployment(authzToken, DEFAULT_GATEWAY, deployment));
client.addGatewayComputeResourcePreference(authzToken, getGatewayResourceProfile().getGatewayID(), host.getComputeResourceId(), DocumentCreatorUtils.createComputeResourcePreference(host.getComputeResourceId(), "/home1/01437/ogce", "TG-STA110014S", false, null, null, null));
return host.getComputeResourceId() + "," + application.getApplicationInterfaceId();
}
use of org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission in project airavata by apache.
the class DocumentCreatorNew method createPBSDocsForOGCE_Echo.
//
// public void createGramDocs() {
// // /*
// // creating host descriptor for gram
// // */
// // HostDescription host = new HostDescription(GlobusHostType.type);
// // host.getType().setHostAddress(trestleshpcHostAddress);
// // host.getType().setHostName(trestleshpcHostAddress);
// // ((GlobusHostType) host.getType()).setGlobusGateKeeperEndPointArray(new String[]{gramAddress});
// // ((GlobusHostType) host.getType()).setGridFTPEndPointArray(new String[]{gridftpAddress});
// // try {
// // airavataAPI.getApplicationManager().saveHostDescription(host);
// // } catch (AiravataAPIInvocationException e) {
// // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
// // }
// //
// //
// // /*
// // * Service Description creation and saving
// // */
// // String serviceName = "SimpleEcho1";
// // ServiceDescription serv = new ServiceDescription();
// // serv.getType().setName(serviceName);
// //
// // List<InputParameterType> inputList = new ArrayList<InputParameterType>();
// // List<OutputParameterType> outputList = new ArrayList<OutputParameterType>();
// //
// // InputParameterType input = InputParameterType.Factory.newInstance();
// // input.setParameterName("echo_input");
// // ParameterType parameterType = input.addNewParameterType();
// // parameterType.setType(DataType.STRING);
// // parameterType.setName("String");
// //
// // OutputParameterType output = OutputParameterType.Factory.newInstance();
// // output.setParameterName("echo_output");
// // ParameterType parameterType1 = output.addNewParameterType();
// // parameterType1.setType(DataType.STRING);
// // parameterType1.setName("String");
// //
// // inputList.add(input);
// // outputList.add(output);
// //
// // InputParameterType[] inputParamList = inputList.toArray(new InputParameterType[inputList.size()]);
// // OutputParameterType[] outputParamList = outputList.toArray(new OutputParameterType[outputList.size()]);
// //
// // serv.getType().setInputParametersArray(inputParamList);
// // serv.getType().setOutputParametersArray(outputParamList);
// // try {
// // airavataAPI.getApplicationManager().saveServiceDescription(serv);
// // } catch (AiravataAPIInvocationException e) {
// // e.printStackTrace();
// // }
// //
// // /*
// // Application descriptor creation and saving
// // */
// // ApplicationDescription appDesc = new ApplicationDescription(HpcApplicationDeploymentType.type);
// // HpcApplicationDeploymentType app = (HpcApplicationDeploymentType) appDesc.getType();
// // ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance();
// // name.setStringValue("EchoLocal");
// // app.setApplicationName(name);
// // ProjectAccountType projectAccountType = app.addNewProjectAccount();
// // projectAccountType.setProjectAccountNumber("sds128");
// //
// // QueueType queueType = app.addNewQueue();
// // queueType.setQueueName("normal");
// //
// // app.setCpuCount(1);
// // app.setJobType(JobTypeType.SERIAL);
// // app.setNodeCount(1);
// // app.setProcessorsPerNode(1);
// //
// // /*
// // * Use bat file if it is compiled on Windows
// // */
// // app.setExecutableLocation("/bin/echo");
// //
// // /*
// // * Default tmp location
// // */
// // String tempDir = "/home/ogce/scratch";
// // app.setScratchWorkingDirectory(tempDir);
// // app.setMaxMemory(10);
// //
// //
// // try {
// // airavataAPI.getApplicationManager().saveApplicationDescription(serviceName, trestleshpcHostAddress, appDesc);
// // } catch (AiravataAPIInvocationException e) {
// // e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
// // }
// }
//
public String createPBSDocsForOGCE_Echo() throws AppCatalogException, InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
ComputeResourceDescription host = DocumentCreatorUtils.createComputeResourceDescription(trestleshpcHostAddress, null, null);
host.addToIpAddresses(trestleshpcHostAddress);
host.addToHostAliases(trestleshpcHostAddress);
host.setComputeResourceId(client.registerComputeResource(authzToken, host));
SSHJobSubmission sshJobSubmission = new SSHJobSubmission();
ResourceJobManager resourceJobManager = DocumentCreatorUtils.createResourceJobManager(ResourceJobManagerType.PBS, "/opt/torque/bin/", null, null);
sshJobSubmission.setResourceJobManager(resourceJobManager);
sshJobSubmission.setSecurityProtocol(SecurityProtocol.GSI);
sshJobSubmission.setSshPort(22);
client.addSSHJobSubmissionDetails(authzToken, host.getComputeResourceId(), 1, sshJobSubmission);
SCPDataMovement scpDataMovement = new SCPDataMovement();
scpDataMovement.setSecurityProtocol(SecurityProtocol.GSI);
scpDataMovement.setSshPort(22);
client.addSCPDataMovementDetails(authzToken, host.getComputeResourceId(), 1, scpDataMovement);
ApplicationModule module1 = DocumentCreatorUtils.createApplicationModule("echo", "1.2", null);
module1.setAppModuleId(client.registerApplicationModule(authzToken, DEFAULT_GATEWAY, module1));
ApplicationInterfaceDescription application = new ApplicationInterfaceDescription();
// application.setIsEmpty(false);
application.setApplicationName("SimpleEcho2");
application.addToApplicationModules(module1.getAppModuleId());
application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("echo_input", "echo_input", "echo_input", null, DataType.STRING));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("echo_output", null, DataType.STRING));
application.setApplicationInterfaceId(client.registerApplicationInterface(authzToken, DEFAULT_GATEWAY, application));
ApplicationDeploymentDescription deployment = DocumentCreatorUtils.createApplicationDeployment(host.getComputeResourceId(), module1.getAppModuleId(), "/home/ogce/echo.sh", ApplicationParallelismType.SERIAL, "Echo application");
deployment.setAppDeploymentId(client.registerApplicationDeployment(authzToken, DEFAULT_GATEWAY, deployment));
client.addGatewayComputeResourcePreference(authzToken, getGatewayResourceProfile().getGatewayID(), host.getComputeResourceId(), DocumentCreatorUtils.createComputeResourcePreference(host.getComputeResourceId(), "/oasis/scratch/trestles/ogce/temp_project/", "sds128", false, null, null, null));
return host.getComputeResourceId() + "," + application.getApplicationInterfaceId();
}
use of org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission in project airavata by apache.
the class DocumentCreatorNew method createSlurmDocs.
public String createSlurmDocs() throws AppCatalogException, InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
ComputeResourceDescription host = DocumentCreatorUtils.createComputeResourceDescription(stampedeHostAddress, null, null);
host.addToHostAliases(stampedeHostAddress);
host.addToIpAddresses(stampedeHostAddress);
host.setComputeResourceId(client.registerComputeResource(authzToken, host));
ResourceJobManager resourceJobManager = DocumentCreatorUtils.createResourceJobManager(ResourceJobManagerType.SLURM, "/usr/bin/", null, "push");
SSHJobSubmission sshJobSubmission = new SSHJobSubmission();
sshJobSubmission.setResourceJobManager(resourceJobManager);
sshJobSubmission.setSecurityProtocol(SecurityProtocol.GSI);
sshJobSubmission.setSshPort(2222);
client.addSSHJobSubmissionDetails(authzToken, host.getComputeResourceId(), 1, sshJobSubmission);
SCPDataMovement scpDataMovement = new SCPDataMovement();
scpDataMovement.setSecurityProtocol(SecurityProtocol.GSI);
scpDataMovement.setSshPort(22);
client.addSCPDataMovementDetails(authzToken, host.getComputeResourceId(), 1, scpDataMovement);
ApplicationModule module = DocumentCreatorUtils.createApplicationModule("echo", "1.3", null);
module.setAppModuleId(client.registerApplicationModule(authzToken, DEFAULT_GATEWAY, module));
ApplicationInterfaceDescription application = new ApplicationInterfaceDescription();
// application.setIsEmpty(false);
application.setApplicationName("SimpleEcho3");
application.addToApplicationModules(module.getAppModuleId());
application.addToApplicationInputs(DocumentCreatorUtils.createAppInput("echo_input", "echo_input", null, null, DataType.STRING));
application.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("echo_output", null, DataType.STRING));
application.setApplicationInterfaceId(client.registerApplicationInterface(authzToken, DEFAULT_GATEWAY, application));
ApplicationDeploymentDescription deployment = DocumentCreatorUtils.createApplicationDeployment(host.getComputeResourceId(), module.getAppModuleId(), "/bin/echo", ApplicationParallelismType.SERIAL, "EchoLocal");
deployment.setAppDeploymentId(client.registerApplicationDeployment(authzToken, DEFAULT_GATEWAY, deployment));
client.addGatewayComputeResourcePreference(authzToken, getGatewayResourceProfile().getGatewayID(), host.getComputeResourceId(), DocumentCreatorUtils.createComputeResourcePreference(host.getComputeResourceId(), "/home1/01437/ogce", "TG-STA110014S", false, null, null, null));
return host.getComputeResourceId() + "," + application.getApplicationInterfaceId();
}
use of org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission in project airavata by apache.
the class DocumentCreatorNew method createSlumWRFDocs.
public String createSlumWRFDocs() throws AppCatalogException, TException {
ComputeResourceDescription host = DocumentCreatorUtils.createComputeResourceDescription(stampedeHostAddress, null, null);
host.addToHostAliases(stampedeHostAddress);
host.addToIpAddresses(stampedeHostAddress);
host.setComputeResourceId(client.registerComputeResource(authzToken, host));
ResourceJobManager resourceJobManager = DocumentCreatorUtils.createResourceJobManager(ResourceJobManagerType.SLURM, "/usr/bin/", null, "push");
SSHJobSubmission sshJobSubmission = new SSHJobSubmission();
sshJobSubmission.setResourceJobManager(resourceJobManager);
sshJobSubmission.setSecurityProtocol(SecurityProtocol.GSI);
sshJobSubmission.setSshPort(2222);
client.addSSHJobSubmissionDetails(authzToken, host.getComputeResourceId(), 1, sshJobSubmission);
SCPDataMovement scpDataMovement = new SCPDataMovement();
scpDataMovement.setSecurityProtocol(SecurityProtocol.GSI);
scpDataMovement.setSshPort(22);
client.addSCPDataMovementDetails(authzToken, host.getComputeResourceId(), 1, scpDataMovement);
client.addSCPDataMovementDetails(authzToken, host.getComputeResourceId(), 1, scpDataMovement);
client.addGatewayComputeResourcePreference(authzToken, getGatewayResourceProfile().getGatewayID(), host.getComputeResourceId(), DocumentCreatorUtils.createComputeResourcePreference(host.getComputeResourceId(), "/home1/01437/ogce", "TG-STA110014S", false, null, null, null));
ApplicationModule module2 = DocumentCreatorUtils.createApplicationModule("wrf", "1.0.0", null);
module2.setAppModuleId(client.registerApplicationModule(authzToken, DEFAULT_GATEWAY, module2));
ApplicationInterfaceDescription application2 = new ApplicationInterfaceDescription();
// application2.setIsEmpty(false);
application2.setApplicationName("WRF");
application2.addToApplicationModules(module2.getAppModuleId());
application2.addToApplicationInputs(DocumentCreatorUtils.createAppInput("WRF_Namelist", "WRF_Namelist", null, null, DataType.URI));
application2.addToApplicationInputs(DocumentCreatorUtils.createAppInput("WRF_Boundary_File", "WRF_Boundary_File", null, null, DataType.URI));
application2.addToApplicationInputs(DocumentCreatorUtils.createAppInput("WRF_Input_File", "WRF_Input_File", null, null, DataType.URI));
application2.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("WRF_Output", null, DataType.URI));
application2.addToApplicationOutputs(DocumentCreatorUtils.createAppOutput("WRF_Execution_Log", null, DataType.URI));
application2.setApplicationInterfaceId(client.registerApplicationInterface(authzToken, DEFAULT_GATEWAY, application2));
ApplicationDeploymentDescription deployment2 = DocumentCreatorUtils.createApplicationDeployment(host.getComputeResourceId(), module2.getAppModuleId(), "/home1/01437/ogce/production/app_wrappers/wrf_wrapper.sh", ApplicationParallelismType.MPI, "WRF");
deployment2.setAppDeploymentId(client.registerApplicationDeployment(authzToken, DEFAULT_GATEWAY, deployment2));
return host.getComputeResourceId() + "," + application2.getApplicationInterfaceId();
}
Aggregations