Java Code Examples for org.apache.flink.runtime.concurrent.FutureUtils#completeAll()

The following examples show how to use org.apache.flink.runtime.concurrent.FutureUtils#completeAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Void> closeMetricSystem() {
	synchronized (lock) {
		final ArrayList<CompletableFuture<Void>> terminationFutures = new ArrayList<>(2);

		// metrics shutdown
		if (metricRegistry != null) {
			terminationFutures.add(metricRegistry.shutdown());
			metricRegistry = null;
		}

		if (metricQueryServiceActorSystem != null) {
			terminationFutures.add(AkkaUtils.terminateActorSystem(metricQueryServiceActorSystem));
		}

		return FutureUtils.completeAll(terminationFutures);
	}
}
 
Example 2
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private CompletionStage<Void> terminateRpcServices() {
	synchronized (lock) {
		final int numRpcServices = 1 + rpcServices.size();

		final Collection<CompletableFuture<?>> rpcTerminationFutures = new ArrayList<>(numRpcServices);

		rpcTerminationFutures.add(commonRpcService.stopService());

		for (RpcService rpcService : rpcServices) {
			rpcTerminationFutures.add(rpcService.stopService());
		}

		commonRpcService = null;
		rpcServices.clear();

		return FutureUtils.completeAll(rpcTerminationFutures);
	}
}
 
Example 3
Source File: MiniCluster.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private CompletionStage<Void> terminateRpcServices() {
	synchronized (lock) {
		final int numRpcServices = 1 + rpcServices.size();

		final Collection<CompletableFuture<?>> rpcTerminationFutures = new ArrayList<>(numRpcServices);

		rpcTerminationFutures.add(commonRpcService.stopService());

		for (RpcService rpcService : rpcServices) {
			rpcTerminationFutures.add(rpcService.stopService());
		}

		commonRpcService = null;
		rpcServices.clear();

		return FutureUtils.completeAll(rpcTerminationFutures);
	}
}
 
Example 4
Source File: MiniCluster.java    From flink with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Void> closeMetricSystem() {
	synchronized (lock) {
		final ArrayList<CompletableFuture<Void>> terminationFutures = new ArrayList<>(2);

		if (processMetricGroup != null) {
			processMetricGroup.close();
			processMetricGroup = null;
		}

		// metrics shutdown
		if (metricRegistry != null) {
			terminationFutures.add(metricRegistry.shutdown());
			metricRegistry = null;
		}

		return FutureUtils.completeAll(terminationFutures);
	}
}
 
Example 5
Source File: MiniCluster.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private CompletableFuture<Void> terminateRpcServices() {
	synchronized (lock) {
		final int numRpcServices = 1 + rpcServices.size();

		final Collection<CompletableFuture<?>> rpcTerminationFutures = new ArrayList<>(numRpcServices);

		rpcTerminationFutures.add(commonRpcService.stopService());

		for (RpcService rpcService : rpcServices) {
			rpcTerminationFutures.add(rpcService.stopService());
		}

		commonRpcService = null;
		rpcServices.clear();

		return FutureUtils.completeAll(rpcTerminationFutures);
	}
}
 
Example 6
Source File: JobMaster.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Suspend the job and shutdown all other services including rpc.
 */
@Override
public CompletableFuture<Void> onStop() {
	log.info("Stopping the JobMaster for job {}({}).", jobGraph.getName(), jobGraph.getJobID());

	// disconnect from all registered TaskExecutors
	final Set<ResourceID> taskManagerResourceIds = new HashSet<>(registeredTaskManagers.keySet());
	final FlinkException cause = new FlinkException("Stopping JobMaster for job " + jobGraph.getName() +
		'(' + jobGraph.getJobID() + ").");

	for (ResourceID taskManagerResourceId : taskManagerResourceIds) {
		disconnectTaskManager(taskManagerResourceId, cause);
	}

	// make sure there is a graceful exit
	suspendExecution(new FlinkException("JobManager is shutting down."));

	// shut down will internally release all registered slots
	slotPool.close();

	final CompletableFuture<Void> disposeInternalSavepointFuture;

	if (lastInternalSavepoint != null) {
		disposeInternalSavepointFuture = CompletableFuture.runAsync(() -> disposeSavepoint(lastInternalSavepoint));
	} else {
		disposeInternalSavepointFuture = CompletableFuture.completedFuture(null);
	}

	return FutureUtils.completeAll(Collections.singletonList(disposeInternalSavepointFuture));
}
 
Example 7
Source File: MiniCluster.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> closeMetricSystem() {
	synchronized (lock) {
		final ArrayList<CompletableFuture<Void>> terminationFutures = new ArrayList<>(2);

		// metrics shutdown
		if (metricRegistry != null) {
			terminationFutures.add(metricRegistry.shutdown());
			metricRegistry = null;
		}

		return FutureUtils.completeAll(terminationFutures);
	}
}
 
Example 8
Source File: DefaultDispatcherRunner.java    From flink with Apache License 2.0 5 votes vote down vote up
private void stopDispatcherLeaderProcess() {
	final CompletableFuture<Void> terminationFuture = dispatcherLeaderProcess.closeAsync();
	previousDispatcherLeaderProcessTerminationFuture = FutureUtils.completeAll(
		Arrays.asList(
			previousDispatcherLeaderProcessTerminationFuture,
			terminationFuture));
}
 
Example 9
Source File: DispatcherRunnerLeaderElectionLifecycleManager.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> closeAsync() {
	final CompletableFuture<Void> servicesTerminationFuture = stopServices();
	final CompletableFuture<Void> dispatcherRunnerTerminationFuture = dispatcherRunner.closeAsync();

	return FutureUtils.completeAll(Arrays.asList(servicesTerminationFuture, dispatcherRunnerTerminationFuture));
}
 
Example 10
Source File: Dispatcher.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private CompletableFuture<Void> terminateJobManagerRunnersAndGetTerminationFuture() {
	terminateJobManagerRunners();
	final Collection<CompletableFuture<Void>> values = jobManagerTerminationFutures.values();
	return FutureUtils.completeAll(values);
}
 
Example 11
Source File: Dispatcher.java    From flink with Apache License 2.0 4 votes vote down vote up
private CompletableFuture<Void> terminateJobManagerRunnersAndGetTerminationFuture() {
	terminateJobManagerRunners();
	final Collection<CompletableFuture<Void>> values = jobManagerTerminationFutures.values();
	return FutureUtils.completeAll(values);
}
 
Example 12
Source File: MiniCluster.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the mini cluster, failing all currently executing jobs.
 * The mini cluster can be started again by calling the {@link #start()} method again.
 *
 * <p>This method shuts down all started services and components,
 * even if an exception occurs in the process of shutting down some component.
 *
 * @return Future which is completed once the MiniCluster has been completely shut down
 */
@Override
public CompletableFuture<Void> closeAsync() {
	synchronized (lock) {
		if (running) {
			LOG.info("Shutting down Flink Mini Cluster");
			try {
				final long shutdownTimeoutMillis = miniClusterConfiguration.getConfiguration().getLong(ClusterOptions.CLUSTER_SERVICES_SHUTDOWN_TIMEOUT);
				final int numComponents = 2 + miniClusterConfiguration.getNumTaskManagers();
				final Collection<CompletableFuture<Void>> componentTerminationFutures = new ArrayList<>(numComponents);

				componentTerminationFutures.addAll(terminateTaskExecutors());

				componentTerminationFutures.add(shutDownResourceManagerComponents());

				final FutureUtils.ConjunctFuture<Void> componentsTerminationFuture = FutureUtils.completeAll(componentTerminationFutures);

				final CompletableFuture<Void> metricSystemTerminationFuture = FutureUtils.composeAfterwards(
					componentsTerminationFuture,
					this::closeMetricSystem);

				final CompletableFuture<Void> rpcServicesTerminationFuture = FutureUtils.composeAfterwards(
					metricSystemTerminationFuture,
					this::terminateRpcServices);

				final CompletableFuture<Void> remainingServicesTerminationFuture = FutureUtils.runAfterwards(
					rpcServicesTerminationFuture,
					this::terminateMiniClusterServices);

				final CompletableFuture<Void> executorsTerminationFuture = FutureUtils.composeAfterwards(
					remainingServicesTerminationFuture,
					() -> terminateExecutors(shutdownTimeoutMillis));

				executorsTerminationFuture.whenComplete(
						(Void ignored, Throwable throwable) -> {
							if (throwable != null) {
								terminationFuture.completeExceptionally(ExceptionUtils.stripCompletionException(throwable));
							} else {
								terminationFuture.complete(null);
							}
						});
			} finally {
				running = false;
			}
		}

		return terminationFuture;
	}
}
 
Example 13
Source File: Dispatcher.java    From flink with Apache License 2.0 4 votes vote down vote up
private CompletableFuture<Void> terminateJobManagerRunnersAndGetTerminationFuture() {
	terminateJobManagerRunners();
	final Collection<CompletableFuture<Void>> values = jobManagerTerminationFutures.values();
	return FutureUtils.completeAll(values);
}