Search in sources :

Example 6 with NormalizedResourceRequest

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

the class Nimbus method addSpoutAggStats.

/**
 * If aggStats are not populated, compute common and component(spout) 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 spout AggStats
 * @param topology     storm topology used to get spout names
 * @param topoConf     storm topology config
 */
private void addSpoutAggStats(TopologyPageInfo topoPageInfo, StormTopology topology, Map<String, Object> topoConf) {
    Map<String, NormalizedResourceRequest> spoutResources = ResourceUtils.getSpoutsResources(topology, topoConf);
    // if agg stats were not populated yet, create placeholder
    if (topoPageInfo.get_id_to_spout_agg_stats().isEmpty()) {
        for (Entry<String, SpoutSpec> entry : topology.get_spouts().entrySet()) {
            String spoutName = entry.getKey();
            SpoutSpec spoutSpec = entry.getValue();
            // component
            ComponentAggregateStats placeholderComponentStats = new ComponentAggregateStats();
            placeholderComponentStats.set_type(ComponentType.SPOUT);
            // common aggregate
            CommonAggregateStats commonStats = getPlaceholderCommonAggregateStats(spoutSpec);
            commonStats.set_resources_map(spoutResources.getOrDefault(spoutName, new NormalizedResourceRequest()).toNormalizedMap());
            placeholderComponentStats.set_common_stats(commonStats);
            // spout aggregate
            SpoutAggregateStats spoutAggStats = new SpoutAggregateStats();
            spoutAggStats.set_complete_latency_ms(0);
            SpecificAggregateStats specificStats = new SpecificAggregateStats();
            specificStats.set_spout(spoutAggStats);
            placeholderComponentStats.set_specific_stats(specificStats);
            topoPageInfo.get_id_to_spout_agg_stats().put(spoutName, placeholderComponentStats);
        }
    } else {
        for (Entry<String, ComponentAggregateStats> entry : topoPageInfo.get_id_to_spout_agg_stats().entrySet()) {
            CommonAggregateStats commonStats = entry.getValue().get_common_stats();
            setResourcesDefaultIfNotSet(spoutResources, entry.getKey(), topoConf);
            commonStats.set_resources_map(spoutResources.get(entry.getKey()).toNormalizedMap());
        }
    }
}
Also used : NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) SpoutSpec(org.apache.storm.generated.SpoutSpec) SpecificAggregateStats(org.apache.storm.generated.SpecificAggregateStats) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) SpoutAggregateStats(org.apache.storm.generated.SpoutAggregateStats) CommonAggregateStats(org.apache.storm.generated.CommonAggregateStats)

Example 7 with NormalizedResourceRequest

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

the class Nimbus method getComponentPageInfo.

@Override
public ComponentPageInfo getComponentPageInfo(String topoId, String componentId, String window, boolean includeSys) throws NotAliveException, AuthorizationException, TException {
    try {
        getComponentPageInfoCalls.mark();
        CommonTopoInfo info = getCommonTopoInfo(topoId, "getComponentPageInfo");
        if (info.base == null) {
            throw new WrappedNotAliveException(topoId);
        }
        StormTopology topology = info.topology;
        Map<String, Object> topoConf = info.topoConf;
        topoConf = Utils.merge(conf, topoConf);
        Assignment assignment = info.assignment;
        Map<List<Long>, List<Object>> exec2NodePort = new HashMap<>();
        Map<String, String> nodeToHost;
        Map<List<Long>, List<Object>> exec2HostPort = new HashMap<>();
        if (assignment != null) {
            Map<List<Long>, NodeInfo> execToNodeInfo = assignment.get_executor_node_port();
            nodeToHost = assignment.get_node_host();
            for (Entry<List<Long>, NodeInfo> entry : execToNodeInfo.entrySet()) {
                NodeInfo ni = entry.getValue();
                List<Object> nodePort = Arrays.asList(ni.get_node(), ni.get_port_iterator().next());
                List<Object> hostPort = Arrays.asList(nodeToHost.get(ni.get_node()), ni.get_port_iterator().next());
                exec2NodePort.put(entry.getKey(), nodePort);
                exec2HostPort.put(entry.getKey(), hostPort);
            }
        } else {
            nodeToHost = Collections.emptyMap();
        }
        ComponentPageInfo compPageInfo = StatsUtil.aggCompExecsStats(exec2HostPort, info.taskToComponent, info.beats, window, includeSys, topoId, topology, componentId);
        if (compPageInfo.get_component_type() == ComponentType.SPOUT) {
            NormalizedResourceRequest spoutResources = ResourceUtils.getSpoutResources(topology, topoConf, componentId);
            if (spoutResources == null) {
                spoutResources = new NormalizedResourceRequest(topoConf, componentId);
            }
            compPageInfo.set_resources_map(spoutResources.toNormalizedMap());
        } else {
            // bolt
            NormalizedResourceRequest boltResources = ResourceUtils.getBoltResources(topology, topoConf, componentId);
            if (boltResources == null) {
                boltResources = new NormalizedResourceRequest(topoConf, componentId);
            }
            compPageInfo.set_resources_map(boltResources.toNormalizedMap());
        }
        compPageInfo.set_topology_name(info.topoName);
        compPageInfo.set_errors(stormClusterState.errors(topoId, componentId));
        compPageInfo.set_topology_status(extractStatusStr(info.base));
        if (info.base.is_set_component_debug()) {
            DebugOptions debug = info.base.get_component_debug().get(componentId);
            if (debug != null) {
                compPageInfo.set_debug_options(debug);
            }
        }
        // Add the event logger details.
        Map<String, List<Integer>> compToTasks = Utils.reverseMap(info.taskToComponent);
        if (compToTasks.containsKey(StormCommon.EVENTLOGGER_COMPONENT_ID)) {
            List<Integer> tasks = compToTasks.get(StormCommon.EVENTLOGGER_COMPONENT_ID);
            tasks.sort(null);
            // Find the task the events from this component route to.
            int taskIndex = TupleUtils.chooseTaskIndex(Collections.singletonList(componentId), tasks.size());
            int taskId = tasks.get(taskIndex);
            String host = null;
            Integer port = null;
            for (Entry<List<Long>, List<Object>> entry : exec2HostPort.entrySet()) {
                int start = entry.getKey().get(0).intValue();
                int end = entry.getKey().get(1).intValue();
                if (taskId >= start && taskId <= end) {
                    host = (String) entry.getValue().get(0);
                    port = ((Number) entry.getValue().get(1)).intValue();
                    break;
                }
            }
            if (host != null && port != null) {
                compPageInfo.set_eventlog_host(host);
                compPageInfo.set_eventlog_port(port);
            }
        }
        return compPageInfo;
    } catch (Exception e) {
        LOG.warn("getComponentPageInfo exception. (topo id='{}')", topoId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.storm.thrift.TException) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) DebugOptions(org.apache.storm.generated.DebugOptions) Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) ArrayList(java.util.ArrayList) List(java.util.List) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) DataPoint(org.apache.storm.metric.api.DataPoint) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException) ComponentPageInfo(org.apache.storm.generated.ComponentPageInfo) NodeInfo(org.apache.storm.generated.NodeInfo)

Example 8 with NormalizedResourceRequest

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

the class Cluster method freeSlot.

/**
 * Free the specified slot.
 *
 * @param slot the slot to free
 */
public void freeSlot(WorkerSlot slot) {
    // remove the slot from the existing assignments
    final String nodeId = slot.getNodeId();
    for (SchedulerAssignmentImpl assignment : assignments.values()) {
        if (assignment.isSlotOccupied(slot)) {
            final String topologyId = assignment.getTopologyId();
            assertValidTopologyForModification(topologyId);
            assignment.unassignBySlot(slot);
            topoIdToNodeIdToSlotIdToExecutors.computeIfAbsent(topologyId, Cluster::makeMap).computeIfAbsent(nodeId, Cluster::makeMap).computeIfAbsent(slot.getId(), Cluster::makeSet).clear();
            TopologyDetails td = topologies.getById(topologyId);
            assignment.setTotalSharedOffHeapNodeMemory(nodeId, calculateSharedOffHeapNodeMemory(nodeId, td));
            nodeToScheduledResourcesCache.computeIfAbsent(nodeId, Cluster::makeMap).put(slot, new NormalizedResourceRequest());
            nodeToUsedSlotsCache.computeIfAbsent(nodeId, Cluster::makeSet).remove(slot);
        }
    }
    // Invalidate the cache as something on the node changed
    totalResourcesPerNodeCache.remove(nodeId);
}
Also used : NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest)

Example 9 with NormalizedResourceRequest

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

the class TopologyDetails method addDefaultResforExec.

/**
 * Add default resource requirements for a executor.
 */
private void addDefaultResforExec(ExecutorDetails exec) {
    String componentId = getExecutorToComponent().get(exec);
    addResourcesForExec(exec, new NormalizedResourceRequest(topologyConf, componentId));
}
Also used : NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest)

Example 10 with NormalizedResourceRequest

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

the class TestNodeSorterHostProximity method testAntiAffinityWithMultipleTopologies.

/**
 * Schedule two topologies, once with special resources and another without.
 * There are enough special resources to hold one topology with special resource ("my.gpu").
 * If the sort order is incorrect, scheduling will not succeed.
 */
@Test
public void testAntiAffinityWithMultipleTopologies() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisorsWithRacks(1, 40, 66, 0, 0, 4700, 226200, new HashMap<>());
    HashMap<String, Double> extraResources = new HashMap<>();
    extraResources.put("my.gpu", 1.0);
    supMap.putAll(genSupervisorsWithRacks(1, 40, 66, 1, 0, 4700, 226200, extraResources));
    Config config = new Config();
    config.putAll(createGrasClusterConfig(88, 775, 25, null, null));
    IScheduler scheduler = new ResourceAwareScheduler();
    scheduler.prepare(config, new StormMetricsRegistry());
    TopologyDetails tdSimple = genTopology("topology-simple", config, 1, 5, 100, 300, 0, 0, "user", 8192);
    // Schedule the simple topology first
    Topologies topologies = new Topologies(tdSimple);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
    {
        NodeSorterHostProximity nodeSorter = new NodeSorterHostProximity(cluster, tdSimple);
        for (ExecutorDetails exec : tdSimple.getExecutors()) {
            nodeSorter.prepare(exec);
            List<ObjectResourcesItem> sortedRacks = StreamSupport.stream(nodeSorter.getSortedRacks().spliterator(), false).collect(Collectors.toList());
            String rackSummaries = StreamSupport.stream(sortedRacks.spliterator(), false).map(x -> String.format("Rack %s -> scheduled-cnt %d, min-avail %f, avg-avail %f, cpu %f, mem %f", x.id, nodeSorter.getScheduledExecCntByRackId().getOrDefault(x.id, new AtomicInteger(-1)).get(), x.minResourcePercent, x.avgResourcePercent, x.availableResources.getTotalCpu(), x.availableResources.getTotalMemoryMb())).collect(Collectors.joining("\n\t"));
            NormalizedResourceRequest topoResourceRequest = tdSimple.getApproximateTotalResources();
            String topoRequest = String.format("Topo %s, approx-requested-resources %s", tdSimple.getId(), topoResourceRequest.toString());
            Assert.assertEquals(rackSummaries + "\n# of racks sorted", 2, sortedRacks.size());
            Assert.assertEquals(rackSummaries + "\nFirst rack sorted", "rack-000", sortedRacks.get(0).id);
            Assert.assertEquals(rackSummaries + "\nSecond rack sorted", "rack-001", sortedRacks.get(1).id);
        }
    }
    scheduler.schedule(topologies, cluster);
    TopologyBuilder builder = topologyBuilder(1, 5, 100, 300);
    builder.setBolt("gpu-bolt", new TestBolt(), 40).addResource("my.gpu", 1.0).shuffleGrouping("spout-0");
    TopologyDetails tdGpu = topoToTopologyDetails("topology-gpu", config, builder.createTopology(), 0, 0, "user", 8192);
    // Now schedule GPU but with the simple topology in place.
    topologies = new Topologies(tdSimple, tdGpu);
    cluster = new Cluster(cluster, topologies);
    {
        NodeSorterHostProximity nodeSorter = new NodeSorterHostProximity(cluster, tdGpu);
        for (ExecutorDetails exec : tdGpu.getExecutors()) {
            String comp = tdGpu.getComponentFromExecutor(exec);
            nodeSorter.prepare(exec);
            List<ObjectResourcesItem> sortedRacks = StreamSupport.stream(nodeSorter.getSortedRacks().spliterator(), false).collect(Collectors.toList());
            String rackSummaries = sortedRacks.stream().map(x -> String.format("Rack %s -> scheduled-cnt %d, min-avail %f, avg-avail %f, cpu %f, mem %f", x.id, nodeSorter.getScheduledExecCntByRackId().getOrDefault(x.id, new AtomicInteger(-1)).get(), x.minResourcePercent, x.avgResourcePercent, x.availableResources.getTotalCpu(), x.availableResources.getTotalMemoryMb())).collect(Collectors.joining("\n\t"));
            NormalizedResourceRequest topoResourceRequest = tdSimple.getApproximateTotalResources();
            String topoRequest = String.format("Topo %s, approx-requested-resources %s", tdSimple.getId(), topoResourceRequest.toString());
            Assert.assertEquals(rackSummaries + "\n# of racks sorted", 2, sortedRacks.size());
            if (comp.equals("gpu-bolt")) {
                Assert.assertEquals(rackSummaries + "\nFirst rack sorted for " + comp, "rack-001", sortedRacks.get(0).id);
                Assert.assertEquals(rackSummaries + "\nSecond rack sorted for " + comp, "rack-000", sortedRacks.get(1).id);
            } else {
                Assert.assertEquals(rackSummaries + "\nFirst rack sorted for " + comp, "rack-000", sortedRacks.get(0).id);
                Assert.assertEquals(rackSummaries + "\nSecond rack sorted for " + comp, "rack-001", sortedRacks.get(1).id);
            }
        }
    }
    scheduler.schedule(topologies, cluster);
    Map<String, SchedulerAssignment> assignments = new TreeMap<>(cluster.getAssignments());
    assertEquals(2, assignments.size());
    Map<String, Map<String, AtomicLong>> topoPerRackCount = new HashMap<>();
    for (Map.Entry<String, SchedulerAssignment> entry : assignments.entrySet()) {
        SchedulerAssignment sa = entry.getValue();
        Map<String, AtomicLong> slotsPerRack = new TreeMap<>();
        for (WorkerSlot slot : sa.getSlots()) {
            String nodeId = slot.getNodeId();
            String rack = supervisorIdToRackName(nodeId);
            slotsPerRack.computeIfAbsent(rack, (r) -> new AtomicLong(0)).incrementAndGet();
        }
        LOG.info("{} => {}", entry.getKey(), slotsPerRack);
        topoPerRackCount.put(entry.getKey(), slotsPerRack);
    }
    Map<String, AtomicLong> simpleCount = topoPerRackCount.get("topology-simple-0");
    assertNotNull(simpleCount);
    // Because the simple topology was scheduled first we want to be sure that it didn't put anything on
    // the GPU nodes.
    // Only 1 rack is in use
    assertEquals(1, simpleCount.size());
    // r001 is the second rack with GPUs
    assertFalse(simpleCount.containsKey("r001"));
    // r000 is the first rack with no GPUs
    assertTrue(simpleCount.containsKey("r000"));
// We don't really care too much about the scheduling of topology-gpu-0, because it was scheduled.
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) Arrays(java.util.Arrays) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) DefaultResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategy) LoggerFactory(org.slf4j.LoggerFactory) RasNodes(org.apache.storm.scheduler.resource.RasNodes) INimbus(org.apache.storm.scheduler.INimbus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Map(java.util.Map) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) DNSToSwitchMapping(org.apache.storm.networktopography.DNSToSwitchMapping) Collection(java.util.Collection) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) Assert.assertFalse(org.junit.Assert.assertFalse) Config(org.apache.storm.Config) ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) IScheduler(org.apache.storm.scheduler.IScheduler) HashMap(java.util.HashMap) BaseResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.BaseResourceAwareStrategy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Topologies(org.apache.storm.scheduler.Topologies) NormalizedResourcesExtension(org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension) StreamSupport(java.util.stream.StreamSupport) LinkedList(java.util.LinkedList) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) GenericResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.GenericResourceAwareStrategy) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Cluster(org.apache.storm.scheduler.Cluster) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) ObjectResourcesItem(org.apache.storm.scheduler.resource.strategies.scheduling.ObjectResourcesItem) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Topologies(org.apache.storm.scheduler.Topologies) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TreeMap(java.util.TreeMap) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) AtomicLong(java.util.concurrent.atomic.AtomicLong) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IScheduler(org.apache.storm.scheduler.IScheduler) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test)

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