Search in sources :

Example 11 with JMSJobEventListener

use of org.apache.oozie.jms.JMSJobEventListener in project oozie by apache.

the class TestJMSJobEventListener method testOnCoordinatorJobFailureEvent.

@Test
public void testOnCoordinatorJobFailureEvent() throws ParseException {
    JMSJobEventListener coordEventListener = new JMSJobEventListener();
    coordEventListener.init(conf);
    Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
    Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
    Date endDate = new Date();
    CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED, "user1", "wf-app-name1", nominalTime, startDate, null);
    cae.setEndTime(endDate);
    cae.setErrorCode("E0101");
    cae.setErrorMessage("dummyError");
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, coordEventListener.getTopic(cae));
        coordEventListener.onCoordinatorActionEvent(cae);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertFalse(message.getText().contains("missingDependency"));
        CoordinatorActionMessage coordActionFailMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(CoordinatorAction.Status.FAILED, coordActionFailMessage.getStatus());
        assertEquals(startDate, coordActionFailMessage.getStartTime());
        assertEquals(endDate, coordActionFailMessage.getEndTime());
        assertEquals("caJobId1", coordActionFailMessage.getParentId());
        assertEquals("caId1", coordActionFailMessage.getId());
        assertEquals(MessageType.JOB, coordActionFailMessage.getMessageType());
        assertEquals(AppType.COORDINATOR_ACTION, coordActionFailMessage.getAppType());
        assertEquals(EventStatus.FAILURE, coordActionFailMessage.getEventStatus());
        assertEquals("user1", coordActionFailMessage.getUser());
        assertEquals("wf-app-name1", coordActionFailMessage.getAppName());
        assertEquals("E0101", coordActionFailMessage.getErrorCode());
        assertEquals("dummyError", coordActionFailMessage.getErrorMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CoordinatorActionMessage(org.apache.oozie.client.event.message.CoordinatorActionMessage) MessageConsumer(javax.jms.MessageConsumer) 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 12 with JMSJobEventListener

use of org.apache.oozie.jms.JMSJobEventListener in project oozie by apache.

the class TestJMSJobEventListener method testOnWorkflowJobSuspendEvent.

@Test
public void testOnWorkflowJobSuspendEvent() 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.SUSPENDED, "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 wfFailMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(WorkflowJob.Status.SUSPENDED, wfFailMessage.getStatus());
        assertEquals(startDate, wfFailMessage.getStartTime());
        assertEquals("wfId1", wfFailMessage.getId());
        assertEquals("caId1", wfFailMessage.getParentId());
        assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
        assertEquals(AppType.WORKFLOW_JOB, wfFailMessage.getAppType());
        assertEquals(EventStatus.SUSPEND, wfFailMessage.getEventStatus());
        assertEquals("user1", wfFailMessage.getUser());
        assertEquals("wf-app-name1", wfFailMessage.getAppName());
        assertNull(wfFailMessage.getErrorCode());
        assertNull(wfFailMessage.getErrorMessage());
        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 13 with JMSJobEventListener

use of org.apache.oozie.jms.JMSJobEventListener in project oozie by apache.

the class TestJMSJobEventListener method testOnWorkflowJobFailureEvent.

@Test
public void testOnWorkflowJobFailureEvent() 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.FAILED, "user1", "wf-app-name1", startDate, endDate);
    wfe.setErrorCode("dummyErrorCode");
    wfe.setErrorMessage("dummyErrorMessage");
    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 wfFailMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(WorkflowJob.Status.FAILED, wfFailMessage.getStatus());
        assertEquals(startDate, wfFailMessage.getStartTime());
        assertEquals(endDate, wfFailMessage.getEndTime());
        assertEquals("wfId1", wfFailMessage.getId());
        assertEquals("caId1", wfFailMessage.getParentId());
        assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
        assertEquals(AppType.WORKFLOW_JOB, wfFailMessage.getAppType());
        assertEquals(EventStatus.FAILURE, wfFailMessage.getEventStatus());
        assertEquals("user1", wfFailMessage.getUser());
        assertEquals("wf-app-name1", wfFailMessage.getAppName());
        assertEquals("dummyErrorCode", wfFailMessage.getErrorCode());
        assertEquals("dummyErrorMessage", wfFailMessage.getErrorMessage());
        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 14 with JMSJobEventListener

use of org.apache.oozie.jms.JMSJobEventListener in project oozie by apache.

the class TestJMSJobEventListener method testWorkflowJobSelectorsNegative.

@Test
public void testWorkflowJobSelectorsNegative() {
    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 which wont match and assert for null message
        String selector = JMSHeaderConstants.USER + "='Non_matching_user'";
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe), selector);
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertNull(message);
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) 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 15 with JMSJobEventListener

use of org.apache.oozie.jms.JMSJobEventListener in project oozie by apache.

the class TestJMSJobEventListener method testWorkflowJobSelectorsOr.

@Test
public void testWorkflowJobSelectorsOr() {
    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 OR condition
        String selector = JMSHeaderConstants.USER + "='Non_matching_user' OR " + JMSHeaderConstants.APP_NAME + "='wf-app-name1'";
        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)

Aggregations

ParseException (java.text.ParseException)15 Date (java.util.Date)15 MessageConsumer (javax.jms.MessageConsumer)15 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)15 ConnectionContext (org.apache.oozie.jms.ConnectionContext)15 JMSJobEventListener (org.apache.oozie.jms.JMSJobEventListener)15 Test (org.junit.Test)15 WorkflowJobMessage (org.apache.oozie.client.event.message.WorkflowJobMessage)7 CoordinatorActionMessage (org.apache.oozie.client.event.message.CoordinatorActionMessage)5 Random (java.util.Random)1 BrokerService (org.apache.activemq.broker.BrokerService)1 Configuration (org.apache.hadoop.conf.Configuration)1 JMSAccessorService (org.apache.oozie.service.JMSAccessorService)1 Services (org.apache.oozie.service.Services)1