Search in sources :

Example 1 with SLAMessage

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

the class MessageDeserializer method getEventMessage.

/**
 * Constructs the event message from JMS message
 *
 * @param <T> the type
 * @param message the JMS message
 * @return EventMessage
 * @throws JMSException in case of JMS error
 */
@SuppressWarnings("unchecked")
public <T extends EventMessage> T getEventMessage(Message message) throws JMSException {
    TextMessage textMessage = (TextMessage) message;
    String appTypeString = textMessage.getStringProperty(JMSHeaderConstants.APP_TYPE);
    String msgType = textMessage.getStringProperty(JMSHeaderConstants.MESSAGE_TYPE);
    String messageBody = textMessage.getText();
    T eventMsg = null;
    if (appTypeString == null || appTypeString.isEmpty() || messageBody == null || messageBody.isEmpty()) {
        throw new IllegalArgumentException("Could not extract OozieEventMessage. " + "AppType and/or MessageBody is null/empty." + "Apptype is " + appTypeString + " MessageBody is " + messageBody);
    }
    if (MessageType.valueOf(msgType) == MessageType.JOB) {
        switch(AppType.valueOf(appTypeString)) {
            case WORKFLOW_JOB:
                WorkflowJobMessage wfJobMsg = getDeserializedObject(messageBody, WorkflowJobMessage.class);
                wfJobMsg.setProperties(textMessage);
                eventMsg = (T) wfJobMsg;
                break;
            case COORDINATOR_ACTION:
                CoordinatorActionMessage caActionMsg = getDeserializedObject(messageBody, CoordinatorActionMessage.class);
                caActionMsg.setProperties(textMessage);
                eventMsg = (T) caActionMsg;
                break;
            default:
                throw new UnsupportedOperationException("Conversion of " + appTypeString + " to Event message is not supported");
        }
    } else if (MessageType.valueOf(msgType) == MessageType.SLA) {
        SLAMessage SLAMsg = getDeserializedObject(messageBody, SLAMessage.class);
        SLAMsg.setProperties(textMessage);
        eventMsg = (T) SLAMsg;
    }
    return eventMsg;
}
Also used : CoordinatorActionMessage(org.apache.oozie.client.event.message.CoordinatorActionMessage) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) TextMessage(javax.jms.TextMessage) SLAMessage(org.apache.oozie.client.event.message.SLAMessage)

Example 2 with SLAMessage

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

the class TestJMSSLAEventListener method testOnSLAEndMissEvent.

public void testOnSLAEndMissEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus endMiss = _createSLACalcStatus(id);
    SLARegistrationBean endMissBean = endMiss.getSLARegistrationBean();
    Date expectedEndDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    Date actualEndDate = DateUtils.parseDateUTC("2013-01-01T01:00Z");
    endMiss.setId(id);
    endMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    endMissBean.setAppName("Test-SLA-End-Miss");
    endMiss.setEventStatus(EventStatus.END_MISS);
    endMiss.setSLAStatus(SLAStatus.IN_PROCESS);
    endMissBean.setAppType(AppType.COORDINATOR_ACTION);
    endMissBean.setUser("dummyuser");
    endMissBean.setNotificationMsg("notification of end miss");
    endMissBean.setExpectedEnd(expectedEndDate);
    endMiss.setActualEnd(actualEndDate);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(endMiss));
    slaListener.onEndMiss(endMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage slaEndMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.END_MISS, slaEndMissMsg.getEventStatus());
    assertEquals(SLAStatus.IN_PROCESS, slaEndMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, slaEndMissMsg.getAppType());
    assertEquals(MessageType.SLA, slaEndMissMsg.getMessageType());
    assertEquals("Test-SLA-End-Miss", 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 miss", 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 3 with SLAMessage

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

the class TestJMSSLAEventListener method testSLAJobSelectors.

@Test
public void testSLAJobSelectors() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus startMiss = _createSLACalcStatus(id);
    SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
    startMiss.setId(id);
    startMissBean.setAppName("Test-SLA-Start-Miss");
    startMissBean.setAppType(AppType.COORDINATOR_ACTION);
    startMissBean.setUser("dummyuser");
    startMiss.setEventStatus(EventStatus.START_MISS);
    startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
    startMiss.setMsgType(MessageType.SLA);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    String selector = JMSHeaderConstants.EVENT_STATUS + "='START_MISS'";
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMiss), selector);
    slaListener.onStartMiss(startMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    System.out.println("\n Text " + message.getText());
    SLAMessage startMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    assertEquals("dummyuser", startMissMsg.getUser());
    assertEquals(EventStatus.START_MISS, startMissMsg.getEventStatus());
    assertEquals(MessageType.SLA, startMissMsg.getMessageType());
}
Also used : SLARegistrationBean(org.apache.oozie.sla.SLARegistrationBean) MessageConsumer(javax.jms.MessageConsumer) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) SLAMessage(org.apache.oozie.client.event.message.SLAMessage) Test(org.junit.Test)

Example 4 with SLAMessage

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

the class TestJMSSLAEventListener method testOnSLAStartMetEvent.

@Test
public void testOnSLAStartMetEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus startMet = _createSLACalcStatus(id);
    SLARegistrationBean startMetBean = startMet.getSLARegistrationBean();
    Date expectedStartDate = DateUtils.parseDateUTC("2013-01-01T10:00Z");
    Date actualStartDate = DateUtils.parseDateUTC("2013-01-01T09:55Z");
    startMetBean.setAppName("Test-SLA-Start-Met");
    startMet.setEventStatus(EventStatus.START_MET);
    startMet.setSLAStatus(SLAStatus.IN_PROCESS);
    startMetBean.setAppType(AppType.COORDINATOR_ACTION);
    startMet.setId(id);
    startMetBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    startMetBean.setUser("dummyuser");
    startMetBean.setNotificationMsg("notification of start miss");
    startMetBean.setJobData("random job data");
    startMetBean.setExpectedStart(expectedStartDate);
    startMet.setActualStart(actualStartDate);
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMet));
    slaListener.onStartMet(startMet);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage slaStartMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.START_MET, slaStartMissMsg.getEventStatus());
    assertEquals(SLAStatus.IN_PROCESS, slaStartMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, slaStartMissMsg.getAppType());
    assertEquals(MessageType.SLA, slaStartMissMsg.getMessageType());
    assertEquals("Test-SLA-Start-Met", slaStartMissMsg.getAppName());
    assertEquals("dummyuser", slaStartMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", slaStartMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", slaStartMissMsg.getParentId());
    assertEquals(expectedStartDate, slaStartMissMsg.getExpectedStartTime());
    assertEquals(actualStartDate, slaStartMissMsg.getActualStartTime());
}
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) Test(org.junit.Test)

Example 5 with SLAMessage

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

the class TestJMSSLAEventListener method testOnSLAStartMissEvent.

@Test
public void testOnSLAStartMissEvent() throws Exception {
    JMSSLAEventListener slaListener = new JMSSLAEventListener();
    slaListener.init(conf);
    String id = "0000000-000000000000001-oozie-wrkf-C@1";
    SLACalcStatus startMiss = _createSLACalcStatus(id);
    SLARegistrationBean startMissBean = startMiss.getSLARegistrationBean();
    Date startDate = DateUtils.parseDateUTC("2013-01-01T00:00Z");
    startMiss.setId(id);
    startMissBean.setParentId("0000000-000000000000001-oozie-wrkf-C");
    startMissBean.setAppName("Test-SLA-Start-Miss");
    startMissBean.setUser("dummyuser");
    startMissBean.setExpectedStart(startDate);
    startMissBean.setNotificationMsg("notification of start miss");
    startMissBean.setJobData("random job data");
    startMiss.setEventStatus(EventStatus.START_MISS);
    startMiss.setSLAStatus(SLAStatus.NOT_STARTED);
    startMissBean.setAppType(AppType.COORDINATOR_ACTION);
    startMiss.setActualStart(DateUtils.parseDateUTC("2013-01-01T01:00Z"));
    ConnectionContext jmsContext = getConnectionContext();
    Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = jmsContext.createConsumer(session, slaListener.getTopic(startMiss));
    slaListener.onStartMiss(startMiss);
    TextMessage message = (TextMessage) consumer.receive(5000);
    SLAMessage slaStartMissMsg = (SLAMessage) JMSMessagingUtils.getEventMessage(message);
    // check msg header
    assertEquals(EventStatus.START_MISS, slaStartMissMsg.getEventStatus());
    assertEquals(SLAStatus.NOT_STARTED, slaStartMissMsg.getSLAStatus());
    assertEquals(AppType.COORDINATOR_ACTION, slaStartMissMsg.getAppType());
    assertEquals(MessageType.SLA, slaStartMissMsg.getMessageType());
    assertEquals("Test-SLA-Start-Miss", slaStartMissMsg.getAppName());
    assertEquals("dummyuser", slaStartMissMsg.getUser());
    // check msg body
    assertEquals("0000000-000000000000001-oozie-wrkf-C@1", slaStartMissMsg.getId());
    assertEquals("0000000-000000000000001-oozie-wrkf-C", slaStartMissMsg.getParentId());
    assertEquals(startDate, slaStartMissMsg.getExpectedStartTime());
    assertEquals("notification of start miss", slaStartMissMsg.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) Test(org.junit.Test)

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