Search in sources :

Example 1 with TestSLAService

use of org.apache.oozie.sla.TestSLAService in project oozie by apache.

the class DummySLACalculatorMemory method testSLAFailOverWithHA.

public void testSLAFailOverWithHA() throws Exception {
    SLAService slas = Services.get().get(SLAService.class);
    SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
    EventHandlerService ehs = Services.get().get(EventHandlerService.class);
    // start another dummy oozie instance (dummy sla and eventhandler
    // services)
    DummyZKOozie dummyOozie_1 = null;
    try {
        dummyOozie_1 = new DummyZKOozie("a", "http://blah");
        DummySLACalculatorMemory dummyCalc = new DummySLACalculatorMemory();
        EventHandlerService dummyEhs = new EventHandlerService();
        dummyCalc.setEventHandlerService(dummyEhs);
        dummyEhs.init(Services.get());
        dummyCalc.init(Services.get().getConf());
        // Case 1 workflow job submitted to dummy server,
        // but before start running, the dummy server is down
        WorkflowJobBean wfJob1 = createWorkflow("job-1-W");
        SLARegistrationBean sla1 = TestSLAService._createSLARegistration("job-1-W", AppType.WORKFLOW_JOB);
        // 2 hr before
        sla1.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
        // 1 hr before
        sla1.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 3600 * 1000));
        // 10 mins
        sla1.setExpectedDuration(10 * 60 * 1000);
        dummyCalc.addRegistration(sla1.getId(), sla1);
        dummyCalc.updateAllSlaStatus();
        // Case 2. workflow job submitted to dummy server, start running,
        // then the dummy server is down
        WorkflowJobBean wfJob2 = createWorkflow("job-2-W");
        SLARegistrationBean sla2 = TestSLAService._createSLARegistration("job-2-W", AppType.WORKFLOW_JOB);
        // 2hr before
        sla2.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000));
        // 1hr ahead
        sla2.setExpectedEnd(new Date(System.currentTimeMillis() + 1 * 3600 * 1000));
        // 10 mins
        sla2.setExpectedDuration(10 * 60 * 1000);
        dummyCalc.addRegistration(sla2.getId(), sla2);
        dummyCalc.addJobStatus(sla2.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
        dummyCalc.updateAllSlaStatus();
        dummyEhs.new EventWorker().run();
        assertTrue(output.toString().contains(sla2.getId() + " Sla START - MISS!!!"));
        // suppose dummy Server is down
        dummyCalc.clear();
        dummyCalc = null;
        dummyOozie_1.teardown();
        slaCalcMem.updateAllSlaStatus();
        // Job 1 started running on the living server --> start miss
        slaCalcMem.addJobStatus(sla1.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(), new Date());
        // job 1 is added to slamap of living oozie server
        assertNotNull(slaCalcMem.get(sla1.getId()));
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla1.getId() + " Sla START - MISS!!!"));
        wfJob1.setStatus(WorkflowJob.Status.SUCCEEDED);
        wfJob1.setEndTime(new Date());
        wfJob1.setStartTime(new Date());
        WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob1);
        // Job 1 succeeded on the living server --> duration met and end miss
        slaCalcMem.addJobStatus(sla1.getId(), WorkflowJob.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(), new Date());
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla1.getId() + " Sla DURATION - MET!!!"));
        assertTrue(output.toString().contains(sla1.getId() + " Sla END - MISS!!!"));
        wfJob2.setStatus(WorkflowJob.Status.SUCCEEDED);
        wfJob2.setEndTime(new Date());
        wfJob2.setStartTime(new Date());
        WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_START_END, wfJob2);
        // Job 2 succeeded on the living server --> duration met and end met
        slaCalcMem.addJobStatus(sla2.getId(), WorkflowJob.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(), new Date());
        // eventProc >= 7(already processed duration/end met), should be removed from slaMap
        assertNull(slaCalcMem.get(sla2.getId()));
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla2.getId() + " Sla DURATION - MET!!!"));
        assertTrue(output.toString().contains(sla2.getId() + " Sla END - MET!!!"));
    } finally {
        if (dummyOozie_1 != null) {
            dummyOozie_1.teardown();
        }
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) TestSLAService(org.apache.oozie.sla.TestSLAService) SLAService(org.apache.oozie.sla.service.SLAService) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)1 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)1 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)1 TestSLAService (org.apache.oozie.sla.TestSLAService)1 SLAService (org.apache.oozie.sla.service.SLAService)1