Search in sources :

Example 36 with OozieClient

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

the class TestLocalOozieClientCoord method testHeaderMethods.

public void testHeaderMethods() {
    OozieClient client = LocalOozie.getCoordClient();
    client.setHeader("h", "v");
    assertTrue("no-op, should be null/empty", StringUtils.isBlank(client.getHeader("h")));
    Iterator<String> hit = client.getHeaderNames();
    assertFalse(hit.hasNext());
    try {
        hit.next();
        fail("NoSuchElementException expected.");
    } catch (NoSuchElementException nsee) {
    // expected
    }
    client.removeHeader("h");
    assertTrue("no-op, should be null/empty", StringUtils.isBlank(client.getHeader("h")));
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) NoSuchElementException(java.util.NoSuchElementException)

Example 37 with OozieClient

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

the class TestActionFailover method testFsFailover.

public void testFsFailover() throws Exception {
    Path wf = new Path(getFsTestCaseDir(), "workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("failover-fs-wf.xml", -1);
    Writer writer = new OutputStreamWriter(getFileSystem().create(wf));
    IOUtils.copyCharStream(reader, writer);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, wf.toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty(OozieClient.GROUP_NAME, getTestGroup());
    final Path source = new Path(getFsTestCaseDir(), "fsfailover-source");
    getFileSystem().mkdirs(source);
    final Path target = new Path(getFsTestCaseDir().toString(), "fsfailover-target");
    conf.setProperty("source", source.toString());
    conf.setProperty("target", target.toUri().getPath());
    final String jobId1 = wfClient.submit(conf);
    setSystemProperty(FaultInjection.FAULT_INJECTION, "true");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "true");
    try {
        wfClient.start(jobId1);
        fail("Should have skipped commit for failover testing");
    } catch (OozieClientException oce) {
        assertTrue(oce.getMessage().contains("Skipping Commit for Failover Testing"));
    }
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return getFileSystem().exists(target);
        }
    });
    assertFalse(getFileSystem().exists(target));
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection");
        }
    });
    assertFalse(FaultInjection.isActive("org.apache.oozie.command.SkipCommitFaultInjection"));
    assertEquals(WorkflowJob.Status.RUNNING, wfClient.getJobInfo(jobId1).getStatus());
    WorkflowStore store = Services.get().get(WorkflowStoreService.class).create();
    List<WorkflowActionBean> actions = store.getActionsForWorkflow(jobId1, false);
    assertEquals(1, actions.size());
    WorkflowActionBean action = actions.get(0);
    assertEquals(WorkflowAction.Status.PREP, action.getStatus());
    assertEquals(StartActionExecutor.TYPE, action.getType());
    setSystemProperty(FaultInjection.FAULT_INJECTION, "false");
    setSystemProperty(SkipCommitFaultInjection.ACTION_FAILOVER_FAULT_INJECTION, "false");
    ActionStartXCommand actionStartCommand = new ActionStartXCommand(action.getId(), action.getType());
    actionStartCommand.call();
    sleep(500);
    store = Services.get().get(WorkflowStoreService.class).create();
    actions = store.getActionsForWorkflow(jobId1, false);
    action = actions.get(0);
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    final String jobId2 = wfClient.submit(conf);
    wfClient.start(jobId2);
    waitFor(10 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId2).getStatus() == WorkflowJob.Status.KILLED;
        }
    });
    assertEquals(WorkflowJob.Status.KILLED, wfClient.getJobInfo(jobId2).getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowStore(org.apache.oozie.store.WorkflowStore) WorkflowStoreService(org.apache.oozie.service.WorkflowStoreService) Reader(java.io.Reader) Properties(java.util.Properties) OozieClientException(org.apache.oozie.client.OozieClientException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) OozieClient(org.apache.oozie.client.OozieClient) ActionStartXCommand(org.apache.oozie.command.wf.ActionStartXCommand) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 38 with OozieClient

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

the class TestSubWorkflowActionExecutor method testParentGlobalConf.

public void testParentGlobalConf() throws Exception {
    try {
        Path subWorkflowAppPath = createSubWorkflowXml();
        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");
        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.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()));
        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"));
    } 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 39 with OozieClient

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

the class TestSubWorkflowActionExecutor method testConfigPropagation.

public void testConfigPropagation() 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");
    String defaultConf = workflow.getConf();
    XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
    newConf.set("abc", "xyz");
    newConf.set("job_prop", "job_prop_val");
    workflow.setConf(newConf.toXmlString());
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "      <propagate-configuration />" + "      <configuration>" + "        <property>" + "          <name>a</name>" + "          <value>A</value>" + "        </property>" + "        <property>" + "          <name>job_prop</name>" + "          <value>sub_prop_val</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());
    WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
    Configuration childConf = getWorkflowConfig(wf);
    assertEquals("xyz", childConf.get("abc"));
    assertEquals("A", childConf.get("a"));
    assertEquals("sub_prop_val", childConf.get("job_prop"));
}
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 40 with OozieClient

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

the class TestSubWorkflowActionExecutor method testSubworkflowLib.

public void testSubworkflowLib() throws Exception {
    XConfiguration protoConf = getBaseProtoConf();
    WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W");
    FileSystem fs = getFileSystem();
    Path parentLibJar = new Path(getFsTestCaseDir(), "lib/parentLibrary.jar");
    fs.create(parentLibJar);
    assertTrue(fs.exists(parentLibJar));
    String defaultConf = workflow.getConf();
    XConfiguration newConf = new XConfiguration(new StringReader(defaultConf));
    newConf.set(OozieClient.LIBPATH, parentLibJar.getParent().toString());
    workflow.setConf(newConf.toXmlString());
    Path subWorkflowAppPath = new Path(getFsTestCaseDir().toString(), "subwf");
    Path workflowPath = new Path(subWorkflowAppPath, "workflow.xml");
    Writer writer = new OutputStreamWriter(fs.create(workflowPath));
    writer.write(APP1);
    writer.close();
    Path subwfLibJar = new Path(subWorkflowAppPath, "lib/subwfLibrary.jar");
    fs.create(subwfLibJar);
    assertTrue(fs.exists(subwfLibJar));
    final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0);
    action.setConf("<sub-workflow xmlns='uri:oozie:workflow:0.1' name='subwf'>" + "      <app-path>" + workflowPath.toString() + "</app-path>" + "</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());
    WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
    WorkflowJob wf = oozieClient.getJobInfo(action.getExternalId());
    Configuration childConf = getWorkflowConfig(wf);
    childConf = wps.createProtoActionConf(childConf, true);
    assertEquals(childConf.get(WorkflowAppService.APP_LIB_PATH_LIST), subwfLibJar.toString());
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) 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)

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