code: private ResourceGrant waitForJTGrant(
        ResourceTracker resourceTracker,
        SessionDriver sessionDriver,
        List<ResourceGrant> previousGrants)
      throws IOException, InterruptedException {
      LOG.info("Waiting for JT grant for " + attemptJobId);
      ResourceRequest req = resourceTracker.newJobTrackerRequest();
      for (ResourceGrant prev: previousGrants) {
        LOG.info("Adding " + prev.getNodeName() + " to excluded hosts");
        req.addToExcludeHosts(prev.getAddress().getHost());
      }
      resourceTracker.recordRequest(req);
      List<ResourceRequest> newRequests = resourceTracker.getWantedResources();
      sessionDriver.requestResources(newRequests);
      final List<ResourceGrant> grants = new ArrayList<ResourceGrant>();
      ResourceTracker.ResourceProcessor proc =
        new ResourceTracker.ResourceProcessor() {
          @Override
          public boolean processAvailableResource(ResourceGrant resource) {
            grants.add(resource);
            final boolean consumed = true;
            return consumed;
          }
        };
      while (true) {
        // Try to get JT grant while periodically checking for session driver
        // exceptions.
        long timeout = 60 * 1000; // 1 min.
        resourceTracker.processAvailableGrants(proc, 1, timeout);
        IOException e = sessionDriver.getFailed();
        if (e != null) {
          throw e;
        }
        if (!grants.isEmpty()) {
          return grants.get(0);
        }
      }
    }
docs: Wait for a JOBTRACKER grant.
  @param resourceTracker The resource tracker object for getting the grant
  @param sessionDriver The session driver for getting the grant
  @param previousGrants Previous grants that could not be used successfully.
  @return A new JOBTRACKER grant.
  @throws IOException
  @throws InterruptedException