Source:
private void onContainersOfPriorityAllocated(Priority priority, List<Container> containers) { final Optional<TaskExecutorProcessSpec> taskExecutorProcessSpecOpt = taskExecutorProcessSpecContainerResourcePriorityAdapter.getTaskExecutorProcessSpec(priority); if (!taskExecutorProcessSpecOpt.isPresent()) { log.warn("Receive containers with unrecognized priority {}. This should not happen.", containers.size(), priority.getPriority()); for (Container container : containers) { returnExcessContainer(container); } return; } final TaskExecutorProcessSpec taskExecutorProcessSpec = taskExecutorProcessSpecOpt.get(); final Optional<Resource> resourceOpt = taskExecutorProcessSpecContainerResourcePriorityAdapter.getResource(taskExecutorProcessSpec); Preconditions.checkState(resourceOpt.isPresent()); final Resource resource = resourceOpt.get(); final Queue<CompletableFuture<YarnWorkerNode>> pendingRequestResourceFutures = requestResourceFutures.getOrDefault(taskExecutorProcessSpec, new LinkedList<>()); log.info("Received containers with priority {}, pending container requests.", containers.size(), priority, pendingRequestResourceFutures.size()); final Iterator<Container> containerIterator = containers.iterator(); final Iterator<AMRMClient.ContainerRequest> pendingContainerRequestIterator = getPendingRequestsAndCheckConsistency(priority, resource, pendingRequestResourceFutures.size()).iterator(); int numAccepted = 0; while (containerIterator.hasNext() && pendingContainerRequestIterator.hasNext()) { final Container container = containerIterator.next(); final AMRMClient.ContainerRequest pendingRequest = pendingContainerRequestIterator.next(); final ResourceID resourceId = getContainerResourceId(container); final CompletableFuture<YarnWorkerNode> requestResourceFuture = pendingRequestResourceFutures.poll(); Preconditions.checkState(requestResourceFuture != null); if (pendingRequestResourceFutures.isEmpty()) { requestResourceFutures.remove(taskExecutorProcessSpec); } startTaskExecutorInContainerAsync(container, taskExecutorProcessSpec, resourceId, requestResourceFuture); removeContainerRequest(pendingRequest); numAccepted++; } int numExcess = 0; while (containerIterator.hasNext()) { returnExcessContainer(containerIterator.next()); numExcess++; } log.info("Accepted requested containers, returned excess containers, pending container requests of resource {}.", numAccepted, numExcess, pendingRequestResourceFutures.size(), resource); }

Target:
private void onContainersOfPriorityAllocated(Priority priority, List<Container> containers) { final Optional<TaskExecutorProcessSpecContainerResourcePriorityAdapter.TaskExecutorProcessSpecAndResource> taskExecutorProcessSpecAndResourceOpt = taskExecutorProcessSpecContainerResourcePriorityAdapter.getTaskExecutorProcessSpecAndResource(priority); Preconditions.checkState(taskExecutorProcessSpecAndResourceOpt.isPresent(), "Receive %s containers with unrecognized priority %s. This should not happen.", containers.size(), priority.getPriority()); final TaskExecutorProcessSpec taskExecutorProcessSpec = taskExecutorProcessSpecAndResourceOpt.get().getTaskExecutorProcessSpec(); final Resource resource = taskExecutorProcessSpecAndResourceOpt.get().getResource(); final Queue<CompletableFuture<YarnWorkerNode>> pendingRequestResourceFutures = requestResourceFutures.getOrDefault(taskExecutorProcessSpec, new LinkedList<>()); log.info("Received containers with priority {}, pending container requests.", containers.size(), priority, pendingRequestResourceFutures.size()); final Iterator<Container> containerIterator = containers.iterator(); final Iterator<AMRMClient.ContainerRequest> pendingContainerRequestIterator = getPendingRequestsAndCheckConsistency(priority, resource, pendingRequestResourceFutures.size()).iterator(); int numAccepted = 0; while (containerIterator.hasNext() && pendingContainerRequestIterator.hasNext()) { final Container container = containerIterator.next(); final AMRMClient.ContainerRequest pendingRequest = pendingContainerRequestIterator.next(); final ResourceID resourceId = getContainerResourceId(container); final CompletableFuture<YarnWorkerNode> requestResourceFuture = pendingRequestResourceFutures.poll(); Preconditions.checkState(requestResourceFuture != null); if (pendingRequestResourceFutures.isEmpty()) { requestResourceFutures.remove(taskExecutorProcessSpec); } startTaskExecutorInContainerAsync(container, taskExecutorProcessSpec, resourceId, requestResourceFuture); removeContainerRequest(pendingRequest); numAccepted++; } int numExcess = 0; while (containerIterator.hasNext()) { returnExcessContainer(containerIterator.next()); numExcess++; } log.info("Accepted requested containers, returned excess containers, pending container requests of resource {}.", numAccepted, numExcess, pendingRequestResourceFutures.size(), resource); }