Search in sources :

Example 6 with HCatMessageHandler

use of org.apache.oozie.dependency.hcat.HCatMessageHandler in project oozie by apache.

the class TestHAPartitionDependencyManagerService method addMissingDependencyAndRegister.

protected void addMissingDependencyAndRegister(HCatURI hcatURI, String actionId, PartitionDependencyManagerService pdms) {
    pdms.addMissingDependency(hcatURI, actionId);
    HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
    if (!hcatService.isRegisteredForNotification(hcatURI)) {
        hcatService.registerForNotification(hcatURI, hcatURI.getDb() + "." + hcatURI.getTable(), new HCatMessageHandler(hcatURI.getServer()));
    }
}
Also used : HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler)

Example 7 with HCatMessageHandler

use of org.apache.oozie.dependency.hcat.HCatMessageHandler in project oozie by apache.

the class TestJMSAccessorService method testUnRegisterTopic.

@Test
public void testUnRegisterTopic() {
    try {
        HCatAccessorService hcatService = services.get(HCatAccessorService.class);
        JMSAccessorService jmsService = services.get(JMSAccessorService.class);
        String server = "hcat.server.com:5080";
        String topic = "hcatalog.mydb.mytable";
        JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        assertNotNull(receiver1);
        jmsService.unregisterFromNotification(connInfo, topic);
        receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        assertEquals(null, receiver1);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception encountered : " + e);
    }
}
Also used : HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) MessageReceiver(org.apache.oozie.jms.MessageReceiver) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Example 8 with HCatMessageHandler

use of org.apache.oozie.dependency.hcat.HCatMessageHandler in project oozie by apache.

the class TestJMSAccessorService method testRegisterSingleConsumerPerTopic.

@Test
public void testRegisterSingleConsumerPerTopic() {
    try {
        HCatAccessorService hcatService = services.get(HCatAccessorService.class);
        JMSAccessorService jmsService = services.get(JMSAccessorService.class);
        String server = "hcat.server.com:5080";
        String topic = "hcat.mydb.mytable";
        JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver2 = jmsService.getMessageReceiver(connInfo, topic);
        assertEquals(receiver1, receiver2);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception encountered : " + e);
    }
}
Also used : HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) MessageReceiver(org.apache.oozie.jms.MessageReceiver) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Example 9 with HCatMessageHandler

use of org.apache.oozie.dependency.hcat.HCatMessageHandler 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 10 with HCatMessageHandler

use of org.apache.oozie.dependency.hcat.HCatMessageHandler in project oozie by apache.

the class TestJMSAccessorService method testConnectionRetryMaxAttempt.

@Test
public void testConnectionRetryMaxAttempt() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + "tcp://localhost:12345;connectionFactoryNames#ConnectionFactory";
    Configuration servicesConf = services.getConf();
    servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
    servicesConf.set(JMSAccessorService.CONF_RETRY_MAX_ATTEMPTS, "1");
    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";
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
    jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(publisherAuthority));
    assertTrue(jmsService.isConnectionInRetryList(connInfo));
    assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    assertFalse(jmsService.isListeningToTopic(connInfo, topic));
    Thread.sleep(1100);
    // Should not retry again as max attempt is 1
    assertTrue(jmsService.isConnectionInRetryList(connInfo));
    assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    assertFalse(jmsService.isListeningToTopic(connInfo, topic));
    assertEquals(1, jmsService.getNumConnectionAttempts(connInfo));
    assertFalse(jmsService.retryConnection(connInfo));
    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) Test(org.junit.Test)

Aggregations

HCatMessageHandler (org.apache.oozie.dependency.hcat.HCatMessageHandler)10 Test (org.junit.Test)6 URI (java.net.URI)5 JMSConnectionInfo (org.apache.oozie.jms.JMSConnectionInfo)5 Configuration (org.apache.hadoop.conf.Configuration)3 Message (javax.jms.Message)2 BrokerService (org.apache.activemq.broker.BrokerService)2 HCatEventMessage (org.apache.hive.hcatalog.messaging.HCatEventMessage)2 JSONAddPartitionMessage (org.apache.hive.hcatalog.messaging.json.JSONAddPartitionMessage)2 MessageReceiver (org.apache.oozie.jms.MessageReceiver)2 HCatAccessorService (org.apache.oozie.service.HCatAccessorService)2 PartitionDependencyManagerService (org.apache.oozie.service.PartitionDependencyManagerService)2 HCatURI (org.apache.oozie.util.HCatURI)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MessageProducer (javax.jms.MessageProducer)1 Topic (javax.jms.Topic)1 HCatClient (org.apache.hive.hcatalog.api.HCatClient)1