Search in sources :

Example 91 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.

the class TestCoordActionsKillXCommand method testActionKillCommandDate.

/**
 * Test the working of CoordActionKillXCommand by passing range
 * as date
 *
 * @throws Exception
 */
public void testActionKillCommandDate() throws Exception {
    JPAService jpaService = services.get(JPAService.class);
    String[] ids = createDBRecords();
    System.out.println(DateUtils.parseDateOozieTZ("2009-12-15T01:00Z"));
    System.out.println(DateUtils.parseDateOozieTZ("2009-12-15T02:00Z"));
    new CoordActionsKillXCommand(ids[0], "date", "2009-12-15T01:00Z::2009-12-15T02:00Z").call();
    CoordinatorActionBean action = jpaService.execute(new CoordActionGetForCheckJPAExecutor(ids[1]));
    System.out.println(action.getNominalTime());
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
    action = jpaService.execute(new CoordActionGetForCheckJPAExecutor(ids[2]));
    System.out.println(action.getNominalTime());
    assertEquals(CoordinatorAction.Status.KILLED, action.getStatus());
    sleep(100);
    WorkflowJobBean wf = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_FOR_SLA, ids[3]);
    assertEquals(WorkflowJob.Status.KILLED, wf.getStatus());
    CoordinatorJobBean job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.RUNNING, job.getStatus());
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    job = jpaService.execute(new CoordJobGetJPAExecutor(ids[0]));
    assertEquals(CoordinatorJob.Status.KILLED, job.getStatus());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) CoordActionGetForCheckJPAExecutor(org.apache.oozie.executor.jpa.CoordActionGetForCheckJPAExecutor)

Example 92 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangeEndTimeDeleteAction.

// Testcase to test deletion of lookahead action in case of end-date change
public void testCoordChangeEndTimeDeleteAction() throws Exception {
    Date startTime = DateUtils.parseDateOozieTZ("2013-08-01T00:00Z");
    Date endTime = DateUtils.parseDateOozieTZ("2013-08-01T05:00Z");
    Date changeEndTime = DateUtils.parseDateOozieTZ("2013-08-01T02:00Z");
    String endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(changeEndTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.RUNNING, startTime, endTime, endTime, true, false, 4);
    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-01T01:00Z"));
    addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"));
    addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0, DateUtils.parseDateOozieTZ("2013-08-01T03:00Z"));
    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.RUNNING, coordJob.getStatus());
    assertEquals(2, coordJob.getLastActionNumber());
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 2));
    } catch (JPAExecutorException jpae) {
        fail(" Action should be there");
    }
    try {
        jpaService.execute(new CoordJobGetActionByActionNumberJPAExecutor(job.getId(), 3));
        fail("Expected to fail as action 3 should have been deleted");
    } catch (JPAExecutorException jpae) {
        assertEquals(ErrorCode.E0603, jpae.getErrorCode());
    }
    assertEquals(DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"), coordJob.getNextMaterializedTime());
    assertEquals(DateUtils.parseDateOozieTZ("2013-08-01T02:00Z"), coordJob.getLastActionTime());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) CoordJobGetActionByActionNumberJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetActionByActionNumberJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 93 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.

the class TestCoordChangeXCommand method testCoordStatus_Killed.

// Status change from Killed- successful
public void testCoordStatus_Killed() 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.KILLED, 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 94 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangeStatus.

/**
 * Change the pause time and end time of a failed coordinator job. Check whether the status changes
 * to RUNNINGWITHERROR
 * @throws Exception
 */
public void testCoordChangeStatus() throws Exception {
    Services.get().destroy();
    setSystemProperty(StatusTransitService.CONF_BACKWARD_SUPPORT_FOR_STATES_WITHOUT_ERROR, "false");
    services = new Services();
    services.init();
    services.get(SchedulerService.class).destroy();
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + (20 * 60 * 1000));
    final CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.FAILED, startTime, endTime, true, true, 0);
    String pauseTime = convertDateToString(startTime.getTime() + 10 * 60 * 1000);
    String newEndTime = convertDateToString(startTime.getTime() + 40 * 60 * 1000);
    new CoordChangeXCommand(job.getId(), "endtime=" + newEndTime + ";pausetime=" + pauseTime).call();
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.RUNNINGWITHERROR, coordJob.getStatus());
}
Also used : Services(org.apache.oozie.service.Services) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SchedulerService(org.apache.oozie.service.SchedulerService) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) JPAService(org.apache.oozie.service.JPAService) Date(java.util.Date)

Example 95 with CoordJobGetJPAExecutor

use of org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor in project oozie by apache.

the class TestCoordChangeXCommand method testCoordChangeEndTimeBeforeStart.

// Testcase to check status for coord whose enddate is set before startdate.
public void testCoordChangeEndTimeBeforeStart() throws Exception {
    Date start = new Date();
    // 4 hrs
    Date end = new Date(start.getTime() + (4 * HOURS_IN_MS));
    Date endTime = new Date(start.getTime() - 3000);
    String endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(endTime);
    final CoordinatorJobBean job = addRecordToCoordJobTableForPauseTimeTest(CoordinatorJob.Status.PREP, start, end, end, true, false, 0);
    JPAService jpaService = Services.get().get(JPAService.class);
    CoordJobGetJPAExecutor coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    CoordinatorJobBean coordJob = jpaService.execute(coordGetCmd);
    assertEquals(Job.Status.PREP, coordJob.getStatus());
    assertEquals(0, coordJob.getLastActionNumber());
    new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
    coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getEndTime()), DateUtils.formatDateOozieTZ(endTime));
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
    Date newEndTime = new Date(start.getTime() - 2000);
    endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(newEndTime);
    new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
    coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getEndTime()), DateUtils.formatDateOozieTZ(newEndTime));
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
    // setting end date after startdate should make coord in running state
    newEndTime = new Date(start.getTime() + (4 * 60 * 60 * 1000));
    endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(newEndTime);
    new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
    coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getEndTime()), DateUtils.formatDateOozieTZ(newEndTime));
    assertEquals(Job.Status.RUNNING, coordJob.getStatus());
    // setting end date before startdate should make coord in SUCCEEDED state
    newEndTime = new Date(start.getTime() - 1000);
    endTimeChangeStr = "endtime=" + DateUtils.formatDateOozieTZ(newEndTime);
    new CoordChangeXCommand(job.getId(), endTimeChangeStr).call();
    coordGetCmd = new CoordJobGetJPAExecutor(job.getId());
    coordJob = jpaService.execute(coordGetCmd);
    assertEquals(DateUtils.formatDateOozieTZ(coordJob.getEndTime()), DateUtils.formatDateOozieTZ(newEndTime));
    assertEquals(Job.Status.SUCCEEDED, coordJob.getStatus());
}
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

CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)121 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)114 JPAService (org.apache.oozie.service.JPAService)85 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)79 Date (java.util.Date)66 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)42 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)32 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)30 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)29 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)25 BundleJobBean (org.apache.oozie.BundleJobBean)21 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)21 BundleActionBean (org.apache.oozie.BundleActionBean)20 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)20 WorkflowActionGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowActionGetJPAExecutor)20 CommandException (org.apache.oozie.command.CommandException)18 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)16 IOException (java.io.IOException)5 CoordMaterializeTriggerRunnable (org.apache.oozie.service.CoordMaterializeTriggerService.CoordMaterializeTriggerRunnable)5 Services (org.apache.oozie.service.Services)5