Search in sources :

Example 16 with ConnectionContext

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

the class JMSAccessorService method getConnectionContextImpl.

private ConnectionContext getConnectionContextImpl() {
    Class<?> defaultClazz = ConfigurationService.getClass(conf, JMS_CONNECTION_CONTEXT_IMPL);
    ConnectionContext connCtx = null;
    if (defaultClazz == DefaultConnectionContext.class) {
        connCtx = new DefaultConnectionContext();
    } else {
        connCtx = (ConnectionContext) ReflectionUtils.newInstance(defaultClazz, null);
    }
    return connCtx;
}
Also used : DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext)

Example 17 with ConnectionContext

use of org.apache.oozie.jms.ConnectionContext 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)

Example 18 with ConnectionContext

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

the class TestJMSAccessorService method testConnection.

@Test
public void testConnection() throws Exception {
    HCatAccessorService hcatService = services.get(HCatAccessorService.class);
    JMSAccessorService jmsService = services.get(JMSAccessorService.class);
    // both servers should connect to default JMS server
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcatserver.blue.server.com:8020"));
    ConnectionContext ctxt1 = jmsService.createConnectionContext(connInfo);
    assertTrue(ctxt1.isConnectionInitialized());
    JMSConnectionInfo connInfo1 = hcatService.getJMSConnectionInfo(new URI("http://unknown:80"));
    ConnectionContext ctxt2 = jmsService.createConnectionContext(connInfo1);
    assertTrue(ctxt2.isConnectionInitialized());
    assertEquals(ctxt1, ctxt2);
    ctxt1.close();
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) URI(java.net.URI) Test(org.junit.Test)

Example 19 with ConnectionContext

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

the class TestJMSAccessorService method testConnectionRetryExceptionListener.

@Test
public void testConnectionRetryExceptionListener() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    int randomPort = 30000 + random.nextInt(10000);
    String brokerURL = "tcp://localhost:" + randomPort;
    String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURL + ";" + "connectionFactoryNames#" + "ConnectionFactory";
    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=" + jndiPropertiesString);
    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";
    // Start the broker
    BrokerService broker = new BrokerService();
    broker.addConnector(brokerURL);
    broker.setDataDirectory(getTestCaseDir());
    broker.start();
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
    jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(publisherAuthority));
    assertTrue(jmsService.isListeningToTopic(connInfo, topic));
    assertFalse(jmsService.isConnectionInRetryList(connInfo));
    assertFalse(jmsService.isTopicInRetryList(connInfo, topic));
    ConnectionContext connCtxt = jmsService.createConnectionContext(connInfo);
    broker.stop();
    try {
        connCtxt.createSession(Session.AUTO_ACKNOWLEDGE);
        fail("Exception expected");
    } catch (Exception e) {
        Thread.sleep(100);
        assertFalse(jmsService.isListeningToTopic(connInfo, topic));
        assertTrue(jmsService.isConnectionInRetryList(connInfo));
        assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    }
    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) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) Test(org.junit.Test)

Example 20 with ConnectionContext

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

the class TestJMSJobEventListener method getConnectionContext.

private ConnectionContext getConnectionContext() {
    Configuration conf = services.getConf();
    String jmsProps = conf.get(JMSJobEventListener.JMS_CONNECTION_PROPERTIES);
    JMSConnectionInfo connInfo = new JMSConnectionInfo(jmsProps);
    JMSAccessorService jmsService = Services.get().get(JMSAccessorService.class);
    ConnectionContext jmsContext = jmsService.createProducerConnectionContext(connInfo);
    return jmsContext;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) ConnectionContext(org.apache.oozie.jms.ConnectionContext) JMSAccessorService(org.apache.oozie.service.JMSAccessorService)

Aggregations

ConnectionContext (org.apache.oozie.jms.ConnectionContext)24 Test (org.junit.Test)18 ParseException (java.text.ParseException)15 Date (java.util.Date)15 MessageConsumer (javax.jms.MessageConsumer)15 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)15 JMSJobEventListener (org.apache.oozie.jms.JMSJobEventListener)15 DefaultConnectionContext (org.apache.oozie.jms.DefaultConnectionContext)8 WorkflowJobMessage (org.apache.oozie.client.event.message.WorkflowJobMessage)7 CoordinatorActionMessage (org.apache.oozie.client.event.message.CoordinatorActionMessage)5 Configuration (org.apache.hadoop.conf.Configuration)4 JMSConnectionInfo (org.apache.oozie.jms.JMSConnectionInfo)4 URI (java.net.URI)3 BrokerService (org.apache.activemq.broker.BrokerService)3 MessageReceiver (org.apache.oozie.jms.MessageReceiver)2 JMSAccessorService (org.apache.oozie.service.JMSAccessorService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1