public static int countSlotsUsed(String topId, Collection<Node> nodes) { int total = 0; for (Node n : nodes) { total += n.totalSlotsUsed(topId); } return total; }
public static int slotsAvailable(NodePool[] pools) { int slotsAvailable = 0; for (NodePool pool : pools) { slotsAvailable += pool.slotsAvailable(); } return slotsAvailable; }
@Override public int nodesAvailable() { int total = 0; for (Node n : _nodes) { if (n.isAlive()) total++; } return total; }
@Override public void init(Cluster cluster, Map<String, Node> nodeIdToNode) { super.init(cluster, nodeIdToNode); for (Node n : nodeIdToNode.values()) { if (n.isTotallyFree() && n.isAlive()) { _nodes.add(n); _totalSlots += n.totalSlotsFree(); } } LOG.debug("Found {} nodes with {} slots", _nodes.size(), _totalSlots); }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; LinkedList<Node> sortedNodes = new LinkedList<>(_nodes); Collections.sort(sortedNodes, Node.FREE_NODE_COMPARATOR_DEC); for (Node n : sortedNodes) { if (slotsNeeded <= 0) { break; } if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
public int totalSlots() { return totalSlotsFree() + totalSlotsUsed(); }
public static int countFreeSlotsAlive(Collection<Node> nodes) { int total = 0; for (Node n : nodes) { if (n.isAlive()) { total += n.totalSlotsFree(); } } return total; }
public static int countTotalSlotsAlive(Collection<Node> nodes) { int total = 0; for (Node n : nodes) { if (n.isAlive()) { total += n.totalSlots(); } } return total; }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int slotsFound = 0; int nodesFound = 0; Iterator<Node> it = _nodes.iterator(); while (it.hasNext() && slotsNeeded > 0) { Node n = it.next(); nodesFound++; int totalSlots = n.totalSlots(); slotsFound += totalSlots; slotsNeeded -= totalSlots; } return new NodeAndSlotCounts(nodesFound, slotsFound); }
public static Collection<Node> takeNodesBySlot(int slotsNeeded, NodePool[] pools) { LOG.debug("Trying to grab {} free slots from {}", slotsNeeded, pools); HashSet<Node> ret = new HashSet<>(); for (NodePool pool : pools) { Collection<Node> got = pool.takeNodesBySlots(slotsNeeded); ret.addAll(got); slotsNeeded -= Node.countFreeSlotsAlive(got); LOG.debug("Got {} nodes so far need {} more slots", ret.size(), slotsNeeded); if (slotsNeeded <= 0) { break; } } return ret; }
@Override public int slotsAvailable() { return Node.countTotalSlotsAlive(_nodes); }
public static int nodesAvailable(NodePool[] pools) { int nodesAvailable = 0; for (NodePool pool : pools) { nodesAvailable += pool.nodesAvailable(); } return nodesAvailable; }
@Override public Map config() { return getUserConf(); }
public static int getNodeCountIfSlotsWereTaken(int slots, NodePool[] pools) { LOG.debug("How many nodes to get {} slots from {}", slots, pools); int total = 0; for (NodePool pool : pools) { NodeAndSlotCounts ns = pool.getNodeAndSlotCountIfSlotsWereTaken(slots); total += ns._nodes; slots -= ns._slots; LOG.debug("Found {} nodes so far {} more slots needed", total, slots); if (slots <= 0) { break; } } return total; }
@Override public Collection<Node> takeNodes(int nodesNeeded) { HashSet<Node> ret = new HashSet<>(); Iterator<Node> it = _nodes.iterator(); while (it.hasNext() && nodesNeeded > ret.size()) { Node n = it.next(); ret.add(n); _totalSlots -= n.totalSlotsFree(); it.remove(); } return ret; }
@Override public NodeAndSlotCounts getNodeAndSlotCountIfSlotsWereTaken(int slotsNeeded) { int nodesFound = 0; int slotsFound = 0; for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { for (Node n : entry.getValue()) { if (n.isAlive()) { nodesFound++; int totalSlotsFree = n.totalSlots(); slotsFound += totalSlotsFree; slotsNeeded -= totalSlotsFree; if (slotsNeeded <= 0) { return new NodeAndSlotCounts(nodesFound, slotsFound); } } } } } return new NodeAndSlotCounts(nodesFound, slotsFound); }
private Node findBestNode(Collection<Node> nodes) { Node ret = null; for (Node node : nodes) { if (ret == null) { if (node.totalSlotsFree() > 0) { ret = node; } } else { if (node.totalSlotsFree() > 0) { if (node.totalSlotsUsed() < ret.totalSlotsUsed()) { ret = node; } else if (node.totalSlotsUsed() == ret.totalSlotsUsed()) { if (node.totalSlotsFree() > ret.totalSlotsFree()) { ret = node; } } } } } return ret; }
public static int countSlotsUsed(Collection<Node> nodes) { int total = 0; for (Node n : nodes) { total += n.totalSlotsUsed(); } return total; }
@Override public int slotsAvailable() { int total = 0; for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { total += Node.countTotalSlotsAlive(entry.getValue()); } } return total; }
@Override public int compare(Node o1, Node o2) { return o1.totalSlotsUsed() - o2.totalSlotsUsed(); } };