+ getTaskNameById(workflowInst
.getCurrentTaskId()));
continue;
}
WorkflowTask task = getTaskById(workflowInst.getWorkflow(),workflowInst.getCurrentTaskId());
//WorkflowTask task = (WorkflowTask) taskIterator.next();
//workflowInst.setCurrentTaskId(task.getTaskId());
// now persist it
//persistWorkflowInstance();
// check to see if req met fields are present
// if they aren't, set the status to METERROR, and then fail
//if (!checkTaskRequiredMetadata(task, this.workflowInst
// .getSharedContext())) {
// this.workflowInst.setStatus(METADATA_MISSING);
// persistWorkflowInstance();
// now break out of this run loop
// return;
//}
// this is where the pre-conditions come in
// only execute the below code when it's passed all of its
// pre-conditions
/*if (task.getConditions() != null) {
while (!satisfied(task.getConditions(), task.getTaskId()) && !isStopped()) {
// if we're not paused, go ahead and pause us now
if (!isPaused()) {
pause();
}
LOG.log(Level.FINEST, "Pre-conditions for task: "
+ task.getTaskName() + " unsatisfied: waiting: "
+ waitForConditionSatisfy
+ " seconds before checking again.");
try {
Thread.currentThread().sleep(
waitForConditionSatisfy * 1000);
} catch (InterruptedException ignore) {
}
// check to see if we've been resumed, if so, break
// the loop and start
if (!isPaused()) {
break;
}
}
// check to see if we've been killed
if (isStopped()){
break;
}
// un pause us (if needed)
if (isPaused()) {
resume();
}
}*/
// task execution
LOG.log(Level.FINEST,
"IterativeWorkflowProcessorThread: Executing task: "
+ task.getTaskName());
WorkflowTaskInstance taskInstance = GenericWorkflowObjectFactory
.getTaskObjectFromClassName(task.getTaskInstanceClassName());
// add the TaskId and the JobId and ProcessingNode
// TODO: unfake the JobId
workflowInst.getSharedContext().replaceMetadata(TASK_ID,
task.getTaskId());
workflowInst.getSharedContext().replaceMetadata(WORKFLOW_INST_ID,
workflowInst.getId());
workflowInst.getSharedContext().replaceMetadata(JOB_ID,
workflowInst.getId());
workflowInst.getSharedContext().replaceMetadata(PROCESSING_NODE,
getHostname());
workflowInst.getSharedContext().replaceMetadata(
WORKFLOW_MANAGER_URL, this.wmgrParentUrl.toString());
if (rClient != null) {
// build up the Job
// and the Job Input
Job taskJob = new Job();
taskJob.setName(task.getTaskId());
taskJob
.setJobInstanceClassName("org.apache.oodt.cas.workflow.structs.TaskJob");
taskJob
.setJobInputClassName("org.apache.oodt.cas.workflow.structs.TaskJobInput");
taskJob.setLoadValue(new Integer(2));
taskJob.setQueueName(task.getTaskConfig().getProperty(
QUEUE_NAME) != null ? task.getTaskConfig()
.getProperty(QUEUE_NAME) : DEFAULT_QUEUE_NAME);
TaskJobInput in = new TaskJobInput();
in.setDynMetadata(workflowInst.getSharedContext());
in.setTaskConfig(task.getTaskConfig());
in.setWorkflowTaskInstanceClassName(task
.getTaskInstanceClassName());
workflowInst.setStatus(RESMGR_SUBMIT);
persistWorkflowInstance();
try {
// this is * NOT * a blocking operation so when it returns
// the job may not actually have finished executing
// so we go into a waiting/sleep behavior using the passed
// back job id to wait until the job has actually finished
// executing
this.currentJobId = rClient.submitJob(taskJob, in);
while (!safeCheckJobComplete(this.currentJobId) && !isStopped()) {
// sleep for 5 seconds then come back
// and check again
try {
Thread.currentThread()
.sleep(pollingWaitTime * 1000);
} catch (InterruptedException ignore) {
}
}
// okay job is done: TODO: fix this hack
// the task update time was set remotely
// by remote task, so let's read it now
// from the instRepo (which will have the updated
// time)
if (isStopped()) {
// this means that this workflow was killed, so
// gracefully exit
break;
}
WorkflowInstance updatedInst = null;
try {
updatedInst = instanceRepository
.getWorkflowInstanceById(workflowInst.getId());
workflowInst = updatedInst;
} catch (InstanceRepositoryException e) {
e.printStackTrace();
LOG.log(Level.WARNING, "Unable to get "
+ "updated workflow " + "instance record "
+ "when executing remote job: Message: "
+ e.getMessage());
}
} catch (JobExecutionException e) {
LOG.log(Level.WARNING,
"Job execution exception using resource manager to execute job: Message: "
+ e.getMessage());
}
} else {
// we started, so mark it
workflowInst.setStatus(STARTED);
// go ahead and persist the workflow instance, after we
// save the current task start date time
String currentTaskIsoStartDateTimeStr = DateConvert
.isoFormat(new Date());
workflowInst
.setCurrentTaskStartDateTimeIsoStr(currentTaskIsoStartDateTimeStr);
workflowInst.setCurrentTaskEndDateTimeIsoStr(null); /*
* clear
* this out
* until
* it's
* ready
*/
persistWorkflowInstance();
executeTaskLocally(taskInstance, workflowInst
.getSharedContext(), task.getTaskConfig(), task
.getTaskName());
String currentTaskIsoEndDateTimeStr = DateConvert
.isoFormat(new Date());
workflowInst
.setCurrentTaskEndDateTimeIsoStr(currentTaskIsoEndDateTimeStr);
persistWorkflowInstance();
}
LOG.log(Level.FINEST,
"IterativeWorkflowProcessorThread: Completed task: "
+ task.getTaskName());
}
LOG.log(Level.FINEST,
"IterativeWorkflowProcessorThread: Completed workflow: "