Search in sources :

Example 1 with JMSConnectionInfo

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;
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) MappingRule(org.apache.oozie.util.MappingRule)

Example 2 with JMSConnectionInfo

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");
    }
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) MappingRule(org.apache.oozie.util.MappingRule)

Example 3 with JMSConnectionInfo

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);
    }
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo)

Example 4 with JMSConnectionInfo

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());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Example 5 with JMSConnectionInfo

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();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) BrokerService(org.apache.activemq.broker.BrokerService) Test(org.junit.Test)

Aggregations

JMSConnectionInfo (org.apache.oozie.jms.JMSConnectionInfo)17 URI (java.net.URI)10 Test (org.junit.Test)10 Configuration (org.apache.hadoop.conf.Configuration)8 HCatMessageHandler (org.apache.oozie.dependency.hcat.HCatMessageHandler)5 ConnectionContext (org.apache.oozie.jms.ConnectionContext)4 BrokerService (org.apache.activemq.broker.BrokerService)3 DefaultConnectionContext (org.apache.oozie.jms.DefaultConnectionContext)3 MessageReceiver (org.apache.oozie.jms.MessageReceiver)2 HCatURI (org.apache.oozie.util.HCatURI)2 MappingRule (org.apache.oozie.util.MappingRule)2 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 JMSConnectionInfoBean (org.apache.oozie.client.rest.JMSConnectionInfoBean)1 JMSAccessorService (org.apache.oozie.service.JMSAccessorService)1 JMSTopicService (org.apache.oozie.service.JMSTopicService)1