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

The following examples show how to use org.apache.flink.runtime.concurrent.FutureUtils#runAfterwards() . 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: Dispatcher.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Void> onStop() {
	log.info("Stopping dispatcher {}.", getAddress());

	final CompletableFuture<Void> allJobManagerRunnersTerminationFuture = terminateJobManagerRunnersAndGetTerminationFuture();

	return FutureUtils.runAfterwards(
		allJobManagerRunnersTerminationFuture,
		() -> {
			dispatcherBootstrap.stop();

			stopDispatcherServices();

			log.info("Stopped dispatcher {}.", getAddress());
		});
}
 
Example 2
Source File: MesosSessionClusterEntrypoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 3
Source File: MesosJobClusterEntrypoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 4
Source File: Dispatcher.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> onStop() {
	log.info("Stopping dispatcher {}.", getAddress());

	final CompletableFuture<Void> allJobManagerRunnersTerminationFuture = terminateJobManagerRunnersAndGetTerminationFuture();

	return FutureUtils.runAfterwards(
		allJobManagerRunnersTerminationFuture,
		() -> {
			stopDispatcherServices();

			log.info("Stopped dispatcher {}.", getAddress());
		});
}
 
Example 5
Source File: ClusterEntrypoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<ApplicationStatus> shutDownAsync(
		ApplicationStatus applicationStatus,
		@Nullable String diagnostics,
		boolean cleanupHaData) {
	if (isShutDown.compareAndSet(false, true)) {
		LOG.info("Shutting {} down with application status {}. Diagnostics {}.",
			getClass().getSimpleName(),
			applicationStatus,
			diagnostics);

		final CompletableFuture<Void> shutDownApplicationFuture = closeClusterComponent(applicationStatus, diagnostics);

		final CompletableFuture<Void> serviceShutdownFuture = FutureUtils.composeAfterwards(
			shutDownApplicationFuture,
			() -> stopClusterServices(cleanupHaData));

		final CompletableFuture<Void> cleanupDirectoriesFuture = FutureUtils.runAfterwards(
			serviceShutdownFuture,
			this::cleanupDirectories);

		cleanupDirectoriesFuture.whenComplete(
			(Void ignored2, Throwable serviceThrowable) -> {
				if (serviceThrowable != null) {
					terminationFuture.completeExceptionally(serviceThrowable);
				} else {
					terminationFuture.complete(applicationStatus);
				}
			});
	}

	return terminationFuture;
}
 
Example 6
Source File: MesosSessionClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 7
Source File: MesosJobClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 8
Source File: Dispatcher.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> onStop() {
	log.info("Stopping dispatcher {}.", getAddress());

	final CompletableFuture<Void> allJobManagerRunnersTerminationFuture = terminateJobManagerRunnersAndGetTerminationFuture();

	return FutureUtils.runAfterwards(
		allJobManagerRunnersTerminationFuture,
		() -> {
			stopDispatcherServices();

			log.info("Stopped dispatcher {}.", getAddress());
		});
}
 
Example 9
Source File: ClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<ApplicationStatus> shutDownAsync(
		ApplicationStatus applicationStatus,
		@Nullable String diagnostics,
		boolean cleanupHaData) {
	if (isShutDown.compareAndSet(false, true)) {
		LOG.info("Shutting {} down with application status {}. Diagnostics {}.",
			getClass().getSimpleName(),
			applicationStatus,
			diagnostics);

		final CompletableFuture<Void> shutDownApplicationFuture = closeClusterComponent(applicationStatus, diagnostics);

		final CompletableFuture<Void> serviceShutdownFuture = FutureUtils.composeAfterwards(
			shutDownApplicationFuture,
			() -> stopClusterServices(cleanupHaData));

		final CompletableFuture<Void> cleanupDirectoriesFuture = FutureUtils.runAfterwards(
			serviceShutdownFuture,
			this::cleanupDirectories);

		cleanupDirectoriesFuture.whenComplete(
			(Void ignored2, Throwable serviceThrowable) -> {
				if (serviceThrowable != null) {
					terminationFuture.completeExceptionally(serviceThrowable);
				} else {
					terminationFuture.complete(applicationStatus);
				}
			});
	}

	return terminationFuture;
}
 
Example 10
Source File: MesosSessionClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 11
Source File: MesosJobClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<Void> stopClusterServices(boolean cleanupHaData) {
	final CompletableFuture<Void> serviceShutDownFuture = super.stopClusterServices(cleanupHaData);

	return FutureUtils.runAfterwards(
		serviceShutDownFuture,
		() -> {
			if (mesosServices != null) {
				mesosServices.close(cleanupHaData);
			}
		});
}
 
Example 12
Source File: ClusterEntrypoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<ApplicationStatus> shutDownAsync(
		ApplicationStatus applicationStatus,
		@Nullable String diagnostics,
		boolean cleanupHaData) {
	if (isShutDown.compareAndSet(false, true)) {
		LOG.info("Shutting {} down with application status {}. Diagnostics {}.",
			getClass().getSimpleName(),
			applicationStatus,
			diagnostics);

		final CompletableFuture<Void> shutDownApplicationFuture = closeClusterComponent(applicationStatus, diagnostics);

		final CompletableFuture<Void> serviceShutdownFuture = FutureUtils.composeAfterwards(
			shutDownApplicationFuture,
			() -> stopClusterServices(cleanupHaData));

		final CompletableFuture<Void> cleanupDirectoriesFuture = FutureUtils.runAfterwards(
			serviceShutdownFuture,
			this::cleanupDirectories);

		cleanupDirectoriesFuture.whenComplete(
			(Void ignored2, Throwable serviceThrowable) -> {
				if (serviceThrowable != null) {
					terminationFuture.completeExceptionally(serviceThrowable);
				} else {
					terminationFuture.complete(applicationStatus);
				}
			});
	}

	return terminationFuture;
}
 
Example 13
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;
	}
}