Search in sources :

Example 46 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangeConcurrency.

public void testCoordChangeConcurrency() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T04:59Z");
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
    CoordinatorActionBean ca1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    CoordinatorActionBean ca2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    CoordinatorActionBean ca3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
    CoordinatorActionBean ca4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.READY, "coord-action-get.xml", 0);
    new CoordChangeXCommand(job.getId(), "concurrency=4").call();
    Thread.sleep(100);
    ca1 = CoordActionQueryExecutor.getInstance().get(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, job.getId() + "@1");
    ca2 = CoordActionQueryExecutor.getInstance().get(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, job.getId() + "@2");
    ca3 = CoordActionQueryExecutor.getInstance().get(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, job.getId() + "@3");
    ca4 = CoordActionQueryExecutor.getInstance().get(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, job.getId() + "@4");
    assertEquals(CoordinatorAction.Status.RUNNING.toString(), ca1.getStatusStr());
    assertEquals(CoordinatorAction.Status.RUNNING.toString(), ca2.getStatusStr());
    assertEquals(CoordinatorAction.Status.READY.toString(), ca3.getStatusStr());
    assertEquals(CoordinatorAction.Status.READY.toString(), ca4.getStatusStr());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date)

Example 47 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordChangeXCommand method checkCoordJobs.

private void checkCoordJobs(String jobId, Date endTime, Integer concurrency, Date pauseTime, boolean checkPauseTime) throws StoreException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(jobId);
        CoordinatorJobBean job = null;
        job = jpaService.execute(coordGetCmd);
        if (endTime != null) {
            Date d = job.getEndTime();
            if (d.compareTo(endTime) != 0) {
                fail("Endtime is not updated properly job_end_time=" + d + ", expected_end_time=" + endTime);
            }
            CoordinatorJob.Status status = job.getStatus();
            if (status != CoordinatorJob.Status.RUNNING) {
                fail("Coordinator job's status is not updated properly");
            }
        }
        if (concurrency != null) {
            int c = job.getConcurrency();
            if (c != concurrency) {
                fail("Concurrency is not updated properly");
            }
        }
        if (checkPauseTime) {
            Date d = job.getPauseTime();
            if (pauseTime == null) {
                if (d != null) {
                    fail("Pausetime is not updated properly job_pause_time=" + d + ", expected_pause_time=" + pauseTime);
                }
            } else {
                if (d.compareTo(pauseTime) != 0) {
                    fail("Pausetime is not updated properly job_pause_time=" + d + ", expected_pause_time=" + pauseTime);
                }
            }
        }
    } catch (JPAExecutorException e) {
        e.printStackTrace();
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorJob(org.apache.oozie.client.CoordinatorJob) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 48 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordChangeXCommand method testCoordStatus_Failed.

// Status change from failed- successful
public void testCoordStatus_Failed() throws Exception {
    Date start = new Date();
    // 5 hrs
    Date end = new Date(start.getTime() + (5 * HOURS_IN_MS));
    String status = "status=RUNNING";
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.FAILED, start, end, end, true, false, 4);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0);
    addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
    try {
        new CoordChangeXCommand(job.getId(), status).call();
        JPAService jpaService = Services.get().get(JPAService.class);
        CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
        CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
        assertEquals(coordJob.getStatusStr(), "RUNNING");
    } catch (CommandException e) {
        e.printStackTrace();
        if (e.getErrorCode() != ErrorCode.E1022) {
            fail("Error code should be E1022");
        }
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 49 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangeEndTime3.

/**
 * Testcase when changing end-time to after original end-time
 * but before nextMaterializedTime should not cause unnecessary changes
 *
 * @throws Exception
 */
public void testCoordChangeEndTime3() throws Exception {
    JPAService jpaService = Services.get().get(JPAService.class);
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (10 * 60 * 1000));
    CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, true, true, 1);
    coordJob.setNextMaterializedTime(new Date(startTime.getTime() + (40 * 60 * 1000)));
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, coordJob);
    addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
    Runnable runnable = new StatusTransitService.StatusTransitRunnable();
    runnable.run();
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(coordJob.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
    assertFalse(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
    String newEndTime = convertDateToString(startTime.getTime() + 20 * 60 * 1000);
    try {
        new CoordChangeXCommand(coordJob.getId(), "endtime=" + newEndTime).call();
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Didn't change endtime. Endtime is in between coord end time and next materialization time"));
    }
    coordJob = jpaService.execute(coordGetCmd);
    assertFalse(Job.Status.RUNNING == coordJob.getStatus());
    assertFalse(coordJob.isPending());
    assertTrue(coordJob.isDoneMaterialization());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) StoreException(org.apache.oozie.store.StoreException) CommandException(org.apache.oozie.command.CommandException)

Example 50 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordChangeXCommand method testProcessLookaheadActions.

// Testcase to test deletion of lookahead action in case of end-date change
// Added one more test case to test processLookaheadActions with day frequency and SUSPENDED status.
public void testProcessLookaheadActions() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-29T00:00Z");
    Date changeEndTime = DateUtils.parseDateOozieTZ("2013-08-05T00:00Z");
    String endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(changeEndTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.SUSPENDED, startTime, endTime, endTime, true, false, 6);
    addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T00:00Z"));
    addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-02T00:00Z"));
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-03T00:00Z"));
    addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-04T00:00Z"));
    addRecordToCoordActionTable(job.getId(), 5, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"));
    addRecordToCoordActionTable(job.getId(), 6, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-06T00:00Z"));
    job.setFrequency("1");
    job.setTimeUnit(Timeunit.DAY);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQuery.UPDATE_COORD_JOB, job);
    JPAService jpaService = Services.get().get(JPAService.class);
    new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(coordJob.getEndTime(), changeEndTime);
    assertEquals(Job.Status.SUSPENDED, coordJob.getStatus());
    assertEquals(4, coordJob.getLastActionNumber());
    assertEquals(DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"), coordJob.getNextMaterializedTime());
    assertEquals(DateUtils.parseDateOozieTZ("2013-08-05T00:00Z"), coordJob.getLastActionTime());
    assertEquals(changeEndTime, coordJob.getEndTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Aggregations

CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)373 Date (java.util.Date)177 JPAService (org.apache.oozie.service.JPAService)153 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)149 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)121 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)114 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 CommandException (org.apache.oozie.command.CommandException)49 BundleJobBean (org.apache.oozie.BundleJobBean)46 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)43 IOException (java.io.IOException)39 XConfiguration (org.apache.oozie.util.XConfiguration)38 ArrayList (java.util.ArrayList)36 BundleActionBean (org.apache.oozie.BundleActionBean)36 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)34 Configuration (org.apache.hadoop.conf.Configuration)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)30 Path (org.apache.hadoop.fs.Path)24