Search in sources :

Example 1 with WorkflowJobEvent

use of org.apache.oozie.event.WorkflowJobEvent in project oozie by apache.

the class TestEventHandlerService method testEventListener.

@Test
public void testEventListener() throws Exception {
    EventHandlerService ehs = _testEventHandlerService();
    /*
         * Workflow Job events
         */
    WorkflowJobEvent event = new WorkflowJobEvent("jobid", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp", null, null);
    ehs.queueEvent(event);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Job event STARTED"));
    output.setLength(0);
    event.setStatus(WorkflowJob.Status.SUSPENDED);
    ehs.queueEvent(event);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Job event SUSPEND"));
    output.setLength(0);
    event.setStatus(WorkflowJob.Status.SUCCEEDED);
    ehs.queueEvent(event);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Job event SUCCESS"));
    output.setLength(0);
    event.setStatus(WorkflowJob.Status.KILLED);
    ehs.queueEvent(event);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Job event FAILURE"));
    output.setLength(0);
    /*
         * Coordinator Action events
         */
    CoordinatorActionEvent event2 = new CoordinatorActionEvent("parentid@1", "parentid", CoordinatorAction.Status.WAITING, getTestUser(), "myapp", null, null, null);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event WAITING"));
    output.setLength(0);
    event2.setStatus(CoordinatorAction.Status.RUNNING);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event STARTED"));
    output.setLength(0);
    event2.setStatus(CoordinatorAction.Status.SUSPENDED);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event SUSPEND"));
    output.setLength(0);
    event2.setStatus(CoordinatorAction.Status.SUCCEEDED);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event SUCCESS"));
    output.setLength(0);
    event2.setStatus(CoordinatorAction.Status.TIMEDOUT);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event FAILURE"));
    output.setLength(0);
    event2.setStatus(CoordinatorAction.Status.KILLED);
    ehs.queueEvent(event2);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Coord Action event FAILURE"));
    output.setLength(0);
    /*
         * Workflow Action events
         */
    WorkflowActionEvent event3 = new WorkflowActionEvent("parentid@wfaction", "parentid", WorkflowAction.Status.RUNNING, getTestUser(), "myapp", null, null);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event STARTED"));
    output.setLength(0);
    event3.setStatus(WorkflowAction.Status.START_MANUAL);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event SUSPEND"));
    output.setLength(0);
    event3.setStatus(WorkflowAction.Status.OK);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event SUCCESS"));
    output.setLength(0);
    event3.setStatus(WorkflowAction.Status.ERROR);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event FAILURE"));
    output.setLength(0);
    event3.setStatus(WorkflowAction.Status.KILLED);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event FAILURE"));
    output.setLength(0);
    event3.setStatus(WorkflowAction.Status.FAILED);
    ehs.queueEvent(event3);
    ehs.new EventWorker().run();
    assertTrue(output.toString().contains("Workflow Action event FAILURE"));
    output.setLength(0);
}
Also used : CoordinatorActionEvent(org.apache.oozie.event.CoordinatorActionEvent) WorkflowJobEvent(org.apache.oozie.event.WorkflowJobEvent) WorkflowActionEvent(org.apache.oozie.event.WorkflowActionEvent) Test(org.junit.Test)

Example 2 with WorkflowJobEvent

use of org.apache.oozie.event.WorkflowJobEvent in project oozie by apache.

the class TestEventHandlerService method testEventLogging.

@Test
public void testEventLogging() throws Exception {
    EventHandlerService ehs = _testEventHandlerService();
    // job event
    WorkflowJobEvent event = new WorkflowJobEvent("jobid", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp", null, null);
    TestLogAppender appender = null;
    Logger logger = null;
    try {
        appender = getTestLogAppender();
        logger = Logger.getLogger(EventHandlerService.class);
        logger.addAppender(appender);
        logger.setLevel(Level.DEBUG);
        ehs.queueEvent(event);
        List<LoggingEvent> log = appender.getLog();
        LoggingEvent logEntry = log.get(0);
        assertEquals(Level.DEBUG, logEntry.getLevel());
        assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid] ACTION[-] Queueing event : ID: jobid"));
        assertEquals("org.apache.oozie.service.EventHandlerService", logEntry.getLoggerName());
        ehs.new EventWorker().run();
        log = appender.getLog();
        logEntry = log.get(1);
        assertEquals(Level.DEBUG, logEntry.getLevel());
        assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid] ACTION[-] Processing event : ID: jobid"));
        // action event
        CoordinatorActionEvent event2 = new CoordinatorActionEvent("jobid2@1", "parentid", CoordinatorAction.Status.WAITING, getTestUser(), "myapp", null, null, null);
        ehs.queueEvent(event2);
        log = appender.getLog();
        logEntry = log.get(2);
        assertTrue(logEntry.getMessage().toString().contains("APP[myapp] JOB[jobid2] ACTION[jobid2@1] Queueing event : ID: jobid2@1"));
        WorkflowJobEvent event3 = new WorkflowJobEvent("jobid-other", "parentid", WorkflowJob.Status.RUNNING, getTestUser(), "myapp-other", null, null);
        ehs.queueEvent(event3);
        log = appender.getLog();
        logEntry = log.get(3);
        assertTrue(logEntry.getMessage().toString().contains("APP[myapp-other] JOB[jobid-other] ACTION[-] Queueing event : ID: jobid-other"));
    } finally {
        logger.removeAppender(appender);
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) CoordinatorActionEvent(org.apache.oozie.event.CoordinatorActionEvent) Logger(org.apache.log4j.Logger) WorkflowJobEvent(org.apache.oozie.event.WorkflowJobEvent) Test(org.junit.Test)

Example 3 with WorkflowJobEvent

use of org.apache.oozie.event.WorkflowJobEvent in project oozie by apache.

the class WorkflowXCommand method generateEvent.

protected static void generateEvent(WorkflowJobBean wfJob, String errorCode, String errorMsg) {
    if (eventService.isSupportedApptype(AppType.WORKFLOW_JOB.name())) {
        WorkflowJobEvent event = new WorkflowJobEvent(wfJob.getId(), wfJob.getParentId(), wfJob.getStatus(), wfJob.getUser(), wfJob.getAppName(), wfJob.getStartTime(), wfJob.getEndTime());
        event.setErrorCode(errorCode);
        event.setErrorMessage(errorMsg);
        eventService.queueEvent(event);
    }
}
Also used : WorkflowJobEvent(org.apache.oozie.event.WorkflowJobEvent)

Example 4 with WorkflowJobEvent

use of org.apache.oozie.event.WorkflowJobEvent 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

WorkflowJobEvent (org.apache.oozie.event.WorkflowJobEvent)4 CoordinatorActionEvent (org.apache.oozie.event.CoordinatorActionEvent)3 Test (org.junit.Test)3 WorkflowActionEvent (org.apache.oozie.event.WorkflowActionEvent)2 Date (java.util.Date)1 Logger (org.apache.log4j.Logger)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 SLAJobEventListener (org.apache.oozie.sla.listener.SLAJobEventListener)1 SLAService (org.apache.oozie.sla.service.SLAService)1