use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.
the class BESJobSubmissionTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
StorageClient sc = null;
ProcessContext processContext = taskContext.getParentProcessContext();
// FIXME - use original output dir
setInputOutputLocations(processContext);
try {
// con't reuse if UserDN has been changed.
secProperties = getSecurityConfig(processContext);
// try secProperties = secProperties.clone() if we can't use already initialized ClientConfigurations.
} catch (GFacException e) {
String msg = "Unicorn security context initialization error";
log.error(msg, e);
taskStatus.setState(TaskState.FAILED);
taskStatus.setReason(msg);
return taskStatus;
}
try {
JobSubmissionProtocol protocol = processContext.getJobSubmissionProtocol();
JobSubmissionInterface jobSubmissionInterface = GFacUtils.getPreferredJobSubmissionInterface(processContext);
String factoryUrl = null;
if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
}
EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
eprt.addNewAddress().setStringValue(factoryUrl);
String userDN = processContext.getProcessModel().getUserDn();
CreateActivityDocument cad = CreateActivityDocument.Factory.newInstance();
// create storage
StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
sc = storageCreator.createStorage();
JobDefinitionType jobDefinition = JSDLGenerator.buildJSDLInstance(processContext, sc.getUrl()).getJobDefinition();
cad.addNewCreateActivity().addNewActivityDocument().setJobDefinition(jobDefinition);
log.info("Submitted JSDL: " + jobDefinition.getJobDescription());
// copy files to local
copyInputFilesToLocal(taskContext);
// upload files if any
DataTransferrer dt = new DataTransferrer(processContext, sc);
dt.uploadLocalFiles();
JobModel jobDetails = new JobModel();
jobDetails.setTaskId(taskContext.getTaskId());
jobDetails.setProcessId(taskContext.getProcessId());
FactoryClient factory = new FactoryClient(eprt, secProperties);
log.info("Activity Submitting to {} ... \n", factoryUrl);
CreateActivityResponseDocument response = factory.createActivity(cad);
log.info("Activity Submitted to {} ... \n", factoryUrl);
EndpointReferenceType activityEpr = response.getCreateActivityResponse().getActivityIdentifier();
log.info("Activity : " + activityEpr.getAddress().getStringValue() + " Submitted.");
// factory.waitWhileActivityIsDone(activityEpr, 1000);
jobId = WSUtilities.extractResourceID(activityEpr);
if (jobId == null) {
jobId = new Long(Calendar.getInstance().getTimeInMillis()).toString();
}
log.info("JobID: " + jobId);
jobDetails.setJobId(jobId);
jobDetails.setJobDescription(activityEpr.toString());
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(JobState.SUBMITTED)));
processContext.setJobModel(jobDetails);
GFacUtils.saveJobModel(processContext, jobDetails);
GFacUtils.saveJobStatus(processContext, jobDetails);
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr).toString()));
waitUntilDone(eprt, activityEpr, processContext, secProperties);
ActivityStatusType activityStatus = null;
activityStatus = getStatus(factory, activityEpr);
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
ActivityClient activityClient;
activityClient = new ActivityClient(activityEpr, secProperties);
// now use the activity working directory property
dt.setStorageClient(activityClient.getUspaceClient());
List<OutputDataObjectType> copyOutput = null;
if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
String error = activityStatus.getFault().getFaultcode().getLocalPart() + "\n" + activityStatus.getFault().getFaultstring() + "\n EXITCODE: " + activityStatus.getExitCode();
log.error(error);
JobState applicationJobStatus = JobState.FAILED;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
sendNotification(processContext, jobDetails);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
// What if job is failed before execution and there are not stdouts generated yet?
log.debug("Downloading any standard output and error files, if they were produced.");
copyOutput = dt.downloadRemoteFiles();
} else if (activityStatus.getState() == ActivityStateEnumeration.CANCELLED) {
JobState applicationJobStatus = JobState.CANCELED;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
GFacUtils.saveJobStatus(processContext, jobDetails);
throw new GFacException(processContext.getExperimentId() + "Job Canceled");
} else if (activityStatus.getState() == ActivityStateEnumeration.FINISHED) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
JobState applicationJobStatus = JobState.COMPLETE;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
GFacUtils.saveJobStatus(processContext, jobDetails);
log.info("Job Id: {}, exit code: {}, exit status: {}", jobDetails.getJobId(), activityStatus.getExitCode(), ActivityStateEnumeration.FINISHED.toString());
// if (activityStatus.getExitCode() == 0) {
// } else {
// dt.downloadStdOuts();
// }
copyOutput = dt.downloadRemoteFiles();
}
if (copyOutput != null) {
copyOutputFilesToStorage(taskContext, copyOutput);
for (OutputDataObjectType outputDataObjectType : copyOutput) {
GFacUtils.saveExperimentOutput(processContext, outputDataObjectType.getName(), outputDataObjectType.getValue());
}
}
// dt.publishFinalOutputs();
taskStatus.setState(TaskState.COMPLETED);
} catch (AppCatalogException e) {
log.error("Error while retrieving UNICORE job submission..", e);
taskStatus.setState(TaskState.FAILED);
} catch (Exception e) {
log.error("BES task failed... ", e);
taskStatus.setState(TaskState.FAILED);
}
return taskStatus;
}
use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface 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.JobSubmissionInterface in project airavata by apache.
the class DocumentCreatorUtils method createJobSubmissionInterface.
public static JobSubmissionInterface createJobSubmissionInterface(String jobSubmissionInterfaceId, JobSubmissionProtocol jobSubmissionProtocolType, int priorityOrder) {
JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface();
jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId);
jobSubmissionInterface.setJobSubmissionProtocol(jobSubmissionProtocolType);
jobSubmissionInterface.setPriorityOrder(priorityOrder);
return jobSubmissionInterface;
}
use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.
the class CreateLaunchBES method registerUnicoreEndpoint.
public static String registerUnicoreEndpoint(String hostName, String hostDesc, JobSubmissionProtocol protocol, SecurityProtocol securityProtocol) throws TException {
ComputeResourceDescription computeResourceDescription = RegisterSampleApplicationsUtils.createComputeResourceDescription(hostName, hostDesc, null, null);
fsdResourceId = airavataClient.registerComputeResource(new AuthzToken(""), computeResourceDescription);
if (fsdResourceId.isEmpty())
throw new AiravataClientException();
System.out.println("FSD Compute ResourceID: " + fsdResourceId);
JobSubmissionInterface jobSubmission = RegisterSampleApplicationsUtils.createJobSubmissionInterface(fsdResourceId, protocol, 2);
UnicoreJobSubmission ucrJobSubmission = new UnicoreJobSubmission();
ucrJobSubmission.setSecurityProtocol(securityProtocol);
ucrJobSubmission.setUnicoreEndPointURL(unicoreEndPointURL);
return jobSubmission.getJobSubmissionInterfaceId();
}
use of org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface in project airavata by apache.
the class OrchestratorUtils method getPreferredJobSubmissionInterface.
public static JobSubmissionInterface getPreferredJobSubmissionInterface(OrchestratorContext context, ProcessModel processModel, String gatewayId) throws RegistryException {
try {
String resourceHostId = processModel.getComputeResourceId();
ComputeResourcePreference resourcePreference = getComputeResourcePreference(context, processModel, gatewayId);
JobSubmissionProtocol preferredJobSubmissionProtocol = resourcePreference.getPreferredJobSubmissionProtocol();
ComputeResourceDescription resourceDescription = context.getRegistry().getAppCatalog().getComputeResource().getComputeResource(resourceHostId);
List<JobSubmissionInterface> jobSubmissionInterfaces = resourceDescription.getJobSubmissionInterfaces();
Map<JobSubmissionProtocol, List<JobSubmissionInterface>> orderedInterfaces = new HashMap<>();
List<JobSubmissionInterface> interfaces = new ArrayList<>();
if (jobSubmissionInterfaces != null && !jobSubmissionInterfaces.isEmpty()) {
for (JobSubmissionInterface submissionInterface : jobSubmissionInterfaces) {
if (preferredJobSubmissionProtocol != null) {
if (preferredJobSubmissionProtocol.toString().equals(submissionInterface.getJobSubmissionProtocol().toString())) {
if (orderedInterfaces.containsKey(submissionInterface.getJobSubmissionProtocol())) {
List<JobSubmissionInterface> interfaceList = orderedInterfaces.get(submissionInterface.getJobSubmissionProtocol());
interfaceList.add(submissionInterface);
} else {
interfaces.add(submissionInterface);
orderedInterfaces.put(submissionInterface.getJobSubmissionProtocol(), interfaces);
}
}
} else {
Collections.sort(jobSubmissionInterfaces, (jobSubmissionInterface, jobSubmissionInterface2) -> jobSubmissionInterface.getPriorityOrder() - jobSubmissionInterface2.getPriorityOrder());
}
}
interfaces = orderedInterfaces.get(preferredJobSubmissionProtocol);
Collections.sort(interfaces, (jobSubmissionInterface, jobSubmissionInterface2) -> jobSubmissionInterface.getPriorityOrder() - jobSubmissionInterface2.getPriorityOrder());
} else {
throw new RegistryException("Compute resource should have at least one job submission interface defined...");
}
return interfaces.get(0);
} catch (AppCatalogException e) {
throw new RegistryException("Error occurred while retrieving data from app catalog", e);
}
}
Aggregations