Search in sources :

Example 26 with WorkflowJob

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

the class TestJavaActionExecutor method testGlobalConfigurationWithActionDefaults.

public void testGlobalConfigurationWithActionDefaults() throws Exception {
    try {
        String workflowUri = helper.createTestWorkflowXml(getWorkflowGlobalXml(), helper.getJavaActionXml(""));
        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);
        WorkflowJob workflow = wfClient.getJobInfo(jobId);
        waitFor(20 * 1000, new Predicate() {

            @Override
            public boolean evaluate() throws Exception {
                WorkflowAction javaAction = helper.getJavaAction(wfClient.getJobInfo(jobId));
                return javaAction != null && !javaAction.getStatus().equals("PREP");
            }
        });
        final WorkflowAction workflowAction = helper.getJavaAction(workflow);
        Element eConf = XmlUtils.parseXml(workflowAction.getConf());
        Element element = eConf.getChild("configuration", eConf.getNamespace());
        Configuration actionConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(element).toString()));
        assertEquals("Config value set in <global> section is not propagated correctly", "foo2", actionConf.get("action.foo"));
    } finally {
        LocalOozie.stop();
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowAction(org.apache.oozie.client.WorkflowAction) Element(org.jdom.Element) StringReader(java.io.StringReader) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 27 with WorkflowJob

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

the class TestJavaActionExecutor method testResourceManagerInGlobalConfigurationCanBeOverridenWithJobTrackerInAction.

public void testResourceManagerInGlobalConfigurationCanBeOverridenWithJobTrackerInAction() throws Exception {
    try {
        final String global = "<global>" + "<resource-manager>RM</resource-manager>" + "</global>";
        final String workflowUri = helper.createTestWorkflowXml(global, helper.getJavaActionXml(""));
        LocalOozie.start();
        final OozieClient wfClient = LocalOozie.getClient();
        final 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);
        WorkflowJob workflow = wfClient.getJobInfo(jobId);
        waitFor(20 * 1000, new Predicate() {

            @Override
            public boolean evaluate() throws Exception {
                WorkflowAction javaAction = helper.getJavaAction(wfClient.getJobInfo(jobId));
                return javaAction != null && !javaAction.getStatus().equals("PREP");
            }
        });
        final WorkflowAction workflowAction = helper.getJavaAction(workflow);
        final String actualConfig = workflowAction.getConf();
        final String actualJobTrackerURI = XmlUtils.parseXml(actualConfig).getChildTextNormalize("job-tracker", null);
        assertEquals(getJobTrackerUri(), actualJobTrackerURI);
    } finally {
        LocalOozie.stop();
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) WorkflowAction(org.apache.oozie.client.WorkflowAction) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) IOException(java.io.IOException)

Example 28 with WorkflowJob

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

the class TestSharelibConfigs method launchJavaActionAndValidateSharelibValues.

private void launchJavaActionAndValidateSharelibValues(String globalConfig, String localConfig, String oozieSharelibForJavaPropertyValue, String oozieSharelibPropertyValue) throws Exception {
    final String workflowUri = helper.createTestWorkflowXml(globalConfig, helper.getJavaActionXml(localConfig));
    final OozieClient wfClient = LocalOozie.getClient();
    final Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, workflowUri);
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("appName", "var-app-name");
    conf.setProperty(OozieClient.USE_SYSTEM_LIBPATH, "true");
    final String jobId = wfClient.submit(conf);
    wfClient.start(jobId);
    WorkflowJob workflow = wfClient.getJobInfo(jobId);
    waitFor(20 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            WorkflowAction javaAction = helper.getJavaAction(wfClient.getJobInfo(jobId));
            return javaAction != null && !javaAction.getStatus().equals("PREP");
        }
    });
    final XConfiguration actionConf = getJavaActionConfiguration(workflow);
    assertThat("Configuration priorities are incorrect! Global/local configs are not overwriting each other.", actionConf.get(LauncherAM.OOZIE_LAUNCHER_SHARELIB_PROPERTY), is(oozieSharelibPropertyValue));
    assertThat("Configuration priorities are incorrect! Global/local configs are not overwriting each other.", actionConf.get("oozie.action.sharelib.for.java"), is(oozieSharelibForJavaPropertyValue));
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowAction(org.apache.oozie.client.WorkflowAction) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) IOException(java.io.IOException)

Example 29 with WorkflowJob

use of org.apache.oozie.client.WorkflowJob 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 30 with WorkflowJob

use of org.apache.oozie.client.WorkflowJob 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)

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