use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.
the class HCatAccessorService method getJMSConnectionInfo.
/**
* Given a publisher host:port return the connection details of JMS server that the publisher
* publishes to
*
* @param publisherURI URI of the publisher
* @return JMSConnectionInfo to connect to the JMS server that the publisher publishes to
*/
public JMSConnectionInfo getJMSConnectionInfo(URI publisherURI) {
String publisherAuthority = publisherURI.getAuthority();
JMSConnectionInfo connInfo = null;
if (publisherJMSConnInfoMap.containsKey(publisherAuthority)) {
connInfo = publisherJMSConnInfoMap.get(publisherAuthority);
} else {
String schemeWithAuthority = publisherURI.getScheme() + "://" + publisherAuthority;
for (MappingRule mr : mappingRules) {
String jndiPropertiesString = mr.applyRule(schemeWithAuthority);
if (jndiPropertiesString != null) {
connInfo = new JMSConnectionInfo(jndiPropertiesString);
publisherJMSConnInfoMap.put(publisherAuthority, connInfo);
LOG.info("Adding hcat server [{0}] to the list of JMS publishers", schemeWithAuthority);
break;
}
}
if (connInfo == null && defaultJMSConnInfo != null) {
connInfo = defaultJMSConnInfo;
publisherJMSConnInfoMap.put(publisherAuthority, defaultJMSConnInfo);
LOG.info("Adding hcat server [{0}] to the list of JMS publishers", schemeWithAuthority);
} else {
nonJMSPublishers.add(publisherAuthority);
LOG.info("Adding hcat server [{0}] to the list of non JMS publishers", schemeWithAuthority);
}
}
return connInfo;
}
use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.
the class HCatAccessorService method initializeMappingRules.
private void initializeMappingRules() {
String[] connections = ConfigurationService.getStrings(conf, JMS_CONNECTIONS_PROPERTIES);
if (connections != null) {
mappingRules = new ArrayList<MappingRule>(connections.length);
for (String connection : connections) {
String[] values = connection.split("=", 2);
String key = values[0].trim();
String value = values[1].trim();
if (key.equals("default")) {
defaultJMSConnInfo = new JMSConnectionInfo(value);
} else {
mappingRules.add(new MappingRule(key, value));
}
}
} else {
LOG.warn("No JMS connection defined");
}
}
use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.
the class HCatAccessorService method unregisterFromNotification.
public void unregisterFromNotification(HCatURI hcatURI) {
String topic = registeredTopicsMap.remove(getKeyForRegisteredTopicsMap(hcatURI));
if (topic != null) {
JMSConnectionInfo connInfo = getJMSConnectionInfo(hcatURI.getURI());
jmsService.unregisterFromNotification(connInfo, topic);
}
}
use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.
the class TestHCatAccessorService method testGetJMSConnectionInfo.
@Test
public void testGetJMSConnectionInfo() throws Exception {
services.destroy();
services = super.setupServicesForHCatalog();
Configuration conf = services.getConf();
String server1 = "default=java.naming.factory.initial#org.apache.activemq.jndi.ActiveMQInitialContextFactory;" + "java.naming.provider.url#vm://localhost?broker.persistent=false";
String server2 = "hcat://${1}.${2}.server.com:8020=java.naming.factory.initial#Dummy.Factory;" + "java.naming.provider.url#tcp://broker.${2}:61616";
String server3 = "hcat://xyz.corp.dummy.com=java.naming.factory.initial#Dummy.Factory;" + "java.naming.provider.url#tcp:localhost:61616";
String jmsConnectionURL = server1 + "," + server2 + "," + server3;
conf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, jmsConnectionURL);
services.init();
HCatAccessorService hcatService = services.get(HCatAccessorService.class);
JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcatserver.blue.server.com:8020"));
// rules will be applied
assertEquals("java.naming.factory.initial#Dummy.Factory;java.naming.provider.url#tcp://broker.blue:61616", connInfo.getJNDIPropertiesString());
connInfo = hcatService.getJMSConnectionInfo(new URI("http://unknown:9999/fs"));
// will map to default
assertEquals("java.naming.factory.initial#org.apache.activemq.jndi.ActiveMQInitialContextFactory;" + "java.naming.provider.url#vm://localhost?broker.persistent=false", connInfo.getJNDIPropertiesString());
connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://xyz.corp.dummy.com"));
assertEquals("java.naming.factory.initial#Dummy.Factory;java.naming.provider.url#tcp:localhost:61616", connInfo.getJNDIPropertiesString());
}
use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.
the class TestJMSAccessorService method testConnectionRetry.
@Test
public void testConnectionRetry() throws Exception {
services.destroy();
services = super.setupServicesForHCatalog();
int randomPort = 30000 + random.nextInt(10000);
String brokerURl = "tcp://localhost:" + randomPort;
Configuration servicesConf = services.getConf();
servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
servicesConf.set(JMSAccessorService.CONF_RETRY_MAX_ATTEMPTS, "3");
servicesConf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, "default=java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURl + ";" + "connectionFactoryNames#" + "ConnectionFactory");
services.init();
HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
JMSAccessorService jmsService = Services.get().get(JMSAccessorService.class);
String publisherAuthority = "hcat.server.com:5080";
String topic = "topic.topic1";
JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(publisherAuthority));
assertFalse(jmsService.isListeningToTopic(connInfo, topic));
assertTrue(jmsService.isConnectionInRetryList(connInfo));
assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
// Start the broker and check if listening to topic now
BrokerService broker = new BrokerService();
broker.addConnector(brokerURl);
broker.setDataDirectory(getTestCaseDir());
broker.start();
Thread.sleep(1000);
assertTrue(jmsService.isListeningToTopic(connInfo, topic));
assertFalse(jmsService.isConnectionInRetryList(connInfo));
assertFalse(jmsService.isTopicInRetryList(connInfo, topic));
broker.stop();
jmsService.destroy();
}
Aggregations