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); }
@Override public Collection<Node> takeNodesBySlots(int slotsNeeded) { HashSet<Node> ret = new HashSet<>(); for (Entry<String, Set<Node>> entry : _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { Iterator<Node> it = entry.getValue().iterator(); while (it.hasNext()) { Node n = it.next(); if (n.isAlive()) { it.remove(); _usedNodes--; n.freeAllSlots(_cluster); ret.add(n); slotsNeeded -= n.totalSlots(); if (slotsNeeded <= 0) { return ret; } } } } } return ret; }
@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); }
@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); }
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); }
@Override public Collection<Node> takeNodesBySlots(int slotsNeeded) { HashSet<Node> ret = new HashSet<>(); for (Entry<String, Set<Node>> entry: _topologyIdToNodes.entrySet()) { if (!_isolated.contains(entry.getKey())) { Iterator<Node> it = entry.getValue().iterator(); while (it.hasNext()) { Node n = it.next(); if (n.isAlive()) { it.remove(); _usedNodes--; n.freeAllSlots(_cluster); ret.add(n); slotsNeeded -= n.totalSlots(); if (slotsNeeded <= 0) { return ret; } } } } } return ret; }
@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); }
@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); }