public void readClusterFromZk() throws Exception { List<String> processes; List<String> tasks; tasks = zkClient.getChildren(taskPath); processes = zkClient.getChildren(processPath); taskNumber = tasks.size(); for (int i = 0; i < processes.size(); i++) { ZNRecord process = zkClient.readData(processPath + "/" + processes.get(i), true); if (process != null) { int partition = Integer.parseInt(process.getSimpleField("partition")); String host = process.getSimpleField("host"); int port = Integer.parseInt(process.getSimpleField("port")); String taskId = process.getSimpleField("taskId"); ClusterNode node = new ClusterNode(partition, port, host, taskId); nodes.add(node); } } app = new App(); app.cluster = clusterName; try { ZNRecord appRecord = zkClient.readData(appPath); app.name = appRecord.getSimpleField("name"); app.uri = appRecord.getSimpleField("s4r_uri"); } catch (ZkNoNodeException e) { logger.warn(appPath + " doesn't exist"); } }
private void readStreamFromZk() throws Exception { List<String> consumerNodes = zkClient.getChildren(consumerPath); for (String node : consumerNodes) { ZNRecord consumer = zkClient.readData(consumerPath + "/" + node, true); consumers.add(consumer.getSimpleField("clusterName")); } List<String> producerNodes = zkClient.getChildren(producerPath); for (String node : producerNodes) { ZNRecord consumer = zkClient.readData(producerPath + "/" + node, true); producers.add(consumer.getSimpleField("clusterName")); } getAppNames(); }
private static String getApp(String clusterName, ZkClient zkClient) { String appPath = "/s4/clusters/" + clusterName + "/app/s4App"; if (zkClient.exists(appPath)) { ZNRecord appRecord = zkClient.readData("/s4/clusters/" + clusterName + "/app/s4App"); return appRecord.getSimpleField("name"); } return NONE; }