code: private ScheduledPair scheduleOneTask(long nodeWait, long rackWait) {
      if (!nodeManager.existRunnableNodes(type)) {
        return null;
      }
  
      Queue<PoolGroupSchedulable> poolGroupQueue =
          poolGroupManager.getScheduleQueue();
      while (!poolGroupQueue.isEmpty()) {
        PoolGroupSchedulable poolGroup = poolGroupQueue.poll();
        if (poolGroup.reachedMaximum()) {
          continue;
        }
        // Get the appropriate pool from the pool group to schedule, then
        // schedule the best session
        Queue<PoolSchedulable> poolQueue = poolGroup.getScheduleQueue();
        while (!poolQueue.isEmpty()) {
          PoolSchedulable pool = poolQueue.poll();
          if (pool.reachedMaximum()) {
            continue;
          }
          Queue<SessionSchedulable> sessionQueue = pool.getScheduleQueue();
          while (!sessionQueue.isEmpty()) {
            SessionSchedulable schedulable = sessionQueue.poll();
            Session session = schedulable.getSession();
            long now = ClusterManager.clock.getTime();
            MatchedPair pair = doMatch(
              schedulable, now, nodeWait, rackWait);
            synchronized (session) {
              if (session.isDeleted()) {
                continue;
              }
              if (pair != null) {
                ResourceGrant grant = commitMatchedResource(session, pair);
                if (grant != null) {
                  poolGroup.incGranted(1);
                  pool.incGranted(1);
                  schedulable.incGranted(1);
                  // Put back to the queue only if we scheduled successfully
                  poolGroupQueue.add(poolGroup);
                  poolQueue.add(pool);
                  sessionQueue.add(schedulable);
                  return new ScheduledPair(
                      session.getSessionId().toString(), grant);
                }
              }
            }
          }
        }
      }
      return null;
    }
docs: Try match one request to one node
  
  @param nodeWait Time to wait for node locality
  @param rackWait Time to wait for rack locality
  @return The pair contains a session id and a granted resource
  or null when no task can be scheduled