@Override public int getAssignedNumWorkers(TopologyDetails topology) { SchedulerAssignment assignment = topology != null ? this.getAssignmentById(topology.getId()) : null; if (assignment == null) { return 0; } Set<WorkerSlot> slots = new HashSet<>(); slots.addAll(assignment.getExecutorToSlot().values()); return slots.size(); }
@Override public void addTopology(TopologyDetails td) { String topId = td.getId(); LOG.debug("Adding in Topology {}", topId); _tds.put(topId, td); SchedulerAssignment assignment = _cluster.getAssignmentById(topId); if (assignment != null) { for (WorkerSlot ws : assignment.getSlots()) { Node n = _nodeIdToNode.get(ws.getNodeId()); _nodes.add(n); } } }
private Map<String, AtomicInteger> getScheduledCount(TopologyDetails topologyDetails) { String topoId = topologyDetails.getId(); SchedulerAssignment assignment = cluster.getAssignmentById(topoId); Map<String, AtomicInteger> scheduledCount = new HashMap<>(); if (assignment != null) { for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : assignment.getSlotToExecutors().entrySet()) { String superId = entry.getKey().getNodeId(); String rackId = superIdToRack.get(superId); scheduledCount.computeIfAbsent(rackId, (rid) -> new AtomicInteger(0)) .getAndAdd(entry.getValue().size()); } } return scheduledCount; }
@Override public Collection<ExecutorDetails> getUnassignedExecutors(TopologyDetails topology) { if (topology == null) { return new ArrayList<>(0); } Collection<ExecutorDetails> ret = new HashSet<>(topology.getExecutors()); SchedulerAssignment assignment = getAssignmentById(topology.getId()); if (assignment != null) { Set<ExecutorDetails> assignedExecutors = assignment.getExecutors(); ret.removeAll(assignedExecutors); } return ret; }
public static Map<WorkerSlot, List<ExecutorDetails>> getAliveAssignedWorkerSlotExecutors(Cluster cluster, String topologyId) { SchedulerAssignment existingAssignment = cluster.getAssignmentById(topologyId); Map<ExecutorDetails, WorkerSlot> executorToSlot = null; if (existingAssignment != null) { executorToSlot = existingAssignment.getExecutorToSlot(); } return Utils.reverseMap(executorToSlot); }
@Override public void addTopology(TopologyDetails td) { String topId = td.getId(); LOG.debug("Adding in Topology {}", topId); SchedulerAssignment assignment = _cluster.getAssignmentById(topId); Set<Node> assignedNodes = new HashSet<>(); if (assignment != null) { for (WorkerSlot ws : assignment.getSlots()) { Node n = _nodeIdToNode.get(ws.getNodeId()); assignedNodes.add(n); } } _usedNodes += assignedNodes.size(); _topologyIdToNodes.put(topId, assignedNodes); _tds.put(topId, td); if (td.getConf().get(Config.TOPOLOGY_ISOLATED_MACHINES) != null) { _isolated.add(topId); } }
public LazyNodeSorting(TopologyDetails td, ExecutorDetails exec, List<String> favoredNodeIds, List<String> unFavoredNodeIds) { this.favoredNodeIds = favoredNodeIds; this.unFavoredNodeIds = unFavoredNodeIds; this.unFavoredNodeIds.removeAll(favoredNodeIds); skippedNodeIds.addAll(favoredNodeIds); skippedNodeIds.addAll(unFavoredNodeIds); this.td = td; this.exec = exec; String topoId = td.getId(); SchedulerAssignment assignment = cluster.getAssignmentById(topoId); if (assignment != null) { for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : assignment.getSlotToExecutors().entrySet()) { String superId = entry.getKey().getNodeId(); perNodeScheduledCount.computeIfAbsent(superId, (sid) -> new AtomicInteger(0)) .getAndAdd(entry.getValue().size()); } } sortedRacks = sortRacks(exec, td); }
private static boolean checkSpreadSchedulingValid(Cluster cluster, TopologyDetails topo) { LOG.info("Checking for a valid scheduling..."); assert (cluster.getAssignmentById(topo.getId()) != null); Map<ExecutorDetails, WorkerSlot> result = cluster.getAssignmentById(topo.getId()).getExecutorToSlot(); Map<ExecutorDetails, String> execToComp = topo.getExecutorToComponent(); Map<WorkerSlot, HashSet<ExecutorDetails>> workerExecMap = new HashMap<>();
/** * Check if constraints are satisfied. */ private static boolean checkConstraintsSatisfied(Cluster cluster, TopologyDetails topo) { LOG.info("Checking constraints..."); assert (cluster.getAssignmentById(topo.getId()) != null); Map<ExecutorDetails, WorkerSlot> result = cluster.getAssignmentById(topo.getId()).getExecutorToSlot(); Map<ExecutorDetails, String> execToComp = topo.getExecutorToComponent(); //get topology constraints Map<String, Map<String, Integer>> constraintMatrix = getConstraintMap(topo, new HashSet<>(topo.getExecutorToComponent().values())); Map<WorkerSlot, Set<String>> workerCompMap = new HashMap<>(); result.forEach((exec, worker) -> { String comp = execToComp.get(exec); workerCompMap.computeIfAbsent(worker, (k) -> new HashSet<>()).add(comp); }); for (Map.Entry<WorkerSlot, Set<String>> entry : workerCompMap.entrySet()) { Set<String> comps = entry.getValue(); for (String comp1 : comps) { for (String comp2 : comps) { if (!comp1.equals(comp2) && constraintMatrix.get(comp1).get(comp2) != 0) { LOG.error("Incorrect Scheduling: worker exclusion for Component {} and {} not satisfied on WorkerSlot: {}", comp1, comp2, entry.getKey()); return false; } } } } return true; }
SchedulerAssignment assignment = _cluster.getAssignmentById(_topId); _nodeToComps = new HashMap<>();
@Override public boolean canAdd(TopologyDetails td) { //Only add topologies that are not sharing nodes with other topologies String topId = td.getId(); SchedulerAssignment assignment = _cluster.getAssignmentById(topId); if (assignment != null) { for (WorkerSlot ws : assignment.getSlots()) { Node n = _nodeIdToNode.get(ws.getNodeId()); if (n.getRunningTopologies().size() > 1) { return false; } } } return true; }
SchedulerAssignment existingAssignment = cluster.getAssignmentById(td.getId()); if (existingAssignment != null) { existingAssignment.getExecutorToSlot().forEach((exec, ws) -> {
public static void assertTopologiesFullyScheduled(Cluster cluster, String... topoNames) { Topologies topologies = cluster.getTopologies(); for (String topoName : topoNames) { TopologyDetails td = topologies.getByName(topoName); assert (td != null) : topoName; String topoId = td.getId(); assertStatusSuccess(cluster, topoId); assert (cluster.getAssignmentById(topoId) != null) : topoName; assert (cluster.needsSchedulingRas(td) == false) : topoName; } }
public static void assertTopologiesNotScheduled(Cluster cluster, String... topoNames) { Topologies topologies = cluster.getTopologies(); for (String topoName : topoNames) { TopologyDetails td = topologies.getByName(topoName); assert (td != null) : topoName; String topoId = td.getId(); String status = cluster.getStatus(topoId); assert (status != null) : topoName; assert (!isStatusSuccess(status)) : topoName; assert (cluster.getAssignmentById(topoId) == null) : topoName; assert (cluster.needsSchedulingRas(td)) : topoName; } }
/** * When the first topology failed to be scheduled make sure subsequent schedulings can still succeed */ @Test public void testSchedulingAfterFailedScheduling() { INimbus iNimbus = new INimbusTest(); Map<String, SupervisorDetails> supMap = genSupervisors(8, 4, 100, 1000); Config config = createClusterConfig(100, 500, 500, null); TopologyDetails topo1 = genTopology("topo-1", config, 8, 0, 2, 0, currentTime - 2, 10, "jerry"); TopologyDetails topo2 = genTopology("topo-2", config, 2, 0, 2, 0, currentTime - 2, 20, "jerry"); TopologyDetails topo3 = genTopology("topo-3", config, 1, 2, 1, 1, currentTime - 2, 20, "jerry"); Topologies topologies = new Topologies(topo1, topo2, topo3); Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config); ResourceAwareScheduler rs = new ResourceAwareScheduler(); rs.prepare(config); rs.schedule(topologies, cluster); assertTrue("Topo-2 scheduled?", cluster.getAssignmentById(topo2.getId()) != null); assertEquals("Topo-2 all executors scheduled?", 4, cluster.getAssignmentById(topo2.getId()).getExecutorToSlot().size()); assertTrue("Topo-3 scheduled?", cluster.getAssignmentById(topo3.getId()) != null); assertEquals("Topo-3 all executors scheduled?", 3, cluster.getAssignmentById(topo3.getId()).getExecutorToSlot().size()); }
0, cluster.getUnassignedExecutors(topo).size()); Assert.assertTrue("Valid Scheduling?", ConstraintSolverStrategy.validateSolution(cluster, topo)); LOG.info("Slots Used {}", cluster.getAssignmentById(topo.getId()).getSlots()); LOG.info("Assignment {}", cluster.getAssignmentById(topo.getId()).getSlotToExecutors()); SchedulerAssignment assignment = cluster.getAssignmentById(topo.getId());
@Test public void sanityTestOfScheduling() { INimbus iNimbus = new INimbusTest(); Map<String, SupervisorDetails> supMap = genSupervisors(1, 2, 400, 2000); Config config = new Config(); config.putAll(defaultTopologyConf); ResourceAwareScheduler rs = new ResourceAwareScheduler(); TopologyDetails topology1 = genTopology("topology1", config, 1, 1, 1, 1, 0, 0, "user"); Topologies topologies = new Topologies(topology1); Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config); rs.prepare(config); rs.schedule(topologies, cluster); SchedulerAssignment assignment = cluster.getAssignmentById(topology1.getId()); Set<WorkerSlot> assignedSlots = assignment.getSlots(); Set<String> nodesIDs = new HashSet<>(); for (WorkerSlot slot : assignedSlots) { nodesIDs.add(slot.getNodeId()); } Collection<ExecutorDetails> executors = assignment.getExecutors(); assertEquals(1, assignedSlots.size()); assertEquals(1, nodesIDs.size()); assertEquals(2, executors.size()); assertEquals("Running - Fully Scheduled by DefaultResourceAwareStrategy", cluster.getStatusMap().get(topology1.getId())); }
new ExecutorDetails(5, 5)))); //bolt-3 HashSet<HashSet<ExecutorDetails>> foundScheduling = new HashSet<>(); SchedulerAssignment assignment = cluster.getAssignmentById("testTopology-id"); for (Collection<ExecutorDetails> execs : assignment.getSlotToExecutors().values()) { foundScheduling.add(new HashSet<>(execs));
rs.schedule(topologies, cluster); SchedulerAssignment assignment1 = cluster.getAssignmentById(topology1.getId()); Map<WorkerSlot, WorkerResources> assignedSlots1 = assignment1.getScheduledResources(); double assignedMemory = 0.0;
rs.schedule(topologies, cluster); assertTrue("Topo scheduled?", cluster.getAssignmentById(topo.getId()) != null); assertEquals("Topo all executors scheduled?", 25, cluster.getAssignmentById(topo.getId()).getExecutorToSlot().size());