Search in sources :

Example 1 with EventHandlerService

use of org.apache.oozie.service.EventHandlerService in project oozie by apache.

the class SLAService method init.

@Override
public void init(Services services) throws ServiceException {
    try {
        Configuration conf = services.getConf();
        Class<? extends SLACalculator> calcClazz = (Class<? extends SLACalculator>) ConfigurationService.getClass(conf, CONF_CALCULATOR_IMPL);
        calcImpl = calcClazz == null ? new SLACalculatorMemory() : (SLACalculator) calcClazz.newInstance();
        calcImpl.init(conf);
        eventHandler = Services.get().get(EventHandlerService.class);
        if (eventHandler == null) {
            throw new ServiceException(ErrorCode.E0103, "EventHandlerService", "Add it under config " + Services.CONF_SERVICE_EXT_CLASSES + " or declare it BEFORE SLAService");
        }
        LOG = XLog.getLog(getClass());
        java.util.Set<String> appTypes = eventHandler.getAppTypes();
        appTypes.add("workflow_action");
        eventHandler.setAppTypes(appTypes);
        Runnable slaThread = new SLAWorker(calcImpl);
        // schedule runnable by default every 30 sec
        int slaCheckInterval = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INTERVAL);
        int slaCheckInitialDelay = ConfigurationService.getInt(conf, CONF_SLA_CHECK_INITIAL_DELAY);
        services.get(SchedulerService.class).schedule(slaThread, slaCheckInitialDelay, slaCheckInterval, SchedulerService.Unit.SEC);
        slaEnabled = true;
        LOG.info("SLAService initialized with impl [{0}] capacity [{1}]", calcImpl.getClass().getName(), conf.get(SLAService.CONF_CAPACITY));
    } catch (Exception ex) {
        throw new ServiceException(ErrorCode.E0102, ex.getMessage(), ex);
    }
}
Also used : SchedulerService(org.apache.oozie.service.SchedulerService) Configuration(org.apache.hadoop.conf.Configuration) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) ServiceException(org.apache.oozie.service.ServiceException) EventHandlerService(org.apache.oozie.service.EventHandlerService) SLACalculator(org.apache.oozie.sla.SLACalculator) ServiceException(org.apache.oozie.service.ServiceException)

Example 2 with EventHandlerService

use of org.apache.oozie.service.EventHandlerService in project oozie by apache.

the class TestSLACalculatorMemory method testSLAEvents1.

@Test
public void testSLAEvents1() throws Exception {
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
    // 1 hour
    slaRegBean.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
    slaRegBean.setExpectedDuration(2 * 3600 * 1000);
    // 1 hour
    slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
    String jobId = slaRegBean.getId();
    slaCalcMemory.addRegistration(jobId, slaRegBean);
    assertEquals(1, slaCalcMemory.size());
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
    assertEquals("PREP", slaSummary.getJobStatus());
    slaCalcMemory.updateJobSla(jobId);
    assertEquals(2, ehs.getEventQueue().size());
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // both start miss and end miss (101)
    assertEquals(5, slaSummary.getEventProcessed());
    assertEquals(SLAEvent.EventStatus.END_MISS, slaSummary.getEventStatus());
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    job1.setStatusStr(WorkflowJob.Status.SUSPENDED.toString());
    job1.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, job1);
    slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUSPENDED.toString(), EventStatus.SUSPEND, sdf.parse("2012-01-01"), null);
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    assertEquals(WorkflowJob.Status.SUSPENDED.toString(), slaSummary.getJobStatus());
    assertEquals(5, slaSummary.getEventProcessed());
    job1.setStatusStr(WorkflowJob.Status.SUCCEEDED.toString());
    job1.setLastModifiedTime(new Date());
    job1.setStartTime(sdf.parse("2012-01-01"));
    job1.setEndTime(sdf.parse("2012-01-02"));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1);
    slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-01-01"), sdf.parse("2012-01-02"));
    assertEquals(3, ehs.getEventQueue().size());
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // All events processed and actual times stored (1000)
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(SLAStatus.MET, slaSummary.getSLAStatus());
    assertEquals(WorkflowJob.Status.SUCCEEDED.toString(), slaSummary.getJobStatus());
    assertEquals(SLAEvent.EventStatus.DURATION_MISS, slaSummary.getEventStatus());
    assertEquals(sdf.parse("2012-01-01").getTime(), slaSummary.getActualStart().getTime());
    assertEquals(sdf.parse("2012-01-02").getTime(), slaSummary.getActualEnd().getTime());
    assertEquals(sdf.parse("2012-01-02").getTime() - sdf.parse("2012-01-01").getTime(), slaSummary.getActualDuration());
    assertEquals(0, slaCalcMemory.size());
}
Also used : EventHandlerService(org.apache.oozie.service.EventHandlerService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Example 3 with EventHandlerService

use of org.apache.oozie.service.EventHandlerService in project oozie by apache.

the class TestSLACalculatorMemory method testDuplicateEndMiss.

@Test
public void testDuplicateEndMiss() throws Exception {
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
    // 1 hour ahead
    Date startTime = new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000);
    slaRegBean.setExpectedStart(startTime);
    slaRegBean.setExpectedDuration(3600 * 1000);
    // 1 hour back
    slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
    String jobId = slaRegBean.getId();
    slaCalcMemory.addRegistration(slaRegBean.getId(), slaRegBean);
    slaCalcMemory.updateJobSla(jobId);
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    slaRegBean = SLARegistrationQueryExecutor.getInstance().get(SLARegQuery.GET_SLA_REG_ALL, jobId);
    assertNotNull(slaRegBean.getCreatedTimestamp());
    assertEquals(slaRegBean.getCreatedTimestamp(), slaSummary.getCreatedTimestamp());
    // Only end sla should be processed (100)
    assertEquals(4, slaSummary.getEventProcessed());
    slaCalcMemory.updateJobSla(jobId);
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    assertEquals(4, slaSummary.getEventProcessed());
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    job1.setId(job1.getId());
    job1.setStatus(WorkflowJob.Status.SUCCEEDED);
    job1.setStartTime(new Date(System.currentTimeMillis()));
    job1.setEndTime(new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1);
    slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000));
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // Only Duration sla should be processed as end is already processed
    // (110)
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    // Recieve start event
    assertTrue(slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.RUNNING.toString(), EventStatus.STARTED, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 1 * 1 * 3600 * 1000)));
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // Start event received so all bits should be processed (111)
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    assertEquals(0, slaCalcMemory.size());
    assertEquals(3, ehs.getEventQueue().size());
}
Also used : EventHandlerService(org.apache.oozie.service.EventHandlerService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Example 4 with EventHandlerService

use of org.apache.oozie.service.EventHandlerService in project oozie by apache.

the class TestSLACalculatorMemory method testSLAEvents2.

@Test
public void testSLAEvents2() throws Exception {
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    SLARegistrationBean slaRegBean = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
    slaRegBean.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
    slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000));
    String jobId = slaRegBean.getId();
    slaCalcMemory.addRegistration(jobId, slaRegBean);
    assertEquals(1, slaCalcMemory.size());
    slaCalcMemory.updateJobSla(jobId);
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // Duration bit should be processed as expected duration is not set
    assertEquals(3, slaSummary.getEventProcessed());
    // check only start event in queue
    assertEquals(1, ehs.getEventQueue().size());
    ehs.getEventQueue().clear();
    // set back to 1, to make duration event not processed
    slaSummary.setEventProcessed(1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummary);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    job1.setStatus(WorkflowJob.Status.SUCCEEDED);
    job1.setStartTime(sdf.parse("2012-01-01"));
    job1.setEndTime(sdf.parse("2012-01-02"));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job1);
    slaCalcMemory.addJobStatus(jobId, WorkflowJob.Status.SUCCEEDED.toString(), EventStatus.SUCCESS, sdf.parse("2012-01-01"), sdf.parse("2012-01-02"));
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // all should be processed
    assertEquals(8, slaSummary.getEventProcessed());
    // check only end event is in queue
    assertEquals(1, ehs.getEventQueue().size());
    ehs.getEventQueue().clear();
    slaSummary.setEventProcessed(1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummary);
    WorkflowJobBean job2 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
    slaRegBean = _createSLARegistration(job2.getId(), AppType.WORKFLOW_JOB);
    slaRegBean.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000));
    slaRegBean.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 1 * 3600 * 1000));
    jobId = slaRegBean.getId();
    slaCalcMemory.addRegistration(jobId, slaRegBean);
    assertEquals(1, slaCalcMemory.size());
    job2.setStatus(WorkflowJob.Status.KILLED);
    job2.setEndTime(sdf.parse("2012-01-02"));
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, job2);
    slaCalcMemory.addJobStatus(job2.getId(), WorkflowJob.Status.KILLED.toString(), EventStatus.FAILURE, null, sdf.parse("2012-01-02"));
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId);
    // Actual start null, so all events processed
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(1, ehs.getEventQueue().size());
    assertNull(slaSummary.getActualStart());
    assertEquals(sdf.parse("2012-01-02"), slaSummary.getActualEnd());
    assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
    assertEquals(SLAEvent.EventStatus.END_MISS, slaSummary.getEventStatus());
}
Also used : EventHandlerService(org.apache.oozie.service.EventHandlerService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Example 5 with EventHandlerService

use of org.apache.oozie.service.EventHandlerService in project oozie by apache.

the class TestSLAJobEventListener method testListenerConfigured.

@Test
public void testListenerConfigured() throws Exception {
    EventHandlerService ehs = services.get(EventHandlerService.class);
    assertNotNull(ehs);
    assertTrue(SLAService.isEnabled());
    assertTrue(ehs.listEventListeners().contains(SLAJobEventListener.class.getCanonicalName()));
}
Also used : EventHandlerService(org.apache.oozie.service.EventHandlerService) Test(org.junit.Test)

Aggregations

EventHandlerService (org.apache.oozie.service.EventHandlerService)13 Test (org.junit.Test)9 Date (java.util.Date)8 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)7 FailingDBHelperForTest (org.apache.oozie.util.db.FailingDBHelperForTest)4 SLAService (org.apache.oozie.sla.service.SLAService)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Configuration (org.apache.hadoop.conf.Configuration)2 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2 JPAService (org.apache.oozie.service.JPAService)2 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)1 WorkflowJobInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor)1 SchedulerService (org.apache.oozie.service.SchedulerService)1 ServiceException (org.apache.oozie.service.ServiceException)1 Services (org.apache.oozie.service.Services)1 SLACalculator (org.apache.oozie.sla.SLACalculator)1 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)1 Pair (org.apache.oozie.util.Pair)1 XConfiguration (org.apache.oozie.util.XConfiguration)1