code: public List<Container> allocateContainers() throws Exception {
      for (int attempt = 0; attempt < MAX_WORKER_CONTAINER_REQUEST_ATTEMPTS; attempt++) {
        LOG.debug("Attempt {} of {} to allocate containers",
            attempt, MAX_WORKER_CONTAINER_REQUEST_ATTEMPTS);
        int numContainersToRequest = mTargetNumContainers - mAllocatedContainerHosts.size();
        LOG.debug("Requesting {} containers", numContainersToRequest);
        mOutstandingContainerRequestsLatch = new CountDownLatch(numContainersToRequest);
        requestContainers();
        // Wait for all outstanding requests to be responded to before beginning the next round.
        mOutstandingContainerRequestsLatch.await();
        if (mAllocatedContainerHosts.size() == mTargetNumContainers) {
          break;
        }
      }
      if (mAllocatedContainers.size() != mTargetNumContainers) {
        throw new RuntimeException(String.format("Failed to allocate %d %s containers",
            mTargetNumContainers, mContainerName));
      }
      return mAllocatedContainers;
    }
docs: Allocates the containers specified by the constructor.
  
  @return the allocated containers