/** * Get a runnable node in the given rack that is not present in the excluded list * * @param requestedNode the node to look up rack locality for * @param excluded the list of nodes to ignore * @return the runnable node from the rack satisfying conditions, null if the node was not found */ public ClusterNode getRunnableNodeForRack(RequestedNode requestedNode, Set<String> excluded) { NodeContainer nodeContainer = requestedNode.getRackNodes(); getRunnableNodeForRackCounter += 1; if (nodeContainer == null) { return null; } synchronized (nodeContainer) { if (nodeContainer.isEmpty()) { return null; } if (getRunnableNodeForRackCounter % RACK_SHUFFLE_PERIOD == 0) { // This balances more evenly across nodes in a rack nodeContainer.shuffle(); } for (ClusterNode node : nodeContainer) { if (excluded == null || !excluded.contains(node.getHost())) { if (resourceLimit.hasEnoughResource(node)) { return node; } } } } return null; }