use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class TestLiteWorkflowLib method testDecision.
public void testDecision() throws WorkflowException {
List<String> decTrans = new ArrayList<String>();
decTrans.add("one");
decTrans.add("two");
decTrans.add("three");
LiteWorkflowApp def = new LiteWorkflowApp("testWf", "<worklfow-app/>", new StartNodeDef(TestControlNodeHandler.class, "d")).addNode(new DecisionNodeDef("d", "", TestDecisionNodeHandler.class, decTrans)).addNode(new NodeDef("one", null, SynchNodeHandler.class, Arrays.asList(new String[] { "end" }))).addNode(new NodeDef("two", null, SynchNodeHandler.class, Arrays.asList(new String[] { "end" }))).addNode(new NodeDef("three", null, SynchNodeHandler.class, Arrays.asList(new String[] { "end" }))).addNode(new EndNodeDef("end", TestControlNodeHandler.class));
LiteWorkflowInstance job = new LiteWorkflowInstance(def, new XConfiguration(), "abcde");
job.start();
assertEquals(WorkflowInstance.Status.RUNNING, job.getStatus());
job.signal("/", "one");
assertEquals(WorkflowInstance.Status.SUCCEEDED, job.getStatus());
assertEquals(2, enters.size());
assertEquals(2, exits.size());
assertTrue(enters.containsKey("one"));
assertTrue(!enters.containsKey("two"));
assertTrue(!enters.containsKey("three"));
enters.clear();
job = new LiteWorkflowInstance(def, new XConfiguration(), "abcde");
job.start();
assertEquals(WorkflowInstance.Status.RUNNING, job.getStatus());
job.signal("/", "two");
assertEquals(WorkflowInstance.Status.SUCCEEDED, job.getStatus());
assertTrue(!enters.containsKey("one"));
assertTrue(enters.containsKey("two"));
assertTrue(!enters.containsKey("three"));
enters.clear();
job = new LiteWorkflowInstance(def, new XConfiguration(), "abcde");
job.start();
assertEquals(WorkflowInstance.Status.RUNNING, job.getStatus());
job.signal("/", "three");
assertEquals(WorkflowInstance.Status.SUCCEEDED, job.getStatus());
assertTrue(!enters.containsKey("one"));
assertTrue(!enters.containsKey("two"));
assertTrue(enters.containsKey("three"));
enters.clear();
job = new LiteWorkflowInstance(def, new XConfiguration(), "abcde");
job.start();
assertEquals(WorkflowInstance.Status.RUNNING, job.getStatus());
try {
job.signal("/", "bla");
fail();
} catch (Exception e) {
}
assertEquals(WorkflowInstance.Status.FAILED, job.getStatus());
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class TestLiteWorkflowLib method testImmediateError.
public void testImmediateError() throws WorkflowException {
LiteWorkflowApp workflowDef = new LiteWorkflowApp("testWf", "<worklfow-app/>", new StartNodeDef(TestControlNodeHandler.class, "one")).addNode(new NodeDef("one", null, SynchNodeHandler.class, Arrays.asList(new String[] { "two" }))).addNode(new NodeDef("two", null, SynchNodeHandler.class, Arrays.asList(new String[] { "four" }))).addNode(new NodeDef("three", null, SynchNodeHandler.class, Arrays.asList(new String[] { "end" }))).addNode(new EndNodeDef("end", TestControlNodeHandler.class));
LiteWorkflowInstance workflowJob = new LiteWorkflowInstance(workflowDef, new XConfiguration(), "abcde");
try {
workflowJob.start();
} catch (WorkflowException e) {
}
assertEquals(WorkflowInstance.Status.FAILED, workflowJob.getStatus());
assertEquals(2, enters.size());
assertEquals(2, exits.size());
assertEquals(0, kills.size());
assertEquals(0, fails.size());
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class TestLiteWorkflowLib method testWfFailWithRunningNodes.
public void testWfFailWithRunningNodes() throws WorkflowException {
LiteWorkflowApp def = new LiteWorkflowApp("wf", "<worklfow-app/>", new StartNodeDef(TestControlNodeHandler.class, "f")).addNode(new ForkNodeDef("f", TestControlNodeHandler.class, Arrays.asList(new String[] { "a", "b" }))).addNode(new NodeDef("a", null, AsynchNodeHandler.class, Arrays.asList(new String[] { "j" }))).addNode(new NodeDef("b", null, AsynchNodeHandler.class, Arrays.asList(new String[] { "x" }))).addNode(new JoinNodeDef("j", TestControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", TestControlNodeHandler.class));
LiteWorkflowInstance job = new LiteWorkflowInstance(def, new XConfiguration(), "1");
try {
job.start();
job.signal("/b/", "");
} catch (WorkflowException ex) {
}
assertEquals(WorkflowInstance.Status.FAILED, job.getStatus());
assertEquals(2, enters.size());
assertEquals(1, fails.size());
// assertEquals(1, kills.size());
assertEquals(1, exits.size());
assertEquals(1, fails.size());
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class ActionXCommand method failJob.
/**
* Fail the job due to failed action
*
* @param context the execution context.
* @param action the action that caused the workflow to fail
* @throws CommandException thrown if unable to fail job
*/
public void failJob(ActionExecutor.Context context, WorkflowActionBean action) throws CommandException {
WorkflowJobBean workflow = (WorkflowJobBean) context.getWorkflow();
if (!handleUserRetry(context, action)) {
incrActionErrorCounter(action.getType(), "failed", 1);
LOG.warn("Failing Job due to failed action [{0}]", action.getName());
try {
workflow.getWorkflowInstance().fail(action.getName());
WorkflowInstance wfInstance = workflow.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.FAILED);
workflow.setWorkflowInstance(wfInstance);
workflow.setStatus(WorkflowJob.Status.FAILED);
action.setStatus(WorkflowAction.Status.FAILED);
action.resetPending();
queue(new WorkflowNotificationXCommand(workflow, action));
queue(new KillXCommand(workflow.getId()));
InstrumentUtils.incrJobCounter(INSTR_FAILED_JOBS_COUNTER_NAME, 1, getInstrumentation());
} catch (WorkflowException ex) {
throw new CommandException(ex);
}
}
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class ResumeXCommand method execute.
@Override
protected Void execute() throws CommandException {
try {
if (workflow.getStatus() == WorkflowJob.Status.SUSPENDED) {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
workflow.getWorkflowInstance().resume();
WorkflowInstance wfInstance = workflow.getWorkflowInstance();
((LiteWorkflowInstance) wfInstance).setStatus(WorkflowInstance.Status.RUNNING);
workflow.setWorkflowInstance(wfInstance);
workflow.setStatus(WorkflowJob.Status.RUNNING);
// for (WorkflowActionBean action : store.getActionsForWorkflow(id, false)) {
for (WorkflowActionBean action : jpaService.execute(new WorkflowJobGetActionsJPAExecutor(id))) {
// START_MANUAL or END_RETRY or END_MANUAL
if (action.isRetryOrManual()) {
action.setPendingOnly();
updateList.add(new UpdateEntry<WorkflowActionQuery>(WorkflowActionQuery.UPDATE_ACTION_STATUS_PENDING, action));
}
if (action.isPending()) {
if (action.getStatus() == WorkflowActionBean.Status.PREP || action.getStatus() == WorkflowActionBean.Status.START_MANUAL) {
// a repeated transient error, we have to clean up the action dir
if (// The control actions have invalid
!action.getType().equals(StartActionExecutor.TYPE) && // action dir paths because they
!action.getType().equals(ForkActionExecutor.TYPE) && // contain ":" (colons)
!action.getType().equals(JoinActionExecutor.TYPE) && !action.getType().equals(KillActionExecutor.TYPE) && !action.getType().equals(EndActionExecutor.TYPE)) {
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(workflow, action, false, false);
if (context.getAppFileSystem().exists(context.getActionDir())) {
context.getAppFileSystem().delete(context.getActionDir(), true);
}
}
queue(new ActionStartXCommand(action.getId(), action.getType()));
} else {
if (action.getStatus() == WorkflowActionBean.Status.START_RETRY) {
Date nextRunTime = action.getPendingAge();
queue(new ActionStartXCommand(action.getId(), action.getType()), nextRunTime.getTime() - System.currentTimeMillis());
} else {
if (action.getStatus() == WorkflowActionBean.Status.DONE || action.getStatus() == WorkflowActionBean.Status.END_MANUAL) {
queue(new ActionEndXCommand(action.getId(), action.getType()));
} else {
if (action.getStatus() == WorkflowActionBean.Status.END_RETRY) {
Date nextRunTime = action.getPendingAge();
queue(new ActionEndXCommand(action.getId(), action.getType()), nextRunTime.getTime() - System.currentTimeMillis());
}
}
}
}
}
}
workflow.setLastModifiedTime(new Date());
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MODIFIED, workflow));
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(null, updateList, null);
if (EventHandlerService.isEnabled()) {
generateEvent(workflow);
}
queue(new WorkflowNotificationXCommand(workflow));
}
return null;
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (JPAExecutorException e) {
throw new CommandException(e);
} catch (HadoopAccessorException e) {
throw new CommandException(e);
} catch (IOException e) {
throw new CommandException(ErrorCode.E0902, e.getMessage(), e);
} catch (URISyntaxException e) {
throw new CommandException(ErrorCode.E0902, e.getMessage(), e);
} finally {
updateParentIfNecessary(workflow);
}
}
Aggregations