code: private MatchedPair matchNodeForSession(
      Session session, LocalityLevel level) {
      Iterator<ResourceRequestInfo> pendingRequestIterator =
          session.getPendingRequestIteratorForType(type);
      while (pendingRequestIterator.hasNext()) {
        ResourceRequestInfo req = pendingRequestIterator.next();
        Set<String> excluded = req.getExcludeHosts();
        if (req.getHosts() == null || req.getHosts().size() == 0) {
          // No locality requirement
          String host = null;
          ClusterNode node = nodeManager.getRunnableNode(
              host, LocalityLevel.ANY, type, excluded);
          if (node != null) {
            return new MatchedPair(node, req);
          }
          continue;
        }
        for (RequestedNode requestedNode : req.getRequestedNodes()) {
          ClusterNode node = nodeManager.getRunnableNode(
              requestedNode, level, type, excluded);
          if (node != null) {
            return new MatchedPair(node, req);
          }
        }
      }
      return null;
    }
docs: Find a matching pair of node, request by looping through the requests in
  the session, looking at the hosts in each request and making look-ups
  into the node manager.
  @param session The session
  @param level The locality level at which we are trying to schedule.
  @return A match if found, null if not.