backtype.storm.generated.ClusterSummary Java Examples

The following examples show how to use backtype.storm.generated.ClusterSummary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StormSubmitter.java    From eagle with Apache License 2.0 6 votes vote down vote up
private static boolean topologyNameExists(Map conf, String name) {
    NimbusClient client = NimbusClient.getConfiguredClient(conf);
    try {
        ClusterSummary summary = client.getClient().getClusterInfo();
        for (TopologySummary s : summary.get_topologies()) {
            if (s.get_name().equals(name)) {
                return true;
            }
        }
        return false;

    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
 
Example #2
Source File: JStormHelper.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static void cleanCluster() {
    try {
        NimbusClient client = getNimbusClient(null);

        ClusterSummary clusterSummary = client.getClient().getClusterInfo();

        List<TopologySummary> topologySummaries = clusterSummary.get_topologies();

        KillOptions killOption = new KillOptions();
        killOption.set_wait_secs(1);
        for (TopologySummary topologySummary : topologySummaries) {
            client.getClient().killTopologyWithOpts(topologySummary.get_name(), killOption);
            LOG.info("Successfully kill " + topologySummary.get_name());
        }
    } catch (Exception e) {
        if (client != null) {
            client.close();
            client = null;

        }

        LOG.error("Failed to kill all topology ", e);
    }
}
 
Example #3
Source File: Monitor.java    From jstorm with Apache License 2.0 6 votes vote down vote up
/**
 * @@@ Don't be compatible with Storm
 * 
 *     Here skip the logic
 * @param client
 * @param topology
 * @return
 * @throws Exception
 */
private HashSet<String> getComponents(Nimbus.Client client, String topology) throws Exception {
    HashSet<String> components = new HashSet<String>();
    ClusterSummary clusterSummary = client.getClusterInfo();
    TopologySummary topologySummary = null;
    for (TopologySummary ts : clusterSummary.get_topologies()) {
        if (topology.equals(ts.get_name())) {
            topologySummary = ts;
            break;
        }
    }
    if (topologySummary == null) {
        throw new IllegalArgumentException("topology: " + topology + " not found");
    } else {
        String id = topologySummary.get_id();
        // GetInfoOptions getInfoOpts = new GetInfoOptions();
        // getInfoOpts.set_num_err_choice(NumErrorsChoice.NONE);
        // TopologyInfo info = client.getTopologyInfoWithOpts(id, getInfoOpts);
        // for (ExecutorSummary es: info.get_executors()) {
        // components.add(es.get_component_id());
        // }
    }
    return components;
}
 
Example #4
Source File: list.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    NimbusClient client = null;
    try {
        Map conf = Utils.readStormConfig();
        client = NimbusClient.getConfiguredClient(conf);

        if (args.length > 0 && !StringUtils.isBlank(args[0])) {
            String topologyName = args[0];
            TopologyInfo info = client.getClient().getTopologyInfoByName(topologyName);
            System.out.println("Successfully get topology info \n" + Utils.toPrettyJsonString(info));
        } else {
            ClusterSummary clusterSummary = client.getClient().getClusterInfo();
            System.out.println("Successfully get cluster info \n" + Utils.toPrettyJsonString(clusterSummary));
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
Example #5
Source File: MetricsUtils.java    From storm-benchmark with Apache License 2.0 5 votes vote down vote up
public static TopologySummary getTopologySummary(ClusterSummary cs, String name) {
  for (TopologySummary ts : cs.get_topologies()) {
    if (name.equals(ts.get_name())) {
      return ts;
    }
  }
  return null;
}
 
Example #6
Source File: MetricsUtilsTest.java    From storm-benchmark with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #7
Source File: JStormHelper.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static List<String> getSupervisorHosts() throws Exception {
    try {
        List<String> hosts = new ArrayList<>();
        NimbusClient client = getNimbusClient(null);
        ClusterSummary clusterSummary = client.getClient().getClusterInfo();
        List<SupervisorSummary> supervisorSummaries = clusterSummary.get_supervisors();
        Collections.sort(supervisorSummaries, new Comparator<SupervisorSummary>() {

            @Override
            public int compare(SupervisorSummary o1, SupervisorSummary o2) {
                int o1Left = o1.get_numWorkers() - o1.get_numUsedWorkers();
                int o2Left = o2.get_numWorkers() - o2.get_numUsedWorkers();
                return o1Left - o2Left;
            }

        });

        for (SupervisorSummary supervisorSummary : supervisorSummaries) {
            hosts.add(supervisorSummary.get_host());
        }
        return hosts;
    } catch (Exception e) {
        if (client != null) {
            client.close();
            client = null;
        }

        LOG.error("Failed to kill all topologies ", e);
        throw new RuntimeException(e);
    }

}
 
Example #8
Source File: ClusterInfoBolt.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private void getClusterInfo(Client client) {
    try {
        ClusterSummary clusterSummary = client.getClusterInfo();
        List<SupervisorSummary> supervisorSummaryList = clusterSummary.get_supervisors();
        int totalWorkers = 0;
        int usedWorkers = 0;
        for(SupervisorSummary summary : supervisorSummaryList){
            totalWorkers += summary.get_num_workers() ;
            usedWorkers += summary.get_num_used_workers();
        }
        int freeWorkers = totalWorkers - usedWorkers;
        LOGGER.info("cluster totalWorkers = " + totalWorkers 
                + ", usedWorkers = " + usedWorkers 
                + ", freeWorkers  = " +  freeWorkers);
        
        HttpCatClient.sendMetric("ClusterMonitor", "freeSlots", "avg", String.valueOf(freeWorkers));
        HttpCatClient.sendMetric("ClusterMonitor", "totalSlots", "avg", String.valueOf(totalWorkers));
        
        List<TopologySummary> topologySummaryList = clusterSummary.get_topologies();
        long clusterTPS = 0l;
        for(TopologySummary topology : topologySummaryList){
            long topologyTPS = getTopologyTPS(topology, client);
            clusterTPS += topologyTPS;
            if(topology.get_name().startsWith("ClusterMonitor")){
                continue;
            }
            HttpCatClient.sendMetric(topology.get_name(), topology.get_name() + "-TPS", "avg", String.valueOf(topologyTPS));
        }
        HttpCatClient.sendMetric("ClusterMonitor", "ClusterEmitTPS", "avg", String.valueOf(clusterTPS));
        
    } catch (TException e) {
        initClient(configMap);
        LOGGER.error("get client info error.", e);
    }
    catch(NotAliveException nae){
        LOGGER.warn("topology is dead.", nae);
    }
}
 
Example #9
Source File: Monitor.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public void metrics(Nimbus.Client client, long now, MetricsState state) throws Exception {
    long totalStatted = 0;

    int componentParallelism = 0;
    boolean streamFound = false;
    ClusterSummary clusterSummary = client.getClusterInfo();
    TopologySummary topologySummary = null;
    for (TopologySummary ts : clusterSummary.get_topologies()) {
        if (_topology.equals(ts.get_name())) {
            topologySummary = ts;
            break;
        }
    }
    if (topologySummary == null) {
        throw new IllegalArgumentException("topology: " + _topology + " not found");
    } else {
        // String id = topologySummary.get_id();
        // GetInfoOptions getInfoOpts = new GetInfoOptions();
        // getInfoOpts.set_num_err_choice(NumErrorsChoice.NONE);
        // TopologyInfo info = client.getTopologyInfoWithOpts(id, getInfoOpts);
        // for (ExecutorSummary es: info.get_executors()) {
        // if (_component.equals(es.get_component_id())) {
        // componentParallelism ++;
        // ExecutorStats stats = es.get_stats();
        // if (stats != null) {
        // Map<String,Map<String,Long>> statted =
        // WATCH_EMITTED.equals(_watch) ? stats.get_emitted() : stats.get_transferred();
        // if ( statted != null) {
        // Map<String, Long> e2 = statted.get(":all-time");
        // if (e2 != null) {
        // Long stream = e2.get(_stream);
        // if (stream != null){
        // streamFound = true;
        // totalStatted += stream;
        // }
        // }
        // }
        // }
        // }
        // }
    }

    if (componentParallelism <= 0) {
        HashSet<String> components = getComponents(client, _topology);
        System.out.println("Available components for " + _topology + " :");
        System.out.println("------------------");
        for (String comp : components) {
            System.out.println(comp);
        }
        System.out.println("------------------");
        throw new IllegalArgumentException("component: " + _component + " not found");
    }

    if (!streamFound) {
        throw new IllegalArgumentException("stream: " + _stream + " not found");
    }
    long timeDelta = now - state.getLastTime();
    long stattedDelta = totalStatted - state.getLastStatted();
    state.setLastTime(now);
    state.setLastStatted(totalStatted);
    double throughput = (stattedDelta == 0 || timeDelta == 0) ? 0.0 : ((double) stattedDelta / (double) timeDelta);
    System.out.println(_topology + "\t" + _component + "\t" + componentParallelism + "\t" + _stream + "\t" + timeDelta + "\t" + stattedDelta + "\t"
            + throughput);
}
 
Example #10
Source File: ILocalCluster.java    From jstorm with Apache License 2.0 votes vote down vote up
ClusterSummary getClusterInfo();