/** * Factory method to create instance of {@link KafkaZkConnection} taking into consideration chRoot * * @param zkStringRaw zk connection string as defined in the broker zk property. It has the pattern * "hostname1:port1,hostname2:port2,hostname3:port3/chroot/path" */ public static KafkaZkConnection newInstance(String zkStringRaw) { final String[] split = zkStringRaw.split("/", 2); String zkString; String chRoot; zkString = split[0]; if (split.length > 1) { chRoot = "/" + split[1]; if (!chRoot.endsWith("/")) { chRoot = chRoot + "/"; } } else { chRoot = "/"; } return new KafkaZkConnection(zkString, chRoot); }
public KafkaBrokersInfo<String> getBrokerInfoFromZk() throws ZookeeperClientException, IOException { final String brokerIdsZkPath = kafkaZkConnection.buildZkRootPath(ZK_RELATIVE_PATH_KAFKA_BROKERS_IDS); final List<String> brokerIds = zkCli.getChildren(brokerIdsZkPath); List<String> brokerInfo = null; if (brokerIds != null) { brokerInfo = new ArrayList<>(); for (String bkId : brokerIds) { final byte[] bytes = zkCli.getData(brokerIdsZkPath + "/" + bkId); brokerInfo.add(new String(bytes, "UTF-8")); } } return KafkaBrokersInfo.fromZk(brokerInfo, getSecurity(), getKafkaBrokerListeners()); }
/** * Creates and starts a {@link ZookeeperClient} connection as part of the object construction process. * The connection must be closed. See {@link KafkaMetadataService} */ public static KafkaMetadataService newInstance( EnvironmentService environmentService, Long clusterId, SecurityContext securityContext) throws ServiceConfigurationNotFoundException, IOException, ServiceNotFoundException, ServiceComponentNotFoundException { final KafkaZkConnection kafkaZkConnection = KafkaZkConnection.newInstance( getZkStringRaw(environmentService, clusterId, AMBARI_JSON_CONFIG_KAFKA_BROKER)); final ZookeeperClient zkCli = ZookeeperClient.newInstance(kafkaZkConnection); zkCli.start(); return new KafkaMetadataService(zkCli, kafkaZkConnection, securityContext, getKafkaBrokerComponent(environmentService, clusterId), getKafkaBrokers(environmentService, clusterId), getServiceConfig(environmentService, clusterId, AMBARI_JSON_CONFIG_KAFKA_BROKER), getServiceConfig(environmentService, clusterId, AMBARI_JSON_CONFIG_KAFKA_ENV)); }
public KafkaBrokersInfo<KafkaBrokersInfo.BrokerId> getBrokerIdsFromZk() throws ZookeeperClientException, IOException { final List<String> brokerIds = zkCli.getChildren(kafkaZkConnection.buildZkRootPath(ZK_RELATIVE_PATH_KAFKA_BROKERS_IDS)); return KafkaBrokersInfo.brokerIds(brokerIds, getSecurity(), getKafkaBrokerListeners()); }
public KafkaTopics getTopicsFromZk() throws ZookeeperClientException, IOException { final Security security = getSecurity(); final List<String> topics = zkCli.getChildren(kafkaZkConnection.buildZkRootPath(ZK_RELATIVE_PATH_KAFKA_TOPICS)); return topics == null ? new KafkaTopics(Collections.emptyList(), security) : new KafkaTopics(topics, security); }