Search in sources :

Example 1 with WorkflowJobMessage

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

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

the class TestJMSJobEventListener method testOnWorkflowJobSuccessEvent.

@Test
public void testOnWorkflowJobSuccessEvent() throws ParseException {
    JMSJobEventListener wfEventListener = new JMSJobEventListener();
    wfEventListener.init(conf);
    Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
    Date endDate = new Date();
    WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.SUCCEEDED, "user1", "wf-app-name1", startDate, endDate);
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe));
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        WorkflowJobMessage wfSuccMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(WorkflowJob.Status.SUCCEEDED, wfSuccMessage.getStatus());
        assertEquals(startDate, wfSuccMessage.getStartTime());
        assertEquals(endDate, wfSuccMessage.getEndTime());
        assertEquals("wfId1", wfSuccMessage.getId());
        assertEquals("caId1", wfSuccMessage.getParentId());
        assertEquals(MessageType.JOB, wfSuccMessage.getMessageType());
        assertEquals(AppType.WORKFLOW_JOB, wfSuccMessage.getAppType());
        assertEquals(EventStatus.SUCCESS, wfSuccMessage.getEventStatus());
        assertEquals("user1", wfSuccMessage.getUser());
        assertEquals("wf-app-name1", wfSuccMessage.getAppName());
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with WorkflowJobMessage

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

the class TestJMSJobEventListener method testOnWorkflowJobStartedEvent.

@Test
public void testOnWorkflowJobStartedEvent() throws ParseException {
    JMSJobEventListener wfEventListener = new JMSJobEventListener();
    wfEventListener.init(conf);
    Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
    WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", startDate, null);
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe));
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertFalse(message.getText().contains("endTime"));
        WorkflowJobMessage wfStartMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(WorkflowJob.Status.RUNNING, wfStartMessage.getStatus());
        assertEquals(startDate, wfStartMessage.getStartTime());
        assertEquals("wfId1", wfStartMessage.getId());
        assertEquals("caId1", wfStartMessage.getParentId());
        assertEquals(MessageType.JOB, wfStartMessage.getMessageType());
        assertEquals(AppType.WORKFLOW_JOB, wfStartMessage.getAppType());
        assertEquals(EventStatus.STARTED, wfStartMessage.getEventStatus());
        assertEquals("user1", wfStartMessage.getUser());
        assertEquals("wf-app-name1", wfStartMessage.getAppName());
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 4 with WorkflowJobMessage

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

the class TestJMSJobEventListener method testWorkflowJobSelectorsAnd.

@Test
public void testWorkflowJobSelectorsAnd() {
    JMSJobEventListener wfEventListener = new JMSJobEventListener();
    wfEventListener.init(conf);
    WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1", "wf-app-name1", new Date(), new Date());
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        // Pass a selector using AND condition
        String selector = JMSHeaderConstants.EVENT_STATUS + "='FAILURE' AND " + JMSHeaderConstants.APP_TYPE + "='WORKFLOW_JOB' AND " + JMSHeaderConstants.MESSAGE_TYPE + "='JOB'";
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe), selector);
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        WorkflowJobMessage wfFailMessage = JMSMessagingUtils.getEventMessage(message);
        Assert.assertEquals(WorkflowJob.Status.FAILED, wfFailMessage.getStatus());
        assertEquals("user1", wfFailMessage.getUser());
        assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with WorkflowJobMessage

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

the class TestJMSJobEventListener method testWorkflowJobSelectors.

@Test
public void testWorkflowJobSelectors() throws ParseException {
    JMSJobEventListener wfEventListener = new JMSJobEventListener();
    wfEventListener.init(conf);
    WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user_1", "wf-app-name1", new Date(), new Date());
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        String selector = JMSHeaderConstants.USER + "='user_1'";
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe), selector);
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        WorkflowJobMessage wfFailMessage = JMSMessagingUtils.getEventMessage(message);
        Assert.assertEquals(WorkflowJob.Status.FAILED, wfFailMessage.getStatus());
        assertEquals("user_1", wfFailMessage.getUser());
        assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

WorkflowJobMessage (org.apache.oozie.client.event.message.WorkflowJobMessage)9 TextMessage (javax.jms.TextMessage)8 ParseException (java.text.ParseException)7 Date (java.util.Date)7 MessageConsumer (javax.jms.MessageConsumer)7 Session (javax.jms.Session)7 ConnectionContext (org.apache.oozie.jms.ConnectionContext)7 JMSJobEventListener (org.apache.oozie.jms.JMSJobEventListener)7 Test (org.junit.Test)7 CoordinatorActionMessage (org.apache.oozie.client.event.message.CoordinatorActionMessage)1 SLAMessage (org.apache.oozie.client.event.message.SLAMessage)1