}
if ((action == null) || (action.isComplete() && action.isPending())) {
try {
if (workflow.getStatus() == WorkflowJob.Status.RUNNING
|| workflow.getStatus() == WorkflowJob.Status.PREP) {
WorkflowInstance workflowInstance = workflow.getWorkflowInstance();
workflowInstance.setTransientVar(WorkflowStoreService.WORKFLOW_BEAN, workflow);
boolean completed;
if (action == null) {
if (workflow.getStatus() == WorkflowJob.Status.PREP) {
completed = workflowInstance.start();
workflow.setStatus(WorkflowJob.Status.RUNNING);
workflow.setStartTime(new Date());
workflow.setWorkflowInstance(workflowInstance);
// 1. Add SLA status event for WF-JOB with status
// STARTED
// 2. Add SLA registration events for all WF_ACTIONS
SLADbOperations.writeStausEvent(workflow.getSlaXml(), jobId, store, Status.STARTED,
SlaAppType.WORKFLOW_JOB);
writeSLARegistrationForAllActions(workflowInstance.getApp().getDefinition(), workflow
.getUser(), workflow.getGroup(), workflow.getConf(), store);
queueCallable(new NotificationCommand(workflow));
}
else {
throw new CommandException(ErrorCode.E0801, workflow.getId());
}
}
else {
String skipVar = workflowInstance.getVar(action.getName() + WorkflowInstance.NODE_VAR_SEPARATOR
+ ReRunCommand.TO_SKIP);
if (skipVar != null) {
skipAction = skipVar.equals("true");
}
completed = workflowInstance.signal(action.getExecutionPath(), action.getSignalValue());
workflow.setWorkflowInstance(workflowInstance);
action.resetPending();
if (!skipAction) {
action.setTransition(workflowInstance.getTransition(action.getName()));
}
store.updateAction(action);
}
if (completed) {
for (String actionToKillId : WorkflowStoreService.getActionsToKill(workflowInstance)) {
WorkflowActionBean actionToKill = store.getAction(actionToKillId, false);
actionToKill.setPending();
actionToKill.setStatus(WorkflowActionBean.Status.KILLED);
store.updateAction(actionToKill);
queueCallable(new ActionKillCommand(actionToKill.getId(), actionToKill.getType()));
}
for (String actionToFailId : WorkflowStoreService.getActionsToFail(workflowInstance)) {
WorkflowActionBean actionToFail = store.getAction(actionToFailId, false);
actionToFail.resetPending();
actionToFail.setStatus(WorkflowActionBean.Status.FAILED);
SLADbOperations.writeStausEvent(action.getSlaXml(), action.getId(), store, Status.FAILED,
SlaAppType.WORKFLOW_ACTION);
store.updateAction(actionToFail);
}
workflow.setStatus(WorkflowJob.Status.valueOf(workflowInstance.getStatus().toString()));
workflow.setEndTime(new Date());
workflow.setWorkflowInstance(workflowInstance);
Status slaStatus = Status.SUCCEEDED;
switch (workflow.getStatus()) {
case SUCCEEDED:
slaStatus = Status.SUCCEEDED;
break;
case KILLED:
slaStatus = Status.KILLED;
break;
case FAILED:
slaStatus = Status.FAILED;
break;
default: // TODO about SUSPENDED
}
SLADbOperations.writeStausEvent(workflow.getSlaXml(), jobId, store, slaStatus,
SlaAppType.WORKFLOW_JOB);
queueCallable(new NotificationCommand(workflow));
if (workflow.getStatus() == WorkflowJob.Status.SUCCEEDED) {
incrJobCounter(INSTR_SUCCEEDED_JOBS_COUNTER_NAME, 1);
}
}
else {
for (WorkflowActionBean newAction : WorkflowStoreService.getStartedActions(workflowInstance)) {
String skipVar = workflowInstance.getVar(newAction.getName()
+ WorkflowInstance.NODE_VAR_SEPARATOR + ReRunCommand.TO_SKIP);
boolean skipNewAction = false;
if (skipVar != null) {
skipNewAction = skipVar.equals("true");
}
if (skipNewAction) {
WorkflowActionBean oldAction = store.getAction(newAction.getId(), false);
oldAction.setPending();
store.updateAction(oldAction);
queueCallable(new SignalCommand(jobId, oldAction.getId()));
}
else {
newAction.setPending();
String actionSlaXml = getActionSLAXml(newAction.getName(), workflowInstance.getApp()
.getDefinition(), workflow.getConf());
// System.out.println("111111 actionXml " +
// actionSlaXml);
// newAction.setSlaXml(workflow.getSlaXml());
newAction.setSlaXml(actionSlaXml);