Search in sources :

Example 31 with SLARegistrationBean

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

the class TestJMSSLAEventListener method testOnSLADurationMetEvent.

public void testOnSLADurationMetEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus durationMet = _createSLACalcStatus(id);
    SLARegistrationBean durationMetBean = durationMet.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-01T14:00Z");
    long expectedDuration = (expectedEndDate.getTime() - actualStartDate.getTime()) / (1000 * 60);
    durationMet.setId(id);
    durationMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    durationMetBean.setAppName("Test-SLA-Duration-Met");
    durationMet.setEventStatus(EventStatus.DURATION_MET);
    durationMet.setSLAStatus(SLAStatus.MET);
    durationMetBean.setAppType(AppType.COORDINATOR_ACTION);
    durationMetBean.setUser("dummyuser");
    durationMetBean.setNotificationMsg("notification of duration met");
    durationMetBean.setExpectedStart(expectedStartDate);
    durationMet.setActualStart(actualStartDate);
    durationMetBean.setExpectedEnd(expectedEndDate);
    durationMet.setActualEnd(actualEndDate);
    durationMetBean.setExpectedDuration(expectedDuration);
    long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
    durationMet.setActualDuration(actualDuration);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(durationMet));
    slaListener.onDurationMet(durationMet);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage durationMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.DURATION_MET, durationMissMsg.getEventStatus());
    assertEquals(SLAStatus.MET, durationMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, durationMissMsg.getAppType());
    assertEquals(MessageType.SLA, durationMissMsg.getMessageType());
    assertEquals("Test-SLA-Duration-Met", durationMissMsg.getAppName());
    assertEquals("dummyuser", durationMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", durationMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", durationMissMsg.getParentId());
    assertEquals(expectedStartDate, durationMissMsg.getExpectedStartTime());
    assertEquals(actualStartDate, durationMissMsg.getActualStartTime());
    assertEquals(expectedEndDate, durationMissMsg.getExpectedEndTime());
    assertEquals(actualEndDate, durationMissMsg.getActualEndTime());
    assertEquals(expectedDuration, durationMissMsg.getExpectedDuration());
    assertEquals(actualDuration, durationMissMsg.getActualDuration());
    assertEquals("notification of duration met", durationMissMsg.getNotificationMessage());
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) Date(java.util.Date) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 32 with SLARegistrationBean

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

the class TestJMSSLAEventListener method testOnSLADurationMissEvent.

public void testOnSLADurationMissEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus durationMiss = _createSLACalcStatus(id);
    SLARegistrationBean durationMissBean = durationMiss.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-01T14:00Z");
    long expectedDuration = (expectedEndDate.getTime() - actualStartDate.getTime()) / (1000 * 60);
    durationMiss.setId(id);
    durationMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    durationMissBean.setAppName("Test-SLA-Duration-Miss");
    durationMiss.setEventStatus(EventStatus.DURATION_MISS);
    durationMiss.setSLAStatus(SLAStatus.IN_PROCESS);
    durationMissBean.setAppType(AppType.COORDINATOR_ACTION);
    durationMissBean.setUser("dummyuser");
    durationMissBean.setNotificationMsg("notification of duration miss");
    durationMissBean.setExpectedStart(expectedStartDate);
    durationMiss.setActualStart(actualStartDate);
    durationMissBean.setExpectedEnd(expectedEndDate);
    durationMiss.setActualEnd(actualEndDate);
    durationMissBean.setExpectedDuration(expectedDuration);
    long actualDuration = actualEndDate.getTime() - actualStartDate.getTime();
    durationMiss.setActualDuration(actualDuration);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(durationMiss));
    slaListener.onDurationMiss(durationMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage durationMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.DURATION_MISS, durationMissMsg.getEventStatus());
    assertEquals(SLAStatus.IN_PROCESS, durationMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, durationMissMsg.getAppType());
    assertEquals(MessageType.SLA, durationMissMsg.getMessageType());
    assertEquals("Test-SLA-Duration-Miss", durationMissMsg.getAppName());
    assertEquals("dummyuser", durationMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", durationMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", durationMissMsg.getParentId());
    assertEquals(expectedStartDate, durationMissMsg.getExpectedStartTime());
    assertEquals(actualStartDate, durationMissMsg.getActualStartTime());
    assertEquals(expectedEndDate, durationMissMsg.getExpectedEndTime());
    assertEquals(actualEndDate, durationMissMsg.getActualEndTime());
    assertEquals(expectedDuration, durationMissMsg.getExpectedDuration());
    assertEquals(actualDuration, durationMissMsg.getActualDuration());
    assertEquals("notification of duration miss", durationMissMsg.getNotificationMessage());
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) Date(java.util.Date) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 33 with SLARegistrationBean

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

the class TestSLAEmailEventListener method testNoDestAddress.

public void testNoDestAddress() throws Exception {
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus event = _createSLACalcStatus(id);
    SLARegistrationBean eventBean = event.getSLARegistrationBean();
    Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    // set empty address as alert contact
    eventBean.setAlertContact("");
    event.setEventStatus(EventStatus.START_MISS);
    event.setId(id);
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    eventBean.setAppName("Test-SLA-Start-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setExpectedStart(startDate);
    eventBean.setNotificationMsg("notification of start miss");
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    event.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
    slaEmailListener.onStartMiss(event);
    MimeMessage[] msgs = greenMail.getReceivedMessages();
    assertEquals(msgs.length, 0);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

Example 34 with SLARegistrationBean

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

the class TestSLAEmailEventListener method testUserAlertEventSetting.

public void testUserAlertEventSetting() throws Exception {
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus event = _createSLACalcStatus(id);
    SLARegistrationBean eventBean = event.getSLARegistrationBean();
    // user choose only END MISS, thus, START_MISS email should not be sent
    eventBean.setAlertEvents(EventStatus.END_MISS.name());
    Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    Date actualstartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
    event.setEventStatus(EventStatus.START_MISS);
    event.setId(id);
    eventBean.setAppName("Test-SLA-Start-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setNominalTime(startDate);
    eventBean.setExpectedStart(startDate);
    eventBean.setAlertContact("alert-receiver@oozie.com");
    event.setActualStart(actualstartDate);
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    slaEmailListener.onStartMiss(event);
    // START_MISS should not be sent
    MimeMessage[] msgs = greenMail.getReceivedMessages();
    assertEquals(msgs.length, 0);
    // DURATION_MISS should not be sent
    event.setEventStatus(EventStatus.DURATION_MISS);
    slaEmailListener.onDurationMiss(event);
    msgs = greenMail.getReceivedMessages();
    assertEquals(msgs.length, 0);
    // END_MISS should be sent
    event.setEventStatus(EventStatus.END_MISS);
    slaEmailListener.onEndMiss(event);
    msgs = greenMail.getReceivedMessages();
    assertNotNull(msgs[0]);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

Example 35 with SLARegistrationBean

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

the class TestSLAEmailEventListener method testOnStartMiss.

public void testOnStartMiss() throws Exception {
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus event = _createSLACalcStatus(id);
    SLARegistrationBean eventBean = event.getSLARegistrationBean();
    Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    Date actualstartDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
    event.setEventStatus(EventStatus.START_MISS);
    event.setJobStatus(JobEvent.EventStatus.STARTED.toString());
    event.setId(id);
    eventBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    eventBean.setAppName("Test-SLA-Start-Miss");
    eventBean.setUser("dummyuser");
    eventBean.setNominalTime(startDate);
    eventBean.setExpectedStart(startDate);
    eventBean.setNotificationMsg("Notification of Missing Expected Start Time");
    eventBean.setAlertContact("alert-receiver@oozie.com");
    event.setActualStart(actualstartDate);
    eventBean.setAppType(AppType.COORDINATOR_ACTION);
    slaEmailListener.onStartMiss(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@oozie.com");
    assertEquals(msg.getSubject(), "OOZIE - SLA " + EventStatus.START_MISS + " (AppName=Test-SLA-Start-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.START_MISS.toString()) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.JOB_STATUS.toString() + sep + JobEvent.EventStatus.STARTED.toString()) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.NOTIFICATION_MESSAGE.toString() + sep + "Notification of Missing Expected Start Time") > -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-Start-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 + startDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.EXPECTED_START_TIME.toString() + sep + startDate) > -1);
    assertTrue(msgBody.indexOf(indent + EmailField.ACTUAL_START_TIME.toString() + sep + actualstartDate) > -1);
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) MimeMessage(javax.mail.internet.MimeMessage) Date(java.util.Date)

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