Search in sources :

Example 6 with CoordKillXCommand

use of org.apache.oozie.command.coord.CoordKillXCommand in project oozie by apache.

the class TestStatusTransitService method testBundleStatusTransitServiceKilled.

/**
 * Test : kill a bundle job - bundle job's pending will be updated to false.
 * <p/>
 * The pending is updated bottom-up. workflow job -> coordinator action -> coordinator job -> bundle action ->
 * bundle job
 *
 * @throws Exception
 */
public void testBundleStatusTransitServiceKilled() throws Exception {
    BundleJobBean bundleJob = this.addRecordToBundleJobTable(Job.Status.KILLED, true);
    final JPAService jpaService = Services.get().get(JPAService.class);
    assertNotNull(jpaService);
    final String bundleId = bundleJob.getId();
    addRecordToBundleActionTable(bundleId, "action1-C", 1, Job.Status.KILLED);
    addRecordToBundleActionTable(bundleId, "action2-C", 1, Job.Status.KILLED);
    String currentDatePlusMonth = XDataTestCase.getCurrentDateafterIncrementingInMonths(1);
    Date start = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    Date end = DateUtils.parseDateOozieTZ(currentDatePlusMonth);
    addRecordToCoordJobTableWithBundle(bundleId, "action1-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    addRecordToCoordJobTableWithBundle(bundleId, "action2-C", CoordinatorJob.Status.RUNNING, start, end, false, true, 2);
    WorkflowJobBean wfJob1_1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_2 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_3 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowJobBean wfJob1_4 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    final CoordinatorActionBean coordAction1_1 = addRecordToCoordActionTable("action1-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_1.getId(), wfJob1_1.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_2 = addRecordToCoordActionTable("action1-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_2.getId(), wfJob1_2.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_3 = addRecordToCoordActionTable("action2-C", 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_3.getId(), wfJob1_3.getStatusStr(), 0);
    final CoordinatorActionBean coordAction1_4 = addRecordToCoordActionTable("action2-C", 2, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", wfJob1_4.getId(), wfJob1_4.getStatusStr(), 0);
    new CoordKillXCommand("action1-C").call();
    new CoordKillXCommand("action2-C").call();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            WorkflowJobBean wfJob = jpaService.execute(new WorkflowJobGetJPAExecutor(coordAction1_4.getExternalId()));
            return wfJob.getStatus().equals(Job.Status.KILLED);
        }
    });
    Runnable runnable = new StatusTransitRunnable();
    runnable.run();
    waitFor(5 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            BundleJobBean bundle = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
            return bundle.isPending() == false;
        }
    });
    bundleJob = jpaService.execute(new BundleJobGetJPAExecutor(bundleId));
    assertFalse(bundleJob.isPending());
    assertEquals(Job.Status.KILLED, bundleJob.getStatus());
    BundleActionBean bundleAction1 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action1-C"));
    assertFalse(bundleAction1.isPending());
    assertEquals(Job.Status.KILLED, bundleAction1.getStatus());
    CoordinatorJobBean coordJob1 = jpaService.execute(new CoordJobGetJPAExecutor("action1-C"));
    assertFalse(coordJob1.isPending());
    assertEquals(Job.Status.KILLED, coordJob1.getStatus());
    BundleActionBean bundleAction2 = jpaService.execute(new BundleActionGetJPAExecutor(bundleId, "action2-C"));
    assertFalse(bundleAction2.isPending());
    assertEquals(Job.Status.KILLED, bundleAction2.getStatus());
    CoordinatorJobBean coordJob2 = jpaService.execute(new CoordJobGetJPAExecutor("action2-C"));
    assertFalse(coordJob2.isPending());
    assertEquals(Job.Status.KILLED, coordJob2.getStatus());
}
Also used : WorkflowJobGetJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) BundleActionGetJPAExecutor(org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) BundleJobGetJPAExecutor(org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor) BundleJobBean(org.apache.oozie.BundleJobBean) CoordJobGetJPAExecutor(org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) StatusTransitRunnable(org.apache.oozie.service.StatusTransitService.StatusTransitRunnable) BundleActionBean(org.apache.oozie.BundleActionBean)

Example 7 with CoordKillXCommand

use of org.apache.oozie.command.coord.CoordKillXCommand in project oozie by apache.

the class TestSLAEventGeneration method testFailureAndMissEventsOnKill.

/**
 * Test Coord action KILLED from WAITING generates corresponding events Job
 * - FAILURE and SLA - END_MISS
 *
 * @throws Exception
 */
public void testFailureAndMissEventsOnKill() throws Exception {
    assertEquals(0, ehs.getEventQueue().size());
    // CASE 1: Coord Job status - RUNNING (similar to RunningWithError,Paused and PausedWithError for
    // this test's purpose)
    CoordinatorJobBean job = this.addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
    CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.WAITING, "coord-action-sla1.xml", 0);
    // reset dummy externalId set by above test method
    action.setExternalId(null);
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
    services.get(SLAService.class).addRegistrationEvent(TestSLAService._createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION));
    new CoordKillXCommand(job.getId()).call();
    assertEquals(1, ehs.getEventQueue().size());
    CoordinatorActionEvent jobEvent = (CoordinatorActionEvent) ehs.getEventQueue().peek();
    assertEquals(AppType.COORDINATOR_ACTION, jobEvent.getAppType());
    assertEquals(JobEvent.EventStatus.FAILURE, jobEvent.getEventStatus());
    assertEquals(action.getId(), jobEvent.getId());
    ehs.new EventWorker().run();
    SLACalcStatus slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
    assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
    assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
    assertEquals(CoordinatorAction.Status.KILLED.name(), slaEvent.getJobStatus());
    assertEquals(action.getId(), slaEvent.getId());
    assertNotNull(slaEvent.getActualEnd());
    // CASE 2: Coord Job status - PAUSED - Should not create event via CoordKill
    // but via CoordActionUpdate
    assertEquals(0, ehs.getEventQueue().size());
    job = this.addRecordToCoordJobTable(CoordinatorJob.Status.PAUSED, false, false);
    action = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-sla1.xml", 0);
    services.get(SLAService.class).addRegistrationEvent(TestSLAService._createSLARegistration(action.getId(), AppType.COORDINATOR_ACTION));
    new CoordKillXCommand(job.getId()).call();
    assertEquals(0, ehs.getEventQueue().size());
    WorkflowJobBean wf = new WorkflowJobBean();
    wf.setId(action.getExternalId());
    wf.setStatus(WorkflowJob.Status.KILLED);
    wf.setParentId(action.getId());
    wf.setEndTime(new Date());
    jpa.execute(new WorkflowJobInsertJPAExecutor(wf));
    new CoordActionUpdateXCommand(wf).call();
    assertEquals(1, ehs.getEventQueue().size());
    jobEvent = (CoordinatorActionEvent) ehs.getEventQueue().peek();
    assertEquals(AppType.COORDINATOR_ACTION, jobEvent.getAppType());
    assertEquals(JobEvent.EventStatus.FAILURE, jobEvent.getEventStatus());
    assertEquals(action.getId(), jobEvent.getId());
    ehs.new EventWorker().run();
    slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
    assertEquals(EventStatus.END_MISS, slaEvent.getEventStatus());
    assertEquals(SLAStatus.MISS, slaEvent.getSLAStatus());
    assertEquals(CoordinatorAction.Status.KILLED.name(), slaEvent.getJobStatus());
    assertEquals(action.getId(), slaEvent.getId());
    assertNotNull(slaEvent.getActualEnd());
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) SLAService(org.apache.oozie.sla.service.SLAService) CoordKillXCommand(org.apache.oozie.command.coord.CoordKillXCommand) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorActionEvent(org.apache.oozie.event.CoordinatorActionEvent) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) CoordActionUpdateXCommand(org.apache.oozie.command.coord.CoordActionUpdateXCommand)

Aggregations

CoordKillXCommand (org.apache.oozie.command.coord.CoordKillXCommand)7 Date (java.util.Date)5 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)5 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)4 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)4 BundleActionBean (org.apache.oozie.BundleActionBean)3 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)3 BundleJobBean (org.apache.oozie.BundleJobBean)2 BundleActionGetJPAExecutor (org.apache.oozie.executor.jpa.BundleActionGetJPAExecutor)2 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)2 CommandException (org.apache.oozie.command.CommandException)1 CoordActionUpdateXCommand (org.apache.oozie.command.coord.CoordActionUpdateXCommand)1 CoordinatorActionEvent (org.apache.oozie.event.CoordinatorActionEvent)1 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)1 WorkflowJobInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor)1 SLAService (org.apache.oozie.sla.service.SLAService)1