Search in sources :

Example 21 with NormalizedResourceRequest

use of org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest in project storm by apache.

the class Nimbus method addBoltAggStats.

/**
 * If aggStats are not populated, compute common and component(bolt) agg and create placeholder stat.
 * This allow the topology page to show component spec even the topo is not scheduled.
 * Otherwise, just fetch data from current topoPageInfo.
 *
 * @param topoPageInfo  topology page info holding bolt AggStats
 * @param topology      storm topology used to get bolt names
 * @param topoConf      storm topology config
 * @param includeSys    whether to show system bolts
 */
private void addBoltAggStats(TopologyPageInfo topoPageInfo, StormTopology topology, Map<String, Object> topoConf, boolean includeSys) {
    Map<String, NormalizedResourceRequest> boltResources = ResourceUtils.getBoltsResources(topology, topoConf);
    // if agg stats were not populated yet, create placeholder
    if (topoPageInfo.get_id_to_bolt_agg_stats().isEmpty()) {
        for (Entry<String, Bolt> entry : topology.get_bolts().entrySet()) {
            String boltName = entry.getKey();
            Bolt bolt = entry.getValue();
            if ((!includeSys && Utils.isSystemId(boltName)) || boltName.equals(Constants.SYSTEM_COMPONENT_ID)) {
                continue;
            }
            // component
            ComponentAggregateStats placeholderComponentStats = new ComponentAggregateStats();
            placeholderComponentStats.set_type(ComponentType.BOLT);
            // common aggregate
            CommonAggregateStats commonStats = getPlaceholderCommonAggregateStats(bolt);
            commonStats.set_resources_map(boltResources.getOrDefault(boltName, new NormalizedResourceRequest()).toNormalizedMap());
            placeholderComponentStats.set_common_stats(commonStats);
            // bolt aggregate
            BoltAggregateStats boltAggStats = new BoltAggregateStats();
            boltAggStats.set_execute_latency_ms(0);
            boltAggStats.set_process_latency_ms(0);
            boltAggStats.set_executed(0);
            boltAggStats.set_capacity(0);
            SpecificAggregateStats specificStats = new SpecificAggregateStats();
            specificStats.set_bolt(boltAggStats);
            placeholderComponentStats.set_specific_stats(specificStats);
            topoPageInfo.get_id_to_bolt_agg_stats().put(boltName, placeholderComponentStats);
        }
    } else {
        for (Entry<String, ComponentAggregateStats> entry : topoPageInfo.get_id_to_bolt_agg_stats().entrySet()) {
            CommonAggregateStats commonStats = entry.getValue().get_common_stats();
            setResourcesDefaultIfNotSet(boltResources, entry.getKey(), topoConf);
            commonStats.set_resources_map(boltResources.get(entry.getKey()).toNormalizedMap());
        }
    }
}
Also used : NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) SpecificAggregateStats(org.apache.storm.generated.SpecificAggregateStats) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) Bolt(org.apache.storm.generated.Bolt) CommonAggregateStats(org.apache.storm.generated.CommonAggregateStats) BoltAggregateStats(org.apache.storm.generated.BoltAggregateStats)

Aggregations

NormalizedResourceRequest (org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest)21 HashMap (java.util.HashMap)12 Map (java.util.Map)10 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Set (java.util.Set)8 Collection (java.util.Collection)7 Config (org.apache.storm.Config)7 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)7 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Collections (java.util.Collections)6 Iterator (java.util.Iterator)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Collectors (java.util.stream.Collectors)6 DNSToSwitchMapping (org.apache.storm.networktopography.DNSToSwitchMapping)6 Cluster (org.apache.storm.scheduler.Cluster)6 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)6