Example #1
0
    /**
     * 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;
    }
Example #2
0
 /**
  * Get runnable node local to the given host
  *
  * @param requestedNode the requested node that needs local scheduling
  * @return the node that is local to the host, null if there are no runnable nodes local to the
  *     host
  */
 public ClusterNode getRunnableNodeForHost(RequestedNode requestedNode) {
   // there should only be one node per host in the common case
   NodeContainer nodeContainer = requestedNode.getHostNodes();
   if (nodeContainer == null) {
     return null;
   }
   synchronized (nodeContainer) {
     if (nodeContainer.isEmpty()) {
       return null;
     }
     for (ClusterNode node : nodeContainer) {
       if (resourceLimit.hasEnoughResource(node)) {
         return node;
       }
     }
   }
   return null;
 }