Search in sources :

Example 21 with OozieClient

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

the class TestCoordJobsToBeMaterializedJPAExecutor 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)

Example 22 with OozieClient

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

the class TestLocalOozieClientCoord method testJobMethods.

public void testJobMethods() throws Exception {
    final OozieClient client = LocalOozie.getCoordClient();
    // Just in case, check that there are no Coord job records left by previous tests:
    List<CoordinatorJob> list0 = client.getCoordJobsInfo("", 1, 100);
    assertEquals(0, list0.size());
    Properties conf = client.createConfiguration();
    String appPath = getTestCaseFileUri("coordinator.xml");
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"${coord:minutes(20)}\" " + "start=\"2009-02-01T01:00Z\" end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.1\"> <controls> <timeout>10</timeout> <concurrency>1</concurrency> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:minutes(20)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template> </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:minutes(20)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template> </dataset> " + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow> " + "<app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPath);
    conf.setProperty(OozieClient.COORDINATOR_APP_PATH, appPath);
    String jobId0 = client.submit(conf);
    client.kill(jobId0);
    String jobId = client.run(conf);
    client.suspend(jobId);
    client.resume(jobId);
    client.kill(jobId);
    CoordinatorJob job = client.getCoordJobInfo(jobId);
    String appName = job.getAppName();
    assertEquals("NAME", appName);
    List<CoordinatorJob> list = client.getCoordJobsInfo("", 1, 5);
    assertEquals(2, list.size());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJob(org.apache.oozie.client.CoordinatorJob) Properties(java.util.Properties)

Example 23 with OozieClient

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

the class TestLocalOozieClientCoord method testJobsOperations.

public void testJobsOperations() throws Exception {
    final OozieClient client = LocalOozie.getCoordClient();
    // Just in case, check that there are no Coord job records left by previous tests:
    List<CoordinatorJob> list0 = client.getCoordJobsInfo("", 1, 100);
    assertEquals(0, list0.size());
    Properties conf = client.createConfiguration();
    String appPath = storedCoordAppPath();
    conf.setProperty(OozieClient.COORDINATOR_APP_PATH, appPath);
    final String jobId0 = client.run(conf);
    final String jobId1 = client.run(conf);
    final String jobId2 = client.run(conf);
    waitFor(client, jobId0);
    waitFor(client, jobId1);
    waitFor(client, jobId2);
    list0 = client.getCoordJobsInfo("name=NAME", 1, 10);
    assertEquals(3, list0.size());
    JSONObject jsonObject = client.suspendJobs("name=NAME", "coord", 1, 3);
    assertEquals(3, jsonObject.get("total"));
    assertEquals(3, ((JSONArray) jsonObject.get("coordinatorjobs")).size());
    assertEquals(Job.Status.SUSPENDED, client.getCoordJobInfo(jobId0).getStatus());
    assertEquals(Job.Status.SUSPENDED, client.getCoordJobInfo(jobId1).getStatus());
    assertEquals(Job.Status.SUSPENDED, client.getCoordJobInfo(jobId2).getStatus());
    jsonObject = client.resumeJobs("name=NAME", "coord", 1, 3);
    assertEquals(3, jsonObject.get("total"));
    assertEquals(3, ((JSONArray) jsonObject.get("coordinatorjobs")).size());
    assertEquals(Job.Status.RUNNING, client.getCoordJobInfo(jobId0).getStatus());
    assertEquals(Job.Status.RUNNING, client.getCoordJobInfo(jobId1).getStatus());
    assertEquals(Job.Status.RUNNING, client.getCoordJobInfo(jobId2).getStatus());
    jsonObject = client.killJobs("name=NAME", "coord", 1, 3);
    assertEquals(3, jsonObject.get("total"));
    assertEquals(3, ((JSONArray) jsonObject.get("coordinatorjobs")).size());
    assertEquals(Job.Status.KILLED, client.getCoordJobInfo(jobId0).getStatus());
    assertEquals(Job.Status.KILLED, client.getCoordJobInfo(jobId1).getStatus());
    assertEquals(Job.Status.KILLED, client.getCoordJobInfo(jobId2).getStatus());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient) CoordinatorJob(org.apache.oozie.client.CoordinatorJob) JSONObject(org.json.simple.JSONObject) Properties(java.util.Properties)

Example 24 with OozieClient

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

the class TestLocalOozieClientCoord method testGetProtocolUrl.

public void testGetProtocolUrl() throws IOException, OozieClientException {
    OozieClient client = LocalOozie.getCoordClient();
    assertEquals("localoozie", client.getProtocolUrl());
}
Also used : OozieClient(org.apache.oozie.client.OozieClient)

Example 25 with OozieClient

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

the class TestLocalOozieClientCoord method testReRun2.

public void testReRun2() {
    OozieClient client = LocalOozie.getCoordClient();
    try {
        client.reRun("foo-id", client.createConfiguration());
        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)

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