Search in sources :

Example 11 with WorkflowJobInsertJPAExecutor

use of org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor 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

WorkflowJobBean (org.apache.oozie.WorkflowJobBean)11 WorkflowJobInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor)11 Configuration (org.apache.hadoop.conf.Configuration)8 JPAService (org.apache.oozie.service.JPAService)8 WorkflowApp (org.apache.oozie.workflow.WorkflowApp)7 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)7 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)7 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)7 Path (org.apache.hadoop.fs.Path)6 XConfiguration (org.apache.oozie.util.XConfiguration)6 Date (java.util.Date)5 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)5 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)5 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)3 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)2 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)2 SLAService (org.apache.oozie.sla.service.SLAService)2 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)2 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)2 Map (java.util.Map)1