use of org.apache.oozie.client.event.message.CoordinatorActionMessage 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;
}
use of org.apache.oozie.client.event.message.CoordinatorActionMessage in project oozie by apache.
the class TestJMSJobEventListener method testCoordinatorActionSelectors.
@Test
public void testCoordinatorActionSelectors() 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");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED, "user1", "wf-app-name1", nominalTime, startDate, null);
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
String selector = JMSHeaderConstants.USER + "='user1'";
MessageConsumer consumer = jmsContext.createConsumer(session, coordEventListener.getTopic(cae), selector);
coordEventListener.onCoordinatorActionEvent(cae);
TextMessage message = (TextMessage) consumer.receive(5000);
CoordinatorActionMessage coordActionFailMessage = JMSMessagingUtils.getEventMessage(message);
Assert.assertEquals(CoordinatorAction.Status.FAILED, coordActionFailMessage.getStatus());
assertEquals("user1", coordActionFailMessage.getUser());
assertEquals(MessageType.JOB, coordActionFailMessage.getMessageType());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.client.event.message.CoordinatorActionMessage in project oozie by apache.
the class TestJMSJobEventListener method testOnCoordinatorActionWaitingEvent.
@Test
public void testOnCoordinatorActionWaitingEvent() throws ParseException {
JMSJobEventListener wfEventListner = new JMSJobEventListener();
wfEventListner.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.WAITING, "user1", "wf-app-name1", nominalTime, startDate, "missingDep1");
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListner.getTopic(cae));
wfEventListner.onCoordinatorActionEvent(cae);
TextMessage message = (TextMessage) consumer.receive(5000);
assertFalse(message.getText().contains("endTime"));
assertFalse(message.getText().contains("errorCode"));
assertFalse(message.getText().contains("errorMessage"));
CoordinatorActionMessage coordActionWaitingMessage = JMSMessagingUtils.getEventMessage(message);
assertEquals(CoordinatorAction.Status.WAITING, coordActionWaitingMessage.getStatus());
assertEquals(startDate, coordActionWaitingMessage.getStartTime());
assertEquals(nominalTime, coordActionWaitingMessage.getNominalTime());
assertEquals("caJobId1", coordActionWaitingMessage.getParentId());
assertEquals("caId1", coordActionWaitingMessage.getId());
assertEquals(MessageType.JOB, coordActionWaitingMessage.getMessageType());
assertEquals(AppType.COORDINATOR_ACTION, coordActionWaitingMessage.getAppType());
assertEquals(EventStatus.WAITING, coordActionWaitingMessage.getEventStatus());
assertEquals("user1", coordActionWaitingMessage.getUser());
assertEquals("wf-app-name1", coordActionWaitingMessage.getAppName());
assertEquals("missingDep1", coordActionWaitingMessage.getMissingDependency());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.client.event.message.CoordinatorActionMessage in project oozie by apache.
the class TestJMSJobEventListener method testOnCoordinatorActionStartEvent.
@Test
public void testOnCoordinatorActionStartEvent() 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");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.RUNNING, "user1", "wf-app-name1", nominalTime, startDate, null);
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("endTime"));
assertFalse(message.getText().contains("errorCode"));
assertFalse(message.getText().contains("errorMessage"));
assertFalse(message.getText().contains("missingDependency"));
CoordinatorActionMessage coordActionStartMessage = JMSMessagingUtils.getEventMessage(message);
assertEquals(CoordinatorAction.Status.RUNNING, coordActionStartMessage.getStatus());
assertEquals(startDate, coordActionStartMessage.getStartTime());
assertEquals("caJobId1", coordActionStartMessage.getParentId());
assertEquals("caId1", coordActionStartMessage.getId());
assertEquals(MessageType.JOB, coordActionStartMessage.getMessageType());
assertEquals(AppType.COORDINATOR_ACTION, coordActionStartMessage.getAppType());
assertEquals(EventStatus.STARTED, coordActionStartMessage.getEventStatus());
assertEquals("user1", coordActionStartMessage.getUser());
assertEquals("wf-app-name1", coordActionStartMessage.getAppName());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.client.event.message.CoordinatorActionMessage in project oozie by apache.
the class TestJMSJobEventListener method testOnCoordinatorJobSuccessEvent.
@Test
public void testOnCoordinatorJobSuccessEvent() 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.SUCCEEDED, "user1", "wf-app-name1", nominalTime, startDate, null);
cae.setEndTime(endDate);
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("errorCode"));
assertFalse(message.getText().contains("errorMessage"));
assertFalse(message.getText().contains("missingDependency"));
CoordinatorActionMessage coordActionSuccessMessage = JMSMessagingUtils.getEventMessage(message);
assertEquals(CoordinatorAction.Status.SUCCEEDED, coordActionSuccessMessage.getStatus());
assertEquals(startDate, coordActionSuccessMessage.getStartTime());
assertEquals(endDate, coordActionSuccessMessage.getEndTime());
assertEquals("caJobId1", coordActionSuccessMessage.getParentId());
assertEquals("caId1", coordActionSuccessMessage.getId());
assertEquals(MessageType.JOB, coordActionSuccessMessage.getMessageType());
assertEquals(AppType.COORDINATOR_ACTION, coordActionSuccessMessage.getAppType());
assertEquals(EventStatus.SUCCESS, coordActionSuccessMessage.getEventStatus());
assertEquals("user1", coordActionSuccessMessage.getUser());
assertEquals("wf-app-name1", coordActionSuccessMessage.getAppName());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations