Esempio n. 1
0
  /**
   * Get a runnable node.
   *
   * @param requestedNode The request information.
   * @param maxLevel The maximum locality level that we can go to.
   * @param type The type of resource.
   * @param excluded The excluded nodes.
   * @return The runnable node that can be used.
   */
  public ClusterNode getRunnableNode(
      RequestedNode requestedNode,
      LocalityLevel maxLevel,
      ResourceType type,
      Set<String> excluded) {
    ClusterNode node = null;
    RunnableIndices r = typeToIndices.get(type);

    // find host local
    node = r.getRunnableNodeForHost(requestedNode);

    if (maxLevel == LocalityLevel.NODE || node != null) {
      return node;
    }
    node = r.getRunnableNodeForRack(requestedNode, excluded);

    if (maxLevel == LocalityLevel.RACK || node != null) {
      return node;
    }

    // find any node
    node = r.getRunnableNodeForAny(excluded);

    return node;
  }
Esempio n. 2
0
 /**
  * Find the best matching node for this host subject to the maxLevel constraint
  *
  * @param host the host of the request
  * @param maxLevel the max locality level to consider
  * @param type the type of resource needed on the node
  * @param excluded the list of nodes to exclude from consideration
  * @return the runnable node satisfying the constraints
  */
 public ClusterNode getRunnableNode(
     String host, LocalityLevel maxLevel, ResourceType type, Set<String> excluded) {
   if (host == null) {
     RunnableIndices r = typeToIndices.get(type);
     return r.getRunnableNodeForAny(excluded);
   }
   RequestedNode node = resolve(host, type);
   return getRunnableNode(node, maxLevel, type, excluded);
 }