Search in sources :

Example 16 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 17 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 18 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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 19 with WorkflowActionBean

use of org.apache.oozie.WorkflowActionBean 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)

Example 20 with WorkflowActionBean

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

the class TestActionStartXCommand method testActionReuseWfJobAppPath.

public void testActionReuseWfJobAppPath() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    WorkflowJobBean job = this.addRecordToWfJobTableWithCustomAppPath(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTableWithAppPathConfig(job.getId(), "1", WorkflowAction.Status.PREP);
    WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
    new ActionStartXCommand(action.getId(), "map-reduce").call();
    action = jpaService.execute(wfActionGetCmd);
    assertNotNull(action.getExternalId());
    Element actionXml = XmlUtils.parseXml(action.getConf());
    Namespace ns = actionXml.getNamespace();
    Element configElem = actionXml.getChild("configuration", ns);
    String strConf = XmlUtils.prettyPrint(configElem).toString();
    XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
    String workDir = inlineConf.get("work.dir", null);
    assertNotNull(workDir);
    assertFalse(workDir.contains("workflow.xml"));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) StringReader(java.io.StringReader) WorkflowActionGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) Namespace(org.jdom.Namespace)

Aggregations

WorkflowActionBean (org.apache.oozie.WorkflowActionBean)249 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)164 XConfiguration (org.apache.oozie.util.XConfiguration)84 JPAService (org.apache.oozie.service.JPAService)79 Configuration (org.apache.hadoop.conf.Configuration)56 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)51 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)51 Path (org.apache.hadoop.fs.Path)48 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)42 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)32 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)32 ArrayList (java.util.ArrayList)30 Date (java.util.Date)29 Element (org.jdom.Element)29 FileSystem (org.apache.hadoop.fs.FileSystem)25 Writer (java.io.Writer)22 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)21 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)21 IOException (java.io.IOException)20 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)18