Search in sources :

Example 36 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 37 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 38 with XConfiguration

use of org.apache.oozie.util.XConfiguration 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 39 with XConfiguration

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

Example 40 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class TestActionUserRetry method testUserRetryPolicy.

public void testUserRetryPolicy() throws JPAExecutorException, IOException, CommandException {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    // @formatter:off
    String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"1\" retry-policy=\"exponential\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    // @Formatter:on
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("error", "start.error");
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    // set a timeout for exponential retry of action with respect to given
    // retry-interval and retry-max.
    // If retry-interval is 1 then, for first retry, delay will be 1 min,
    // for second retry it will be 2 min, 4, 8, 16 & so on.
    int timeout = (1 + 2) * 60 * 1000;
    waitFor(timeout, 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 : WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService)

Aggregations

XConfiguration (org.apache.oozie.util.XConfiguration)373 Configuration (org.apache.hadoop.conf.Configuration)241 Path (org.apache.hadoop.fs.Path)106 StringReader (java.io.StringReader)97 File (java.io.File)92 IOException (java.io.IOException)78 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)75 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)70 CommandException (org.apache.oozie.command.CommandException)68 Element (org.jdom.Element)66 Writer (java.io.Writer)58 Date (java.util.Date)50 FileSystem (org.apache.hadoop.fs.FileSystem)48 FileWriter (java.io.FileWriter)45 Reader (java.io.Reader)43 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)37 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)28 OutputStream (java.io.OutputStream)27 FileOutputStream (java.io.FileOutputStream)25