Search in sources :

Example 6 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubworkflowDepth.

public void testSubworkflowDepth() throws Exception {
    Path subWorkflowAppPath = getFsTestCaseDir();
    FileSystem fs = getFileSystem();
    Writer writer = new OutputStreamWriter(fs.create(new Path(subWorkflowAppPath, "workflow.xml")));
    // Infinitly recursive workflow
    String appStr = "<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>";
    writer.write(appStr);
    writer.close();
    try {
        Services.get().destroy();
        setSystemProperty(XLogService.LOG4J_FILE, "oozie-log4j.properties");
        LocalOozie.start();
        // Set the max depth to 3
        Services.get().getConf().setInt("oozie.action.subworkflow.max.depth", 3);
        final OozieClient wfClient = LocalOozie.getClient();
        Properties conf = wfClient.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, subWorkflowAppPath.toString());
        conf.setProperty(OozieClient.USER_NAME, getTestUser());
        final String jobId0 = wfClient.submit(conf);
        wfClient.start(jobId0);
        waitFor(20 * 1000, new Predicate() {

            @Override
            public boolean evaluate() throws Exception {
                return wfClient.getJobInfo(jobId0).getStatus() == WorkflowJob.Status.KILLED;
            }
        });
        // All should be KILLED because our infinitly recusrive workflow hit the max
        assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId0).getStatus());
        String jobId1 = wfClient.getJobInfo(jobId0).getActions().get(1).getExternalId();
        assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
        String jobId2 = wfClient.getJobInfo(jobId1).getActions().get(1).getExternalId();
        assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
        String jobId3 = wfClient.getJobInfo(jobId2).getActions().get(1).getExternalId();
        assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId3).getStatus());
        String jobId4 = wfClient.getJobInfo(jobId3).getActions().get(1).getExternalId();
        // A fourth subworkflow shouldn't have been created because we set the max to 3
        assertNull(jobId4);
    } 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)

Example 7 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubWorkflowRecovery.

public void testSubWorkflowRecovery() 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();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    subWorkflow.start(new Context(workflow, action), action);
    final OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    waitFor(JOB_TIMEOUT, new Predicate() {

        public boolean evaluate() throws Exception {
            return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    String extId = action.getExternalId();
    assertEquals(workflow.getId(), oozieClient.getJobInfo(extId).getParentId());
    assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(extId).getStatus());
    WorkflowActionBean action1 = new WorkflowActionBean();
    action1.setId(action.getId());
    action1.setName(action.getName());
    action1.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>wrongAppPath</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    subWorkflow.start(new Context(workflow, action1), action1);
    assertEquals(extId, action1.getExternalId());
    assertEquals(workflow.getId(), oozieClient.getJobInfo(extId).getParentId());
    subWorkflow.check(new Context(workflow, action1), action1);
    assertEquals(WorkflowAction.Status.DONE, action1.getStatus());
    subWorkflow.end(new Context(workflow, action1), action1);
    assertEquals(WorkflowAction.Status.OK, action1.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) 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)

Example 8 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubWorkflowConfCreation.

public void testSubWorkflowConfCreation() throws Exception {
    SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor();
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + "      <app-path>hdfs://foo:9000/user/bar/workflow.xml</app-path>" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "      </configuration>" + "</sub-workflow>");
    OozieClient oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), SubWorkflowActionExecutor.LOCAL);
    assertNotNull(oozieClient);
    oozieClient = subWorkflow.getWorkflowClient(new Context(workflow, action), "http://localhost:8080/oozie");
    assertNotNull(oozieClient);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 9 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubWorkflowStart.

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

        public boolean evaluate() throws Exception {
            return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(action.getExternalId()).getStatus());
    subWorkflow.check(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.DONE, action.getStatus());
    subWorkflow.end(new Context(workflow, action), action);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    assertEquals(workflow.getId(), oozieClient.getJobInfo(action.getExternalId()).getParentId());
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 10 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubWorkflowSuspend.

public void testSubWorkflowSuspend() 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);
            }
        });
        WorkflowJob wf = wfClient.getJobInfo(jobId);
        // Suspending subworkflow
        new SuspendXCommand(wf.getActions().get(1).getExternalId()).call();
        // Check suspend for base workflow
        assertEquals(WorkflowJob.Status.SUSPENDED, wfClient.getJobInfo(jobId).getStatus());
        // Check suspend for sub workflow
        assertEquals(WorkflowJob.Status.SUSPENDED, wfClient.getJobInfo(wf.getActions().get(1).getExternalId()).getStatus());
    } finally {
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SuspendXCommand(org.apache.oozie.command.wf.SuspendXCommand) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob)

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