code: private Map<String, List<ResourceGrant>> scheduleTasks() {
      fullyScheduled = false;
      long nodeWait = configManager.getLocalityWait(type, LocalityLevel.NODE);
      long rackWait = configManager.getLocalityWait(type, LocalityLevel.RACK);
      int tasksToSchedule = configManager.getGrantsPerIteration();
      Map<String, List<ResourceGrant>> sessionIdToGranted =
          new HashMap<String, List<ResourceGrant>>();
      for (int i = 0; i < tasksToSchedule; i++) {
        ScheduledPair scheduled = scheduleOneTask(nodeWait, rackWait);
        if (scheduled == null) {
          // Cannot find matched request-node anymore. We are done.
          fullyScheduled = true;
          break;
        }
        List<ResourceGrant> granted =
          sessionIdToGranted.get(scheduled.sessionId.toString());
        if (granted == null) {
          granted = new LinkedList<ResourceGrant>();
          sessionIdToGranted.put(scheduled.sessionId.toString(), granted);
        }
        granted.add(scheduled.grant);
      }
      return sessionIdToGranted;
    }
docs: Match requests to nodes.
  
  @return The list of granted resources for each session