use of org.apache.oozie.command.CommandException in project oozie by apache.
the class ReRunXCommand method eagerVerifyPrecondition.
/**
* Checks the pre-conditions that are required for workflow to recover - Last run of Workflow should be completed -
* The nodes that are to be skipped are to be completed successfully in the base run.
*
* @throws CommandException
* @throws PreconditionException On failure of pre-conditions
*/
@Override
protected void eagerVerifyPrecondition() throws CommandException, PreconditionException {
// through conf.
if (wfBean.getParentId() != null && !conf.getBoolean(SubWorkflowActionExecutor.SUBWORKFLOW_RERUN, false) && ConfigurationService.getBoolean(DISABLE_CHILD_RERUN)) {
throw new CommandException(ErrorCode.E0755, " Rerun is not allowed through child workflow, please" + " re-run through the parent " + wfBean.getParentId());
}
if (!(wfBean.getStatus().equals(WorkflowJob.Status.FAILED) || wfBean.getStatus().equals(WorkflowJob.Status.KILLED) || wfBean.getStatus().equals(WorkflowJob.Status.SUCCEEDED))) {
throw new CommandException(ErrorCode.E0805, wfBean.getStatus());
}
Set<String> unmachedNodes = new HashSet<String>(nodesToSkip);
for (WorkflowActionBean action : actions) {
if (nodesToSkip.contains(action.getName())) {
if (!action.getStatus().equals(WorkflowAction.Status.OK) && !action.getStatus().equals(WorkflowAction.Status.ERROR)) {
throw new CommandException(ErrorCode.E0806, action.getName());
}
unmachedNodes.remove(action.getName());
}
}
if (unmachedNodes.size() > 0) {
StringBuilder sb = new StringBuilder();
String separator = "";
for (String s : unmachedNodes) {
sb.append(separator).append(s);
separator = ",";
}
throw new CommandException(ErrorCode.E0807, sb);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class ReRunXCommand method loadState.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#loadState()
*/
@Override
protected void loadState() throws CommandException {
try {
this.wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_RERUN, this.jobId);
this.actions = WorkflowActionQueryExecutor.getInstance().getList(WorkflowActionQuery.GET_ACTIONS_FOR_WORKFLOW_RERUN, this.jobId);
} catch (JPAExecutorException jpe) {
throw new CommandException(jpe);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class ExternalIdXCommand method execute.
@Override
protected String execute() throws CommandException {
try {
JPAService jpaService = Services.get().get(JPAService.class);
String wfId = null;
if (jpaService != null) {
wfId = jpaService.execute(new WorkflowIdGetForExternalIdJPAExecutor(externalId));
} else {
LOG.error(ErrorCode.E0610);
}
return wfId;
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class KillXCommand method execute.
@Override
protected Void execute() throws CommandException {
LOG.info("STARTED WorkflowKillXCommand for jobId=" + wfId);
wfJob.setEndTime(new Date());
if (wfJob.getStatus() != WorkflowJob.Status.FAILED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
wfJob.setStatus(WorkflowJob.Status.KILLED);
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(wfJob.getSlaXml(), wfJob.getId(), Status.KILLED, SlaAppType.WORKFLOW_JOB);
if (slaEvent != null) {
insertList.add(slaEvent);
}
try {
wfJob.getWorkflowInstance().kill();
} catch (WorkflowException e) {
throw new CommandException(ErrorCode.E0725, e.getMessage(), e);
}
WorkflowInstance wfInstance = wfJob.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.KILLED);
wfJob.setWorkflowInstance(wfInstance);
}
try {
for (WorkflowActionBean action : actionList) {
if (action.getStatus() == WorkflowActionBean.Status.RUNNING || action.getStatus() == WorkflowActionBean.Status.DONE) {
if (!(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
action.setPending();
}
action.setStatus(WorkflowActionBean.Status.KILLED);
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
queue(new ActionKillXCommand(action.getId(), action.getType()));
} else if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_RETRY || action.getStatus() == WorkflowActionBean.Status.START_MANUAL || action.getStatus() == WorkflowActionBean.Status.END_RETRY || action.getStatus() == WorkflowActionBean.Status.END_MANUAL || action.getStatus() == WorkflowActionBean.Status.USER_RETRY) {
action.setStatus(WorkflowActionBean.Status.KILLED);
action.resetPending();
SLAEventBean slaEvent = SLADbXOperations.createStatusEvent(action.getSlaXml(), action.getId(), Status.KILLED, SlaAppType.WORKFLOW_ACTION);
if (slaEvent != null) {
insertList.add(slaEvent);
}
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
if (EventHandlerService.isEnabled() && !(actionService.getExecutor(action.getType()) instanceof ControlNodeActionExecutor)) {
generateEvent(action, wfJob.getUser());
}
}
}
wfJob.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfJob));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(wfJob);
}
queue(new WorkflowNotificationXCommand(wfJob));
} catch (JPAExecutorException e) {
throw new CommandException(e);
} finally {
if (wfJob.getStatus() == WorkflowJob.Status.KILLED) {
// To delete the WF temp dir
new WfEndXCommand(wfJob).call();
}
updateParentIfNecessary(wfJob);
}
LOG.info("ENDED WorkflowKillXCommand for jobId=" + wfId);
return null;
}
use of org.apache.oozie.command.CommandException in project oozie by apache.
the class ResumeXCommand method loadState.
@Override
protected void loadState() throws CommandException {
jpaService = Services.get().get(JPAService.class);
if (jpaService == null) {
throw new CommandException(ErrorCode.E0610);
}
try {
workflow = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_RESUME, id);
} catch (JPAExecutorException e) {
throw new CommandException(e);
}
LogUtils.setLogInfo(workflow);
}
Aggregations