use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class SignalXCommand method execute.
@Override
protected Void execute() throws CommandException {
LOG.debug("STARTED SignalCommand for jobid=" + jobId + ", actionId=" + actionId);
WorkflowInstance workflowInstance = wfJob.getWorkflowInstance();
workflowInstance.setTransientVar(WorkflowStoreService.WORKFLOW_BEAN, wfJob);
WorkflowJob.Status prevStatus = wfJob.getStatus();
boolean completed = false, skipAction = false;
WorkflowActionBean syncAction = null;
List<WorkflowActionBean> workflowActionBeanListForForked = new ArrayList<WorkflowActionBean>();
if (wfAction == null) {
if (wfJob.getStatus() == WorkflowJob.Status.PREP) {
try {
completed = workflowInstance.start();
} catch (WorkflowException e) {
throw new CommandException(e);
}
wfJob.setStatus(WorkflowJob.Status.RUNNING);
wfJob.setStartTime(new Date());
wfJob.setWorkflowInstance(workflowInstance);
generateEvent = true;
// 1. Add SLA status event for WF-JOB with status STARTED
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), jobId, Status.STARTED, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
// 2. Add SLA registration events for all WF_ACTIONS
createSLARegistrationForAllActions(workflowInstance.getApp().getDefinition(), wfJob.getUser(), wfJob.getGroup(), wfJob.getConf());
queue(new WorkflowNotificationXCommand(wfJob));
} else {
throw new CommandException(ErrorCode.E0801, wfJob.getId());
}
} else {
WorkflowInstance.Status initialStatus = workflowInstance.getStatus();
String skipVar = workflowInstance.getVar(wfAction.getName() + WorkflowInstance.NODE_VAR_SEPARATOR + ReRunXCommand.TO_SKIP);
if (skipVar != null) {
skipAction = skipVar.equals("true");
}
try {
completed = workflowInstance.signal(wfAction.getExecutionPath(), wfAction.getSignalValue());
} catch (WorkflowException e) {
LOG.error("Workflow action failed : " + e.getMessage(), e);
wfJob.setStatus(WorkflowJob.Status.valueOf(workflowInstance.getStatus().toString()));
completed = true;
}
wfJob.setWorkflowInstance(workflowInstance);
wfAction.resetPending();
if (!skipAction) {
wfAction.setTransition(workflowInstance.getTransition(wfAction.getName()));
queue(new WorkflowNotificationXCommand(wfJob, wfAction));
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_PENDING_TRANS, wfAction));
WorkflowInstance.Status endStatus = workflowInstance.getStatus();
if (endStatus != initialStatus) {
generateEvent = true;
}
}
if (completed) {
try {
for (String actionToKillId : WorkflowStoreService.getActionsToKill(workflowInstance)) {
WorkflowActionBean actionToKill;
actionToKill = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_ID_TYPE_LASTCHECK, actionToKillId);
actionToKill.setPending();
actionToKill.setStatus(WorkflowActionBean.Status.KILLED);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, actionToKill));
queue(new ActionKillXCommand(actionToKill.getId(), actionToKill.getType()));
}
for (String actionToFailId : WorkflowStoreService.getActionsToFail(workflowInstance)) {
WorkflowActionBean actionToFail = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_FAIL, actionToFailId);
actionToFail.resetPending();
actionToFail.setStatus(WorkflowActionBean.Status.FAILED);
if (wfJobErrorCode != null) {
wfJobErrorCode = actionToFail.getErrorCode();
wfJobErrorMsg = actionToFail.getErrorMessage();
}
queue(new WorkflowNotificationXCommand(wfJob, actionToFail));
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfAction.getSlaXml(), wfAction.getId(), Status.FAILED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, actionToFail));
}
} catch (JPAExecutorException je) {
throw new CommandException(je);
}
wfJob.setStatus(WorkflowJob.Status.valueOf(workflowInstance.getStatus().toString()));
wfJob.setEndTime(new Date());
wfJob.setWorkflowInstance(workflowInstance);
Status slaStatus = Status.SUCCEEDED;
switch(wfJob.getStatus()) {
case SUCCEEDED:
slaStatus = Status.SUCCEEDED;
break;
case KILLED:
slaStatus = Status.KILLED;
break;
case FAILED:
slaStatus = Status.FAILED;
break;
default:
// TODO SUSPENDED
break;
}
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), jobId, slaStatus, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
queue(new WorkflowNotificationXCommand(wfJob));
if (wfJob.getStatus() == WorkflowJob.Status.SUCCEEDED) {
InstrumentUtils.incrJobCounter(INSTR_SUCCEEDED_JOBS_COUNTER_NAME, 1, getInstrumentation());
}
// output message for Kill node
if (wfAction != null) {
// wfAction could be a no-op job
NodeDef nodeDef = workflowInstance.getNodeDef(wfAction.getExecutionPath());
if (nodeDef != null && nodeDef instanceof KillNodeDef) {
boolean isRetry = false;
boolean isUserRetry = false;
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(wfJob, wfAction, isRetry, isUserRetry);
InstrumentUtils.incrJobCounter(INSTR_KILLED_JOBS_COUNTER_NAME, 1, getInstrumentation());
try {
String tmpNodeConf = nodeDef.getConf();
String message = context.getELEvaluator().evaluate(tmpNodeConf, String.class);
LOG.debug("Try to resolve KillNode message for jobid [{0}], actionId [{1}], before resolve [{2}], " + "after resolve [{3}]", jobId, actionId, tmpNodeConf, message);
if (wfAction.getErrorCode() != null) {
wfAction.setErrorInfo(wfAction.getErrorCode(), message);
} else {
wfAction.setErrorInfo(ErrorCode.E0729.toString(), message);
}
} catch (Exception ex) {
LOG.warn("Exception in SignalXCommand when processing Kill node message: {0}", ex.getMessage(), ex);
wfAction.setErrorInfo(ErrorCode.E0756.toString(), ErrorCode.E0756.format(ex.getMessage()));
wfAction.setStatus(WorkflowAction.Status.ERROR);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_PENDING_TRANS_ERROR, wfAction));
}
}
} else {
for (WorkflowActionBean newAction : WorkflowStoreService.getActionsToStart(workflowInstance)) {
boolean isOldWFAction = false;
// old action. To avoid twice entry for same action, Checking in Db if the workflow action already exist.
if (SubWorkflowActionExecutor.ACTION_TYPE.equals(newAction.getType())) {
try {
WorkflowActionBean oldAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_CHECK, newAction.getId());
newAction.setExternalId(oldAction.getExternalId());
newAction.setCreatedTime(oldAction.getCreatedTime());
isOldWFAction = true;
} catch (JPAExecutorException e) {
if (e.getErrorCode() != ErrorCode.E0605) {
throw new CommandException(e);
}
}
}
String skipVar = workflowInstance.getVar(newAction.getName() + WorkflowInstance.NODE_VAR_SEPARATOR + ReRunXCommand.TO_SKIP);
boolean skipNewAction = false, suspendNewAction = false;
if (skipVar != null) {
skipNewAction = skipVar.equals("true");
}
if (skipNewAction) {
WorkflowActionBean oldAction = new WorkflowActionBean();
oldAction.setId(newAction.getId());
oldAction.setPending();
oldAction.setExecutionPath(newAction.getExecutionPath());
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_PENDING, oldAction));
queue(new SignalXCommand(jobId, oldAction.getId()));
} else {
if (!skipAction) {
try {
// Make sure that transition node for a forked action
// is inserted only once
WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION_ID_TYPE_LASTCHECK, newAction.getId());
continue;
} catch (JPAExecutorException jee) {
}
}
suspendNewAction = checkForSuspendNode(newAction);
newAction.setPending();
String actionSlaXml = getActionSLAXml(newAction.getName(), workflowInstance.getApp().getDefinition(), wfJob.getConf());
newAction.setSlaXml(actionSlaXml);
if (!isOldWFAction) {
newAction.setCreatedTime(new Date());
insertList.add(newAction);
} else {
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_START, newAction));
}
LOG.debug("SignalXCommand: Name: " + newAction.getName() + ", Id: " + newAction.getId() + ", Authcode:" + newAction.getCred());
if (wfAction != null) {
// null during wf job submit
ActionService as = Services.get().get(ActionService.class);
ActionExecutor current = as.getExecutor(wfAction.getType());
LOG.trace("Current Action Type:" + current.getClass());
if (!suspendNewAction) {
if (current instanceof StartActionExecutor) {
// Excluding :start: here from executing first action synchronously since it
// blocks the consumer thread till the action is submitted to Hadoop,
// in turn reducing the number of new submissions the threads can accept.
// Would also be susceptible to longer delays in case Hadoop cluster is busy.
queue(new ActionStartXCommand(newAction.getId(), newAction.getType()));
} else if (current instanceof ForkActionExecutor) {
if (ConfigurationService.getBoolean(SignalXCommand.FORK_PARALLEL_JOBSUBMISSION)) {
workflowActionBeanListForForked.add(newAction);
} else {
queue(new ActionStartXCommand(newAction.getId(), newAction.getType()));
}
} else {
syncAction = newAction;
}
} else {
// will be ignored.
if (ConfigurationService.getBoolean(SignalXCommand.FORK_PARALLEL_JOBSUBMISSION)) {
workflowActionBeanListForForked.add(newAction);
}
}
} else {
// first action after wf submit should always be sync
syncAction = newAction;
}
}
}
}
try {
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob));
// call JPAExecutor to do the bulk writes
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (prevStatus != wfJob.getStatus()) {
LOG.debug("Updated the workflow status to " + wfJob.getId() + " status =" + wfJob.getStatusStr());
}
if (generateEvent && EventHandlerService.isEnabled()) {
generateEvent(wfJob, wfJobErrorCode, wfJobErrorMsg);
}
} catch (JPAExecutorException je) {
throw new CommandException(je);
}
// undue delay from between end of previous and start of next action
if (wfJob.getStatus() != WorkflowJob.Status.RUNNING && wfJob.getStatus() != WorkflowJob.Status.SUSPENDED) {
// only for asynchronous actions, parent coord action's external id will
// persisted and following update will succeed.
updateParentIfNecessary(wfJob);
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
} else if (syncAction != null) {
new ActionStartXCommand(wfJob, syncAction.getId(), syncAction.getType()).call();
} else if (!workflowActionBeanListForForked.isEmpty() && !checkForSuspendNode(workflowActionBeanListForForked)) {
startForkedActions(workflowActionBeanListForForked);
}
LOG.debug("ENDED SignalCommand for jobid=" + jobId + ", actionId=" + actionId);
return null;
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class ActionXCommand method handleTransient.
/**
* Takes care of Transient failures. Sets the action status to retry and increments the retry count if not enough
* attempts have been made. Otherwise returns false.
*
* @param context the execution context.
* @param executor the executor instance being used.
* @param status the status to be set for the action.
* @return true if the action is scheduled for another retry. false if the number of retries has exceeded the
* maximum number of configured retries.
* @throws CommandException thrown if unable to handle transient
*/
protected boolean handleTransient(ActionExecutor.Context context, ActionExecutor executor, WorkflowAction.Status status) throws CommandException {
LOG.debug("Attempting to retry");
ActionExecutorContext aContext = (ActionExecutorContext) context;
WorkflowActionBean action = (WorkflowActionBean) aContext.getAction();
incrActionErrorCounter(action.getType(), "transient", 1);
int actionRetryCount = action.getRetries();
if (actionRetryCount >= executor.getMaxRetries()) {
LOG.warn("Exceeded max retry count [{0}]. Suspending Job", executor.getMaxRetries());
return false;
} else {
action.setStatus(status);
action.setPending();
action.incRetries();
long retryDelayMillis = getRetryDelay(actionRetryCount, executor.getRetryInterval(), executor.getRetryPolicy());
action.setPendingAge(new Date(System.currentTimeMillis() + retryDelayMillis));
LOG.info("Next Retry, Attempt Number [{0}] in [{1}] milliseconds", actionRetryCount + 1, retryDelayMillis);
this.resetUsed();
queueCommandForTransientFailure(retryDelayMillis);
return true;
}
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class ActionXCommand method failJob.
/**
* Fail the job due to failed action
*
* @param context the execution context.
* @throws CommandException thrown if unable to fail job
*/
public void failJob(ActionExecutor.Context context) throws CommandException {
ActionExecutorContext aContext = (ActionExecutorContext) context;
WorkflowActionBean action = (WorkflowActionBean) aContext.getAction();
failJob(context, action);
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class ActionXCommand method handleNonTransient.
/**
* Takes care of non transient failures. The job is suspended, and the state of the action is changed to *MANUAL and
* set pending flag of action to false
*
* @param context the execution context.
* @param executor the executor instance being used.
* @param status the status to be set for the action.
* @throws CommandException thrown if unable to suspend job
*/
protected void handleNonTransient(ActionExecutor.Context context, ActionExecutor executor, WorkflowAction.Status status) throws CommandException {
ActionExecutorContext aContext = (ActionExecutorContext) context;
WorkflowActionBean action = (WorkflowActionBean) aContext.getAction();
incrActionErrorCounter(action.getType(), "nontransient", 1);
WorkflowJobBean workflow = (WorkflowJobBean) context.getWorkflow();
String id = workflow.getId();
action.setStatus(status);
action.resetPendingOnly();
LOG.warn("Suspending Workflow Job id=" + id);
try {
SuspendXCommand.suspendJob(Services.get().get(JPAService.class), workflow, id, action.getId(), null);
} catch (Exception e) {
throw new CommandException(ErrorCode.E0727, id, e.getMessage());
} finally {
updateParentIfNecessary(workflow, 3);
}
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class CoordWfActionInfoXCommand method execute.
@Override
protected List<CoordinatorWfActionBean> execute() throws CommandException {
List<CoordinatorWfActionBean> coordWfActions = new ArrayList<CoordinatorWfActionBean>();
for (CoordinatorActionBean coordAction : coordActions) {
String wfId = coordAction.getExternalId();
String nullReason = null;
WorkflowActionBean wfAction = null;
if (wfId != null) {
String wfActionId = wfId + "@" + actionName;
try {
wfAction = jpaService.execute(new WorkflowActionGetJPAExecutor(wfActionId, true));
if (wfAction == null) {
nullReason = CoordinatorWfAction.NullReason.ACTION_NULL.getNullReason(actionName, wfId);
}
} catch (JPAExecutorException ex) {
throw new CommandException(ex);
}
} else {
nullReason = CoordinatorWfAction.NullReason.PARENT_NULL.getNullReason();
LOG.warn(nullReason);
wfAction = null;
}
int actionNumber = coordAction.getActionNumber();
CoordinatorWfActionBean coordWfAction = new CoordinatorWfActionBean(actionNumber, wfAction, nullReason);
coordWfActions.add(coordWfAction);
}
return coordWfActions;
}
Aggregations