void startDetection() { try { _zkClient.createPersistent(_failedBrokersZkPath); } catch (ZkNodeExistsException znee) { // let it go. } // Load the failed broker information from zookeeper. loadPersistedFailedBrokerList(); // Detect broker failures. detectBrokerFailures(); _zkClient.subscribeChildChanges(ZkUtils.BrokerIdsPath(), new BrokerFailureListener()); }
private int brokerId(ChildData input) { return Integer.parseInt(StringUtils.substringAfter(input.getPath(), ZkUtils.BrokerIdsPath() + "/")); }
private int brokerId(ChildData input) { return Integer.parseInt(StringUtils.substringAfter(input.getPath(), ZkUtils.BrokerIdsPath() + "/")); }
private SimpleConsumer getZkConsumer(int brokerId) { try { Option<String> data = zkUtils.readDataMaybeNull(ZkUtils.BrokerIdsPath() + "/" + brokerId)._1; Map<String, Object> brokerInfo = (Map<String, Object>) JSON.parseFull(data.get()).get(); String host = (String) brokerInfo.get("host"); int port = (int) brokerInfo.get("port"); return new SimpleConsumer(host, port, 10000, 100000, "ConsumerGroupCommand"); } catch (Exception ex) { System.out.println("Could not parse broker info due to " + ex.getMessage()); return null; } }
public List<BrokerInfo> listBrokers() { List<Broker> brokerList = CollectionConvertor.seqConvertJavaList(zkUtils.getAllBrokersInCluster()); return brokerList .parallelStream() .collect(Collectors.toMap(Broker::id, Broker::rack)) .entrySet() .parallelStream() .map( entry -> { String brokerInfoStr = null; try { brokerInfoStr = new String( zkClient.getData().forPath(ZkUtils.BrokerIdsPath() + "/" + entry.getKey())); } catch (Exception e) { e.printStackTrace(); } BrokerInfo brokerInfo = gson.fromJson(brokerInfoStr, BrokerInfo.class); if (entry.getValue().isEmpty()) brokerInfo.setRack(""); else { brokerInfo.setRack(entry.getValue().get()); } brokerInfo.setId(entry.getKey()); return brokerInfo; }) .collect(toList()); }
private SimpleConsumer createSimpleConsumer(Integer brokerId) { try { String brokerInfo = zkClient.readData(ZkUtils.BrokerIdsPath() + "/" + brokerId, true); if (brokerInfo == null) { log.error("Broker clientId %d does not exist", brokerId); return null; } Map<String, Object> map = Resources.jsonMapper.readValue( brokerInfo, new TypeReference<Map<String, Object>>() { } ); String host = (String) map.get("host"); Integer port = (Integer) map.get("port"); return new SimpleConsumer(host, port, 10000, 100000, "KafkaConsumerInfos"); } catch (Exception e) { log.error(e, "Could not parse broker[%d] info", brokerId); return null; } }
brokerPathCache = new PathChildrenCache(curatorFramework, ZkUtils.BrokerIdsPath(), true); brokerPathCache.getListenable().addListener(new BrokerListener()); brokerPathCache.getListenable().addListener((f, e) -> {