Search in sources :

Example 11 with SLACalcStatus

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

the class TestSLAEmailEventListener method testOnDurationMiss.

public void testOnDurationMiss() throws Exception {
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus event = _createSLACalcStatus(id);
    SLARegistrationBean eventBean = event.getSLARegistrationBean();
    Date expectedStartDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T00:10Z");
    Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T00:20Z");
    Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T00:40Z");
    long expectedDuration = expectedEndDate.getTime() - expectedStartDate.getTime();
    long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
    long expectedDurationInMins = expectedDuration / 60000;
    long actualDurationInMins = actualDuration / 60000;
    event.setId(id);
    eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    event.setEventStatus(EventStatus.DURATION_MISS);
    event.setJobStatus(JobEvent.EventStatus.SUCCESS.toString());
    eventBean.setAppName("Test-SLA-Duration-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setNominalTime(expectedStartDate);
    eventBean.setExpectedStart(expectedStartDate);
    eventBean.setExpectedEnd(expectedEndDate);
    eventBean.setNotificationMsg("notification of duration miss");
    eventBean.setAlertContact("alert-receiver-durationmiss@oozie.com");
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    eventBean.setExpectedStart(expectedStartDate);
    eventBean.setExpectedEnd(expectedEndDate);
    event.setActualStart(actualStartDate);
    event.setActualEnd(actualEndDate);
    eventBean.setExpectedDuration(expectedDuration);
    event.setActualDuration(actualDuration);
    slaEmailListener.onEndMiss(event);
    MimeMessage[] msgs = greenMail.getReceivedMessages();
    MimeMessage msg = msgs[0];
    // check message header
    assertEquals(msg.getFrom()[0].toString(), "oozie@localhost");
    assertEquals(msg.getRecipients(RecipientType.TO)[0].toString(), "alert-receiver-durationmiss@oozie.com");
    assertEquals(msg.getSubject(), "OOZIE - SLA " + EventStatus.DURATION_MISS + " (AppName=Test-SLA-Duration-Miss, JobID=0000000-000000000000001-oozie-wrkf-C@1)");
    // check message body
    String msgBody = msg.getContent().toString();
    String headerSep = SLAEmailEventListener.EMAIL_BODY_HEADER_SEPARATER;
    String sep = SLAEmailEventListener.EMAIL_BODY_FIELD_SEPARATER;
    String indent = SLAEmailEventListener.EMAIL_BODY_FIELD_INDENT;
    assertTrue(msgBody.indexOf("Status" + headerSep) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.EVENT_STATUS.toString() + sep + EventStatus.DURATION_MISS.toString()) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.JOB_STATUS.toString() + sep + JobEvent.EventStatus.SUCCESS.toString()) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.NOTIFICATION_MESSAGE.toString() + sep + "notification of duration miss") > -1);
    assertTrue(msgBody.indexOf("Job Details" + headerSep) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.APP_TYPE.toString() + sep + AppType.COORDINATOR_ACTION) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.APP_NAME.toString() + sep + "Test-SLA-Duration-Miss") > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.USER.toString() + sep + "dummyuser") > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.JOBID.toString() + sep + "0000000-000000000000001-oozie-wrkf-C@1") > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.PARENT_JOBID.toString() + sep + "0000000-000000000000001-oozie-wrkf-C") > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.JOB_URL.toString() + sep + conf.get(SLAEmailEventListener.OOZIE_BASE_URL) + "/?job=" + "0000000-000000000000001-oozie-wrkf-C@1") > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.PARENT_JOB_URL.toString() + sep + conf.get(SLAEmailEventListener.OOZIE_BASE_URL) + "/?job=" + "0000000-000000000000001-oozie-wrkf-C") > -1);
    assertTrue(msgBody.indexOf("SLA Details" + headerSep) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.NOMINAL_TIME.toString() + sep + expectedStartDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_START_TIME.toString() + sep + expectedStartDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_START_TIME.toString() + sep + actualStartDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_END_TIME.toString() + sep + expectedEndDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_END_TIME.toString() + sep + actualEndDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_DURATION.toString() + sep + expectedDurationInMins) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_DURATION.toString() + sep + actualDurationInMins) > -1);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

Example 12 with SLACalcStatus

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

the class TestSLAEmailEventListener method _createSLACalcStatus.

private SLACalcStatus _createSLACalcStatus(String actionId) {
    SLARegistrationBean reg = new SLARegistrationBean();
    reg.setId(actionId);
    reg.setAppType(AppType.COORDINATOR_ACTION);
    return new SLACalcStatus(reg);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus)

Example 13 with SLACalcStatus

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

the class SLAJobEventXCommand method processForRunning.

/**
 * Process for running.
 */
private void processForRunning() {
    byte eventProc = slaCalc.getEventProcessed();
    if (eventProc != 8 && slaCalc.getActualStart() != null) {
        slaCalc.setSLAStatus(SLAStatus.IN_PROCESS);
    }
    if (eventProc != 8 && (eventProc & 1) == 0) {
        if (slaCalc.getExpectedStart() == null) {
            eventProc++;
        } else if (slaCalc.getActualStart() != null) {
            if (slaCalc.getExpectedStart().getTime() < slaCalc.getActualStart().getTime()) {
                slaCalc.setEventStatus(EventStatus.START_MISS);
            } else {
                slaCalc.setEventStatus(EventStatus.START_MET);
            }
            if (shouldAlert(slaCalc)) {
                queueEvent(new SLACalcStatus(slaCalc));
            }
            eventProc++;
        } else if (slaCalc.getExpectedStart() != null && slaCalc.getExpectedStart().getTime() < System.currentTimeMillis()) {
            slaCalc.setEventStatus(EventStatus.START_MISS);
            if (shouldAlert(slaCalc)) {
                queueEvent(new SLACalcStatus(slaCalc));
            }
            eventProc++;
        }
    }
    if (eventProc != 8 && ((eventProc >> 1) & 1) == 0) {
        if (slaCalc.getExpectedDuration() == -1) {
            eventProc += 2;
        } else if (slaCalc.getActualStart() != null && slaCalc.getExpectedDuration() != -1) {
            if (System.currentTimeMillis() - slaCalc.getActualStart().getTime() > slaCalc.getExpectedDuration()) {
                slaCalc.setEventStatus(EventStatus.DURATION_MISS);
                if (shouldAlert(slaCalc)) {
                    queueEvent(new SLACalcStatus(slaCalc));
                }
                eventProc += 2;
            }
        }
    }
    if (eventProc < 4) {
        if (slaCalc.getExpectedEnd() != null) {
            if (slaCalc.getExpectedEnd().getTime() < System.currentTimeMillis()) {
                slaCalc.setEventStatus(EventStatus.END_MISS);
                slaCalc.setSLAStatus(SLAStatus.MISS);
                if (shouldAlert(slaCalc)) {
                    queueEvent(new SLACalcStatus(slaCalc));
                }
                eventProc += 4;
            }
        } else {
            eventProc += 4;
        }
    }
    slaCalc.setEventProcessed(eventProc);
}
Also used : SLACalcStatus(org.apache.oozie.sla.SLACalcStatus)

Example 14 with SLACalcStatus

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

the class SLAJobEventXCommand method processForEnd.

/**
 * Process for end.
 */
private void processForEnd() {
    byte eventProc = slaCalc.getEventProcessed();
    LOG.debug("Job {0} has ended. endtime = [{1}]", slaCalc.getId(), slaCalc.getActualEnd());
    if (isEndMiss()) {
        slaCalc.setSLAStatus(SLAStatus.MISS);
    } else {
        slaCalc.setSLAStatus(SLAStatus.MET);
    }
    if (eventProc != 8 && slaCalc.getActualStart() != null) {
        if ((eventProc & 1) == 0) {
            if (slaCalc.getExpectedStart() != null) {
                if (slaCalc.getExpectedStart().getTime() < slaCalc.getActualStart().getTime()) {
                    slaCalc.setEventStatus(EventStatus.START_MISS);
                } else {
                    slaCalc.setEventStatus(EventStatus.START_MET);
                }
                if (shouldAlert(slaCalc)) {
                    queueEvent(new SLACalcStatus(slaCalc));
                }
            }
        }
        slaCalc.setActualDuration(slaCalc.getActualEnd().getTime() - slaCalc.getActualStart().getTime());
        if (((eventProc >> 1) & 1) == 0) {
            processDurationSLA(slaCalc.getExpectedDuration(), slaCalc.getActualDuration(), slaCalc);
        }
    }
    if (eventProc != 8 && eventProc < 4) {
        if (isEndMiss()) {
            slaCalc.setEventStatus(EventStatus.END_MISS);
        } else {
            slaCalc.setEventStatus(EventStatus.END_MET);
        }
        if (shouldAlert(slaCalc)) {
            queueEvent(new SLACalcStatus(slaCalc));
        }
    }
    slaCalc.setEventProcessed(8);
}
Also used : SLACalcStatus(org.apache.oozie.sla.SLACalcStatus)

Example 15 with SLACalcStatus

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

the class TestCoordSubmitXCommand method testSLAAlertWithNewlyCreatedActions.

public void testSLAAlertWithNewlyCreatedActions() 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(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 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();
    CoordinatorJobBean job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    job.setMatThrottling(1);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, job);
    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)));
    assertEquals(slaCalc.getExpectedDuration(), 1800000);
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    assertEquals(job.getLastActionNumber(), 1);
    String newParams = RestConstants.SLA_MAX_DURATION + "=${5 * MINUTES}";
    new CoordSLAChangeXCommand(coordId, null, null, JobUtils.parseChangeValue(newParams)).call();
    new CoordSLAAlertsDisableXCommand(coordId, null, null).call();
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    job.setMatThrottling(2);
    CoordJobQueryExecutor.getInstance().executeUpdate(CoordJobQueryExecutor.CoordJobQuery.UPDATE_COORD_JOB, job);
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    job = CoordJobQueryExecutor.getInstance().get(CoordJobQueryExecutor.CoordJobQuery.GET_COORD_JOB, coordId);
    slaCalc = calc.get(coordId + "@" + job.getLastActionNumber());
    assertEquals(slaCalc.getExpectedDuration(), 300000);
    // newly action should have sla disable after coord disable command on coord job
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    Element eAction = XmlUtils.parseXml(job.getJobXml());
    Element eSla = eAction.getChild("action", eAction.getNamespace()).getChild("info", eAction.getNamespace("sla"));
    assertEquals(SLAOperations.getTagElement(eSla, "max-duration"), "${5 * MINUTES}");
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) 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) Element(org.jdom.Element) 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)

Aggregations

SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)24 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)18 Date (java.util.Date)17 MessageConsumer (javax.jms.MessageConsumer)8 Session (javax.jms.Session)8 TextMessage (javax.jms.TextMessage)8 MimeMessage (javax.mail.internet.MimeMessage)8 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)7 SLAService (org.apache.oozie.sla.service.SLAService)4 Test (org.junit.Test)4 File (java.io.File)2 FileWriter (java.io.FileWriter)2 Reader (java.io.Reader)2 Writer (java.io.Writer)2 Configuration (org.apache.hadoop.conf.Configuration)2 SLACalculator (org.apache.oozie.sla.SLACalculator)2 SLACalculatorMemory (org.apache.oozie.sla.SLACalculatorMemory)2 TestSLAService (org.apache.oozie.sla.TestSLAService)2 XConfiguration (org.apache.oozie.util.XConfiguration)2 ArrayList (java.util.ArrayList)1