@Test
  public void testGetTopologySummary() {
    ClusterSummary cs = mock(ClusterSummary.class);
    TopologySummary ts = mock(TopologySummary.class);
    String tsName = "benchmarks";
    String fakeName = "fake";

    when(cs.get_topologies()).thenReturn(Lists.newArrayList(ts));
    when(ts.get_name()).thenReturn(tsName);

    assertThat(MetricsUtils.getTopologySummary(cs, tsName)).isEqualTo(ts);
    assertThat(MetricsUtils.getTopologySummary(cs, fakeName)).isNull();
  }
  private void printExecutorLocation(Client client) throws Exception {
    ClusterSummary summary = client.getClusterInfo();
    StringBuilder executorBuilder = new StringBuilder();

    for (TopologySummary ts : summary.get_topologies()) {
      String id = ts.get_id();
      TopologyInfo info = client.getTopologyInfo(id);

      executorBuilder.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
      for (ExecutorSummary es : info.get_executors()) {
        executorBuilder.append(
            es.get_executor_info().get_task_start()
                + ","
                + es.get_component_id()
                + ","
                + es.get_host()
                + "\n");
      }
      executorBuilder.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    }

    System.out.println(executorBuilder.toString());
  }
  @Override
  public ApplicationEntity.Status status(
      Application<StormEnvironment, StormTopology> executor, com.typesafe.config.Config config) {
    String appId = config.getString("appId");
    LOG.info("Fetching {} status", appId);
    List<TopologySummary> topologySummaries;
    ApplicationEntity.Status status = null;
    try {
      if (Objects.equals(config.getString("mode"), ApplicationEntity.Mode.CLUSTER.name())) {
        Nimbus.Client stormClient =
            NimbusClient.getConfiguredClient(getStormConfig(config)).getClient();
        topologySummaries = stormClient.getClusterInfo().get_topologies();
      } else {
        topologySummaries = getLocalCluster().getClusterInfo().get_topologies();
      }

      for (TopologySummary topologySummary : topologySummaries) {
        if (topologySummary.get_name().equalsIgnoreCase(appId)) {
          if (topologySummary.get_status().equalsIgnoreCase("ACTIVE")) {
            status = ApplicationEntity.Status.RUNNING;
          } else if (topologySummary.get_status().equalsIgnoreCase("INACTIVE")) {
            status = ApplicationEntity.Status.STOPPED;
          } else if (topologySummary.get_status().equalsIgnoreCase("KILLED")) {
            status = ApplicationEntity.Status.STOPPED;
          } else {
            LOG.error(
                "Unknown storm topology ({}) status: {}",
                topologySummary.get_status(),
                topologySummary.get_status());
          }
        }
      }
      // If not exist, return removed
      if (status == null) {
        status = ApplicationEntity.Status.REMOVED;
      }
    } catch (TException e) {
      LOG.error("Got error to fetch status of {}", appId, e);
      status = ApplicationEntity.Status.UNKNOWN;
    }
    LOG.info("{} status is {}", appId, status);
    return status;
  }
  public boolean metrics(
      Nimbus.Client client, int size, long now, MetricsState state, String message)
      throws Exception {
    ClusterSummary summary = client.getClusterInfo();
    long time = now - state.lastTime;
    state.lastTime = now;
    int numSupervisors = summary.get_supervisors_size();
    int totalSlots = 0;
    int totalUsedSlots = 0;

    //////////
    // String namaSupervisor = "";
    for (SupervisorSummary sup : summary.get_supervisors()) {
      totalSlots += sup.get_num_workers();
      totalUsedSlots += sup.get_num_used_workers();
      // namaSupervisor = namaSupervisor + sup.get_host() + ",";
    }
    // System.out.println(namaSupervisor);

    int slotsUsedDiff = totalUsedSlots - state.slotsUsed;
    state.slotsUsed = totalUsedSlots;

    int numTopologies = summary.get_topologies_size();
    long totalTransferred = 0;
    int totalExecutors = 0;
    int executorsWithMetrics = 0;
    for (TopologySummary ts : summary.get_topologies()) {
      String id = ts.get_id();
      TopologyInfo info = client.getTopologyInfo(id);

      //// SOE Addition
      PerftestWriter.print(summary, info, new HashMap<String, Long>());
      ////

      for (ExecutorSummary es : info.get_executors()) {
        ExecutorStats stats = es.get_stats();
        totalExecutors++;
        if (stats != null) {
          Map<String, Map<String, Long>> transferred = stats.get_emitted(); /* .get_transferred();*/
          if (transferred != null) {
            Map<String, Long> e2 = transferred.get(":all-time");
            if (e2 != null) {
              executorsWithMetrics++;
              // The SOL messages are always on the default stream, so just count those
              Long dflt = e2.get("default");
              if (dflt != null) {
                totalTransferred += dflt;
              }
            }
          }
        }
      }
    }
    // long transferredDiff = totalTransferred - state.transferred;
    state.transferred = totalTransferred;
    // double throughput = (transferredDiff == 0 || time == 0) ? 0.0 : (transferredDiff *
    // size)/(1024.0 * 1024.0)/(time/1000.0);
    // System.out.println(message+"\t"+numTopologies+"\t"+totalSlots+"\t"+totalUsedSlots+"\t"+totalExecutors+"\t"+executorsWithMetrics+"\t"+now+"\t"+time+"\t"+transferredDiff+"\t"+throughput);
    System.out.println(
        message
            + ","
            + totalSlots
            + ","
            + totalUsedSlots
            + ","
            + totalExecutors
            + ","
            + executorsWithMetrics
            + ","
            + time);
    if ("WAITING".equals(message)) {
      // System.err.println(" !("+totalUsedSlots+" > 0 && "+slotsUsedDiff+" == 0 &&
      // "+totalExecutors+" > 0 && "+executorsWithMetrics+" >= "+totalExecutors+")");
    }
    return !(totalUsedSlots > 0
        && slotsUsedDiff == 0
        && totalExecutors > 0
        && executorsWithMetrics >= totalExecutors);
  }