use of org.apache.airavata.model.status.JobState in project airavata by apache.
the class BESJobSubmissionTask method waitUntilDone.
protected void waitUntilDone(EndpointReferenceType factoryEpr, EndpointReferenceType activityEpr, ProcessContext processContext, DefaultClientConfiguration secProperties) throws Exception {
try {
FactoryClient factoryClient = new FactoryClient(factoryEpr, secProperties);
JobState applicationJobStatus = null;
ActivityStateEnumeration.Enum activityStatus = factoryClient.getActivityStatus(activityEpr);
while ((activityStatus != ActivityStateEnumeration.FINISHED) && (activityStatus != ActivityStateEnumeration.FAILED) && (activityStatus != ActivityStateEnumeration.CANCELLED) && (applicationJobStatus != JobState.COMPLETE)) {
ActivityStatusType activityStatusType = getStatus(factoryClient, activityEpr);
applicationJobStatus = getApplicationJobStatus(activityStatusType);
sendNotification(processContext, processContext.getJobModel());
// applicationJobStatus);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
activityStatus = factoryClient.getActivityStatus(activityEpr);
}
} catch (Exception e) {
log.error("Error monitoring job status..");
throw e;
}
}
use of org.apache.airavata.model.status.JobState 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;
}
Aggregations