/** * frees a single executor. * * @param exec is the executor to free * @param topo the topology the executor is a part of */ public void freeSingleExecutor(ExecutorDetails exec, TopologyDetails topo) { Map<String, Collection<ExecutorDetails>> usedSlots = topIdToUsedSlots.get(topo.getId()); if (usedSlots == null) { throw new IllegalArgumentException("Topology " + topo + " is not assigned"); } WorkerSlot ws = null; Set<ExecutorDetails> updatedAssignment = new HashSet<>(); for (Entry<String, Collection<ExecutorDetails>> entry : usedSlots.entrySet()) { if (entry.getValue().contains(exec)) { ws = slots.get(entry.getKey()); updatedAssignment.addAll(entry.getValue()); updatedAssignment.remove(exec); break; } } if (ws == null) { throw new IllegalArgumentException( "Executor " + exec + " is not assinged on this node to " + topo); } free(ws); if (!updatedAssignment.isEmpty()) { assign(ws, topo, updatedAssignment); } }
/** * Assign a single executor to a slot, even if other things are in the slot. * @param ws the slot to assign it to. * @param exec the executor to assign. * @param td the topology for the executor. */ public void assignSingleExecutor(WorkerSlot ws, ExecutorDetails exec, TopologyDetails td) { if (!isAlive) { throw new IllegalStateException("Trying to adding to a dead node " + nodeId); } Collection<WorkerSlot> freeSlots = getFreeSlots(); Set<ExecutorDetails> toAssign = new HashSet<>(); toAssign.add(exec); if (!freeSlots.contains(ws)) { Map<String, Collection<ExecutorDetails>> usedSlots = topIdToUsedSlots.get(td.getId()); if (usedSlots == null) { throw new IllegalArgumentException( "Slot " + ws + " is not availble to schedue " + exec + " on"); } Collection<ExecutorDetails> alreadyHere = usedSlots.get(ws.getId()); if (alreadyHere == null) { throw new IllegalArgumentException( "Slot " + ws + " is not availble to schedue " + exec + " on"); } toAssign.addAll(alreadyHere); free(ws); } assign(ws, td, toAssign); }
ExecutorDetails targetExec = executorIterator.next(); node.assign(targetSlot, topo2, Arrays.asList(targetExec));
ExecutorDetails targetExec = executorIterator.next(); node.assign(targetSlot, topo2, Arrays.asList(targetExec));
node.assign(node.getFreeSlots().iterator().next(), topology1, executors11); assertEquals(1, node.getRunningTopologies().size()); assertFalse(node.isTotallyFree()); node.assign(node.getFreeSlots().iterator().next(), topology1, executors12); assertEquals(1, node.getRunningTopologies().size()); assertFalse(node.isTotallyFree()); node.assign(node.getFreeSlots().iterator().next(), topology2, executors21); assertEquals(2, node.getRunningTopologies().size()); assertFalse(node.isTotallyFree()); node.assign(node.getFreeSlots().iterator().next(), topology2, executors22); assertEquals(2, node.getRunningTopologies().size()); assertFalse(node.isTotallyFree());
targetNode.assign(targetSlot, td, execsNeedScheduling);