Search in sources :

Example 6 with SLAMessage

use of org.apache.oozie.client.event.message.SLAMessage in project oozie by apache.

the class TestJMSSLAEventListener method testOnSLAEndMetEvent.

public void testOnSLAEndMetEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus endMet = _createSLACalcStatus(id);
    SLARegistrationBean endMetBean = endMet.getSLARegistrationBean();
    Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T12:00Z");
    Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T11:00Z");
    endMet.setId(id);
    endMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    endMetBean.setAppName("Test-SLA-End-Met");
    endMet.setEventStatus(EventStatus.END_MET);
    endMet.setSLAStatus(SLAStatus.MET);
    endMetBean.setAppType(AppType.COORDINATOR_ACTION);
    endMetBean.setUser("dummyuser");
    endMetBean.setNotificationMsg("notification of end met");
    endMetBean.setExpectedEnd(expectedEndDate);
    endMet.setActualEnd(actualEndDate);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(endMet));
    slaListener.onEndMet(endMet);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage slaEndMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.END_MET, slaEndMissMsg.getEventStatus());
    assertEquals(SLAStatus.MET, slaEndMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, slaEndMissMsg.getAppType());
    assertEquals(MessageType.SLA, slaEndMissMsg.getMessageType());
    assertEquals("Test-SLA-End-Met", slaEndMissMsg.getAppName());
    assertEquals("dummyuser", slaEndMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", slaEndMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", slaEndMissMsg.getParentId());
    assertEquals(expectedEndDate, slaEndMissMsg.getExpectedEndTime());
    assertEquals(actualEndDate, slaEndMissMsg.getActualEndTime());
    assertEquals("notification of end met", slaEndMissMsg.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 7 with SLAMessage

use of org.apache.oozie.client.event.message.SLAMessage in project oozie by apache.

the class JMSSLAEventListener method sendSLANotification.

protected void sendSLANotification(SLAEvent event) {
    SLAMessage slaMsg = MessageFactory.createSLAMessage(event);
    MessageSerializer serializer = MessageFactory.getMessageSerializer();
    String messageBody = serializer.getSerializedObject(slaMsg);
    String serializerMessageFormat = serializer.getMessageFormat();
    String topicName = getTopic(event);
    sendJMSMessage(slaMsg, messageBody, topicName, serializerMessageFormat);
}
Also used : MessageSerializer(org.apache.oozie.event.messaging.MessageSerializer) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 8 with SLAMessage

use of org.apache.oozie.client.event.message.SLAMessage 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 9 with SLAMessage

use of org.apache.oozie.client.event.message.SLAMessage 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)

Aggregations

SLAMessage (org.apache.oozie.client.event.message.SLAMessage)9 TextMessage (javax.jms.TextMessage)8 MessageConsumer (javax.jms.MessageConsumer)7 Session (javax.jms.Session)7 SLACalcStatus (org.apache.oozie.sla.SLACalcStatus)7 SLARegistrationBean (org.apache.oozie.sla.SLARegistrationBean)7 Date (java.util.Date)6 Test (org.junit.Test)3 CoordinatorActionMessage (org.apache.oozie.client.event.message.CoordinatorActionMessage)1 WorkflowJobMessage (org.apache.oozie.client.event.message.WorkflowJobMessage)1 MessageSerializer (org.apache.oozie.event.messaging.MessageSerializer)1