Search in sources :

Example 1 with CoordinatorJob

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

the class TestOozieCLIMethods method createBundleJob.

private static BundleJob createBundleJob(DataObject dtObject) {
    BundleJob bundleJobMock = mock(BundleJob.class);
    when(bundleJobMock.getId()).thenReturn(dtObject.deamonName);
    when(bundleJobMock.getAppName()).thenReturn(dtObject.appName);
    when(bundleJobMock.getAppPath()).thenReturn(dtObject.appPath);
    when(bundleJobMock.getStatus()).thenReturn(org.apache.oozie.client.Job.Status.RUNNING);
    CoordinatorJob coordinatorJobMock = createCoordinatorJob(dtObject);
    when(bundleJobMock.getCoordinators()).thenReturn(ImmutableList.of(coordinatorJobMock));
    return bundleJobMock;
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) BundleJob(org.apache.oozie.client.BundleJob)

Example 2 with CoordinatorJob

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

the class TestOozieCLIMethods method testValidatePrintCoordJobsOutput.

/**
 * Create {@code CoordinatorJob} mock,
 * call {@code new OozieCLI().printCoordJobs() }
 * and validate {@code System.out} on match with expected pattern
 * <p>
 * Method do pass only if output matched with predefined pattern
 * </p>
 */
@Test
public void testValidatePrintCoordJobsOutput() throws IOException {
    final DataObject dtObject1 = new DataObject() {

        {
            this.deamonName = "testCoordJob1";
            this.appName = "testCoordinatorJobApp1";
            this.appPath = "testCoordinatorJobAppPath1";
        }
    };
    final DataObject dtObject2 = new DataObject() {

        {
            this.deamonName = "testCoordJob2";
            this.appName = "testCoordinatorJobApp2";
            this.appPath = "testCoordinatorJobAppPath2";
        }
    };
    final ImmutableList<CoordinatorJob> coordJobs = ImmutableList.of(createCoordinatorJob(dtObject1), createCoordinatorJob(dtObject2));
    Pattern pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" + dtObject1.appName + "[\\s]+" + dtObject1.appPath);
    assertPrintCoordJobsOutput(readCoordJobsOutput(coordJobs, true), pattern);
    pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" + dtObject1.appName);
    assertPrintCoordJobsOutput(readCoordJobsOutput(coordJobs, false), pattern);
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) Pattern(java.util.regex.Pattern) Test(org.junit.Test)

Example 3 with CoordinatorJob

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

the class TestOozieCLIMethods method createCoordinatorJob.

private static CoordinatorJob createCoordinatorJob(DataObject dtObject) {
    CoordinatorJob coordinatorJobMock = mock(CoordinatorJob.class);
    when(coordinatorJobMock.getId()).thenReturn(dtObject.deamonName);
    when(coordinatorJobMock.getAppName()).thenReturn(dtObject.appName);
    when(coordinatorJobMock.getAppPath()).thenReturn(dtObject.appPath);
    when(coordinatorJobMock.getConcurrency()).thenReturn(15);
    when(coordinatorJobMock.getStatus()).thenReturn(CoordinatorJob.Status.RUNNING);
    when(coordinatorJobMock.getUser()).thenReturn("test");
    when(coordinatorJobMock.getGroup()).thenReturn("test-group");
    ImmutableList.Builder<CoordinatorAction> builder = ImmutableList.builder();
    for (final String id : Arrays.asList("1", "2")) builder.add(createCoordinatorAction(new DataObject() {

        {
            this.deamonName = id;
            this.appName = "testCoordinatorAction";
        }
    }));
    when(coordinatorJobMock.getActions()).thenReturn(builder.build());
    return coordinatorJobMock;
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) ImmutableList(com.google.common.collect.ImmutableList) CoordinatorAction(org.apache.oozie.client.CoordinatorAction)

Example 4 with CoordinatorJob

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

the class TestJsonToBean method testParseCoordinatorJob.

@SuppressWarnings("unchecked")
public void testParseCoordinatorJob() {
    JSONObject json = createJsonCoordinatorJob();
    CoordinatorJob job = JsonToBean.createCoordinatorJob(json);
    assertEquals("a", job.getAppPath());
    assertEquals("b", job.getAppName());
    assertEquals("c", job.getId());
    assertEquals("d", job.getConf());
    assertEquals(CoordinatorJob.Status.RUNNING, job.getStatus());
    assertEquals(CoordinatorJob.Execution.FIFO, job.getExecutionOrder());
    assertEquals("1", job.getFrequency());
    assertEquals(CoordinatorJob.Timeunit.DAY, job.getTimeUnit());
    assertEquals("e", job.getTimeZone());
    assertEquals(2, job.getConcurrency());
    assertEquals(3, job.getTimeout());
    assertEquals(JsonUtils.parseDateRfc822(LAST_ACTION), job.getLastActionTime());
    assertEquals(JsonUtils.parseDateRfc822(NEXT_MATERIALIZED), job.getNextMaterializedTime());
    assertEquals(JsonUtils.parseDateRfc822(CREATED_TIME), job.getCreatedTime());
    assertEquals(JsonUtils.parseDateRfc822(START_TIME), job.getStartTime());
    assertEquals(JsonUtils.parseDateRfc822(END_TIME), job.getEndTime());
    assertEquals(JsonUtils.parseDateRfc822(PAUSE_TIME), job.getPauseTime());
    assertEquals("f", job.getUser());
    assertEquals("g", job.getGroup());
    assertEquals("h", job.getConsoleUrl());
    assertEquals(2, job.getActions().size());
    assertEquals("ca1", job.getActions().get(0).getId());
    assertEquals("ca2", job.getActions().get(1).getId());
    // Test backward compatibility with 3.x. 3.x will not be forward compatible with 4.x though.
    // i.e 4.1 client can be used with 3.x server. But 3.x client cannot be used with 4.x server.
    // Frequency was a int in 3.x but was changed to String in 4.x for cron support
    json.put(JsonTags.COORDINATOR_JOB_FREQUENCY, 1L);
    CoordinatorJob oozie3xjob = JsonToBean.createCoordinatorJob(json);
    assertEquals("1", oozie3xjob.getFrequency());
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) JSONObject(org.json.simple.JSONObject)

Example 5 with CoordinatorJob

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

the class TestJsonToBean method testParseCoordinatorJobs.

@SuppressWarnings("unchecked")
public void testParseCoordinatorJobs() {
    JSONArray array = createJsonCoordinatorJobList();
    List<CoordinatorJob> list = JsonToBean.createCoordinatorJobList(array);
    assertEquals(2, list.size());
    assertEquals("cj1", list.get(0).getId());
    assertEquals("cj2", list.get(1).getId());
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) JSONArray(org.json.simple.JSONArray)

Aggregations

CoordinatorJob (org.apache.oozie.client.CoordinatorJob)30 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)9 IOException (java.io.IOException)8 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)8 BundleJob (org.apache.oozie.client.BundleJob)5 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 OozieClientException (org.apache.oozie.client.OozieClientException)3 StoreException (org.apache.oozie.store.StoreException)3 JSONObject (org.json.simple.JSONObject)3 File (java.io.File)2 List (java.util.List)2 Properties (java.util.Properties)2 CoordinatorEngine (org.apache.oozie.CoordinatorEngine)2 BulkResponse (org.apache.oozie.client.BulkResponse)2 OozieClient (org.apache.oozie.client.OozieClient)2 CommandException (org.apache.oozie.command.CommandException)2 CoordActionInputCheckXCommand (org.apache.oozie.command.coord.CoordActionInputCheckXCommand)2 CoordActionStartXCommand (org.apache.oozie.command.coord.CoordActionStartXCommand)2 CoordMaterializeTransitionXCommand (org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand)2