use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class JMSAccessorService method retryConnection.
@VisibleForTesting
boolean retryConnection(JMSConnectionInfo connInfo) {
ConnectionRetryInfo connRetryInfo = retryConnectionsMap.get(connInfo);
if (connRetryInfo.getNumAttempt() >= retryMaxAttempts) {
LOG.info("Not attempting connection [{0}] again. Reached max attempts [{1}]", connInfo, retryMaxAttempts);
return false;
}
LOG.info("Attempting retry of connection [{0}]", connInfo);
connRetryInfo.setNumAttempt(connRetryInfo.getNumAttempt() + 1);
connRetryInfo.setNextDelay(connRetryInfo.getNextDelay() * retryMultiplier);
ConnectionContext connCtxt = createConnectionContext(connInfo);
boolean shouldRetry = false;
if (connCtxt == null) {
shouldRetry = true;
} else {
Map<String, MessageHandler> retryTopicsMap = connRetryInfo.getTopicsToRetry();
Map<String, MessageReceiver> listeningTopicsMap = getReceiversTopicsMap(connInfo);
List<String> topicsToRemoveList = new ArrayList<String>();
// For each topic in the retry list, try to register the MessageHandler for that topic
for (Entry<String, MessageHandler> topicEntry : retryTopicsMap.entrySet()) {
String topic = topicEntry.getKey();
if (listeningTopicsMap.containsKey(topic)) {
continue;
}
synchronized (listeningTopicsMap) {
if (!listeningTopicsMap.containsKey(topic)) {
MessageReceiver receiver = registerForTopic(connInfo, connCtxt, topic, topicEntry.getValue());
if (receiver == null) {
LOG.warn("Failed to register a listener for topic {0} on {1}", topic, connInfo);
} else {
listeningTopicsMap.put(topic, receiver);
topicsToRemoveList.add(topic);
LOG.info("Registered a listener for topic {0} on {1}", topic, connInfo);
}
}
}
}
for (String topic : topicsToRemoveList) {
retryTopicsMap.remove(topic);
}
if (retryTopicsMap.isEmpty()) {
shouldRetry = false;
}
}
if (shouldRetry) {
scheduleRetry(connInfo, connRetryInfo.getNextDelay());
} else {
retryConnectionsMap.remove(connInfo);
}
return true;
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class JMSAccessorService method registerForNotification.
/**
* Register for notifications on a JMS topic.
*
* @param connInfo Information to connect to a JMS compliant messaging service.
* @param topic Topic in which the JMS messages are published
* @param msgHandler Handler which will process the messages received on the topic
*/
public void registerForNotification(JMSConnectionInfo connInfo, String topic, MessageHandler msgHandler) {
if (!isTopicInRetryList(connInfo, topic)) {
if (isConnectionInRetryList(connInfo)) {
queueTopicForRetry(connInfo, topic, msgHandler);
} else {
Map<String, MessageReceiver> topicsMap = getReceiversTopicsMap(connInfo);
if (!topicsMap.containsKey(topic)) {
synchronized (topicsMap) {
if (!topicsMap.containsKey(topic)) {
ConnectionContext connCtxt = createConnectionContext(connInfo);
if (connCtxt == null) {
queueTopicForRetry(connInfo, topic, msgHandler);
return;
}
MessageReceiver receiver = registerForTopic(connInfo, connCtxt, topic, msgHandler);
if (receiver == null) {
queueTopicForRetry(connInfo, topic, msgHandler);
} else {
LOG.info("Registered a listener for topic {0} on {1}", topic, connInfo);
topicsMap.put(topic, receiver);
}
}
}
}
}
}
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class JMSAccessorService method destroy.
@Override
public void destroy() {
LOG.info("Destroying JMSAccessor service ");
receiversMap.clear();
LOG.info("Closing JMS connections");
for (ConnectionContext conn : connectionMap.values()) {
conn.close();
}
if (jmsProducerConnContext != null) {
jmsProducerConnContext.close();
}
connectionMap.clear();
}
use of org.apache.oozie.jms.ConnectionContext 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.jms.ConnectionContext 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());
}
}
Aggregations