Search in sources :

Example 1 with ClusterSummary

use of backtype.storm.generated.ClusterSummary in project jstorm by alibaba.

the class JStormHelper method getSupervisorHosts.

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) {
                // TODO Auto-generated method stub
                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 topology ", e);
        throw new RuntimeException(e);
    }
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) ArrayList(java.util.ArrayList) NimbusClient(backtype.storm.utils.NimbusClient) SupervisorSummary(backtype.storm.generated.SupervisorSummary)

Example 2 with ClusterSummary

use of backtype.storm.generated.ClusterSummary in project jstorm by alibaba.

the class Monitor method getComponents.

/**
     * @@@ 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;
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) TopologySummary(backtype.storm.generated.TopologySummary) HashSet(java.util.HashSet)

Example 3 with ClusterSummary

use of backtype.storm.generated.ClusterSummary in project jstorm by alibaba.

the class Monitor method metrics.

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);
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) TopologySummary(backtype.storm.generated.TopologySummary)

Example 4 with ClusterSummary

use of backtype.storm.generated.ClusterSummary in project jstorm by alibaba.

the class ClusterInfoBolt method getClusterInfo.

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);
    }
}
Also used : TException(org.apache.thrift7.TException) NotAliveException(backtype.storm.generated.NotAliveException) ClusterSummary(backtype.storm.generated.ClusterSummary) SupervisorSummary(backtype.storm.generated.SupervisorSummary) TopologySummary(backtype.storm.generated.TopologySummary)

Example 5 with ClusterSummary

use of backtype.storm.generated.ClusterSummary in project jstorm by alibaba.

the class list method main.

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();
        }
    }
}
Also used : ClusterSummary(backtype.storm.generated.ClusterSummary) NimbusClient(backtype.storm.utils.NimbusClient) Map(java.util.Map) TopologyInfo(backtype.storm.generated.TopologyInfo)

Aggregations

ClusterSummary (backtype.storm.generated.ClusterSummary)7 TopologySummary (backtype.storm.generated.TopologySummary)5 SupervisorSummary (backtype.storm.generated.SupervisorSummary)3 NimbusClient (backtype.storm.utils.NimbusClient)3 NotAliveException (backtype.storm.generated.NotAliveException)2 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)1 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)1 KillOptions (backtype.storm.generated.KillOptions)1 NimbusSummary (backtype.storm.generated.NimbusSummary)1 TopologyAssignException (backtype.storm.generated.TopologyAssignException)1 TopologyInfo (backtype.storm.generated.TopologyInfo)1 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)1 SupervisorInfo (com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)1 Assignment (com.alibaba.jstorm.schedule.Assignment)1 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvalidParameterException (java.security.InvalidParameterException)1