Search in sources :

Example 16 with OozieClient

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

the class TestReRunXCommand method testRerunDisableForChild.

/**
 * Rerun workflow should run by parent only if configuration has been set to
 * true for oozie.wf.child.disable.rerun , Default it is disabled.
 * @throws Exception
 */
public void testRerunDisableForChild() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    Date start = DateUtils.parseDateOozieTZ("2009-12-15T01:00Z");
    Date end = DateUtils.parseDateOozieTZ("2009-12-16T01:00Z");
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, false, false, 1);
    CoordinatorActionBean action = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUBMITTED, "coord-action-start-escape-strings.xml", 0);
    String actionId = action.getId();
    new CoordActionStartXCommand(actionId, getTestUser(), "myapp", "myjob").call();
    final JPAService jpaService = Services.get().get(JPAService.class);
    action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
    if (action.getStatus() == CoordinatorAction.Status.SUBMITTED) {
        fail("CoordActionStartCommand didn't work because the status for action id" + actionId + " is :" + action.getStatus() + " expected to be NOT SUBMITTED (i.e. RUNNING)");
    }
    final String wfId = action.getExternalId();
    wfClient.kill(wfId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    Properties newConf = wfClient.createConfiguration();
    newConf.setProperty(OozieClient.RERUN_FAIL_NODES, "true");
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, true);
    try {
        wfClient.reRun(wfId, newConf);
        fail("OozieClientException should have been thrown (" + ErrorCode.E0755 + " Rerun is not allowed through child workflow, please re-run through the parent)");
    } catch (OozieClientException ex) {
        assertEquals(ErrorCode.E0755.toString(), ex.getErrorCode());
    }
    Services.get().getConf().setBoolean(ReRunXCommand.DISABLE_CHILD_RERUN, false);
    wfClient.reRun(wfId, newConf);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(wfId).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(wfId).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) OozieClientException(org.apache.oozie.client.OozieClientException) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordActionStartXCommand(org.apache.oozie.command.coord.CoordActionStartXCommand) CoordActionGetJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Properties(java.util.Properties) Date(java.util.Date) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException)

Example 17 with OozieClient

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

the class TestSignalXCommand method _testSuspendPointsAll.

public void _testSuspendPointsAll() throws Exception {
    services.destroy();
    LocalOozie.start();
    FileSystem fs = getFileSystem();
    Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    Reader reader = IOUtils.getResourceAsReader("wf-suspendpoints.xml", -1);
    Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    IOUtils.copyCharStream(reader, writer);
    writer.close();
    reader.close();
    final OozieClient oc = LocalOozie.getClient();
    Properties conf = oc.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("oozie.suspend.on.nodes", "*");
    final String jobId = oc.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = oc.getJobInfo(jobId);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    oc.start(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action1" }, new String[] { ":start:" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action2" }, new String[] { ":start:", "action1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "decision1" }, new String[] { ":start:", "action1", "action2" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action3" }, new String[] { ":start:", "action1", "action2", "decision1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "fork1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "action4a", "action4b", "action4c" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "join1" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUSPENDED, new String[] { "end" }, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c", "join1" });
    oc.resume(jobId);
    checkSuspendActions(wf, oc, jobId, WorkflowJob.Status.SUCCEEDED, new String[] {}, new String[] { ":start:", "action1", "action2", "decision1", "action3", "fork1", "action4a", "action4b", "action4c", "join1", "end" });
    LocalOozie.stop();
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Reader(java.io.Reader) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 18 with OozieClient

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

the class TestSubmitXCommand method testProtoConfStorage.

// It should not store Hadoop properties
public void testProtoConfStorage() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    String appXml = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='${appName}-foo'> " + "<start to='end' /> " + "<end name='end' /> " + "</workflow-app>";
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.PREP;
        }
    });
    WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId);
    XConfiguration protoConf = new XConfiguration(new StringReader(wf.getProtoActionConf()));
    // Hadoop 2 adds "mapreduce.job.user.name" in addition to "user.name"
    if (protoConf.get("mapreduce.job.user.name") != null) {
        assertEquals(3, protoConf.size());
    } else {
        assertEquals(2, protoConf.size());
    }
    assertNull(protoConf.get(WorkflowAppService.APP_LIB_PATH_LIST));
    new File(getTestCaseDir() + "/lib").mkdirs();
    File.createTempFile("parentLibrary", ".jar", new File(getTestCaseDir() + "/lib"));
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("appName", "var-app-name");
    sc = new SubmitXCommand(conf);
    final String jobId1 = sc.call();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.PREP;
        }
    });
    wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId1);
    protoConf = new XConfiguration(new StringReader(wf.getProtoActionConf()));
    // Hadoop 2 adds "mapreduce.job.user.name" in addition to "user.name"
    if (protoConf.get("mapreduce.job.user.name") != null) {
        assertEquals(4, protoConf.size());
    } else {
        assertEquals(3, protoConf.size());
    }
    assertNotNull(protoConf.get(WorkflowAppService.APP_LIB_PATH_LIST));
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StringReader(java.io.StringReader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) File(java.io.File) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

Example 19 with OozieClient

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

the class TestSubmitXCommand method testWFConfigDefaultVarResolve.

public void testWFConfigDefaultVarResolve() throws Exception {
    final OozieClient wfClient = LocalOozie.getClient();
    OutputStream os = new FileOutputStream(getTestCaseDir() + "/config-default.xml");
    XConfiguration defaultConf = new XConfiguration();
    defaultConf.set("outputDir", "default-output-dir");
    defaultConf.set("foo.bar", "default-foo-bar");
    defaultConf.set("foobarRef", "${foo.bar}");
    defaultConf.set("key", "default_value");
    defaultConf.set("should_resolve", "${should.resolve}");
    defaultConf.set("mixed", "${nameNode}/${outputDir}");
    defaultConf.writeXml(os);
    os.close();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    String actionXml = "<map-reduce>" + "<job-tracker>${jobTracker}</job-tracker>" + "<name-node>${nameNode}</name-node>" + "        <prepare>" + "          <delete path=\"${nameNode}/user/${wf:user()}/mr/${outputDir}\"/>" + "        </prepare>" + "        <configuration>" + "          <property><name>bb</name><value>BB</value></property>" + "          <property><name>cc</name><value>from_action</value></property>" + "        </configuration>" + "      </map-reduce>";
    String wfXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.5\" name=\"map-reduce-wf\">" + "    <start to=\"mr-node\"/>" + "    <action name=\"mr-node\">" + actionXml + "    <ok to=\"end\"/>" + "    <error to=\"fail\"/>" + "</action>" + "<kill name=\"fail\">" + "    <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>" + "</kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    writeToFile(wfXml, workflowUri);
    Configuration conf = new XConfiguration();
    conf.set("nameNode", getNameNodeUri());
    conf.set("jobTracker", getJobTrackerUri());
    conf.set("foobarRef", "foobarRef");
    conf.set("key", "job_prop_value");
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("should.resolve", "resolved");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    String actionId = jobId + "@mr-node";
    WorkflowActionBean action = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQueryExecutor.WorkflowActionQuery.GET_ACTION, actionId);
    Element eAction = XmlUtils.parseXml(action.getConf());
    Element eConf = eAction.getChild("configuration", eAction.getNamespace());
    Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(eConf).toString()));
    assertEquals("default-output-dir", actionConf.get("outputDir"));
    assertEquals("BB", actionConf.get("bb"));
    assertEquals("from_action", actionConf.get("cc"));
    assertEquals("resolved", actionConf.get("should_resolve"));
    assertEquals("default-foo-bar", actionConf.get("foo.bar"));
    assertEquals("default-foo-bar", actionConf.get("foobarRef"));
    assertEquals("default_value", actionConf.get("key"));
    assertEquals(getNameNodeUri() + "/default-output-dir", actionConf.get("mixed"));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Element(org.jdom.Element) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader)

Example 20 with OozieClient

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

the class TestCoordJobsGetForPurgeJPAExecutor method getCoordConf.

private Properties getCoordConf(Path appPath) {
    Path wfAppPath = new Path(getFsTestCaseDir(), "workflow");
    final OozieClient coordClient = LocalOozie.getCoordClient();
    Properties conf = coordClient.createConfiguration();
    conf.setProperty(OozieClient.COORDINATOR_APP_PATH, appPath.toString());
    conf.setProperty("jobTracker", getJobTrackerUri());
    conf.setProperty("nameNode", getNameNodeUri());
    conf.setProperty("wfAppPath", wfAppPath.toString());
    conf.remove("user.name");
    conf.setProperty("user.name", getTestUser());
    return conf;
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) Properties(java.util.Properties)

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