Search in sources :

Example 41 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestSubWorkflowActionExecutor method testGetGroupFromParent.

public void testGetGroupFromParent() throws Exception {
    Path subWorkflowAppPath = getFsTestCaseDir();
    FileSystem fs = getFileSystem();
    Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
    Writer writer = new OutputStreamWriter(fs.create(workflowPath));
    writer.write(APP1);
    writer.close();
    XConfiguration protoConf = getBaseProtoConf();
    final WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    String defaultConf = workflow.getConf();
    XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
    String actionConf = "<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>";
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf(actionConf);
    // negative test
    final SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    workflow.setConf(newConf.toXmlString());
    subWorkflow.start(new Context(workflow, action), action);
    OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    waitFor(5000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            subWorkflow.check(new Context(workflow, action), action);
            return action.getStatus() == WorkflowActionBean.Status.DONE;
        }
    });
    subWorkflow.check(new Context(workflow, action), action);
    subWorkflow.end(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
    Configuration childConf = getWorkflowConfig(wf);
    assertFalse(getTestGroup() == childConf.get(OozieClient.GROUP_NAME));
    // positive test
    newConf.set(OozieClient.GROUP_NAME, getTestGroup());
    workflow.setConf(newConf.toXmlString());
    final WorkflowActionBean action1 = new WorkflowActionBean();
    action1.setConf(actionConf);
    action1.setId("W1");
    subWorkflow.start(new Context(workflow, action1), action1);
    oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action1), SubWorkflowActionExecutor.LOCAL);
    waitFor(5000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            subWorkflow.check(new Context(workflow, action1), action1);
            return action1.getStatus() == WorkflowActionBean.Status.DONE;
        }
    });
    subWorkflow.check(new Context(workflow, action1), action1);
    subWorkflow.end(new Context(workflow, action1), action1);
    wf = oozieClient.getJobInfo(action1.getExternalId());
    childConf = new XConfiguration(new StringReader(wf.getConf()));
    assertEquals(getTestGroup(), childConf.get(OozieClient.GROUP_NAME));
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 42 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestSubWorkflowActionExecutor method testSubWorkflowRerun.

public void testSubWorkflowRerun() throws Exception {
    try {
        Path subWorkflowAppPath = getFsTestCaseDir();
        FileSystem fs = getFileSystem();
        Path subWorkflowPath = new Path(subWorkflowAppPath, "workflow.xml");
        Writer writer = new OutputStreamWriter(fs.create(subWorkflowPath));
        writer.write(getLazyWorkflow());
        writer.close();
        String workflowUri = getTestCaseFileUri("workflow.xml");
        String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.4\" name=\"workflow\">" + "<start to=\"subwf\"/>" + "<action name=\"subwf\">" + "     <sub-workflow xmlns='uri:oozie:workflow:0.4'>" + "          <app-path>" + subWorkflowAppPath.toString() + "</app-path>" + "     </sub-workflow>" + "     <ok to=\"end\"/>" + "     <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + "     <message>Sub workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
        writeToFile(appXml, workflowUri);
        LocalOozie.start();
        final OozieClient wfClient = LocalOozie.getClient();
        Properties conf = wfClient.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, workflowUri);
        conf.setProperty(OozieClient.USER_NAME, getTestUser());
        conf.setProperty("appName", "var-app-name");
        final String jobId = wfClient.submit(conf);
        wfClient.start(jobId);
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.RUNNING);
            }
        });
        String subWorkflowExternalId = wfClient.getJobInfo(jobId).getActions().get(1).getExternalId();
        wfClient.kill(wfClient.getJobInfo(jobId).getActions().get(1).getExternalId());
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.ERROR);
            }
        });
        conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
        wfClient.reRun(jobId, conf);
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) && (wfClient.getJobInfo(jobId).getActions().get(2).getStatus() == WorkflowAction.Status.OK);
            }
        });
        WorkflowJob job = wfClient.getJobInfo(wfClient.getJobInfo(jobId).getActions().get(2).getExternalId());
        assertEquals(WorkflowJob.Status.SUCCEEDED, job.getStatus());
        assertEquals(job.getId(), subWorkflowExternalId);
    } finally {
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 43 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestLastModified method TestLastModifiedInitDestroy.

public void TestLastModifiedInitDestroy() throws Exception {
    try {
        LocalOozie.stop();
        LocalOozie.getClient();
        fail();
    } catch (IllegalStateException ex) {
    // nop
    } catch (Exception ex) {
        fail();
    }
    try {
        LocalOozie.start();
        LocalOozie.start();
        fail();
    } catch (IllegalStateException ex) {
    // nop
    } catch (Exception ex) {
        fail();
    }
    try {
        LocalOozie.stop();
        LocalOozie.start();
        OozieClient wc = LocalOozie.getClient();
        assertNotNull(wc);
        assertEquals("localoozie", wc.getOozieUrl());
    } finally {
        LocalOozie.stop();
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient)

Example 44 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestReRunXCommand method _testRerunFork.

public void _testRerunFork() throws Exception {
    // We need the shell schema and action for this test
    Services.get().setService(ActionService.class);
    Services.get().getConf().set(SchemaService.WF_CONF_EXT_SCHEMAS, "shell-action-0.3.xsd");
    Services.get().setService(SchemaService.class);
    Reader reader = IOUtils.getResourceAsReader("rerun-wf-fork.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty("nameNode", getNameNodeUri());
    conf.setProperty("jobTracker", getJobTrackerUri());
    conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    // expected to fail
    conf.setProperty("cmd4", "echo1");
    final String jobId1 = wfClient.submit(conf);
    wfClient.start(jobId1);
    waitFor(200 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    wfClient.kill(jobId1);
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    List<WorkflowAction> actions = wfClient.getJobInfo(jobId1).getActions();
    // fork
    assertEquals(WorkflowAction.Status.OK, actions.get(1).getStatus());
    // sh1
    assertEquals(WorkflowAction.Status.OK, actions.get(2).getStatus());
    // sh2
    assertEquals(WorkflowAction.Status.OK, actions.get(3).getStatus());
    // sh3
    assertEquals(WorkflowAction.Status.OK, actions.get(4).getStatus());
    // j
    assertEquals(WorkflowAction.Status.OK, actions.get(5).getStatus());
    // sh4
    assertEquals(WorkflowAction.Status.ERROR, actions.get(6).getStatus());
    // rerun failed node, which is after the fork
    conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    conf.setProperty("cmd4", "echo");
    wfClient.reRun(jobId1, conf);
    waitFor(200 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    actions = wfClient.getJobInfo(jobId1).getActions();
    // fork
    assertEquals(WorkflowAction.Status.OK, actions.get(1).getStatus());
    // sh1
    assertEquals(WorkflowAction.Status.OK, actions.get(2).getStatus());
    // sh2
    assertEquals(WorkflowAction.Status.OK, actions.get(3).getStatus());
    // sh3
    assertEquals(WorkflowAction.Status.OK, actions.get(4).getStatus());
    // join
    assertEquals(WorkflowAction.Status.OK, actions.get(5).getStatus());
    // sh4
    assertEquals(WorkflowAction.Status.OK, actions.get(6).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) WorkflowAction(org.apache.oozie.client.WorkflowAction) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Properties(java.util.Properties) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 45 with OozieClient

use of org.apache.oozie.client.OozieClient in project oozie by apache.

the class TestReRunXCommand method testRedeploy.

public void testRedeploy() throws IOException, OozieClientException, InterruptedException {
    Reader reader = IOUtils.getResourceAsReader("rerun-elerr-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("inPath", getFsTestCaseDir().toString());
    conf.setProperty("checkDir", getFsTestCaseDir().toString() + "/check");
    final String jobId1 = wfClient.submit(conf);
    wfClient.start(jobId1);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.FAILED;
        }
    });
    assertEquals(WorkflowJob.Status.FAILED, wfClient.getJobInfo(jobId1).getStatus());
    reader = IOUtils.getResourceAsReader("rerun-el-wf.xml", -1);
    writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    sleep(5000);
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "hdfs11");
    conf.setProperty("WF_NAME", "wf_test");
    conf.setProperty("FEED_NAME", "feed_test");
    wfClient.reRun(jobId1, conf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    assertEquals("wf_test-feed_test", wfClient.getJobInfo(jobId1).getAppName());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Properties(java.util.Properties) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Aggregations

OozieClient (org.apache.oozie.client.OozieClient)49 Properties (java.util.Properties)28 Path (org.apache.hadoop.fs.Path)25 IOException (java.io.IOException)19 WorkflowJob (org.apache.oozie.client.WorkflowJob)18 OozieClientException (org.apache.oozie.client.OozieClientException)16 FileSystem (org.apache.hadoop.fs.FileSystem)15 XConfiguration (org.apache.oozie.util.XConfiguration)15 Writer (java.io.Writer)14 Reader (java.io.Reader)12 Configuration (org.apache.hadoop.conf.Configuration)11 File (java.io.File)10 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)9 FileWriter (java.io.FileWriter)7 OutputStreamWriter (java.io.OutputStreamWriter)7 CommandException (org.apache.oozie.command.CommandException)6 Element (org.jdom.Element)6 StringReader (java.io.StringReader)5 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)5