Search in sources :

Example 1 with ClusterSummary

use of org.apache.storm.generated.ClusterSummary in project storm by apache.

the class StormCluster method getSummaries.

public List<TopologySummary> getSummaries() throws TException {
    final ClusterSummary clusterInfo = client.getClusterInfo();
    log.info("Cluster info: " + clusterInfo);
    return clusterInfo.get_topologies();
}
Also used : ClusterSummary(org.apache.storm.generated.ClusterSummary)

Example 2 with ClusterSummary

use of org.apache.storm.generated.ClusterSummary in project storm by apache.

the class UIHelpers method getClusterSummary.

/**
 * Converts thrift call result into map fit for UI/api.
 * @param clusterSummary Obtained from Nimbus.
 * @param user User Making request
 * @param conf Storm Conf
 * @return Cluster Summary for display on UI/monitoring purposes via API
 */
public static Map<String, Object> getClusterSummary(ClusterSummary clusterSummary, String user, Map<String, Object> conf) {
    Map<String, Object> result = new HashMap();
    if (MEMORIZED_VERSIONS.get() == null) {
        // Races are okay this is just to avoid extra work for each page load.
        NavigableMap<String, IVersionInfo> versionsMap = Utils.getAlternativeVersionsMap(conf);
        List<Map<String, String>> versionList = new ArrayList<>();
        for (Map.Entry<String, IVersionInfo> entry : versionsMap.entrySet()) {
            Map<String, String> single = new HashMap<>(toJsonStruct(entry.getValue()));
            single.put("versionMatch", entry.getKey());
            versionList.add(single);
        }
        MEMORIZED_VERSIONS.set(versionList);
    }
    List<Map<String, String>> versions = MEMORIZED_VERSIONS.get();
    if (!versions.isEmpty()) {
        result.put("alternativeWorkerVersions", versions);
    }
    if (MEMORIZED_FULL_VERSION.get() == null) {
        MEMORIZED_FULL_VERSION.set(toJsonStruct(VersionInfo.OUR_FULL_VERSION));
    }
    result.put("user", user);
    result.put("stormVersion", VersionInfo.getVersion());
    result.put("stormVersionInfo", MEMORIZED_FULL_VERSION.get());
    List<SupervisorSummary> supervisorSummaries = clusterSummary.get_supervisors();
    result.put("supervisors", supervisorSummaries.size());
    result.put("topologies", clusterSummary.get_topologies_size());
    int usedSlots = supervisorSummaries.stream().mapToInt(SupervisorSummary::get_num_used_workers).sum();
    result.put("slotsUsed", usedSlots);
    int totalSlots = supervisorSummaries.stream().mapToInt(SupervisorSummary::get_num_workers).sum();
    result.put("slotsTotal", totalSlots);
    result.put("slotsFree", totalSlots - usedSlots);
    List<TopologySummary> topologySummaries = clusterSummary.get_topologies();
    int totalTasks = topologySummaries.stream().mapToInt(TopologySummary::get_num_tasks).sum();
    result.put("tasksTotal", totalTasks);
    int totalExecutors = topologySummaries.stream().mapToInt(TopologySummary::get_num_executors).sum();
    result.put("executorsTotal", totalExecutors);
    double supervisorTotalMemory = supervisorSummaries.stream().mapToDouble(x -> x.get_total_resources().getOrDefault(Constants.COMMON_TOTAL_MEMORY_RESOURCE_NAME, x.get_total_resources().get(Config.SUPERVISOR_MEMORY_CAPACITY_MB))).sum();
    result.put("totalMem", supervisorTotalMemory);
    double supervisorTotalCpu = supervisorSummaries.stream().mapToDouble(x -> x.get_total_resources().getOrDefault(Constants.COMMON_CPU_RESOURCE_NAME, x.get_total_resources().get(Config.SUPERVISOR_CPU_CAPACITY))).sum();
    result.put("totalCpu", supervisorTotalCpu);
    double supervisorUsedMemory = supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_mem).sum();
    result.put("availMem", supervisorTotalMemory - supervisorUsedMemory);
    double supervisorUsedCpu = supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_used_cpu).sum();
    result.put("availCpu", supervisorTotalCpu - supervisorUsedCpu);
    result.put("fragmentedMem", supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_fragmented_mem).sum());
    result.put("fragmentedCpu", supervisorSummaries.stream().mapToDouble(SupervisorSummary::get_fragmented_cpu).sum());
    result.put("schedulerDisplayResource", conf.get(DaemonConfig.SCHEDULER_DISPLAY_RESOURCE));
    result.put("memAssignedPercentUtil", supervisorTotalMemory > 0 ? StatsUtil.floatStr((supervisorUsedMemory * 100.0) / supervisorTotalMemory) : "0.0");
    result.put("cpuAssignedPercentUtil", supervisorTotalCpu > 0 ? StatsUtil.floatStr((supervisorUsedCpu * 100.0) / supervisorTotalCpu) : "0.0");
    result.put("bugtracker-url", conf.get(DaemonConfig.UI_PROJECT_BUGTRACKER_URL));
    result.put("central-log-url", conf.get(DaemonConfig.UI_CENTRAL_LOGGING_URL));
    Map<String, Double> usedGenericResources = new HashMap<>();
    Map<String, Double> totalGenericResources = new HashMap<>();
    for (SupervisorSummary ss : supervisorSummaries) {
        usedGenericResources = NormalizedResourceRequest.addResourceMap(usedGenericResources, ss.get_used_generic_resources());
        totalGenericResources = NormalizedResourceRequest.addResourceMap(totalGenericResources, ss.get_total_resources());
    }
    Map<String, Double> availGenericResources = NormalizedResourceRequest.subtractResourceMap(totalGenericResources, usedGenericResources);
    result.put("availGenerics", prettifyGenericResources(availGenericResources));
    result.put("totalGenerics", prettifyGenericResources(totalGenericResources));
    return result;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) LogLevel(org.apache.storm.generated.LogLevel) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) WebAppUtils(org.apache.storm.utils.WebAppUtils) TopologyHistoryInfo(org.apache.storm.generated.TopologyHistoryInfo) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) Matcher(java.util.regex.Matcher) ReloadableSslContextFactory(org.apache.storm.daemon.common.ReloadableSslContextFactory) Nimbus(org.apache.storm.generated.Nimbus) DaemonConfig(org.apache.storm.DaemonConfig) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Map(java.util.Map) GetInfoOptions(org.apache.storm.generated.GetInfoOptions) IVersionInfo(org.apache.storm.utils.IVersionInfo) CommonAggregateStats(org.apache.storm.generated.CommonAggregateStats) HttpStatus(org.eclipse.jetty.http.HttpStatus) VersionInfo(org.apache.storm.utils.VersionInfo) Server(org.eclipse.jetty.server.Server) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) KillOptions(org.apache.storm.generated.KillOptions) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentPageInfo(org.apache.storm.generated.ComponentPageInfo) Servlet(javax.servlet.Servlet) BoltAggregateStats(org.apache.storm.generated.BoltAggregateStats) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Set(java.util.Set) SpecificAggregateStats(org.apache.storm.generated.SpecificAggregateStats) LogConfig(org.apache.storm.generated.LogConfig) NavigableMap(java.util.NavigableMap) TopologyInfo(org.apache.storm.generated.TopologyInfo) Collectors(java.util.stream.Collectors) TException(org.apache.storm.thrift.TException) Objects(java.util.Objects) Time(org.apache.storm.utils.Time) List(java.util.List) Response(javax.ws.rs.core.Response) ProfileRequest(org.apache.storm.generated.ProfileRequest) SpoutSpec(org.apache.storm.generated.SpoutSpec) Config(org.apache.storm.Config) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ErrorInfo(org.apache.storm.generated.ErrorInfo) RebalanceOptions(org.apache.storm.generated.RebalanceOptions) ProfileAction(org.apache.storm.generated.ProfileAction) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpVersion(org.eclipse.jetty.http.HttpVersion) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) TopologyPageInfo(org.apache.storm.generated.TopologyPageInfo) HashSet(java.util.HashSet) Bolt(org.apache.storm.generated.Bolt) NumErrorsChoice(org.apache.storm.generated.NumErrorsChoice) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Lists(com.google.common.collect.Lists) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) StormTopology(org.apache.storm.generated.StormTopology) JSONValue(org.json.simple.JSONValue) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) OwnerResourceSummary(org.apache.storm.generated.OwnerResourceSummary) NodeInfo(org.apache.storm.generated.NodeInfo) LinkedList(java.util.LinkedList) SupervisorPageInfo(org.apache.storm.generated.SupervisorPageInfo) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) NimbusSummary(org.apache.storm.generated.NimbusSummary) AccessLoggingFilter(org.apache.storm.logging.filters.AccessLoggingFilter) Logger(org.slf4j.Logger) WorkerSummary(org.apache.storm.generated.WorkerSummary) StringWriter(java.io.StringWriter) Grouping(org.apache.storm.generated.Grouping) ExecutorAggregateStats(org.apache.storm.generated.ExecutorAggregateStats) TopologyStats(org.apache.storm.generated.TopologyStats) Utils(org.apache.storm.utils.Utils) TopologySpoutLag(org.apache.storm.utils.TopologySpoutLag) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) ExecutorSummary(org.apache.storm.generated.ExecutorSummary) ObjectReader(org.apache.storm.utils.ObjectReader) ServerConnector(org.eclipse.jetty.server.ServerConnector) Constants(org.apache.storm.Constants) TreeMap(java.util.TreeMap) LogLevelAction(org.apache.storm.generated.LogLevelAction) DispatcherType(javax.servlet.DispatcherType) TopologySummary(org.apache.storm.generated.TopologySummary) Comparator(java.util.Comparator) ComponentType(org.apache.storm.generated.ComponentType) Collections(java.util.Collections) SpoutAggregateStats(org.apache.storm.generated.SpoutAggregateStats) ClusterSummary(org.apache.storm.generated.ClusterSummary) StatsUtil(org.apache.storm.stats.StatsUtil) IVersionInfo(org.apache.storm.utils.IVersionInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) TopologySummary(org.apache.storm.generated.TopologySummary) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 3 with ClusterSummary

use of org.apache.storm.generated.ClusterSummary in project storm by apache.

the class Nimbus method getClusterInfoImpl.

private ClusterSummary getClusterInfoImpl() throws Exception {
    IStormClusterState state = stormClusterState;
    Map<String, SupervisorInfo> infos = state.allSupervisorInfo();
    List<SupervisorSummary> summaries = new ArrayList<>(infos.size());
    for (Entry<String, SupervisorInfo> entry : infos.entrySet()) {
        summaries.add(makeSupervisorSummary(entry.getKey(), entry.getValue()));
    }
    int uptime = this.uptime.upTime();
    List<NimbusSummary> nimbuses = state.nimbuses();
    // update the isLeader field for each nimbus summary
    NimbusInfo leader = leaderElector.getLeader();
    for (NimbusSummary nimbusSummary : nimbuses) {
        nimbusSummary.set_uptime_secs(Time.deltaSecs(nimbusSummary.get_uptime_secs()));
        // sometimes Leader election indicates the current nimbus is leader, but the host was recently restarted,
        // and is currently not a leader.
        boolean isLeader = leader.getHost().equals(nimbusSummary.get_host()) && leader.getPort() == nimbusSummary.get_port();
        if (isLeader && this.nimbusHostPortInfo.getHost().equals(leader.getHost()) && !this.isLeader()) {
            isLeader = false;
        }
        nimbusSummary.set_isLeader(isLeader);
    }
    List<TopologySummary> topologySummaries = getTopologySummariesImpl();
    ClusterSummary ret = new ClusterSummary(summaries, topologySummaries, nimbuses);
    return ret;
}
Also used : ClusterSummary(org.apache.storm.generated.ClusterSummary) ArrayList(java.util.ArrayList) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) NimbusSummary(org.apache.storm.generated.NimbusSummary) SupervisorInfo(org.apache.storm.generated.SupervisorInfo) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) DataPoint(org.apache.storm.metric.api.DataPoint) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) TopologySummary(org.apache.storm.generated.TopologySummary) IStormClusterState(org.apache.storm.cluster.IStormClusterState)

Example 4 with ClusterSummary

use of org.apache.storm.generated.ClusterSummary in project storm by apache.

the class TestRebalance method checkTopologyUp.

public boolean checkTopologyUp(String topoName, ILocalCluster cluster) throws TException {
    ClusterSummary sum = cluster.getClusterInfo();
    TopologySummary topoSum = cluster.getTopologySummaryByName(topoName);
    if (topoSum != null) {
        return true;
    }
    return false;
}
Also used : ClusterSummary(org.apache.storm.generated.ClusterSummary) TopologySummary(org.apache.storm.generated.TopologySummary)

Example 5 with ClusterSummary

use of org.apache.storm.generated.ClusterSummary in project storm by apache.

the class MetricsSample method factory.

public static MetricsSample factory(Nimbus.Client client, String topologyName) throws Exception {
    // "************ Sampling Metrics *****************
    ClusterSummary clusterSummary = client.getClusterInfo();
    // get topology info
    TopologySummary topSummary = getTopologySummary(clusterSummary, topologyName);
    int topologyExecutors = topSummary.get_num_executors();
    int topologyWorkers = topSummary.get_num_workers();
    int topologyTasks = topSummary.get_num_tasks();
    TopologyInfo topInfo = client.getTopologyInfo(topSummary.get_id());
    MetricsSample sample = getMetricsSample(topInfo);
    sample.numWorkers = topologyWorkers;
    sample.numExecutors = topologyExecutors;
    sample.numTasks = topologyTasks;
    return sample;
}
Also used : ClusterSummary(org.apache.storm.generated.ClusterSummary) TopologySummary(org.apache.storm.generated.TopologySummary) TopologyInfo(org.apache.storm.generated.TopologyInfo)

Aggregations

ClusterSummary (org.apache.storm.generated.ClusterSummary)7 TopologySummary (org.apache.storm.generated.TopologySummary)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 NimbusSummary (org.apache.storm.generated.NimbusSummary)2 SupervisorSummary (org.apache.storm.generated.SupervisorSummary)2 TopologyInfo (org.apache.storm.generated.TopologyInfo)2 Joiner (com.google.common.base.Joiner)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1