Search in sources :

Example 1 with SLAService

use of org.apache.oozie.sla.service.SLAService in project oozie by apache.

the class DummySLACalculatorMemory method testSLAUpdateWithHA.

public void testSLAUpdateWithHA() throws Exception {
    String id1 = "0000001-130521183438837-oozie-test-C@1";
    String id2 = "0000002-130521183438837-oozie-test-C@1";
    String id3 = "0000003-130521183438837-oozie-test-C@1";
    String id4 = "0000004-130521183438837-oozie-test-C@1";
    String id5 = "0000005-130521183438837-oozie-test-C@1";
    String id6 = "0000006-130521183438837-oozie-test-C@1";
    // 2 hrs passed
    Date expectedStartTS = new Date(System.currentTimeMillis() - 2 * 3600 * 1000);
    // 1 hour ahead
    Date expectedEndTS1 = new Date(System.currentTimeMillis() + 1 * 3600 * 1000);
    // 1 hour passed
    Date expectedEndTS2 = new Date(System.currentTimeMillis() - 1 * 3600 * 1000);
    // Coord Action of jobs 1-4 not started yet
    createDBEntry(id1, expectedStartTS, expectedEndTS1);
    createDBEntry(id2, expectedStartTS, expectedEndTS1);
    createDBEntry(id3, expectedStartTS, expectedEndTS1);
    createDBEntry(id4, expectedStartTS, expectedEndTS1);
    // Coord Action of jobs 5-6 already started and currently running (to test history set)
    createDBEntryForStarted(id5, expectedStartTS, expectedEndTS2, 1);
    createDBEntryForStarted(id6, expectedStartTS, expectedEndTS2, 1);
    SLAService slas = Services.get().get(SLAService.class);
    SLACalculatorMemory slaCalcMem = (SLACalculatorMemory) slas.getSLACalculator();
    slaCalcMem.init(Services.get().getConf());
    slaCalcMem.updateAllSlaStatus();
    List<String> slaMapKeys = new ArrayList<String>();
    Iterator<String> itr = slaCalcMem.iterator();
    while (itr.hasNext()) {
        slaMapKeys.add(itr.next());
    }
    // 4 jobs expected end is not yet reached
    // 2 jobs has end miss, waiting for job to complete
    assertEquals(4, slaMapKeys.size());
    assertEquals(2, slaCalcMem.getHistorySet().size());
    DummyZKOozie dummyOozie_1 = null;
    try {
        // start another dummy oozie instance (dummy sla and event handler services)
        dummyOozie_1 = new DummyZKOozie("a", "http://blah");
        DummySLACalculatorMemory dummySlaCalcMem = new DummySLACalculatorMemory();
        EventHandlerService dummyEhs = new EventHandlerService();
        dummySlaCalcMem.setEventHandlerService(dummyEhs);
        dummyEhs.init(Services.get());
        dummySlaCalcMem.init(Services.get().getConf());
        dummySlaCalcMem.updateAllSlaStatus();
        slaMapKeys = new ArrayList<String>();
        itr = dummySlaCalcMem.iterator();
        while (itr.hasNext()) {
            slaMapKeys.add(itr.next());
        }
        assertEquals(4, slaMapKeys.size());
        assertEquals(2, dummySlaCalcMem.getHistorySet().size());
        // Coord Action 1,3 run and update status on *non-dummy* server
        updateCoordAction(id1, "RUNNING");
        slaCalcMem.addJobStatus(id1, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), null);
        updateCoordAction(id3, "FAILED");
        slaCalcMem.addJobStatus(id3, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, null, new Date());
        // Coord Action 2,4 run and update status on *dummy* server
        updateCoordAction(id2, "RUNNING");
        dummySlaCalcMem.addJobStatus(id2, CoordinatorAction.Status.RUNNING.name(), EventStatus.STARTED, new Date(), null);
        updateCoordAction(id4, "FAILED");
        dummySlaCalcMem.addJobStatus(id4, CoordinatorAction.Status.FAILED.name(), EventStatus.FAILURE, null, new Date());
        // Both servers iterate SlaMap (updateAllSlaStatus)
        slaCalcMem.updateAllSlaStatus();
        dummySlaCalcMem.updateAllSlaStatus();
        // SlaMap on both Servers synced
        SLACalcStatus sla1_nodummy = slaCalcMem.get(id1);
        SLACalcStatus sla1_dummy = dummySlaCalcMem.get(id1);
        SLACalcStatus sla2_nodummy = slaCalcMem.get(id2);
        SLACalcStatus sla2_dummy = dummySlaCalcMem.get(id2);
        assertEquals(1, sla1_nodummy.getEventProcessed());
        assertEquals(1, sla1_dummy.getEventProcessed());
        assertEquals(1, sla2_dummy.getEventProcessed());
        assertEquals(1, sla2_nodummy.getEventProcessed());
        assertFalse(slaCalcMem.isJobIdInSLAMap(id3));
        assertFalse(dummySlaCalcMem.isJobIdInSLAMap(id3));
        assertFalse(slaCalcMem.isJobIdInSLAMap(id4));
        assertFalse(dummySlaCalcMem.isJobIdInSLAMap(id4));
        Byte eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id3);
        assertEquals(8, eventProc.byteValue());
        eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id4);
        assertEquals(8, eventProc.byteValue());
        // Action 5 was processed as END_MISS in updateAllSlaStatus, put into history set
        assertTrue(slaCalcMem.isJobIdInHistorySet(id5));
        assertTrue(dummySlaCalcMem.isJobIdInHistorySet(id6));
        // Action 6 was processed as END_MISS in updateAllSlaStatus, put into history set
        assertTrue(slaCalcMem.isJobIdInHistorySet(id5));
        assertTrue(dummySlaCalcMem.isJobIdInHistorySet(id6));
        eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id5);
        assertEquals(7, eventProc.byteValue());
        eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id6);
        assertEquals(7, eventProc.byteValue());
        // Action 1 Succeeded on non-dummy server
        updateCoordAction(id1, "SUCCEEDED");
        slaCalcMem.addJobStatus(id1, CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(System.currentTimeMillis() - 1800 * 1000), new Date());
        // Action 2 Succeeded on dummy server
        updateCoordAction(id2, "SUCCEEDED");
        dummySlaCalcMem.addJobStatus(id2, CoordinatorAction.Status.SUCCEEDED.name(), EventStatus.SUCCESS, new Date(System.currentTimeMillis() - 1800 * 1000), new Date());
        // Both servers iterate SlaMap (updateAllSlaStatus)
        slaCalcMem.updateAllSlaStatus();
        dummySlaCalcMem.updateAllSlaStatus();
        // Action 1, 2 are removed from both servers
        assertNull(slaCalcMem.get(id1));
        assertNull(dummySlaCalcMem.get(id1));
        assertNull(slaCalcMem.get(id2));
        assertNull(dummySlaCalcMem.get(id2));
        eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id1);
        assertEquals(8, eventProc.byteValue());
        eventProc = (Byte) SLASummaryQueryExecutor.getInstance().getSingleValue(SLASummaryQuery.GET_SLA_SUMMARY_EVENTPROCESSED, id2);
        assertEquals(8, eventProc.byteValue());
        // Test HistoryPurgeWorker purges Action 5,6 from history set
        updateCoordAction(id5, "SUCCEEDED");
        slaCalcMem.new HistoryPurgeWorker().run();
        assertFalse(slaCalcMem.isJobIdInHistorySet(id5));
        updateCoordAction(id6, "SUCCEEDED");
        dummySlaCalcMem.new HistoryPurgeWorker().run();
        assertFalse(dummySlaCalcMem.isJobIdInHistorySet(id6));
    } finally {
        if (dummyOozie_1 != null) {
            dummyOozie_1.teardown();
        }
    }
}
Also used : TestSLAService(org.apache.oozie.sla.TestSLAService) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) SLACalculatorMemory(org.apache.oozie.sla.SLACalculatorMemory) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 2 with SLAService

use of org.apache.oozie.sla.service.SLAService in project oozie by apache.

the class TestCoordSubmitXCommand method testSubmitWithSLAAlertsDisable.

public void testSubmitWithSLAAlertsDisable() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    // CASE 1: Failure case i.e. multiple data-in instances
    Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
    Writer writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set("frequency", "coord:days(1)");
    conf.set(OozieClient.USER_NAME, getTestUser());
    reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
    appPathFile = new File(getTestCaseDir(), "workflow.xml");
    writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set("wfAppPath", appPathFile.getPath());
    Date nominalTime = new Date();
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
    String coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    SLAService slaService = services.get(SLAService.class);
    SLACalculator calc = slaService.getSLACalculator();
    SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    Configuration conf1 = new Configuration(conf);
    // CASE I: "ALL"
    conf1.set(OozieClient.SLA_DISABLE_ALERT, "ALL");
    coordId = new CoordSubmitXCommand(conf1).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaService = services.get(SLAService.class);
    calc = slaService.getSLACalculator();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE II: Date Range
    Configuration conf2 = new Configuration(conf);
    Date startRangeDate = new Date(nominalTime.getTime() - 3600 * 1000);
    conf2.set(OozieClient.SLA_DISABLE_ALERT, DateUtils.formatDateOozieTZ(startRangeDate) + "::" + DateUtils.formatDateOozieTZ(nominalTime));
    coordId = new CoordSubmitXCommand(conf2).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE III: Coord name (negative test)
    Configuration conf3 = new Configuration(conf);
    conf3.set(OozieClient.SLA_DISABLE_ALERT_COORD, "test-coord-sla-x");
    coordId = new CoordSubmitXCommand(conf3).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE IV: Older than n(hours)
    Date otherNominalTime = new Date(nominalTime.getTime() - 73 * 3600 * 1000);
    conf = new XConfiguration();
    appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(otherNominalTime));
    conf.setInt(OozieClient.SLA_DISABLE_ALERT_OLDER_THAN, 72);
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // catchup mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // normal mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) SLACalculator(org.apache.oozie.sla.SLACalculator) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 3 with SLAService

use of org.apache.oozie.sla.service.SLAService in project oozie by apache.

the class SLAOperations method createSlaRegistrationEvent.

public static SLARegistrationBean createSlaRegistrationEvent(Element eSla, String jobId, String parentId, AppType appType, String user, String appName, XLog log, boolean rerun, boolean disableAlert) throws CommandException {
    if (eSla == null || !SLAService.isEnabled()) {
        log.debug("Not registering SLA for job [{0}]. Sla-Xml null OR SLAService not enabled", jobId);
        return null;
    }
    SLARegistrationBean sla = new SLARegistrationBean();
    // Setting nominal time
    String strNominalTime = getTagElement(eSla, NOMINAL_TIME);
    Date nominalTime = setNominalTime(strNominalTime, sla);
    // Setting expected start time
    String strExpectedStart = getTagElement(eSla, SHOULD_START);
    setExpectedStart(strExpectedStart, nominalTime, sla);
    // Setting expected end time
    String strExpectedEnd = getTagElement(eSla, SHOULD_END);
    setExpectedEnd(strExpectedEnd, nominalTime, sla);
    // Setting expected duration in milliseconds
    String expectedDurationStr = getTagElement(eSla, MAX_DURATION);
    setExpectedDuration(expectedDurationStr, sla);
    // Parse desired alert-types i.e. start-miss, end-miss, start-met etc..
    String alertEvents = getTagElement(eSla, ALERT_EVENTS);
    if (alertEvents != null) {
        String[] events = alertEvents.split(",");
        StringBuilder alertsStr = new StringBuilder();
        for (int i = 0; i < events.length; i++) {
            String event = events[i].trim().toUpperCase();
            try {
                EventStatus.valueOf(event);
            } catch (IllegalArgumentException iae) {
                XLog.getLog(SLAService.class).warn("Invalid value: [" + event + "]" + " for SLA Alert-event. Should be one of " + EventStatus.values() + ". Setting it to default [" + EventStatus.END_MISS.name() + "]");
                event = EventStatus.END_MISS.name();
            }
            alertsStr.append(event).append(",");
        }
        sla.setAlertEvents(alertsStr.toString().substring(0, alertsStr.lastIndexOf(",")));
    }
    // Other sla config
    sla.setNotificationMsg(getTagElement(eSla, "notification-msg"));
    sla.setAlertContact(getTagElement(eSla, "alert-contact"));
    sla.setUpstreamApps(getTagElement(eSla, "upstream-apps"));
    // disable Alert flag in slaConfig
    if (disableAlert) {
        sla.addToSLAConfigMap(OozieClient.SLA_DISABLE_ALERT, Boolean.toString(disableAlert));
    }
    // Oozie defined
    sla.setId(jobId);
    sla.setAppType(appType);
    sla.setAppName(appName);
    sla.setUser(user);
    sla.setParentId(parentId);
    SLAService slaService = Services.get().get(SLAService.class);
    try {
        if (!rerun) {
            slaService.addRegistrationEvent(sla);
        } else {
            slaService.updateRegistrationEvent(sla);
        }
    } catch (ServiceException e) {
        throw new CommandException(ErrorCode.E1007, " id " + jobId, e.getMessage(), e);
    }
    log.debug("Job [{0}] reg for SLA. Size of Sla Xml = [{1}]", jobId, XmlUtils.prettyPrint(eSla).toString().length());
    return sla;
}
Also used : SLAService(org.apache.oozie.sla.service.SLAService) ServiceException(org.apache.oozie.service.ServiceException) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

Example 4 with SLAService

use of org.apache.oozie.sla.service.SLAService in project oozie by apache.

the class TestSLACalculatorMemory method testWorkflowJobSLAStatusOnRestart.

@Test
public void testWorkflowJobSLAStatusOnRestart() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
    SLACalculatorMemory slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    SLARegistrationBean slaRegBean1 = _createSLARegistration("job-1-W", AppType.WORKFLOW_JOB);
    final String jobId1 = slaRegBean1.getId();
    slaRegBean1.setExpectedEnd(sdf.parse("2013-03-07"));
    slaRegBean1.setExpectedStart(sdf.parse("2012-03-07"));
    slaCalcMemory.addRegistration(jobId1, slaRegBean1);
    SLACalcStatus calc1 = slaCalcMemory.get(jobId1);
    calc1.setEventProcessed(1);
    calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
    calc1.setJobStatus(WorkflowJob.Status.RUNNING.name());
    calc1.setLastModifiedTime(new Date());
    SLASummaryBean slaSummaryBean = new SLASummaryBean(calc1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
    SLASummaryBean slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    // Simulate a lost success event
    WorkflowJobBean wjb = new WorkflowJobBean();
    wjb.setId(jobId1);
    wjb.setStatus(WorkflowJob.Status.SUCCEEDED);
    wjb.setStartTime(sdf.parse("2012-02-07"));
    wjb.setEndTime(sdf.parse("2013-02-07"));
    wjb.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().insert(wjb);
    slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    slaCalcMemory.updateAllSlaStatus();
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    assertEquals("job-1-W", slaSummary.getId());
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(AppType.WORKFLOW_JOB, slaSummary.getAppType());
    assertEquals("SUCCEEDED", slaSummary.getJobStatus());
    assertEquals(SLAEvent.SLAStatus.MET, slaSummary.getSLAStatus());
    assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
    assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
    assertEquals(sdf.parse("2013-02-07").getTime() - sdf.parse("2012-02-07").getTime(), slaSummary.getActualDuration());
    // Simulate a lost failed event
    wjb.setStatus(WorkflowJob.Status.FAILED);
    wjb.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wjb);
    // Reset the summary Bean
    calc1.setEventProcessed(1);
    calc1.setSLAStatus(SLAEvent.SLAStatus.IN_PROCESS);
    calc1.setJobStatus(WorkflowJob.Status.RUNNING.name());
    slaSummaryBean = new SLASummaryBean(calc1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
    slaCalcMemory = new SLACalculatorMemory();
    slaCalcMemory.init(Services.get().get(ConfigurationService.class).getConf());
    slaCalcMemory.updateAllSlaStatus();
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1);
    assertEquals("FAILED", slaSummary.getJobStatus());
    assertEquals(8, slaSummary.getEventProcessed());
    assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
    assertEquals(sdf.parse("2013-02-07"), slaSummary.getActualEnd());
    assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
    // Simulate a lost RUNNING event
    wjb.setStatus(WorkflowJob.Status.RUNNING);
    wjb.setLastModifiedTime(new Date());
    WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_MODTIME, wjb);
    // Reset the summary Bean
    calc1.setEventProcessed(0);
    calc1.setSLAStatus(SLAEvent.SLAStatus.NOT_STARTED);
    calc1.setJobStatus(null);
    slaSummaryBean = new SLASummaryBean(calc1);
    SLASummaryQueryExecutor.getInstance().executeUpdate(SLASummaryQuery.UPDATE_SLA_SUMMARY_ALL, slaSummaryBean);
    SLAService slaService = Services.get().get(SLAService.class);
    slaService.startSLAWorker();
    slaService.addStatusEvent(jobId1, "RUNNING", null, null, null);
    waitFor(60 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            return SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, jobId1).getEventProcessed() == 7;
        }
    });
    slaSummary = SLASummaryQueryExecutor.getInstance().get(SLASummaryQuery.GET_SLA_SUMMARY, slaSummaryBean.getId());
    // since job is already running and it's a old job
    assertEquals(7, slaSummary.getEventProcessed());
    assertEquals("RUNNING", slaSummary.getJobStatus());
    assertEquals(sdf.parse("2012-02-07"), slaSummary.getActualStart());
    assertNull(slaSummary.getActualEnd());
    assertEquals(-1, slaSummary.getActualDuration());
    assertEquals(SLAEvent.SLAStatus.MISS, slaSummary.getSLAStatus());
}
Also used : SLAService(org.apache.oozie.sla.service.SLAService) SimpleDateFormat(java.text.SimpleDateFormat) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) FailingDBHelperForTest(org.apache.oozie.util.db.FailingDBHelperForTest) Test(org.junit.Test)

Example 5 with SLAService

use of org.apache.oozie.sla.service.SLAService in project oozie by apache.

the class TestSLAEventGeneration method testSLASchema1BackwardCompatibilitySubmitStart.

@Test
public void testSLASchema1BackwardCompatibilitySubmitStart() 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();
    conf.set(OozieClient.APP_PATH, appPath.toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    cal.setTime(new Date());
    // for start_miss
    cal.add(Calendar.MINUTE, -20);
    Date nominal = cal.getTime();
    String nominalTime = DateUtils.formatDateOozieTZ(nominal);
    conf.set("nominal_time", nominalTime);
    _testWorkflowJobSubmitStart(conf, slas, false);
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) SLAService(org.apache.oozie.sla.service.SLAService) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SLAService (org.apache.oozie.sla.service.SLAService)21 Date (java.util.Date)17 Test (org.junit.Test)12 Configuration (org.apache.hadoop.conf.Configuration)10 XConfiguration (org.apache.oozie.util.XConfiguration)9 Path (org.apache.hadoop.fs.Path)7 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)6 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)4 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)4 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)4 TestSLAService (org.apache.oozie.sla.TestSLAService)4 CoordSubmitXCommand (org.apache.oozie.command.coord.CoordSubmitXCommand)3 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)3 EventHandlerService (org.apache.oozie.service.EventHandlerService)3 JPAService (org.apache.oozie.service.JPAService)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 ArrayList (java.util.ArrayList)2