Search in sources :

Example 6 with JMSConnectionInfo

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

the class HCatAccessorService method unregisterFromNotification.

public void unregisterFromNotification(String server, String database, String table) {
    String key = server + DELIMITER + database + DELIMITER + table;
    String topic = registeredTopicsMap.remove(key);
    if (topic != null) {
        try {
            JMSConnectionInfo connInfo = getJMSConnectionInfo(new URI("hcat://" + server));
            jmsService.unregisterFromNotification(connInfo, topic);
        } catch (URISyntaxException e) {
            LOG.warn("Error unregistering from notification for topic [{0}]. Hcat table=[{1}]", topic, key, e);
        }
    }
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HCatURI(org.apache.oozie.util.HCatURI)

Example 7 with JMSConnectionInfo

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

the class HCatAccessorService method registerForNotification.

/**
 * Register for notifications on a JMS topic for the specified hcatalog table.
 *
 * @param hcatURI hcatalog partition URI
 * @param topic JMS topic to register to
 * @param msgHandler Handler which will process the messages received on the topic
 */
public void registerForNotification(HCatURI hcatURI, String topic, HCatMessageHandler msgHandler) {
    JMSConnectionInfo connInfo = getJMSConnectionInfo(hcatURI.getURI());
    jmsService.registerForNotification(connInfo, topic, msgHandler);
    registeredTopicsMap.put(getKeyForRegisteredTopicsMap(hcatURI), topic);
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo)

Example 8 with JMSConnectionInfo

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

the class V2AdminServlet method getJMSConnectionInfo.

@Override
protected JsonBean getJMSConnectionInfo(HttpServletRequest request, HttpServletResponse response) throws XServletException, IOException {
    Configuration conf = Services.get().getConf();
    JMSTopicService jmsTopicService = Services.get().get(JMSTopicService.class);
    String connectionProperties = conf.get(JMSJobEventListener.JMS_CONNECTION_PROPERTIES);
    if (connectionProperties == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E1601, "JMS connection property is not defined");
    }
    JMSConnectionInfoBean jmsBean = new JMSConnectionInfoBean();
    JMSConnectionInfo jmsInfo = new JMSConnectionInfo(connectionProperties);
    Properties jmsInfoProps = jmsInfo.getJNDIProperties();
    jmsInfoProps.remove("java.naming.security.principal");
    jmsBean.setJNDIProperties(jmsInfoProps);
    if (jmsTopicService != null) {
        jmsBean.setTopicPrefix(jmsTopicService.getTopicPrefix());
        jmsBean.setTopicPatternProperties(jmsTopicService.getTopicPatternProperties());
    } else {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E1601, "JMSTopicService is not initialized. JMS notification" + "may not be enabled");
    }
    return jmsBean;
}
Also used : JMSTopicService(org.apache.oozie.service.JMSTopicService) Configuration(org.apache.hadoop.conf.Configuration) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) Properties(java.util.Properties) JMSConnectionInfoBean(org.apache.oozie.client.rest.JMSConnectionInfoBean)

Example 9 with JMSConnectionInfo

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

the class TestHCatAccessorService method testGetJMSConnectionInfoNoDefault.

@Test
public void testGetJMSConnectionInfoNoDefault() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    Configuration conf = services.getConf();
    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 = server2 + "," + server3;
    conf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, jmsConnectionURL);
    services.init();
    HCatAccessorService hcatService = services.get(HCatAccessorService.class);
    // No default JMS mapping
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("http://unknown:9999/fs"));
    assertNull(connInfo);
    connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://server1.colo1.server.com:8020/db/table/pk1=val1;pk2=val2"));
    assertEquals("java.naming.factory.initial#Dummy.Factory;java.naming.provider.url#tcp://broker.colo1:61616", connInfo.getJNDIPropertiesString());
    connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://xyz.corp.dummy.com/db/table"));
    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 10 with JMSConnectionInfo

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

the class TestJMSAccessorService method testConnectionContext.

@Test
public void testConnectionContext() throws ServiceException {
    try {
        services.destroy();
        services = super.setupServicesForHCatalog();
        Configuration conf = services.getConf();
        // set the connection factory name
        String jmsURL = "hcat://${1}.${2}.server.com:8020=java.naming.factory.initial#" + "org.apache.activemq.jndi.ActiveMQInitialContextFactory" + ";java.naming.provider.url#vm://localhost?broker.persistent=false;" + "connectionFactoryNames#dynamicFactories/hcat.prod.${1}";
        conf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, jmsURL);
        services.init();
        HCatAccessorService hcatService = services.get(HCatAccessorService.class);
        JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcatserver.blue.server.com:8020"));
        assertEquals("java.naming.factory.initial#org.apache.activemq.jndi.ActiveMQInitialContextFactory;java.naming.provider.url#" + "vm://localhost?broker.persistent=false;connectionFactoryNames#dynamicFactories/hcat.prod.hcatserver", connInfo.getJNDIPropertiesString());
        ConnectionContext ctx1 = new DefaultConnectionContext();
        ctx1.createConnection(connInfo.getJNDIProperties());
        BrokerService broker = new BrokerService();
        broker.setDataDirectory(getTestCaseDir());
        // Without this stop testConnectionRetry fails with
        // javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker
        broker.stop();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unexpected exception " + e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) 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