Search in sources :

Example 1 with SLAJobEventListener

use of org.apache.oozie.sla.listener.SLAJobEventListener in project oozie by apache.

the class TestSLAJobEventListener method testOnJobEvent.

@Test
public void testOnJobEvent() throws Exception {
    SLAService slas = services.get(SLAService.class);
    SLAJobEventListener listener = new SLAJobEventListener();
    listener.init(services.getConf());
    // add dummy registration events to the SLAService map
    SLARegistrationBean job = _createSLARegBean("wf1-W", AppType.WORKFLOW_JOB);
    job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
    job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-23T00:00Z"));
    slas.addRegistrationEvent(job);
    assertEquals(1, slas.getSLACalculator().size());
    Date actualStart = DateUtils.parseDateUTC("2012-07-22T01:00Z");
    createWorkflow("wf1-W", actualStart);
    WorkflowJobEvent wfe = new WorkflowJobEvent("wf1-W", "caId1", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", actualStart, null);
    listener.onWorkflowJobEvent(wfe);
    SLACalcStatus serviceObj = slas.getSLACalculator().get("wf1-W");
    // job will be checked against DB.. since it's old job. all event will get evaluted and job will move to history set.
    // check that start sla has been calculated
    assertEquals(EventStatus.END_MISS, serviceObj.getEventStatus());
    // Job switching to running is only partially
    assertEquals(7, serviceObj.getEventProcessed());
    assertEquals(0, slas.getSLACalculator().size());
    createWorkflowAction("wfId1-W@wa1", "wf1-W");
    job = _createSLARegBean("wfId1-W@wa1", AppType.WORKFLOW_ACTION);
    job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
    slas.addRegistrationEvent(job);
    assertEquals(1, slas.getSLACalculator().size());
    job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
    WorkflowActionEvent wae = new WorkflowActionEvent("wfId1-W@wa1", "wf1-W", WorkflowAction.Status.RUNNING, "user1", "wf-app-name1", actualStart, null);
    listener.onWorkflowActionEvent(wae);
    serviceObj = slas.getSLACalculator().get("wfId1-W@wa1");
    // check that start sla has been calculated
    assertEquals(EventStatus.END_MISS, serviceObj.getEventStatus());
    createCoord("cj1-C");
    CoordinatorActionBean coordAction = createCoordAction("cj1-C@ca1", "cj1-C");
    job = _createSLARegBean("cj1-C@ca1", AppType.COORDINATOR_ACTION);
    job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
    Date actualEnd = DateUtils.parseDateUTC("2012-07-22T02:00Z");
    slas.addRegistrationEvent(job);
    assertEquals(1, slas.getSLACalculator().size());
    CoordinatorActionEvent cae = new CoordinatorActionEvent("cj1-C@ca1", "cj1-C", CoordinatorAction.Status.RUNNING, "user1", "coord-app-name1", null, actualEnd, null);
    listener.onCoordinatorActionEvent(cae);
    coordAction.setStatus(CoordinatorAction.Status.KILLED);
    coordAction.setLastModifiedTime(new Date());
    CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION_STATUS_PENDING_TIME, coordAction);
    cae = new CoordinatorActionEvent("cj1-C@ca1", "cj1-C", CoordinatorAction.Status.KILLED, "user1", "coord-app-name1", null, actualEnd, null);
    listener.onCoordinatorActionEvent(cae);
    SLASummaryBean summary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, "cj1-C@ca1");
    // check that all events are processed
    assertEquals(8, summary.getEventProcessed());
    assertEquals(EventStatus.END_MISS, summary.getEventStatus());
    // all jobs are processed
    assertEquals(0, slas.getSLACalculator().size());
    job = _createSLARegBean("wf2-W", AppType.WORKFLOW_JOB);
    // 2 hour before
    job.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
    // 1 hours after
    job.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
    slas.addRegistrationEvent(job);
    assertEquals(1, slas.getSLACalculator().size());
    createWorkflow("wf2-W", new Date());
    wfe = new WorkflowJobEvent("wf2-W", "caId2", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", null, null);
    listener.onWorkflowJobEvent(wfe);
    serviceObj = slas.getSLACalculator().get("wf2-W");
    assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
    // Only duration and start are processed. Duration = -1
    assertEquals(3, serviceObj.getEventProcessed());
    assertEquals(1, slas.getSLACalculator().size());
}
Also used : SLAJobEventListener(org.apache.oozie.sla.listener.SLAJobEventListener) SLAService(org.apache.oozie.sla.service.SLAService) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorActionEvent(org.apache.oozie.event.CoordinatorActionEvent) WorkflowJobEvent(org.apache.oozie.event.WorkflowJobEvent) WorkflowActionEvent(org.apache.oozie.event.WorkflowActionEvent) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorActionEvent (org.apache.oozie.event.CoordinatorActionEvent)1 WorkflowActionEvent (org.apache.oozie.event.WorkflowActionEvent)1 WorkflowJobEvent (org.apache.oozie.event.WorkflowJobEvent)1 SLAJobEventListener (org.apache.oozie.sla.listener.SLAJobEventListener)1 SLAService (org.apache.oozie.sla.service.SLAService)1 Test (org.junit.Test)1