Search in sources :

Example 11 with SLARegistrationBean

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

the class V2SLAServlet method getSLASummaryList.

private JSONObject getSLASummaryList(HttpServletRequest request, HttpServletResponse response) throws ServletException, CommandException {
    String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? null : request.getParameter(RestConstants.TIME_ZONE_PARAM);
    String filterString = request.getParameter(RestConstants.JOBS_FILTER_PARAM);
    String maxResults = request.getParameter(RestConstants.LEN_PARAM);
    // Default
    int numMaxResults = 1000;
    if (maxResults != null) {
        numMaxResults = Integer.parseInt(maxResults);
    }
    if (filterString == null || filterString.equals("")) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, RestConstants.JOBS_FILTER_PARAM);
    }
    try {
        Map<String, List<String>> filterList = parseFilter(URLDecoder.decode(filterString, "UTF-8"), SLA_FILTER_NAMES);
        SLASummaryFilter filter = new SLASummaryFilter();
        if (!filterList.containsKey(OozieClient.FILTER_SLA_APPNAME) && !filterList.containsKey(OozieClient.FILTER_SLA_ID) && !filterList.containsKey(OozieClient.FILTER_SLA_PARENT_ID) && !filterList.containsKey(OozieClient.FILTER_BUNDLE) && !filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_START) && !filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_END)) {
            StringBuffer st = new StringBuffer();
            st.append("At least one of the filter parameters - ").append(OozieClient.FILTER_SLA_APPNAME).append(",").append(OozieClient.FILTER_SLA_ID).append(",").append(OozieClient.FILTER_SLA_PARENT_ID).append(",").append(OozieClient.FILTER_BUNDLE).append(",").append(OozieClient.FILTER_SLA_NOMINAL_START).append(" or ").append(OozieClient.FILTER_SLA_NOMINAL_END).append(" should be specified in the filter query parameter");
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0305, st.toString());
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_ID)) {
            filter.setJobId(filterList.get(OozieClient.FILTER_SLA_ID).get(0));
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_PARENT_ID)) {
            filter.setParentId(filterList.get(OozieClient.FILTER_SLA_PARENT_ID).get(0));
        }
        if (filterList.containsKey(OozieClient.FILTER_BUNDLE)) {
            String bundle = filterList.get(OozieClient.FILTER_BUNDLE).get(0);
            if (isBundleId(bundle)) {
                filter.setBundleId(bundle);
            } else {
                filter.setBundleName(bundle);
            }
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_EVENT_STATUS)) {
            filter.setEventStatus(filterList.get(OozieClient.FILTER_SLA_EVENT_STATUS).get(0));
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_STATUS)) {
            filter.setSLAStatus(filterList.get(OozieClient.FILTER_SLA_STATUS).get(0));
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_APPNAME)) {
            filter.setAppName(filterList.get(OozieClient.FILTER_SLA_APPNAME).get(0));
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_START)) {
            filter.setNominalStart(DateUtils.parseDateUTC(filterList.get(OozieClient.FILTER_SLA_NOMINAL_START).get(0)));
        }
        if (filterList.containsKey(OozieClient.FILTER_SLA_NOMINAL_END)) {
            filter.setNominalEnd(DateUtils.parseDateUTC(filterList.get(OozieClient.FILTER_SLA_NOMINAL_END).get(0)));
        }
        JPAService jpaService = Services.get().get(JPAService.class);
        List<SLASummaryBean> slaSummaryList = null;
        if (jpaService != null) {
            slaSummaryList = jpaService.execute(new SLASummaryGetForFilterJPAExecutor(filter, numMaxResults));
        } else {
            XLog.getLog(getClass()).error(ErrorCode.E0610);
        }
        List<String> jobIds = new ArrayList<String>();
        for (SLASummaryBean summaryBean : slaSummaryList) {
            jobIds.add(summaryBean.getId());
        }
        List<SLARegistrationBean> SLARegistrationList = SLARegistrationQueryExecutor.getInstance().getList(SLARegQuery.GET_SLA_CONFIGS, jobIds);
        Map<String, Map<String, String>> jobIdSLAConfigMap = new HashMap<String, Map<String, String>>();
        for (SLARegistrationBean registrationBean : SLARegistrationList) {
            jobIdSLAConfigMap.put(registrationBean.getId(), registrationBean.getSLAConfigMap());
        }
        return SLASummaryBean.toJSONObject(slaSummaryList, jobIdSLAConfigMap, timeZoneId);
    } catch (XException ex) {
        throw new CommandException(ex);
    } catch (UnsupportedEncodingException e) {
        throw new XServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ErrorCode.E0307, "Unsupported Encoding", e);
    } catch (ParseException e) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0303, filterString, e);
    }
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandException(org.apache.oozie.command.CommandException) SLASummaryFilter(org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor.SLASummaryFilter) XException(org.apache.oozie.XException) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) JPAService(org.apache.oozie.service.JPAService) SLASummaryGetForFilterJPAExecutor(org.apache.oozie.executor.jpa.sla.SLASummaryGetForFilterJPAExecutor) HashMap(java.util.HashMap) Map(java.util.Map) SLASummaryBean(org.apache.oozie.sla.SLASummaryBean)

Example 12 with SLARegistrationBean

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

the class TestSLAEmailEventListener method testOnEndMiss.

public void testOnEndMiss() 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-01T01:00Z");
    Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T12:00Z");
    Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T13:00Z");
    event.setId(id);
    eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    event.setEventStatus(EventStatus.END_MISS);
    event.setJobStatus(JobEvent.EventStatus.SUCCESS.toString());
    eventBean.setAppName("Test-SLA-End-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setNominalTime(expectedStartDate);
    eventBean.setExpectedStart(expectedStartDate);
    eventBean.setExpectedEnd(expectedEndDate);
    eventBean.setNotificationMsg("notification of end miss");
    eventBean.setAlertContact("alert-receiver-endmiss@oozie.com");
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    eventBean.setExpectedStart(expectedStartDate);
    eventBean.setExpectedEnd(expectedEndDate);
    event.setActualStart(actualStartDate);
    event.setActualEnd(actualEndDate);
    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-endmiss@oozie.com");
    assertEquals(msg.getSubject(), "OOZIE - SLA " + EventStatus.END_MISS + " (AppName=Test-SLA-End-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.END_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 end 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-End-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);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

Example 13 with SLARegistrationBean

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

the class TestSLAEmailEventListener method testBlackList.

public void testBlackList() throws Exception {
    String blackListedEmail = "alert-receiver@oozie.com";
    // add email to blacklist
    slaEmailListener.addBlackList(blackListedEmail);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus event = _createSLACalcStatus(id);
    SLARegistrationBean eventBean = event.getSLARegistrationBean();
    event.setEventStatus(EventStatus.START_MISS);
    eventBean.setAlertContact(blackListedEmail);
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    eventBean.setAppName("Test-SLA-Start-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setAlertContact("alert-receiver@oozie.com");
    event.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
    // blacklist blocks email from being sent out
    slaEmailListener.onStartMiss(event);
    MimeMessage[] msgs = greenMail.getReceivedMessages();
    assertEquals(msgs.length, 0);
    // wait 1.5 sec (cache timeout set to 1sec in test's setup)
    Thread.sleep(1500);
    // cache is evicted
    slaEmailListener.onStartMiss(event);
    msgs = greenMail.getReceivedMessages();
    assertEquals(msgs.length, 1);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage)

Example 14 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean 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 15 with SLARegistrationBean

use of org.apache.oozie.sla.SLARegistrationBean 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)

Aggregations

SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)38 Date (java.util.Date)21 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)18 ArrayList (java.util.ArrayList)8 MessageConsumer (javax.jms.MessageConsumer)8 Session (javax.jms.Session)8 TextMessage (javax.jms.TextMessage)8 MimeMessage (javax.mail.internet.MimeMessage)8 JPAService (org.apache.oozie.service.JPAService)8 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)7 EntityManager (javax.persistence.EntityManager)6 Query (javax.persistence.Query)6 SLASummaryBean (org.apache.oozie.sla.SLASummaryBean)6 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)5 JsonBean (org.apache.oozie.client.rest.JsonBean)5 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 Test (org.junit.Test)4 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)3 SLARegQuery (org.apache.oozie.executor.jpa.SLARegistrationQueryExecutor.SLARegQuery)3