Java Code Examples for kafka.zk.KafkaZkClient#getChildren()
The following examples show how to use
kafka.zk.KafkaZkClient#getChildren() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerServiceImpl.java From kafka-eagle with Apache License 2.0 | 6 votes |
/** Statistics topic partitions total used as page. */ public long partitionNumbers(String clusterAlias, String topic) { long count = 0L; if (Kafka.CONSUMER_OFFSET_TOPIC.equals(topic)) { return count; } KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); try { if (zkc.pathExists(BROKER_TOPICS_PATH + "/" + topic + "/partitions")) { Seq<String> subBrokerTopicsPaths = zkc.getChildren(BROKER_TOPICS_PATH + "/" + topic + "/partitions"); count = JavaConversions.seqAsJavaList(subBrokerTopicsPaths).size(); } } catch (Exception e) { LOG.error("Get topic partition numbers has error, msg is " + e.getCause().getMessage()); e.printStackTrace(); } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } return count; }
Example 2
Source File: BrokerServiceImpl.java From kafka-eagle with Apache License 2.0 | 6 votes |
/** Get kafka broker numbers from zookeeper. */ public long brokerNumbers(String clusterAlias) { long count = 0; KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); try { if (zkc.pathExists(BROKER_IDS_PATH)) { Seq<String> subBrokerIdsPaths = zkc.getChildren(BROKER_IDS_PATH); count = JavaConversions.seqAsJavaList(subBrokerIdsPaths).size(); } } catch (Exception e) { LOG.error("Get kafka broker numbers has error, msg is " + e.getCause().getMessage()); e.printStackTrace(); } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } return count; }
Example 3
Source File: BrokerServiceImpl.java From kafka-eagle with Apache License 2.0 | 6 votes |
/** Get topic list {@link #topicList()} include cgroups from zookeeper. */ public List<String> topicList(String clusterAlias) { List<String> topics = new ArrayList<>(); if (SystemConfigUtils.getBooleanProperty(clusterAlias + ".kafka.eagle.sasl.cgroup.enable")) { topics = SystemConfigUtils.getPropertyArrayList(clusterAlias + ".kafka.eagle.sasl.cgroup.topics", ","); } else if (SystemConfigUtils.getBooleanProperty(clusterAlias + ".kafka.eagle.ssl.cgroup.enable")) { topics = SystemConfigUtils.getPropertyArrayList(clusterAlias + ".kafka.eagle.ssl.cgroup.topics", ","); } else { KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); try { if (zkc.pathExists(BROKER_TOPICS_PATH)) { Seq<String> subBrokerTopicsPaths = zkc.getChildren(BROKER_TOPICS_PATH); topics = JavaConversions.seqAsJavaList(subBrokerTopicsPaths); excludeTopic(topics); } } catch (Exception e) { LOG.error("Get topic list has error, msg is " + e.getCause().getMessage()); e.printStackTrace(); } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } } return topics; }
Example 4
Source File: BrokerServiceImpl.java From kafka-eagle with Apache License 2.0 | 6 votes |
/** Get broker id list. */ public List<Object> getBrokerIdList(String clusterAlias) { List<Object> brokerIds = new ArrayList<>(); KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); try { if (zkc.pathExists(BROKER_IDS_PATH)) { Seq<String> subBrokerIdsPaths = zkc.getChildren(BROKER_IDS_PATH); for (String id : JavaConversions.seqAsJavaList(subBrokerIdsPaths)) { brokerIds.add(Integer.parseInt(id)); } } } catch (Exception e) { LOG.error("Get kafka broker id has error, msg is ", e); e.printStackTrace(); } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } return brokerIds; }
Example 5
Source File: KafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 6 votes |
/** * Get kafka active consumer topic. */ public Set<String> getActiveTopic(String clusterAlias, String group) { KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); Set<String> activeTopics = new HashSet<>(); try { Seq<String> topics = zkc.getChildren(CONSUMERS_PATH + "/" + group + OWNERS); for (String topic : JavaConversions.seqAsJavaList(topics)) { activeTopics.add(topic); } } catch (Exception ex) { LOG.error("Get kafka active topic has error, msg is " + ex.getMessage()); LOG.error(ex.getMessage()); } finally { if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } } return activeTopics; }
Example 6
Source File: ZkServiceImpl.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** Zookeeper ls command. */ public String ls(String clusterAlias, String cmd) { String target = ""; KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); boolean status = zkc.pathExists(cmd); if (status) { Seq<String> seq = zkc.getChildren(cmd); target = JavaConversions.seqAsJavaList(seq).toString(); } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } return target; }
Example 7
Source File: KafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** * Obtaining metadata in zookeeper by topic. * * @param topic * Selected condition. * @return List. */ public List<String> findTopicPartition(String clusterAlias, String topic) { KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); Seq<String> brokerTopicsPaths = zkc.getChildren(BROKER_TOPICS_PATH + "/" + topic + "/partitions"); List<String> topicAndPartitions = JavaConversions.seqAsJavaList(brokerTopicsPaths); if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; brokerTopicsPaths = null; } return topicAndPartitions; }
Example 8
Source File: KafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** * Obtaining kafka consumer information from zookeeper. */ public Map<String, List<String>> getConsumers(String clusterAlias) { KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); Map<String, List<String>> consumers = new HashMap<String, List<String>>(); try { Seq<String> subConsumerPaths = zkc.getChildren(CONSUMERS_PATH); List<String> groups = JavaConversions.seqAsJavaList(subConsumerPaths); for (String group : groups) { String path = CONSUMERS_PATH + "/" + group + "/owners"; if (zkc.pathExists(path)) { Seq<String> owners = zkc.getChildren(path); List<String> ownersSerialize = JavaConversions.seqAsJavaList(owners); consumers.put(group, ownersSerialize); } else { LOG.error("Consumer Path[" + path + "] is not exist."); } } } catch (Exception ex) { LOG.error(ex.getMessage()); } finally { if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } } return consumers; }
Example 9
Source File: TestKafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 5 votes |
public List<String> findTopicPartition(String clusterAlias, String topic) { KafkaZkClient zkc = zkPool.getZkClient(clusterAlias); Seq<String> brokerTopicsPaths = zkc.getChildren(BROKER_TOPICS_PATH + "/" + topic + "/partitions"); List<String> topicAndPartitions = JavaConversions.seqAsJavaList(brokerTopicsPaths); if (zkc != null) { zkPool.release(clusterAlias, zkc); zkc = null; } return topicAndPartitions; }
Example 10
Source File: KafkaServiceImpl.java From kafka-eagle with Apache License 2.0 | 4 votes |
/** * Get all broker list from zookeeper. */ public List<BrokersInfo> getAllBrokersInfo(String clusterAlias) { KafkaZkClient zkc = kafkaZKPool.getZkClient(clusterAlias); List<BrokersInfo> targets = new ArrayList<BrokersInfo>(); if (zkc.pathExists(BROKER_IDS_PATH)) { Seq<String> subBrokerIdsPaths = zkc.getChildren(BROKER_IDS_PATH); List<String> brokerIdss = JavaConversions.seqAsJavaList(subBrokerIdsPaths); int id = 0; for (String ids : brokerIdss) { try { Tuple2<Option<byte[]>, Stat> tuple = zkc.getDataAndStat(BROKER_IDS_PATH + "/" + ids); BrokersInfo broker = new BrokersInfo(); broker.setCreated(CalendarUtils.convertUnixTime2Date(tuple._2.getCtime())); broker.setModify(CalendarUtils.convertUnixTime2Date(tuple._2.getMtime())); String tupleString = new String(tuple._1.get()); if (SystemConfigUtils.getBooleanProperty(clusterAlias + ".kafka.eagle.sasl.enable") || SystemConfigUtils.getBooleanProperty(clusterAlias + ".kafka.eagle.ssl.enable")) { String endpoints = JSON.parseObject(tupleString).getString("endpoints"); String tmp = endpoints.split("//")[1]; broker.setHost(tmp.substring(0, tmp.length() - 2).split(":")[0]); broker.setPort(Integer.valueOf(tmp.substring(0, tmp.length() - 2).split(":")[1])); } else { String host = JSON.parseObject(tupleString).getString("host"); int port = JSON.parseObject(tupleString).getInteger("port"); broker.setHost(host); broker.setPort(port); } broker.setJmxPort(JSON.parseObject(tupleString).getInteger("jmx_port")); broker.setId(++id); broker.setIds(ids); targets.add(broker); } catch (Exception ex) { LOG.error(ex.getMessage()); } } } if (zkc != null) { kafkaZKPool.release(clusterAlias, zkc); zkc = null; } return targets; }