Search in sources :

Example 11 with DagEngine

use of org.apache.oozie.DagEngine in project oozie by apache.

the class TestActionErrors method _testKillNodeErrorMessage.

private WorkflowActionBean _testKillNodeErrorMessage(String workflowXmlFile) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    Reader reader = IOUtils.getResourceAsReader(workflowXmlFile, -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("error", "end.error");
    conf.set("external-status", "FAILED/KILLED");
    conf.set("signal-value", "fail");
    final String jobId = engine.submitJob(conf, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    waitFor(50000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean job = jpaService.execute(wfJobGetCmd);
            return (job.getWorkflowInstance().getStatus() == WorkflowInstance.Status.KILLED);
        }
    });
    WorkflowJobBean job = jpaService.execute(wfJobGetCmd);
    assertEquals(WorkflowJob.Status.KILLED, job.getStatus());
    WorkflowActionsGetForJobJPAExecutor wfActionsGetCmd = new WorkflowActionsGetForJobJPAExecutor(jobId);
    List<WorkflowActionBean> actions = jpaService.execute(wfActionsGetCmd);
    WorkflowActionBean action = null;
    WorkflowActionBean killAction = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
        }
        if (bean.getType().equals(KillActionExecutor.TYPE)) {
            killAction = bean;
        }
    }
    assertNotNull(action);
    assertEquals("TEST_ERROR", action.getErrorCode());
    assertEquals("end", action.getErrorMessage());
    assertEquals(WorkflowAction.Status.ERROR, action.getStatus());
    assertNotNull(killAction);
    return killAction;
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 12 with DagEngine

use of org.apache.oozie.DagEngine in project oozie by apache.

the class TestActionErrors method _testNonTransient.

/**
 * Provides functionality to test non transient failures.
 *
 * @param errorType the error type. (start.non-transient, end.non-transient)
 * @param expStatus1 expected status. (START_MANUAL, END_MANUAL)
 * @param expErrorMsg expected error message.
 * @throws Exception
 */
private void _testNonTransient(String errorType, WorkflowActionBean.Status expStatus1, String expErrorMsg) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("signal-value", "OK");
    conf.set("external-status", "ok");
    conf.set("error", errorType);
    final String jobId = engine.submitJob(conf, true);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
        }
    });
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, true);
    int n = actions.size();
    WorkflowActionBean action = actions.get(n - 1);
    assertEquals("TEST_ERROR", action.getErrorCode());
    assertEquals(expErrorMsg, action.getErrorMessage());
    assertEquals(expStatus1, action.getStatus());
    assertTrue(action.isPending() == false);
    assertTrue(engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
    String actionConf = action.getConf();
    String fixedActionConf = actionConf.replaceAll(errorType, "none");
    action.setConf(fixedActionConf);
    store.updateAction(action);
    store.commitTrx();
    store.closeTrx();
    engine.resume(jobId);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
    final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
    store2.beginTrx();
    actions = store2.getActionsForWorkflow(jobId, false);
    action = actions.get(0);
    assertEquals(null, action.getErrorCode());
    assertEquals(null, action.getErrorMessage());
    assertEquals(WorkflowActionBean.Status.OK, action.getStatus());
    store2.commitTrx();
    store2.closeTrx();
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with DagEngine

use of org.apache.oozie.DagEngine in project oozie by apache.

the class TestActionErrors method _testErrorWithUserRetry.

/**
 * Provides functionality to test user retry
 *
 * @param errorType the error type. (start.non-transient, end.non-transient)
 * @param externalStatus the external status to set.
 * @param signalValue the signal value to set.
 * @throws Exception
 */
private void _testErrorWithUserRetry(String errorType, String externalStatus, String signalValue) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid-user-retry.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("error", errorType);
    conf.set("external-status", externalStatus);
    conf.set("signal-value", signalValue);
    final String jobId = engine.submitJob(conf, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    final WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(2, action.getUserRetryCount());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 14 with DagEngine

use of org.apache.oozie.DagEngine in project oozie by apache.

the class TestActionErrors method _testError.

/**
 * Provides functionality to test errors
 *
 * @param errorType the error type. (start.non-transient, end.non-transient)
 * @param externalStatus the external status to set.
 * @param signalValue the signal value to set.
 * @throws Exception
 */
private void _testError(String errorType, String externalStatus, String signalValue) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("error", errorType);
    conf.set("external-status", externalStatus);
    conf.set("signal-value", signalValue);
    final String jobId = engine.submitJob(conf, true);
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean bean = store.getWorkflow(jobId, false);
            return (bean.getWorkflowInstance().getStatus() == WorkflowInstance.Status.KILLED);
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, engine.getJob(jobId).getStatus());
    store.commitTrx();
    store.closeTrx();
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 15 with DagEngine

use of org.apache.oozie.DagEngine in project oozie by apache.

the class TestActionErrors method _testTransient.

/**
 * Provides functionality to test transient failures.
 *
 * @param errorType the error type. (start.transient, end.transient)
 * @param expStatus1 expected status after the first step (START_RETRY, END_RETRY)
 * @param expStatus2 expected status after the second step (START_MANUAL, END_MANUAL)
 * @param expErrorMsg the expected error message.
 * @throws Exception
 */
private void _testTransient(String errorType, WorkflowActionBean.Status expStatus1, final WorkflowActionBean.Status expStatus2, String expErrorMsg) throws Exception {
    String workflowPath = getTestCaseFileUri("workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final int maxRetries = 2;
    final int retryInterval = 10;
    final DagEngine engine = new DagEngine("u");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set("signal-value", "OK");
    conf.set("external-status", "ok");
    conf.set("error", errorType);
    conf.setInt(OozieClient.ACTION_MAX_RETRIES, maxRetries);
    conf.setInt(OozieClient.ACTION_RETRY_INTERVAL, retryInterval);
    final String jobId = engine.submitJob(conf, true);
    int retryCount = 1;
    WorkflowActionBean.Status expectedStatus = expStatus1;
    int expectedRetryCount = 2;
    Thread.sleep(20000);
    String aId = null;
    final WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    store.beginTrx();
    while (retryCount <= maxRetries) {
        List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId, false);
        WorkflowActionBean action = null;
        for (WorkflowActionBean bean : actions) {
            if (bean.getType().equals("test")) {
                action = bean;
                break;
            }
        }
        assertNotNull(action);
        aId = action.getId();
        assertEquals(expectedStatus, action.getStatus());
        assertEquals(expectedRetryCount, action.getRetries());
        assertEquals("TEST_ERROR", action.getErrorCode());
        assertEquals(expErrorMsg, action.getErrorMessage());
        if (action.getRetries() == maxRetries) {
            expectedRetryCount = 0;
            expectedStatus = expStatus2;
            break;
        } else {
            expectedRetryCount++;
        }
        Thread.sleep(retryInterval * 1000);
        retryCount++;
    }
    store.commitTrx();
    store.closeTrx();
    Thread.sleep(5000);
    final String actionId = aId;
    waitFor(5000, new Predicate() {

        public boolean evaluate() throws Exception {
            return (engine.getWorkflowAction(actionId).getStatus() == expStatus2);
        }
    });
    final WorkflowStore store2 = Services.get().get(WorkflowStoreService.class).create();
    store2.beginTrx();
    WorkflowActionBean action = engine.getWorkflowAction(actionId);
    assertEquals("TEST_ERROR", action.getErrorCode());
    assertEquals(expErrorMsg, action.getErrorMessage());
    assertEquals(expStatus2, action.getStatus());
    assertTrue(action.isPending() == false);
    assertEquals(WorkflowJob.Status.SUSPENDED, engine.getJob(jobId).getStatus());
    store2.commitTrx();
    store2.closeTrx();
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) FileWriter(java.io.FileWriter) Reader(java.io.Reader) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) DagEngine(org.apache.oozie.DagEngine) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Aggregations

DagEngine (org.apache.oozie.DagEngine)36 DagEngineService (org.apache.oozie.service.DagEngineService)22 DagEngineException (org.apache.oozie.DagEngineException)19 XConfiguration (org.apache.oozie.util.XConfiguration)15 Reader (java.io.Reader)14 Writer (java.io.Writer)14 Configuration (org.apache.hadoop.conf.Configuration)14 FileWriter (java.io.FileWriter)13 File (java.io.File)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 JSONObject (org.json.simple.JSONObject)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)7 WorkflowActionsGetForJobJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor)5 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)5 IOException (java.io.IOException)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 JPAService (org.apache.oozie.service.JPAService)4 WorkflowStore (org.apache.oozie.store.WorkflowStore)4 Date (java.util.Date)3 WorkflowsInfo (org.apache.oozie.WorkflowsInfo)3