Search in sources :

Example 26 with OozieClient

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

the class TestLocalOozieClientCoord method testGetOozieUrl.

public void testGetOozieUrl() {
    OozieClient client = LocalOozie.getCoordClient();
    assertEquals("localoozie", client.getOozieUrl());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient)

Example 27 with OozieClient

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

the class TestLocalOozieClientCoord method testGetJobsInfo.

public void testGetJobsInfo() {
    OozieClient client = LocalOozie.getCoordClient();
    try {
        client.getJobsInfo("foo");
        fail("OozieClientException expected.");
    } catch (OozieClientException oce) {
        assertEquals(ErrorCode.E0301.toString(), oce.getErrorCode());
    }
    try {
        client.getJobsInfo("foo", 0, 5);
        fail("OozieClientException expected.");
    } catch (OozieClientException oce) {
        assertEquals(ErrorCode.E0301.toString(), oce.getErrorCode());
    }
    try {
        client.getJobInfo("foo-id");
        fail("OozieClientException expected.");
    } catch (OozieClientException oce) {
        assertEquals(ErrorCode.E0301.toString(), oce.getErrorCode());
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) OozieClientException(org.apache.oozie.client.OozieClientException)

Example 28 with OozieClient

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

the class TestWorkflow method testWorkflowWithStartAndEndCompletesSuccessfully.

public void testWorkflowWithStartAndEndCompletesSuccessfully() throws Exception {
    final String wfApp = "<workflow-app xmlns='uri:oozie:workflow:0.1' name='test-wf'>" + "    <start to='end'/>" + "    <end name='end'/>" + "</workflow-app>";
    final FileSystem fs = getFileSystem();
    final Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    fs.mkdirs(new Path(appPath, "lib"));
    final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    writer.write(wfApp);
    writer.close();
    final OozieClient wc = LocalOozie.getClient();
    final Properties conf = wc.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    final String jobId = wc.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = wc.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    wc.start(jobId);
    waitFor(1000, new Predicate() {

        public boolean evaluate() throws Exception {
            final WorkflowJob wf = wc.getJobInfo(jobId);
            return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    wf = wc.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
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) IOException(java.io.IOException) OozieClientException(org.apache.oozie.client.OozieClientException)

Example 29 with OozieClient

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

the class TestWorkflow method runWorkflowFromFile.

private void runWorkflowFromFile(final String workflowFileName, final Properties additionalWorkflowProperties) throws IOException, OozieClientException {
    final FileSystem fs = getFileSystem();
    final Path appPath = new Path(getFsTestCaseDir(), "app");
    fs.mkdirs(appPath);
    fs.mkdirs(new Path(appPath, "lib"));
    final Reader reader = getResourceAsReader(workflowFileName, -1);
    final Writer writer = new OutputStreamWriter(fs.create(new Path(appPath, "workflow.xml")));
    copyCharStream(reader, writer);
    writer.close();
    reader.close();
    final Path path = getFsTestCaseDir();
    final OozieClient oozieClient = LocalOozie.getClient();
    final Properties conf = oozieClient.createConfiguration();
    conf.setProperty(OozieClient.APP_PATH, new Path(appPath, "workflow.xml").toString());
    conf.setProperty(OozieClient.USER_NAME, getTestUser());
    conf.setProperty("nameNodeBasePath", path.toString());
    conf.setProperty("base", path.toUri().getPath());
    conf.setProperty("nameNode", getNameNodeUri());
    conf.setProperty("jobTracker", getJobTrackerUri());
    for (final String additionalKey : additionalWorkflowProperties.stringPropertyNames()) {
        conf.setProperty(additionalKey, additionalWorkflowProperties.getProperty(additionalKey));
    }
    final String jobId = oozieClient.submit(conf);
    assertNotNull(jobId);
    WorkflowJob wf = oozieClient.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.PREP, wf.getStatus());
    oozieClient.start(jobId);
    waitFor(15 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            final WorkflowJob wf = oozieClient.getJobInfo(jobId);
            return wf.getStatus() == WorkflowJob.Status.SUCCEEDED;
        }
    });
    wf = oozieClient.getJobInfo(jobId);
    assertNotNull(wf);
    assertEquals(WorkflowJob.Status.SUCCEEDED, wf.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) OozieClient(org.apache.oozie.client.OozieClient) FileSystem(org.apache.hadoop.fs.FileSystem) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) WorkflowJob(org.apache.oozie.client.WorkflowJob) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OozieClientException(org.apache.oozie.client.OozieClientException)

Example 30 with OozieClient

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

the class SubWorkflowActionExecutor method kill.

public void kill(Context context, WorkflowAction action) throws ActionExecutorException {
    LOG.info("Killing action");
    try {
        String subWorkflowId = action.getExternalId();
        String oozieUri = action.getTrackerUri();
        if (subWorkflowId != null && oozieUri != null) {
            OozieClient oozieClient = getWorkflowClient(context, oozieUri);
            oozieClient.kill(subWorkflowId);
        }
        context.setEndData(WorkflowAction.Status.KILLED, getActionSignal(WorkflowAction.Status.KILLED));
    } catch (Exception ex) {
        throw convertException(ex);
    }
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) LocalOozieClient(org.apache.oozie.LocalOozieClient) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException)

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