@Test public void testGetMessageBusTopicName() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "testGetMessageBusTopicName_DBName"; String tableName = "testGetMessageBusTopicName_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); String messageBusTopicName = "MY.topic.name"; Map<String, String> tableProperties = new HashMap<String, String>(1); tableProperties.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, messageBusTopicName); client.createTable(HCatCreateTableDesc.create(dbName, tableName, Arrays.asList(new HCatFieldSchema("foo", Type.STRING, ""))).tblProps(tableProperties).build()); assertEquals("MessageBus topic-name doesn't match!", messageBusTopicName, client.getMessageBusTopicName(dbName, tableName)); client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.close(); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception:" + exception.getMessage(), false); } }
@Override public void registerForNotification(URI uri, Configuration conf, String user, String actionID) throws URIHandlerException { HCatURI hcatURI; try { hcatURI = new HCatURI(uri); } catch (URISyntaxException e) { throw new URIHandlerException(ErrorCode.E0906, uri, e); } HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class); if (!hcatService.isRegisteredForNotification(hcatURI)) { HCatClient client = getHCatClient(uri, conf); try { String topic = client.getMessageBusTopicName(hcatURI.getDb(), hcatURI.getTable()); if (topic == null) { return; } hcatService.registerForNotification(hcatURI, topic, new HCatMessageHandler(uri.getAuthority())); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } finally { closeQuietly(client, null, true); } } PartitionDependencyManagerService pdmService = Services.get().get(PartitionDependencyManagerService.class); pdmService.addMissingDependency(hcatURI, actionID); }
@Override public void registerForNotification(URI uri, Configuration conf, String user, String actionID) throws URIHandlerException { HCatURI hcatURI; try { hcatURI = new HCatURI(uri); } catch (URISyntaxException e) { throw new URIHandlerException(ErrorCode.E0906, uri, e); } HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class); if (!hcatService.isRegisteredForNotification(hcatURI)) { HCatClient client = getHCatClient(uri, conf); try { String topic = client.getMessageBusTopicName(hcatURI.getDb(), hcatURI.getTable()); if (topic == null) { return; } hcatService.registerForNotification(hcatURI, topic, new HCatMessageHandler(uri.getAuthority())); } catch (HCatException e) { throw new HCatAccessorException(ErrorCode.E1501, e); } finally { closeQuietly(client, null, true); } } PartitionDependencyManagerService pdmService = Services.get().get(PartitionDependencyManagerService.class); pdmService.addMissingDependency(hcatURI, actionID); }