Search in sources :

Example 31 with OozieClient

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

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

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

the class TestRerun method testRerun.

public void testRerun() throws Exception {
    Path appPath = new Path(getFsTestCaseDir(), "app");
    FileSystem fs = getFileSystem();
    fs.mkdirs(new Path(appPath, "lib"));
    File jarFile = IOUtils.createJar(new File(getTestCaseDir()), "test.jar", MapperReducerForTest.class);
    InputStream is = new FileInputStream(jarFile);
    OutputStream os = fs.create(new Path(appPath, "lib/test.jar"));
    IOUtils.copyStream(is, os);
    Path input = new Path(appPath, "input");
    Path output = new Path(appPath, "output");
    fs.mkdirs(input);
    Writer writer = new OutputStreamWriter(fs.create(new Path(input, "test.txt")));
    writer.write("hello");
    writer.close();
    final String APP1 = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='app'>" + "<start to='end'/>" + "<end name='end'/>" + "</workflow-app>";
    String subWorkflowAppPath = new Path(appPath, "subwf").toString();
    fs.mkdirs(new Path(appPath, "subwf"));
    Writer writer2 = new OutputStreamWriter(fs.create(new Path(subWorkflowAppPath, "workflow.xml")));
    writer2.write(APP1);
    writer2.close();
    Reader reader = IOUtils.getResourceAsReader("recovery-wf.xml", -1);
    Writer writer1 = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    IOUtils.copyCharStream(reader, writer1);
    final OozieClient wfClient = LocalOozie.getClient();
    Properties conf = wfClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty("jobTracker", getJobTrackerUri());
    conf.setProperty("nameNode", getNameNodeUri());
    conf.setProperty("mrclass", MapperReducerForTest.class.getName());
    conf.setProperty("input", input.toString());
    conf.setProperty("output", output.toString());
    conf.setProperty("delPath", output.toString());
    conf.setProperty("subWfApp", appPath.toString() + "/subwf/workflow.xml");
    // conf.setProperty("user.name", getTestUser());
    // first run
    final String jobId1 = wfClient.submit(conf);
    wfClient.start(jobId1);
    waitFor(120 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    // getting external IDs of all actions on first run
    Map<String, String> extId0 = loadExtIds(wfClient.getJobInfo(jobId1).getActions());
    // doing a rerun skipping no nodes
    conf.setProperty(OozieClient.RERUN_SKIP_NODES, "");
    wfClient.reRun(jobId1, conf);
    waitFor(120 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return wfClient.getJobInfo(jobId1).getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    assertEquals(WorkflowJob.Status.SUCCEEDED, wfClient.getJobInfo(jobId1).getStatus());
    // getting external IDs of all actions on rerun
    Map<String, String> extId1 = loadExtIds(wfClient.getJobInfo(jobId1).getActions());
    // comparing external IDs of first run and rerun are different.
    assertNotSame(extId0, extId1);
}
Also used : Path(org.apache.hadoop.fs.Path) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Reader(java.io.Reader) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 34 with OozieClient

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

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

the class TestLocalOozieClientCoord method testValidateWSVersion.

public void testValidateWSVersion() throws IOException, OozieClientException {
    OozieClient client = LocalOozie.getCoordClient();
    client.validateWSVersion();
}
Also used : OozieClient(org.apache.oozie.client.OozieClient)

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