Examples of SLAService


Examples of org.apache.oozie.sla.service.SLAService

     *
     * @throws Exception
     */
    @Test
    public void testWorkflowJobSLARerun() throws Exception {
        SLAService slas = services.get(SLAService.class);

        String wfXml = IOUtils.getResourceAsString("wf-job-sla.xml", -1);
        Path appPath = getFsTestCaseDir();
        writeToFile(wfXml, appPath, "workflow.xml");
        Configuration conf = new XConfiguration();
        conf.set(OozieClient.APP_PATH, appPath.toString());
        conf.set(OozieClient.USER_NAME, getTestUser());

        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, -40); // for start_miss
        Date nominal = cal.getTime();
        String nominalTime = DateUtils.formatDateOozieTZ(nominal);
        conf.set("nominal_time", nominalTime);
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 10); // as per the sla xml
        String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 30); // as per the sla xml
        String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());

        // Call SubmitX
        SubmitXCommand sc = new SubmitXCommand(conf);
        String jobId = sc.call();
        SLACalcStatus slaEvent = slas.getSLACalculator().get(jobId);
        assertEquals(jobId, slaEvent.getId());
        assertEquals("test-wf-job-sla", slaEvent.getAppName());
        assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());
        assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
        assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
        assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));

        slas.runSLAWorker();
        slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
        assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
        assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());
        slas.getSLACalculator().clear();

        JPAService jpaService = Services.get().get(JPAService.class);
        WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
        // set job status to succeeded, so rerun doesn't fail
        wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
        jpaService.execute(new WorkflowJobUpdateJPAExecutor(wfBean));

        // change conf for rerun
        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, -20); // for start_miss
        nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());

        conf.set("nominal_time", nominalTime);
        nominal = cal.getTime();
        cal.add(Calendar.MINUTE, 10); // as per the sla xml
        expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 30); // as per the sla xml
        expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());

        ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
        rerun.call();
        slaEvent = slas.getSLACalculator().get(jobId);
        // assert for new conf
        assertNotNull(slaEvent);
        assertEquals(jobId, slaEvent.getId());
        assertEquals("test-wf-job-sla", slaEvent.getAppName());
        assertEquals(AppType.WORKFLOW_JOB, slaEvent.getAppType());

        // assert for new conf
        assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
        assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
        assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));

        // assert for values in summary bean to be reset
        SLASummaryBean slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(jobId));
        assertEquals( 0, slaSummary.getEventProcessed());
        assertEquals(-1, slaSummary.getActualDuration());
        assertNull(slaSummary.getActualStart());
        assertNull(slaSummary.getActualEnd());
        assertEquals("PREP", slaSummary.getJobStatus());
        assertEquals(SLAStatus.NOT_STARTED, slaSummary.getSLAStatus());
        assertNull(slaEvent.getEventStatus());

        ehs.getEventQueue().clear();
        slas.runSLAWorker();
        slaEvent = (SLACalcStatus) ehs.getEventQueue().poll();
        assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
        assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());

    }
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

     *
     * @throws Exception
     */
    @Test
    public void testWorkflowActionSLARerun() throws Exception {
        SLAService slas = services.get(SLAService.class);
        String wfXml = IOUtils.getResourceAsString("wf-action-sla.xml", -1);
        Path appPath = getFsTestCaseDir();
        writeToFile(wfXml, appPath, "workflow.xml");
        Configuration conf = new XConfiguration();
        conf.set(OozieClient.APP_PATH, appPath.toString());
        conf.set(OozieClient.USER_NAME, getTestUser());

        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, -20); // for start_miss
        Date nominal = cal.getTime();
        String nominalTime = DateUtils.formatDateOozieTZ(nominal);
        conf.set("nominal_time", nominalTime);

        // Call SubmitX
        SubmitXCommand sc = new SubmitXCommand(conf);
        String jobId = sc.call();
        String actionId = jobId+"@grouper";

        slas.getSLACalculator().clear();
        JPAService jpaService = Services.get().get(JPAService.class);
        WorkflowJobBean wfBean = jpaService.execute(new WorkflowJobGetJPAExecutor(jobId));
        // set job status to succeeded, so rerun doesn't fail
        wfBean.setStatus(WorkflowJob.Status.SUCCEEDED);
        jpaService.execute(new WorkflowJobUpdateJPAExecutor(wfBean));

        // change conf for rerun
        cal.setTime(new Date());
        nominalTime = DateUtils.formatDateOozieTZ(cal.getTime());
        conf.set("nominal_time", nominalTime);
        nominal = cal.getTime();
        cal.add(Calendar.MINUTE, 10); // as per the sla xml
        String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 30); // as per the sla xml
        String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());

        ReRunXCommand rerun = new ReRunXCommand(jobId, conf);
        rerun.call();
        SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
        assertNotNull(slaEvent);
        // assert for action configs
        assertEquals(actionId, slaEvent.getId());
        assertEquals("test-wf-action-sla", slaEvent.getAppName());
        assertEquals(AppType.WORKFLOW_ACTION, slaEvent.getAppType());
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

    }

    @Test
    public void testSLASchema1BackwardCompatibility() throws Exception {
        assertNotNull(ehs);
        SLAService slas = services.get(SLAService.class);
        assertNotNull(slas);

        Path appPath = getFsTestCaseDir();
        writeToFile(SLA_XML_1, appPath, "workflow.xml");
        Configuration conf = new XConfiguration();
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

    @Test
    public void testCoordinatorActionCommands() throws Exception {
        // reduce noise from WF Job events (also default) by setting it to only
        // coord action
        ehs.setAppTypes(new HashSet<String>(Arrays.asList(new String[] { "coordinator_action" })));
        SLAService slas = services.get(SLAService.class);

        String coordXml = IOUtils.getResourceAsString("coord-action-sla.xml", -1);
        Path appPath = getFsTestCaseDir();
        writeToFile(coordXml, appPath, "coordinator.xml");
        Configuration conf = new XConfiguration();
        conf.set(OozieClient.COORDINATOR_APP_PATH, appPath.toString());
        String wfXml = IOUtils.getResourceAsString("wf-credentials.xml", -1);
        writeToFile(wfXml, appPath, "workflow.xml");
        conf.set("wfAppPath", appPath.toString());
        conf.set(OozieClient.USER_NAME, getTestUser());

        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, -20); // for start_miss
        Date nominal = cal.getTime();
        String nominalTime = DateUtils.formatDateOozieTZ(nominal);
        conf.set("nominal_time", nominalTime);
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 10); // as per the sla xml
        String expectedStart = DateUtils.formatDateOozieTZ(cal.getTime());
        cal.setTime(nominal);
        cal.add(Calendar.MINUTE, 30); // as per the sla xml
        String expectedEnd = DateUtils.formatDateOozieTZ(cal.getTime());
        String appName = "test-coord-sla";

        // testing creation of new sla registration via Submit + Materialize
        // command
        CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
        String jobId = sc.call();
        Thread.sleep(500); // waiting for materialize command to run
        final CoordActionGetJPAExecutor getCmd = new CoordActionGetJPAExecutor(jobId + "@1");
        CoordinatorActionBean action = jpa.execute(getCmd);
        String actionId = action.getId();
        SLACalcStatus slaEvent = slas.getSLACalculator().get(actionId);
        assertEquals(actionId, slaEvent.getId());
        assertEquals(appName, slaEvent.getAppName());
        assertEquals(AppType.COORDINATOR_ACTION, slaEvent.getAppType());
        assertEquals(nominalTime, DateUtils.formatDateOozieTZ(slaEvent.getNominalTime()));
        assertEquals(expectedStart, DateUtils.formatDateOozieTZ(slaEvent.getExpectedStart()));
        assertEquals(expectedEnd, DateUtils.formatDateOozieTZ(slaEvent.getExpectedEnd()));
        assertEquals(30 * 60 * 1000, slaEvent.getExpectedDuration());
        assertEquals(alert_events, slaEvent.getAlertEvents());
        waitForEventGeneration(200);
        slas.runSLAWorker();
        slaEvent = skipToSLAEvent();
        assertEquals(SLAStatus.NOT_STARTED, slaEvent.getSLAStatus());
        assertEquals(EventStatus.START_MISS, slaEvent.getEventStatus());

        // test that sla processes the Job Event from Start command
        action.setStatus(CoordinatorAction.Status.SUBMITTED);
        final CoordActionUpdateJPAExecutor writeCmd = new CoordActionUpdateJPAExecutor(action);
        jpa.execute(writeCmd);
        new CoordActionStartXCommand(actionId, getTestUser(), appName, jobId).call();
        slaEvent = slas.getSLACalculator().get(actionId);
        slaEvent.setEventProcessed(0); //resetting for testing sla event
        ehs.new EventWorker().run();
        slaEvent = skipToSLAEvent();
        assertEquals(actionId, slaEvent.getId());
        assertNotNull(slaEvent.getActualStart());
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

        assertTrue(ehs.listEventListeners().contains(SLAJobEventListener.class.getCanonicalName()));
    }

    @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", AppType.WORKFLOW_JOB);
        job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
        slas.addRegistrationEvent(job);
        assertEquals(1, slas.getSLACalculator().size());
        Date actualStart = DateUtils.parseDateUTC("2012-07-22T01:00Z");
        WorkflowJobEvent wfe = new WorkflowJobEvent("wf1", "caId1", WorkflowJob.Status.RUNNING, "user1",
                "wf-app-name1", actualStart, null);
        listener.onWorkflowJobEvent(wfe);
        SLACalcStatus serviceObj = slas.getSLACalculator().get("wf1");
        // check that start sla has been calculated
        assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());
        assertEquals(1, serviceObj.getEventProcessed()); //Job switching to running is only partially
                                                       //sla processed. so state = 1

        job = _createSLARegBean("wa1", AppType.WORKFLOW_ACTION);
        slas.addRegistrationEvent(job);
        assertEquals(2, slas.getSLACalculator().size());
        job.setExpectedStart(DateUtils.parseDateUTC("2012-07-22T00:00Z"));
        WorkflowActionEvent wae = new WorkflowActionEvent("wa1", "wfId1", WorkflowAction.Status.RUNNING, "user1",
                "wf-app-name1", actualStart, null);
        listener.onWorkflowActionEvent(wae);
        serviceObj = slas.getSLACalculator().get("wa1");
        // check that start sla has been calculated
        assertEquals(EventStatus.START_MISS, serviceObj.getEventStatus());

        job = _createSLARegBean("cj1", AppType.COORDINATOR_JOB);
        job.setExpectedEnd(DateUtils.parseDateUTC("2012-07-22T01:00Z"));
        slas.addRegistrationEvent(job);
        assertEquals(3, slas.getSLACalculator().size());
        Date actualEnd = DateUtils.parseDateUTC("2012-07-22T00:00Z");
        CoordinatorJobEvent cje = new CoordinatorJobEvent("cj1", "bj1", CoordinatorJob.Status.SUCCEEDED, "user1",
                "coord-app-name1", actualStart, actualEnd);
        listener.onCoordinatorJobEvent(cje);

        SLASummaryBean summary = Services.get().get(JPAService.class).execute(new SLASummaryGetJPAExecutor("cj1"));
        // check that end and duration sla has been calculated
        assertEquals(6, summary.getEventProcessed());

        assertEquals(EventStatus.END_MET, summary.getEventStatus());

        job = _createSLARegBean("ca1", AppType.COORDINATOR_ACTION);
        actualEnd = DateUtils.parseDateUTC("2012-07-22T02:00Z");
        slas.addRegistrationEvent(job);
        assertEquals(4, slas.getSLACalculator().size());
        CoordinatorActionEvent cae = new CoordinatorActionEvent("ca1", "cj1", CoordinatorAction.Status.RUNNING, "user1",
                "coord-app-name1", null, actualEnd, null);
        listener.onCoordinatorActionEvent(cae);
        cae = new CoordinatorActionEvent("ca1", "cj1", CoordinatorAction.Status.KILLED, "user1",
                "coord-app-name1", null, actualEnd, null);
        listener.onCoordinatorActionEvent(cae);
        summary = Services.get().get(JPAService.class).execute(new SLASummaryGetJPAExecutor("ca1"));
        // check that all events are processed
        assertEquals(8, summary.getEventProcessed());
        assertEquals(EventStatus.END_MISS, summary.getEventStatus());
        assertEquals(3, slas.getSLACalculator().size());

    }
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

    }

    @Test
    public void testBasicService() throws Exception {
        Services services = Services.get();
        SLAService slas = services.get(SLAService.class);
        assertNotNull(slas);
        assertTrue(SLAService.isEnabled());

        services.destroy();
        services = new Services();
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

        assertFalse(SLAService.isEnabled());
    }

    @Test
    public void testUpdateSLA() throws Exception {
        SLAService slas = Services.get().get(SLAService.class);
        assertNotNull(slas);
        assertTrue(SLAService.isEnabled());

        EventHandlerService ehs = Services.get().get(EventHandlerService.class);
        // test start-miss
        SLARegistrationBean sla1 = _createSLARegistration("job-1", AppType.WORKFLOW_JOB);
        sla1.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); //1 hour back
        sla1.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1 * 3600 * 1000)); //1 hour back
        sla1.setExpectedDuration(10 * 60 * 1000); //10 mins
        slas.addRegistrationEvent(sla1);
        assertEquals(1, slas.getSLACalculator().size());
        slas.runSLAWorker();
        ehs.new EventWorker().run();
        assertEventNoDuplicates(output.toString(), "Sla START - MISS!!!");
        assertEventNoDuplicates(output.toString(), "Sla END - MISS!!!");
        output.setLength(0);

        // test different jobs and events start-met and end-miss
        sla1 = _createSLARegistration("job-2", AppType.WORKFLOW_JOB);
        sla1.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000)); //1 hour ahead
        sla1.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 3600 * 1000)); //2 hours ahead
        slas.addRegistrationEvent(sla1);
        slas.addStatusEvent(sla1.getId(), WorkflowJob.Status.RUNNING.name(), EventStatus.STARTED, new Date(),
                new Date());
        SLARegistrationBean sla2 = _createSLARegistration("job-3", AppType.COORDINATOR_JOB);
        sla2.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000)); //1 hour ahead only for testing
        sla2.setExpectedEnd(new Date(System.currentTimeMillis() - 2 * 3600 * 1000)); //2 hours back
        sla2.setExpectedDuration(10); //to process duration too
        slas.addRegistrationEvent(sla2);
        assertEquals(3, slas.getSLACalculator().size());
        Date startTime = new Date();
        slas.addStatusEvent(sla2.getId(), CoordinatorJob.Status.RUNNING.name(), EventStatus.STARTED, startTime,
                null);
        slas.addStatusEvent(sla2.getId(), CoordinatorJob.Status.SUCCEEDED.name(), EventStatus.SUCCESS, startTime,
                new Date());
        slas.runSLAWorker();
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla1.getId() + " Sla START - MET!!!"));
        assertTrue(output.toString().contains(sla2.getId() + " Sla END - MISS!!!"));
        assertTrue(output.toString().contains(sla2.getId() + " Sla DURATION - MET!!!"));
        output.setLength(0);

        // test same job multiple events (start-miss, end-miss) through regular check
        WorkflowJobBean job4 = addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
        sla2 = _createSLARegistration(job4.getId(), AppType.WORKFLOW_JOB);
        sla2.setExpectedStart(new Date(System.currentTimeMillis() - 2 * 3600 * 1000)); //2 hours back
        sla2.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 3600 * 1000)); //1 hour back
        slas.addRegistrationEvent(sla2);
        assertEquals(3, slas.getSLACalculator().size()); // tests job slaProcessed == 7 removed from map
        slas.runSLAWorker();
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla2.getId() + " Sla START - MISS!!!"));
        assertTrue(output.toString().contains(sla2.getId() + " Sla END - MISS!!!"));
        output.setLength(0);
        // As expected duration is not set, duration shall be processed and job removed from map
        assertEquals(2, slas.getSLACalculator().size());
        // test same job multiple events (start-met, end-met) through job status event
        sla1 = _createSLARegistration("action-1", AppType.COORDINATOR_ACTION);
        sla1.setExpectedStart(new Date(System.currentTimeMillis() + 1 * 3600 * 1000)); //1 hour ahead
        sla1.setExpectedEnd(new Date(System.currentTimeMillis() + 2 * 3600 * 1000)); //2 hours ahead
        slas.addRegistrationEvent(sla1);
        assertEquals(3, slas.getSLACalculator().size());
        slas.addStatusEvent(sla1.getId(), CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(),
                new Date());
        slas.addStatusEvent(sla1.getId(), CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS,
                new Date(), new Date());
        slas.runSLAWorker();
        assertEquals(2, ehs.getEventQueue().size());
        ehs.new EventWorker().run();
        assertTrue(output.toString().contains(sla1.getId() + " Sla START - MET!!!"));
        assertTrue(output.toString().contains(sla1.getId() + " Sla END - MET!!!"));
    }
View Full Code Here

Examples of org.apache.oozie.sla.service.SLAService

        assertTrue(output.toString().contains(sla1.getId() + " Sla END - MET!!!"));
    }

    @Test
    public void testEndMissDBConfirm() throws Exception {
        SLAService slas = Services.get().get(SLAService.class);
        EventHandlerService ehs = Services.get().get(EventHandlerService.class);
        JPAService jpaService = Services.get().get(JPAService.class);

        // CASE 1: positive test WF job
        WorkflowJobBean job1 = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
        SLARegistrationBean sla = _createSLARegistration(job1.getId(), AppType.WORKFLOW_JOB);
        sla.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1800 * 1000)); // half hour back
        slas.addRegistrationEvent(sla);

        // CASE 2: negative test WF job
        WorkflowJobBean job2 = addRecordToWfJobTable(WorkflowJob.Status.SUCCEEDED, WorkflowInstance.Status.SUCCEEDED);
        job2.setEndTime(new Date(System.currentTimeMillis() - 1 * 1800 * 1000));
        job2.setStartTime(new Date(System.currentTimeMillis() - 1 * 2000 * 1000));
        jpaService.execute(new WorkflowJobUpdateJPAExecutor(job2));
        sla = _createSLARegistration(job2.getId(), AppType.WORKFLOW_JOB);
        sla.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1500 * 1000)); // in past but > actual end
        sla.setExpectedDuration(100); //unreasonable to cause MISS
        slas.addRegistrationEvent(sla);

        // CASE 3: positive test Coord action
        CoordinatorActionBean action1 = addRecordToCoordActionTable("coord-action-1", 1,
                CoordinatorAction.Status.WAITING, "coord-action-get.xml", 0);
        WorkflowJobBean extWf = new WorkflowJobBean();
        extWf.setId(action1.getExternalId());
        extWf.setEndTime(new Date(System.currentTimeMillis() - 1 * 1800 * 1000));
        extWf.setStartTime(new Date(System.currentTimeMillis() - 1 * 2100 * 1000));
        jpaService.execute(new WorkflowJobInsertJPAExecutor(extWf));
        sla = _createSLARegistration(action1.getId(), AppType.COORDINATOR_ACTION);
        sla.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 2000 * 1000)); // past
        slas.addRegistrationEvent(sla);

        // CASE 4: positive test coord action
        CoordinatorActionBean action2 = addRecordToCoordActionTable("coord-action-2", 1,
                CoordinatorAction.Status.FAILED, "coord-action-get.xml", 0);
        extWf = new WorkflowJobBean();
        extWf.setId(action2.getExternalId());
        // actual end before expected. but action is failed
        extWf.setEndTime(new Date(System.currentTimeMillis() - 1 * 1800 * 1000));
        extWf.setStartTime(new Date(System.currentTimeMillis() - 1 * 2000 * 1000));
        jpaService.execute(new WorkflowJobInsertJPAExecutor(extWf));
        sla = _createSLARegistration(action2.getId(), AppType.COORDINATOR_ACTION);
        sla.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1500 * 1000));
        slas.addRegistrationEvent(sla);

        // CASE 5: negative test coord action
        CoordinatorActionBean action3 = addRecordToCoordActionTable("coord-action-3", 1,
                CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
        extWf = new WorkflowJobBean();
        extWf.setId(action3.getExternalId());
        extWf.setStartTime(new Date(System.currentTimeMillis() - 1 * 2100 * 1000));
        extWf.setEndTime(new Date(System.currentTimeMillis() - 1 * 1800 * 1000));
        jpaService.execute(new WorkflowJobInsertJPAExecutor(extWf));
        sla = _createSLARegistration(action3.getId(), AppType.COORDINATOR_ACTION);
        sla.setExpectedStart(new Date(System.currentTimeMillis() - 1 * 3600 * 1000)); // cause start_miss
        sla.setExpectedEnd(new Date(System.currentTimeMillis() - 1 * 1500 * 1000)); // in past but > actual end, end_met
        sla.setExpectedDuration(0); //cause duration miss
        slas.addRegistrationEvent(sla);

        slas.runSLAWorker();
        ehs.new EventWorker().run();
        int count = 0;
        for (int ptr = output.indexOf("END - MISS"); ptr < output.length() && ptr > 0; ptr = output.indexOf(
                "END - MISS", ptr + 1)) {
            count++;
        }
        assertEquals(3, count); // only 3 out of the 5 are correct end_misses
        assertEventNoDuplicates(output.toString(), job1.getId() + " Sla END - MISS!!!");
        assertEventNoDuplicates(output.toString(), action1.getId() + " Sla END - MISS!!!");
        assertEventNoDuplicates(output.toString(), action2.getId() + " Sla END - MISS!!!");
        assertEventNoDuplicates(output.toString(), job2.getId() + " Sla END - MET!!!");
        assertEventNoDuplicates(output.toString(), job2.getId() + " Sla DURATION - MISS!!!");
        assertEventNoDuplicates(output.toString(), action3.getId() + " Sla START - MISS!!!");
        assertEventNoDuplicates(output.toString(), action3.getId() + " Sla DURATION - MISS!!!");
        assertEventNoDuplicates(output.toString(), action3.getId() + " Sla END - MET!!!");

        // negative on MISS after DB check, updated with actual times
        SLASummaryBean slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(job2.getId()));
        assertEquals(job2.getStartTime(), slaSummary.getActualStart());
        assertEquals(job2.getEndTime(), slaSummary.getActualEnd());
        assertEquals(job2.getEndTime().getTime() - job2.getStartTime().getTime(), slaSummary.getActualDuration());
        assertEquals(job2.getStatusStr(), slaSummary.getJobStatus());
        assertEquals(SLAEvent.EventStatus.END_MET, slaSummary.getEventStatus());
        assertEquals(SLAStatus.MET, slaSummary.getSLAStatus());
        assertEquals(8, slaSummary.getEventProcessed());
        assertNull(slas.getSLACalculator().get(job2.getId())); //removed from memory

        // positives but also updated with actual times immediately after DB check
        slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(action2.getId()));
        extWf = jpaService.execute(new WorkflowJobGetJPAExecutor(action2.getExternalId()));
        assertEquals(extWf.getStartTime(), slaSummary.getActualStart());
        assertEquals(extWf.getEndTime(), slaSummary.getActualEnd());
        assertEquals(extWf.getEndTime().getTime() - extWf.getStartTime().getTime(), slaSummary.getActualDuration());
        assertEquals(action2.getStatusStr(), slaSummary.getJobStatus());
        assertEquals(SLAEvent.EventStatus.END_MISS, slaSummary.getEventStatus());
        assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
        assertEquals(8, slaSummary.getEventProcessed());
        assertNull(slas.getSLACalculator().get(action2.getId())); //removed from memory

        slaSummary = jpaService.execute(new SLASummaryGetJPAExecutor(action1.getId()));
        extWf = jpaService.execute(new WorkflowJobGetJPAExecutor(action1.getExternalId()));
        assertEquals(extWf.getStartTime(), slaSummary.getActualStart());
        assertEquals(extWf.getEndTime(), slaSummary.getActualEnd());
        assertEquals(extWf.getEndTime().getTime() - extWf.getStartTime().getTime(), slaSummary.getActualDuration());
        assertEquals(action1.getStatusStr(), slaSummary.getJobStatus());
        assertEquals(SLAEvent.EventStatus.END_MISS, slaSummary.getEventStatus());
        assertEquals(SLAStatus.MISS, slaSummary.getSLAStatus());
        assertEquals(8, slaSummary.getEventProcessed());
        assertNull(slas.getSLACalculator().get(action1.getId())); //removed from memory

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.