示例#1
0
  public static boolean hasChildren(ClusterState clusterState, String path) throws Exception {
    if (clusterState == null || path == null) {
      return false;
    }

    List<String> children = clusterState.get_children(path, false);
    return children != null && !children.isEmpty();
  }
示例#2
0
  public static List<ZookeeperNode> listZKNodes(String clusterName, String parent) {
    List<ZookeeperNode> nodes = new ArrayList<>();
    try {
      ClusterState clusterState = getAndCreateClusterState(clusterName);
      if (clusterState == null) {
        throw new IllegalStateException("Cluster state is null");
      }

      List<String> elements = clusterState.get_children(parent, false);
      for (String element : elements) {
        String path = PathUtils.normalize_path(parent + Cluster.ZK_SEPERATOR + element);
        nodes.add(new ZookeeperNode(parent, element, hasChildren(clusterState, path)));
      }
    } catch (Exception e) {
      LOG.error("Get zookeeper info error!", e);
    }
    return nodes;
  }