@Override public CompletableFuture<Collection<Tuple2<ResourceID, String>>> requestTaskManagerMetricQueryServicePaths(Time timeout) { final ArrayList<CompletableFuture<Optional<Tuple2<ResourceID, String>>>> metricQueryServicePathFutures = new ArrayList<>(taskExecutors.size()); for (Map.Entry<ResourceID, WorkerRegistration<WorkerType>> workerRegistrationEntry : taskExecutors.entrySet()) { final ResourceID tmResourceId = workerRegistrationEntry.getKey(); final WorkerRegistration<WorkerType> workerRegistration = workerRegistrationEntry.getValue(); final TaskExecutorGateway taskExecutorGateway = workerRegistration.getTaskExecutorGateway(); final CompletableFuture<Optional<Tuple2<ResourceID, String>>> metricQueryServicePathFuture = taskExecutorGateway .requestMetricQueryServiceAddress(timeout) .thenApply(optional -> optional.map(path -> Tuple2.of(tmResourceId, path))); metricQueryServicePathFutures.add(metricQueryServicePathFuture); } return FutureUtils.combineAll(metricQueryServicePathFutures).thenApply( collection -> collection .stream() .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList())); }
@Override public CompletableFuture<Collection<Tuple2<ResourceID, String>>> requestTaskManagerMetricQueryServicePaths(Time timeout) { final ArrayList<CompletableFuture<Optional<Tuple2<ResourceID, String>>>> metricQueryServicePathFutures = new ArrayList<>(taskExecutors.size()); for (Map.Entry<ResourceID, WorkerRegistration<WorkerType>> workerRegistrationEntry : taskExecutors.entrySet()) { final ResourceID tmResourceId = workerRegistrationEntry.getKey(); final WorkerRegistration<WorkerType> workerRegistration = workerRegistrationEntry.getValue(); final TaskExecutorGateway taskExecutorGateway = workerRegistration.getTaskExecutorGateway(); final CompletableFuture<Optional<Tuple2<ResourceID, String>>> metricQueryServicePathFuture = taskExecutorGateway .requestMetricQueryServiceAddress(timeout) .thenApply(optional -> optional.map(path -> Tuple2.of(tmResourceId, path))); metricQueryServicePathFutures.add(metricQueryServicePathFuture); } return FutureUtils.combineAll(metricQueryServicePathFutures).thenApply( collection -> collection .stream() .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList())); }
private CompletableFuture<Boolean> tryAcceptLeadershipAndRunJobs(UUID newLeaderSessionID, Collection<JobGraph> recoveredJobs) { final DispatcherId dispatcherId = DispatcherId.fromUuid(newLeaderSessionID); if (leaderElectionService.hasLeadership(newLeaderSessionID)) { log.debug("Dispatcher {} accepted leadership with fencing token {}. Start recovered jobs.", getAddress(), dispatcherId); setNewFencingToken(dispatcherId); Collection<CompletableFuture<?>> runFutures = new ArrayList<>(recoveredJobs.size()); for (JobGraph recoveredJob : recoveredJobs) { final CompletableFuture<?> runFuture = waitForTerminatingJobManager(recoveredJob.getJobID(), recoveredJob, this::runJob); runFutures.add(runFuture); } return FutureUtils.waitForAll(runFutures).thenApply(ignored -> true); } else { log.debug("Dispatcher {} lost leadership before accepting it. Stop recovering jobs for fencing token {}.", getAddress(), dispatcherId); return CompletableFuture.completedFuture(false); } }
private CompletableFuture<Boolean> tryAcceptLeadershipAndRunJobs(UUID newLeaderSessionID, Collection<JobGraph> recoveredJobs) { final DispatcherId dispatcherId = DispatcherId.fromUuid(newLeaderSessionID); if (leaderElectionService.hasLeadership(newLeaderSessionID)) { log.debug("Dispatcher {} accepted leadership with fencing token {}. Start recovered jobs.", getAddress(), dispatcherId); setNewFencingToken(dispatcherId); Collection<CompletableFuture<?>> runFutures = new ArrayList<>(recoveredJobs.size()); for (JobGraph recoveredJob : recoveredJobs) { final CompletableFuture<?> runFuture = waitForTerminatingJobManager(recoveredJob.getJobID(), recoveredJob, this::runJob); runFutures.add(runFuture); } return FutureUtils.waitForAll(runFutures).thenApply(ignored -> true); } else { log.debug("Dispatcher {} lost leadership before accepting it. Stop recovering jobs for fencing token {}.", getAddress(), dispatcherId); return CompletableFuture.completedFuture(false); } }