Search in sources :

Example 11 with OozieClient

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

the class TestSubWorkflowActionExecutor method testParentGlobalConfWithConfigDefault.

public void testParentGlobalConfWithConfigDefault() throws Exception {
    try {
        Path subWorkflowAppPath = createSubWorkflowXml();
        createConfigDefaultXml();
        createSubWorkflowConfigDefaultXml();
        String workflowUri = createTestWorkflowXml(subWorkflowAppPath);
        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");
        conf.setProperty("foo", "other");
        final String jobId = wfClient.submit(conf);
        wfClient.start(jobId);
        // configuration should have overridden value
        assertEquals("other", new XConfiguration(new StringReader(wfClient.getJobInfo(jobId).getConf())).get("foo"));
        waitFor(JOB_TIMEOUT, new Predicate() {

            public boolean evaluate() throws Exception {
                return (wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED) && (wfClient.getJobInfo(jobId).getActions().get(1).getStatus() == WorkflowAction.Status.OK);
            }
        });
        WorkflowJob subWorkflow = wfClient.getJobInfo(wfClient.getJobInfo(jobId).getActions().get(1).getExternalId());
        Configuration subWorkflowConf = getWorkflowConfig(subWorkflow);
        Element eConf = XmlUtils.parseXml(subWorkflow.getActions().get(1).getConf());
        Element element = eConf.getChild("configuration", eConf.getNamespace());
        Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(element).toString()));
        // configuration in subWorkflow should have overridden value
        assertEquals("other", subWorkflowConf.get("foo"));
        assertEquals("foo1", actionConf.get("foo1"));
        assertEquals("subconf", actionConf.get("foo2"));
        assertEquals("foo3", actionConf.get("foo3"));
        // Checking the action conf configuration.
        assertEquals("actionconf", subWorkflowConf.get("foo3"));
        assertEquals("subactionconf", actionConf.get("foo4"));
        // config defaults are present
        assertEquals("default", subWorkflowConf.get("parentConfigDefault"));
        assertEquals("default", actionConf.get("subwfConfigDefault"));
    } finally {
        LocalOozie.stop();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob)

Example 12 with OozieClient

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

the class TestLastModified method testWorkflowRun.

public void testWorkflowRun() throws Exception {
    String wfApp = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='test-wf'>" + "    <start to='end'/>" + "    <end name='end'/>" + "</workflow-app>";
    FileSystem fs = getFileSystem();
    Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    fs.mkdirs(new Path(appPath, "lib"));
    fs.mkdirs(new Path("input-data"));
    Writer inputWriter = new OutputStreamWriter(fs.create(new Path("input-data/data1.txt")));
    inputWriter.write("Hello. This is my input data set.");
    inputWriter.close();
    Path workflowPath = new Path(appPath, "workflow.xml");
    Writer writer = new OutputStreamWriter(fs.create(workflowPath));
    writer.write(wfApp);
    writer.close();
    try {
        LocalOozie.start();
        final OozieClient wc = LocalOozie.getClient();
        Properties conf = wc.createConfiguration();
        conf.setProperty(OozieClient.APP_PATH, workflowPath.toString());
        conf.setProperty(OozieClient.USER_NAME, getTestUser());
        conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
        final String jobId = wc.submit(conf);
        assertNotNull(jobId);
        WorkflowJob wf = wc.getJobInfo(jobId);
        assertNotNull(wf);
        assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
        boolean dateTest = wf.getLastModifiedTime().compareTo(wf.getCreatedTime()) >= 0 ? true : false;
        assertEquals(true, dateTest);
        wc.start(jobId);
        wf = wc.getJobInfo(jobId);
        Date lastModTime = wf.getLastModifiedTime();
        wc.suspend(jobId);
        wf = wc.getJobInfo(jobId);
        dateTest = wf.getLastModifiedTime().compareTo(lastModTime) >= 0 ? true : false;
        assertEquals(true, dateTest);
        lastModTime = wf.getLastModifiedTime();
        sleep(1000);
        wc.resume(jobId);
        wf = wc.getJobInfo(jobId);
        dateTest = wf.getLastModifiedTime().compareTo(lastModTime) >= 0 ? true : false;
        assertEquals(true, dateTest);
        waitFor(600000, new Predicate() {

            public boolean evaluate() throws Exception {
                WorkflowJob wf = wc.getJobInfo(jobId);
                return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
            }
        });
        wf = wc.getJobInfo(jobId);
        assertNotNull(wf);
        assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
        dateTest = wf.getLastModifiedTime().compareTo(wf.getEndTime()) >= 0 ? true : false;
        assertEquals(true, dateTest);
    } finally {
        LocalOozie.stop();
    }
}
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) Date(java.util.Date)

Example 13 with OozieClient

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

the class TestReRunXCommand method testRerunWithExistingConf.

// rerun should use existing wf conf
public void testRerunWithExistingConf() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    final OozieClient wfClient = LocalOozie.getClient();
    final Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("nnbase", path.toString());
    conf.setProperty("base", path.toUri().getPath());
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty("base", path.toUri().getPath());
    final String jobId = wfClient.submit(conf);
    wfClient.start(jobId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId).getStatus());
    try {
        wfClient.reRun(jobId, newConf);
    } catch (OozieClientException e) {
        assertTrue(e.getCause().getMessage().contains(ErrorCode.E0401.toString()));
    }
    newConf = wfClient.createConfiguration();
    // Skip a non-executed node
    getFileSystem().delete(new Path(path, "p2"), true);
    newConf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
    wfClient.reRun(jobId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) OozieClientException(org.apache.oozie.client.OozieClientException) 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 14 with OozieClient

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

the class TestReRunXCommand method testRerun.

public void testRerun() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    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("nnbase", path.toString());
    conf.setProperty("base", path.toUri().getPath());
    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.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    // Skip a non-executed node
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1,fs2,dec3");
    boolean failed = false;
    try {
        wfClient.reRun(jobId1, conf);
    } catch (OozieClientException e) {
        failed = true;
        assertTrue(e.getCause().getMessage().contains(ErrorCode.E0807.toString()));
    }
    assertEquals(true, failed);
    // Skip executed nodes
    getFileSystem().delete(new Path(path, "p2"), true);
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "fs1");
    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());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) OozieClientException(org.apache.oozie.client.OozieClientException) 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 15 with OozieClient

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

the class TestReRunXCommand method testRerunFromFailNodes.

public void testRerunFromFailNodes() throws IOException, OozieClientException {
    Reader reader = IOUtils.getResourceAsReader("rerun-wf.xml", -1);
    Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
    IOUtils.copyCharStream(reader, writer);
    Path path = getFsTestCaseDir();
    getFileSystem().create(new Path(path, "p2"));
    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("nnbase", path.toString());
    conf.setProperty("base", path.toUri().getPath());
    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.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId1).getStatus());
    // Skip succeeded nodes
    getFileSystem().delete(new Path(path, "p2"), true);
    conf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    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());
}
Also used : Path(org.apache.hadoop.fs.Path) 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