Esempio n. 1
0
    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");
      }
    }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
    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();
    }
Esempio n. 4
0
  public static void main(String[] args) {

    StatusArgs statusArgs = new StatusArgs();
    Tools.parseArgs(statusArgs, args);

    List<Cluster> clusterStatus = new ArrayList<Cluster>();
    List<Stream> streamStatus = new ArrayList<Stream>();

    try {
      ZkClient zkClient = new ZkClient(statusArgs.zkConnectionString, statusArgs.timeout);
      zkClient.setZkSerializer(new ZNRecordSerializer());

      List<String> clusters = statusArgs.clusters;
      if (clusters == null) {
        // Load all subclusters
        clusters = zkClient.getChildren("/s4/clusters");
      }

      Set<String> app = null;
      Set<String> requiredAppCluster = new HashSet<String>();
      if (statusArgs.apps != null) {
        app = new HashSet<String>(statusArgs.apps);
      }

      for (String clusterName : clusters) {
        try {
          if (zkClient.exists("/s4/clusters/" + clusterName)) {
            Cluster cluster = new Cluster(clusterName, zkClient);
            if (app == null || app.contains(cluster.app.name)) {
              clusterStatus.add(cluster);
              requiredAppCluster.add(cluster.clusterName);
            }
          } else {
            logger.error("/s4/clusters/" + clusterName + " doesn't exist");
          }
        } catch (Exception e) {
          logger.error("Cannot get the status of " + clusterName, e);
        }
      }

      List<String> streams = statusArgs.streams;
      if (streams == null) {
        // Load all streams published
        streams = zkClient.getChildren("/s4/streams");
      }

      for (String streamName : streams) {
        try {
          if (zkClient.exists("/s4/streams/" + streamName)) {
            Stream stream = new Stream(streamName, zkClient);
            if (app == null) {
              streamStatus.add(stream);
            } else {
              for (String cluster : requiredAppCluster) {
                if (stream.containsCluster(cluster)) {
                  streamStatus.add(stream);
                  break;
                }
              }
            }
          } else {
            logger.error("/s4/streams/" + streamName + " doesn't exist");
          }
        } catch (Exception e) {
          logger.error("Cannot get the status of " + streamName, e);
        }
      }

      System.out.println();
      showAppsStatus(clusterStatus);
      System.out.println("\n\n");
      showClustersStatus(clusterStatus);
      System.out.println("\n\n");
      showStreamsStatus(streamStatus);
      System.out.println("\n\n");

    } catch (Exception e) {
      logger.error("Cannot get the status of S4", e);
    }
  }