// TODO publish the status messages to the message bus
while ((factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FINISHED)
&& (factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.FAILED)
&& (factory.getActivityStatus(activityEpr) != ActivityStateEnumeration.CANCELLED)) {
ActivityStatusType activityStatus = null;
try {
activityStatus = getStatus(factory, activityEpr);
JobState jobStatus = getApplicationJobStatus(activityStatus);
String jobStatusMessage = "Status of job " + jobId + "is " + jobStatus;
jobExecutionContext.getNotifier().publish(new StatusChangeEvent(jobStatusMessage));
details.setJobID(jobId);
GFacUtils.updateJobStatus(jobExecutionContext, details, jobStatus);
} catch (UnknownActivityIdentifierFault e) {
throw new GFacProviderException(e.getMessage(), e.getCause());
}catch (GFacException e) {
throw new GFacProviderException(e.getMessage(), e.getCause());
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
continue;
}
ActivityStatusType activityStatus = null;
try {
activityStatus = getStatus(factory, activityEpr);
} catch (UnknownActivityIdentifierFault e) {
throw new GFacProviderException(e.getMessage(), e.getCause());
}
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState()
.toString()));
if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
String error = activityStatus.getFault().getFaultcode().getLocalPart() + "\n"
+ activityStatus.getFault().getFaultstring() + "\n EXITCODE: " + activityStatus.getExitCode();
log.info(error);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
dt.downloadStdOuts();
} else if (activityStatus.getState() == ActivityStateEnumeration.CANCELLED) {
String experimentID = (String) jobExecutionContext.getProperty(Constants.PROP_TOPIC);
JobState jobStatus = JobState.CANCELED;
String jobStatusMessage = "Status of job " + jobId + "is " + jobStatus;
jobExecutionContext.getNotifier().publish(new StatusChangeEvent(jobStatusMessage));
details.setJobID(jobId);
try {
GFacUtils.saveJobStatus(jobExecutionContext,details, jobStatus);
} catch (GFacException e) {
throw new GFacProviderException(e.getLocalizedMessage(),e);
}
throw new GFacProviderException(experimentID + "Job Canceled");
}
else if (activityStatus.getState() == ActivityStateEnumeration.FINISHED) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
if (activityStatus.getExitCode() == 0) {
dt.downloadRemoteFiles();
} else {
dt.downloadStdOuts();
}
}