Search in sources :

Example 16 with WorkflowJob

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

the class TestDagEngine method testSubmit.

public void testSubmit() 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);
    OutputStream os = new FileOutputStream(new File(getTestCaseDir(), "config-default.xml"));
    XConfiguration defaultConf = new XConfiguration();
    defaultConf.set("a", "AA");
    defaultConf.set("b", "BB");
    defaultConf.set("e", "${d}${d}");
    defaultConf.writeXml(os);
    os.close();
    final DagEngine engine = new DagEngine(getTestUser());
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, workflowPath);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set(OozieClient.LOG_TOKEN, "t");
    conf.set(OozieClient.ACTION_NOTIFICATION_URL, container.getServletURL("/callback") + "?jobId=$jobId&status=$status&nodeName=$nodeName");
    conf.set("signal-value", "OK");
    conf.set("external-status", "ok");
    conf.set("error", "end.error");
    conf.set("b", "B");
    conf.set("c", "C");
    conf.set("d", "${c}${c}");
    conf.set("f", "${e}${e}");
    final String jobId1 = engine.submitJob(conf, true);
    WorkflowJob wf = engine.getJob(jobId1);
    XConfiguration wfConf = new XConfiguration(new StringReader(wf.getConf()));
    assertEquals("AA", wfConf.get("a"));
    assertEquals("B", wfConf.get("b"));
    assertEquals("C", conf.get("c"));
    assertEquals("CC", conf.get("d"));
    assertEquals("CCCC", conf.get("e"));
    assertEquals("CCCCCCCC", conf.get("f"));
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean bean = Services.get().get(WorkflowStoreService.class).create().getWorkflow(jobId1, false);
            return bean.getWorkflowInstance().getStatus().isEndState();
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, engine.getJob(jobId1).getStatus());
    waitFor(10000, new Predicate() {

        public boolean evaluate() throws Exception {
            return CallbackServlet.JOB_ID != null;
        }
    });
    assertEquals(wf.getId(), CallbackServlet.JOB_ID);
    assertTrue("kill".equals(CallbackServlet.NODE_NAME) || "a".equals(CallbackServlet.NODE_NAME));
    assertTrue("T:null".equals(CallbackServlet.STATUS) || "T:kill".equals(CallbackServlet.STATUS));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) FileWriter(java.io.FileWriter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Reader(java.io.Reader) StringReader(java.io.StringReader) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) XConfiguration(org.apache.oozie.util.XConfiguration) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) WorkflowJob(org.apache.oozie.client.WorkflowJob) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 17 with WorkflowJob

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

the class TestBundleEngineSimple method testGetJob3.

public void testGetJob3() {
    BundleEngine be = new BundleEngine();
    try {
        WorkflowJob wj = be.getJob("foo", 0, 1);
        fail("Expected BundleEngineException was not thrown.");
    } catch (BundleEngineException bee) {
        assertEquals(ErrorCode.E0301, bee.getErrorCode());
    }
}
Also used : WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 18 with WorkflowJob

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

the class TestBundleEngineSimple method testGetJob1.

public void testGetJob1() {
    BundleEngine be = new BundleEngine();
    try {
        WorkflowJob wj = be.getJob("foo");
        fail("Expected BundleEngineException was not thrown.");
    } catch (BundleEngineException bee) {
        assertEquals(ErrorCode.E0301, bee.getErrorCode());
    }
}
Also used : WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 19 with WorkflowJob

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

the class TestWorkflow method testWorkflowWithStartAndEndCompletesSuccessfully.

public void testWorkflowWithStartAndEndCompletesSuccessfully() throws Exception {
    final String wfApp = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='test-wf'>" + "    <start to='end'/>" + "    <end name='end'/>" + "</workflow-app>";
    final FileSystem fs = getFileSystem();
    final Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    fs.mkdirs(new Path(appPath, "lib"));
    final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    writer.write(wfApp);
    writer.close();
    final OozieClient wc = LocalOozie.getClient();
    final Properties conf = wc.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    final String jobId = wc.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = wc.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    wc.start(jobId);
    waitFor(1000, new Predicate() {

        public boolean evaluate() throws Exception {
            final WorkflowJob wf = wc.getJobInfo(jobId);
            return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    wf = wc.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OozieClientException(org.apache.oozie.client.OozieClientException)

Example 20 with WorkflowJob

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

the class TestWorkflow method runWorkflowFromFile.

private void runWorkflowFromFile(final String workflowFileName, final Properties additionalWorkflowProperties) throws IOException, OozieClientException {
    final FileSystem fs = getFileSystem();
    final Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    fs.mkdirs(new Path(appPath, "lib"));
    final Reader reader = getResourceAsReader(workflowFileName, -1);
    final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    copyCharStream(reader, writer);
    writer.close();
    reader.close();
    final Path path = getFsTestCaseDir();
    final OozieClient oozieClient = LocalOozie.getClient();
    final Properties conf = oozieClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("nameNodeBasePath", path.toString());
    conf.setProperty("base", path.toUri().getPath());
    conf.setProperty("nameNode", getNameNodeUri());
    conf.setProperty("jobTracker", getJobTrackerUri());
    for (final String additionalKey : additionalWorkflowProperties.stringPropertyNames()) {
        conf.setProperty(additionalKey, additionalWorkflowProperties.getProperty(additionalKey));
    }
    final String jobId = oozieClient.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = oozieClient.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    oozieClient.start(jobId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            final WorkflowJob wf = oozieClient.getJobInfo(jobId);
            return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    wf = oozieClient.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OozieClientException(org.apache.oozie.client.OozieClientException)

Aggregations

WorkflowJob (org.apache.oozie.client.WorkflowJob)35 OozieClient (org.apache.oozie.client.OozieClient)18 Path (org.apache.hadoop.fs.Path)14 Properties (java.util.Properties)12 FileSystem (org.apache.hadoop.fs.FileSystem)12 Configuration (org.apache.hadoop.conf.Configuration)11 XConfiguration (org.apache.oozie.util.XConfiguration)11 IOException (java.io.IOException)10 Writer (java.io.Writer)6 WorkflowAction (org.apache.oozie.client.WorkflowAction)6 OutputStreamWriter (java.io.OutputStreamWriter)5 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)5 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)5 OozieClientException (org.apache.oozie.client.OozieClientException)5 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 Element (org.jdom.Element)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 File (java.io.File)2