예제 #1
0
 /**
  * Get any runnable node that is not one of the excluded nodes
  *
  * @param excluded the list of nodes to ignore
  * @return the runnable node, null if no runnable node can be found
  */
 public ClusterNode getRunnableNodeForAny(Set<String> excluded) {
   double avgLoad = loadManager.getAverageLoad(type);
   // Make two passes over the nodes. In the first pass, try to find a
   // node that has lower than average number of grants on it. If that does
   // not find a node, try looking at all nodes.
   for (int pass = 0; pass < 2; pass++) {
     for (Map.Entry<String, NodeContainer> e : hostToRunnableNodes.entrySet()) {
       NodeContainer nodeContainer = e.getValue();
       if (nodeContainer == null) {
         continue;
       }
       synchronized (nodeContainer) {
         if (nodeContainer.isEmpty()) {
           continue;
         }
         for (ClusterNode node : nodeContainer) {
           if (excluded == null || !excluded.contains(node.getHost())) {
             if (resourceLimit.hasEnoughResource(node)) {
               // When pass == 0, try to average out the load.
               if (pass == 0) {
                 if (node.getGrantCount(type) < avgLoad) {
                   return node;
                 }
               } else {
                 return node;
               }
             }
           }
         }
       }
     }
   }
   return null;
 }