code: private MatchedPair matchSessionForNode(
      Session session, LocalityLevel level) {
      if (level == LocalityLevel.NODE || level == LocalityLevel.ANY) {
        Set<Map.Entry<String, NodeContainer>> hostNodesSet =
          nodeSnapshot.runnableHosts();
        for (Map.Entry<String, NodeContainer> hostNodes : hostNodesSet) {
          Iterator<ClusterNode> clusterNodeIt = hostNodes.getValue().iterator();
          while (clusterNodeIt.hasNext()) {
            ClusterNode node = clusterNodeIt.next();
            if (!nodeManager.hasEnoughResource(node)) {
              continue;
            }
            ResourceRequestInfo req = null;
            if (level == LocalityLevel.NODE) {
              req = session.getPendingRequestOnHost(node.getHost(), type);
            } else {
              req = session.getPendingRequestForAny(node.getHost(), type);
            }
            if (req != null) {
              return new MatchedPair(node, req);
            }
          }
        }
      } else if (level == LocalityLevel.RACK) {
        Set<Map.Entry<Node, NodeContainer>> rackNodesSet =
          nodeSnapshot.runnableRacks();
        for (Map.Entry<Node, NodeContainer> rackNodes: rackNodesSet) {
          Node rack = rackNodes.getKey();
          NodeContainer nodes = rackNodes.getValue();
          Iterator<ClusterNode> clusterNodeIt = nodes.iterator();
          while (clusterNodeIt.hasNext()) {
            ClusterNode node = clusterNodeIt.next();
            if (!nodeManager.hasEnoughResource(node)) {
              continue;
            }
            ResourceRequestInfo req = session.getPendingRequestOnRack(
              node.getHost(), rack, type);
            if (req != null) {
              return new MatchedPair(node, req);
            }
          }
        }
      }
      return null;
    }
docs: Find a matching pair of node, request by looping through runnable nodes
  in the node snapshot created earlier. For each node, we make lookups in the
  session to find a suitable request.
  @param session The session
  @param level The locality level at which we are trying to schedule.
  @return A match if found, null if not.