Search in sources :

Example 21 with WorkflowException

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());
}
Also used : ArrayList(java.util.ArrayList) WorkflowException(org.apache.oozie.workflow.WorkflowException) XConfiguration(org.apache.oozie.util.XConfiguration)

Example 22 with WorkflowException

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());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 23 with WorkflowException

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());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowException(org.apache.oozie.workflow.WorkflowException)

Example 24 with WorkflowException

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);
        }
    }
}
Also used : LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowException(org.apache.oozie.workflow.WorkflowException) CommandException(org.apache.oozie.command.CommandException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowJobBean(org.apache.oozie.WorkflowJobBean)

Example 25 with WorkflowException

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);
    }
}
Also used : WorkflowActionQuery(org.apache.oozie.executor.jpa.WorkflowActionQueryExecutor.WorkflowActionQuery) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowJobGetActionsJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetActionsJPAExecutor) WorkflowException(org.apache.oozie.workflow.WorkflowException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) WorkflowJobQuery(org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery) ActionExecutorContext(org.apache.oozie.command.wf.ActionXCommand.ActionExecutorContext)

Aggregations

WorkflowException (org.apache.oozie.workflow.WorkflowException)41 XConfiguration (org.apache.oozie.util.XConfiguration)23 IOException (java.io.IOException)15 Configuration (org.apache.hadoop.conf.Configuration)15 CommandException (org.apache.oozie.command.CommandException)8 Date (java.util.Date)7 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)7 Element (org.jdom.Element)7 ArrayList (java.util.ArrayList)6 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)6 JDOMException (org.jdom.JDOMException)6 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5 WorkflowJobQuery (org.apache.oozie.executor.jpa.WorkflowJobQueryExecutor.WorkflowJobQuery)5 File (java.io.File)4 Reader (java.io.Reader)4 URI (java.net.URI)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 WorkflowApp (org.apache.oozie.workflow.WorkflowApp)4