use of org.apache.oozie.service.CallableQueueService.CallableWrapper in project oozie by apache.
the class SignalXCommand method startForkedActions.
public void startForkedActions(List<WorkflowActionBean> workflowActionBeanListForForked) throws CommandException {
List<CallableWrapper<ActionExecutorContext>> tasks = new ArrayList<CallableWrapper<ActionExecutorContext>>();
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
List<JsonBean> insertList = new ArrayList<JsonBean>();
boolean endWorkflow = false;
boolean submitJobByQueuing = false;
for (WorkflowActionBean workflowActionBean : workflowActionBeanListForForked) {
LOG.debug("Starting forked actions parallely : " + workflowActionBean.getId());
tasks.add(Services.get().get(CallableQueueService.class).new CallableWrapper<ActionExecutorContext>(new ForkedActionStartXCommand(wfJob, workflowActionBean.getId(), workflowActionBean.getType()), 0));
}
try {
List<Future<ActionExecutorContext>> futures = Services.get().get(CallableQueueService.class).invokeAll(tasks);
for (Future<ActionExecutorContext> result : futures) {
if (result == null) {
submitJobByQueuing = true;
continue;
}
ActionExecutorContext context = result.get();
Map<String, String> contextVariableMap = ((ForkedActionExecutorContext) context).getContextMap();
LOG.debug("contextVariableMap size of action " + context.getAction().getId() + " is " + contextVariableMap.size());
for (String key : contextVariableMap.keySet()) {
context.setVarToWorkflow(key, contextVariableMap.get(key));
}
if (context.getJobStatus() != null && context.getJobStatus().equals(Job.Status.FAILED)) {
LOG.warn("Action has failed, failing job" + context.getAction().getId());
new ActionStartXCommand(context.getAction().getId(), null).failJob(context);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, (WorkflowActionBean) context.getAction()));
if (context.isShouldEndWF()) {
endWorkflow = true;
}
}
if (context.getJobStatus() != null && context.getJobStatus().equals(Job.Status.SUSPENDED)) {
LOG.warn("Action has failed, failing job" + context.getAction().getId());
new ActionStartXCommand(context.getAction().getId(), null).handleNonTransient(context, null, WorkflowAction.Status.START_MANUAL);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, (WorkflowActionBean) context.getAction()));
if (context.isShouldEndWF()) {
endWorkflow = true;
}
}
}
if (endWorkflow) {
endWF(insertList);
}
} catch (Exception e) {
LOG.error("Error running forked jobs parallely", e);
startForkedActionsByQueuing(workflowActionBeanListForForked);
submitJobByQueuing = false;
}
if (submitJobByQueuing && !endWorkflow) {
LOG.error("There is error in running forked jobs parallely");
startForkedActionsByQueuing(workflowActionBeanListForForked);
}
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, wfJob));
try {
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
} catch (JPAExecutorException e) {
throw new CommandException(e);
}
LOG.debug("forked actions submitted parallely");
}
Aggregations