You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2018/10/11 07:10:35 UTC

[flink] branch release-1.6 updated (2ee1609 -> 9f593cd)

This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a change to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git.


    from 2ee1609  [FLINK-10379][docs,table] Fix TableFunction docs
     new ad4aa7c  [hotfix] Generify FutureUtils#toJava
     new 580c048  [hotfix] Add AkkaUtils#terminateActorSystem
     new 1cdabab  [FLINK-10247] Run MetricQueryService in separate ActorSystem
     new 1496c44  [FLINK-10247] Return TaskManager metricy query paths in non-blocking fashion
     new 03ab3a3  [FLINK-10247] Update MiniCluster to run MetricQueryService in separate ActorSystem
     new bb3eba4  [FLINK-10247] Start metrics ActorSystem under metrics
     new c89df00  [hotfix] Add MetricUtils#startMetricsActorSystem
     new 9f593cd  [FLINK-10247] Introduce port range option for Flink's metrics query service

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/_includes/generated/metric_configuration.html |   5 +
 .../apache/flink/client/program/ClusterClient.java |   8 +-
 .../apache/flink/configuration/MetricOptions.java  |  12 ++
 .../apache/flink/types/SerializableOptional.java   |  86 +++++++++++++
 .../apache/flink/util/function/FunctionUtils.java  |  13 ++
 .../clusterframework/MesosResourceManager.java     |   2 +-
 .../runtime/clusterframework/BootstrapTools.java   | 143 ++++++++++++++++++++-
 .../flink/runtime/concurrent/FutureUtils.java      |   7 +-
 .../runtime/entrypoint/ClusterEntrypoint.java      |  17 ++-
 .../flink/runtime/metrics/util/MetricUtils.java    |  18 +++
 .../flink/runtime/minicluster/MiniCluster.java     |  53 +++++---
 .../runtime/resourcemanager/ResourceManager.java   |  22 +++-
 .../runtime/rpc/akka/AkkaRpcServiceUtils.java      |   5 +-
 .../flink/runtime/taskexecutor/TaskExecutor.java   |  12 ++
 .../runtime/taskexecutor/TaskExecutorGateway.java  |   8 ++
 .../runtime/taskexecutor/TaskManagerRunner.java    |  24 +++-
 .../org/apache/flink/runtime/akka/AkkaUtils.scala  | 137 ++++++++++++++++----
 .../runtime/taskexecutor/TaskExecutorITCase.java   |   1 +
 .../runtime/taskexecutor/TaskExecutorTest.java     |  15 +++
 .../taskexecutor/TestingTaskExecutorGateway.java   |   6 +
 .../apache/flink/runtime/akka/AkkaUtilsTest.scala  |  28 +++-
 21 files changed, 548 insertions(+), 74 deletions(-)
 create mode 100644 flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java


[flink] 04/08: [FLINK-10247] Return TaskManager metricy query paths in non-blocking fashion

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 1496c44fe8f241195a513616a4bfa8091bdcff3b
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 10:17:59 2018 +0200

    [FLINK-10247] Return TaskManager metricy query paths in non-blocking fashion
---
 .../apache/flink/types/SerializableOptional.java   | 86 ++++++++++++++++++++++
 .../runtime/resourcemanager/ResourceManager.java   | 26 ++++---
 .../flink/runtime/taskexecutor/TaskExecutor.java   |  8 +-
 .../runtime/taskexecutor/TaskExecutorGateway.java  |  3 +-
 .../taskexecutor/TestingTaskExecutorGateway.java   |  5 +-
 5 files changed, 110 insertions(+), 18 deletions(-)

diff --git a/flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java b/flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java
new file mode 100644
index 0000000..89dcea4
--- /dev/null
+++ b/flink-core/src/main/java/org/apache/flink/types/SerializableOptional.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.types;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.io.Serializable;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * Serializable {@link Optional}.
+ */
+public final class SerializableOptional<T extends Serializable> implements Serializable {
+	private static final long serialVersionUID = -3312769593551775940L;
+
+	private static final SerializableOptional<?> EMPTY = new SerializableOptional<>(null);
+
+	@Nullable
+	private final T value;
+
+	private SerializableOptional(@Nullable T value) {
+		this.value = value;
+	}
+
+	public T get() {
+		if (value == null) {
+			throw new NoSuchElementException("No value present");
+		}
+		return value;
+	}
+
+	public boolean isPresent() {
+		return value != null;
+	}
+
+	public void ifPresent(Consumer<? super T> consumer) {
+		if (value != null) {
+			consumer.accept(value);
+		}
+	}
+
+	public <R> Optional<R> map(Function<? super T, ? extends R> mapper) {
+		if (value == null) {
+			return Optional.empty();
+		} else {
+			return Optional.ofNullable(mapper.apply(value));
+		}
+	}
+
+	public static <T extends Serializable> SerializableOptional<T> of(@Nonnull T value) {
+		return new SerializableOptional<>(value);
+	}
+
+	public static <T extends Serializable> SerializableOptional<T> ofNullable(@Nullable T value) {
+		if (value == null) {
+			return empty();
+		} else {
+			return of(value);
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	public static <T extends Serializable> SerializableOptional<T> empty() {
+		return (SerializableOptional<T>) EMPTY;
+	}
+}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
index 2fd8972..9312791 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
@@ -22,7 +22,6 @@ import org.apache.flink.annotation.VisibleForTesting;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.time.Time;
 import org.apache.flink.api.java.tuple.Tuple2;
-import org.apache.flink.runtime.akka.AkkaUtils;
 import org.apache.flink.runtime.blob.TransientBlobKey;
 import org.apache.flink.runtime.clusterframework.ApplicationStatus;
 import org.apache.flink.runtime.clusterframework.messages.InfoMessage;
@@ -74,11 +73,13 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
 
 import static org.apache.flink.util.Preconditions.checkNotNull;
 
@@ -585,25 +586,26 @@ public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable>
 
 	@Override
 	public CompletableFuture<Collection<Tuple2<ResourceID, String>>> requestTaskManagerMetricQueryServicePaths(Time timeout) {
-		final ArrayList<Tuple2<ResourceID, String>> metricQueryServicePaths = new ArrayList<>(taskExecutors.size());
+		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();
-			String tmMetricQueryServicePath = null;
-			try {
-				tmMetricQueryServicePath =
-					taskExecutorGateway.getMetricQueryServiceAddress(AkkaUtils.getDefaultTimeout()).get();
-			} catch (Exception e) {
-				log.info("Fail to get task manager's metric query service path for worker: {}", taskExecutorGateway.getAddress());
-				continue;
-			}
 
-			metricQueryServicePaths.add(Tuple2.of(tmResourceId, tmMetricQueryServicePath));
+			final CompletableFuture<Optional<Tuple2<ResourceID, String>>> metricQueryServicePathFuture = taskExecutorGateway
+				.requestMetricQueryServiceAddress(timeout)
+				.thenApply(optional -> optional.map(path -> Tuple2.of(tmResourceId, path)));
+
+			metricQueryServicePathFutures.add(metricQueryServicePathFuture);
 		}
 
-		return CompletableFuture.completedFuture(metricQueryServicePaths);
+		return FutureUtils.combineAll(metricQueryServicePathFutures).thenApply(
+			collection -> collection
+				.stream()
+				.filter(Optional::isPresent)
+				.map(Optional::get)
+				.collect(Collectors.toList()));
 	}
 
 	@Override
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
index df6d0dd..9352c47 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
@@ -102,6 +102,7 @@ import org.apache.flink.runtime.taskmanager.Task;
 import org.apache.flink.runtime.taskmanager.TaskExecutionState;
 import org.apache.flink.runtime.taskmanager.TaskManagerActions;
 import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+import org.apache.flink.types.SerializableOptional;
 import org.apache.flink.util.ExceptionUtils;
 import org.apache.flink.util.FlinkException;
 
@@ -158,6 +159,7 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 	private final BlobCacheService blobCacheService;
 
 	/** The path to metric query service on this Task Manager. */
+	@Nullable
 	private final String metricQueryServicePath;
 
 	// --------- TaskManager services --------
@@ -214,7 +216,7 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 			TaskManagerServices taskExecutorServices,
 			HeartbeatServices heartbeatServices,
 			TaskManagerMetricGroup taskManagerMetricGroup,
-			String metricQueryServicePath,
+			@Nullable String metricQueryServicePath,
 			BlobCacheService blobCacheService,
 			FatalErrorHandler fatalErrorHandler) {
 
@@ -853,8 +855,8 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 	}
 
 	@Override
-	public CompletableFuture<String> getMetricQueryServiceAddress(Time timeout) {
-		return CompletableFuture.completedFuture(metricQueryServicePath);
+	public CompletableFuture<SerializableOptional<String>> requestMetricQueryServiceAddress(Time timeout) {
+		return CompletableFuture.completedFuture(SerializableOptional.ofNullable(metricQueryServicePath));
 	}
 
 	// ----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
index abbb979..d6b9e15 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
@@ -36,6 +36,7 @@ import org.apache.flink.runtime.resourcemanager.ResourceManagerId;
 import org.apache.flink.runtime.rpc.RpcGateway;
 import org.apache.flink.runtime.rpc.RpcTimeout;
 import org.apache.flink.runtime.taskmanager.Task;
+import org.apache.flink.types.SerializableOptional;
 
 import java.util.concurrent.CompletableFuture;
 
@@ -201,5 +202,5 @@ public interface TaskExecutorGateway extends RpcGateway {
 	 *
 	 * @return Future String with Fully qualified (RPC) address of Metric Query Service on the TaskManager.
 	 */
-	CompletableFuture<String> getMetricQueryServiceAddress(@RpcTimeout Time timeout);
+	CompletableFuture<SerializableOptional<String>> requestMetricQueryServiceAddress(@RpcTimeout Time timeout);
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
index e86a95f..5fd12a8 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
@@ -34,6 +34,7 @@ import org.apache.flink.runtime.jobmaster.JobMasterId;
 import org.apache.flink.runtime.messages.Acknowledge;
 import org.apache.flink.runtime.messages.StackTraceSampleResponse;
 import org.apache.flink.runtime.resourcemanager.ResourceManagerId;
+import org.apache.flink.types.SerializableOptional;
 import org.apache.flink.util.Preconditions;
 
 import java.util.concurrent.CompletableFuture;
@@ -150,8 +151,8 @@ public class TestingTaskExecutorGateway implements TaskExecutorGateway {
 	}
 
 	@Override
-	public CompletableFuture<String> getMetricQueryServiceAddress(Time timeout) {
-		return CompletableFuture.completedFuture(address);
+	public CompletableFuture<SerializableOptional<String>> requestMetricQueryServiceAddress(Time timeout) {
+		return CompletableFuture.completedFuture(SerializableOptional.of(address));
 	}
 
 	@Override


[flink] 01/08: [hotfix] Generify FutureUtils#toJava

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit ad4aa7c03151c11cf77045c1875590b85090ca9f
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 10:33:08 2018 +0200

    [hotfix] Generify FutureUtils#toJava
---
 .../main/java/org/apache/flink/client/program/ClusterClient.java  | 8 ++++----
 .../mesos/runtime/clusterframework/MesosResourceManager.java      | 2 +-
 .../java/org/apache/flink/runtime/concurrent/FutureUtils.java     | 7 ++++---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/flink-clients/src/main/java/org/apache/flink/client/program/ClusterClient.java b/flink-clients/src/main/java/org/apache/flink/client/program/ClusterClient.java
index 373267f..521b810 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/program/ClusterClient.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/program/ClusterClient.java
@@ -627,7 +627,7 @@ public abstract class ClusterClient<T> {
 
 		Future<Object> response = jobManager.ask(JobManagerMessages.getRequestJobStatus(jobId), timeout);
 
-		CompletableFuture<Object> javaFuture = FutureUtils.<Object>toJava(response);
+		CompletableFuture<Object> javaFuture = FutureUtils.toJava(response);
 
 		return javaFuture.thenApply((responseMessage) -> {
 			if (responseMessage instanceof JobManagerMessages.CurrentJobStatus) {
@@ -734,7 +734,7 @@ public abstract class ClusterClient<T> {
 
 		Future<Object> response = jobManager.ask(new JobManagerMessages.TriggerSavepoint(jobId, Option.<String>apply(savepointDirectory)),
 			new FiniteDuration(1, TimeUnit.HOURS));
-		CompletableFuture<Object> responseFuture = FutureUtils.<Object>toJava(response);
+		CompletableFuture<Object> responseFuture = FutureUtils.toJava(response);
 
 		return responseFuture.thenApply((responseMessage) -> {
 			if (responseMessage instanceof JobManagerMessages.TriggerSavepointSuccess) {
@@ -754,7 +754,7 @@ public abstract class ClusterClient<T> {
 		final ActorGateway jobManager = getJobManagerGateway();
 
 		Object msg = new JobManagerMessages.DisposeSavepoint(savepointPath);
-		CompletableFuture<Object> responseFuture = FutureUtils.<Object>toJava(
+		CompletableFuture<Object> responseFuture = FutureUtils.toJava(
 			jobManager.ask(
 				msg,
 				timeout));
@@ -793,7 +793,7 @@ public abstract class ClusterClient<T> {
 		final ActorGateway jobManager = getJobManagerGateway();
 
 		Future<Object> response = jobManager.ask(new RequestJobDetails(true, false), timeout);
-		CompletableFuture<Object> responseFuture = FutureUtils.<Object>toJava(response);
+		CompletableFuture<Object> responseFuture = FutureUtils.toJava(response);
 
 		return responseFuture.thenApply((responseMessage) -> {
 			if (responseMessage instanceof MultipleJobsDetails) {
diff --git a/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java b/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
index 67aabeb..f398f4f 100644
--- a/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
+++ b/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
@@ -678,7 +678,7 @@ public class MesosResourceManager extends ResourceManager<RegisteredMesosWorkerN
 			return CompletableFuture.completedFuture(true);
 		}
 
-		return FutureUtils.<Boolean>toJava(Patterns.gracefulStop(actorRef, timeout))
+		return FutureUtils.toJava(Patterns.gracefulStop(actorRef, timeout))
 			.exceptionally(
 				(Throwable throwable) -> {
 					// The actor did not stop gracefully in time, try to directly stop it
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FutureUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FutureUtils.java
index 5a19a3f..c1b46e4 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FutureUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FutureUtils.java
@@ -759,14 +759,15 @@ public class FutureUtils {
 	 *
 	 * @param scalaFuture to convert to a Java 8 CompletableFuture
 	 * @param <T> type of the future value
+	 * @param <U> type of the original future
 	 * @return Java 8 CompletableFuture
 	 */
-	public static <T> CompletableFuture<T> toJava(Future<T> scalaFuture) {
+	public static <T, U extends T> CompletableFuture<T> toJava(Future<U> scalaFuture) {
 		final CompletableFuture<T> result = new CompletableFuture<>();
 
-		scalaFuture.onComplete(new OnComplete<T>() {
+		scalaFuture.onComplete(new OnComplete<U>() {
 			@Override
-			public void onComplete(Throwable failure, T success) {
+			public void onComplete(Throwable failure, U success) {
 				if (failure != null) {
 					result.completeExceptionally(failure);
 				} else {


[flink] 05/08: [FLINK-10247] Update MiniCluster to run MetricQueryService in separate ActorSystem

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 03ab3a3f4f368f266d25e8130f0a8d1a3ae33c09
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 12:06:43 2018 +0200

    [FLINK-10247] Update MiniCluster to run MetricQueryService in separate ActorSystem
---
 .../flink/runtime/minicluster/MiniCluster.java     | 52 ++++++++++++++--------
 1 file changed, 34 insertions(+), 18 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
index 065dbdc..f4d5501 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
@@ -32,6 +32,7 @@ import org.apache.flink.runtime.blob.BlobServer;
 import org.apache.flink.runtime.client.ClientUtils;
 import org.apache.flink.runtime.client.JobExecutionException;
 import org.apache.flink.runtime.client.JobStatusMessage;
+import org.apache.flink.runtime.clusterframework.BootstrapTools;
 import org.apache.flink.runtime.clusterframework.FlinkResourceManager;
 import org.apache.flink.runtime.clusterframework.types.ResourceID;
 import org.apache.flink.runtime.concurrent.FutureUtils;
@@ -96,6 +97,7 @@ import java.util.concurrent.CompletionStage;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
+import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
 import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.apache.flink.util.Preconditions.checkState;
 
@@ -132,6 +134,9 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 	private RpcService resourceManagerRpcService;
 
 	@GuardedBy("lock")
+	private ActorSystem metricQueryServiceActorSystem;
+
+	@GuardedBy("lock")
 	private HighAvailabilityServices haServices;
 
 	@GuardedBy("lock")
@@ -247,8 +252,8 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 				commonRpcService = createRpcService(configuration, rpcTimeout, false, null);
 
 				// TODO: Temporary hack until the metric query service is ported to the RpcEndpoint
-				final ActorSystem actorSystem = ((AkkaRpcService) commonRpcService).getActorSystem();
-				metricRegistry.startQueryService(actorSystem, null);
+				metricQueryServiceActorSystem = BootstrapTools.startActorSystem(configuration, commonRpcService.getAddress(), 0, LOG, FIXED_THREAD_POOL_EXECUTOR);
+				metricRegistry.startQueryService(metricQueryServiceActorSystem, null);
 
 				if (useSingleRpcService) {
 					for (int i = 0; i < numTaskManagers; i++) {
@@ -342,7 +347,7 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 					blobServer.getTransientBlobService(),
 					commonRpcService.getExecutor(),
 					new AkkaQueryServiceRetriever(
-						actorSystem,
+						metricQueryServiceActorSystem,
 						Time.milliseconds(configuration.getLong(WebOptions.TIMEOUT))),
 					haServices.getWebMonitorLeaderElectionService(),
 					new ShutDownFatalErrorHandler());
@@ -439,24 +444,12 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 
 					final FutureUtils.ConjunctFuture<Void> componentsTerminationFuture = FutureUtils.completeAll(componentTerminationFutures);
 
-					final CompletableFuture<Void> metricRegistryTerminationFuture = FutureUtils.runAfterwards(
+					final CompletableFuture<Void> metricSystemTerminationFuture = FutureUtils.composeAfterwards(
 						componentsTerminationFuture,
-						() -> {
-							synchronized (lock) {
-								if (jobManagerMetricGroup != null) {
-									jobManagerMetricGroup.close();
-									jobManagerMetricGroup = null;
-								}
-								// metrics shutdown
-								if (metricRegistry != null) {
-									metricRegistry.shutdown();
-									metricRegistry = null;
-								}
-							}
-						});
+						this::closeMetricSystem);
 
 					// shut down the RpcServices
-					final CompletableFuture<Void> rpcServicesTerminationFuture = metricRegistryTerminationFuture
+					final CompletableFuture<Void> rpcServicesTerminationFuture = metricSystemTerminationFuture
 						.thenCompose((Void ignored) -> terminateRpcServices());
 
 					final CompletableFuture<Void> remainingServicesTerminationFuture = FutureUtils.runAfterwards(
@@ -480,6 +473,29 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 		}
 	}
 
+	private CompletableFuture<Void> closeMetricSystem() {
+		synchronized (lock) {
+			if (jobManagerMetricGroup != null) {
+				jobManagerMetricGroup.close();
+				jobManagerMetricGroup = null;
+			}
+
+			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);
+		}
+	}
+
 	// ------------------------------------------------------------------------
 	//  Accessing jobs
 	// ------------------------------------------------------------------------


[flink] 02/08: [hotfix] Add AkkaUtils#terminateActorSystem

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 580c0485f72e34b8a65955b6c2e3c9eea18f629b
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 10:33:54 2018 +0200

    [hotfix] Add AkkaUtils#terminateActorSystem
---
 .../java/org/apache/flink/util/function/FunctionUtils.java | 13 +++++++++++++
 .../scala/org/apache/flink/runtime/akka/AkkaUtils.scala    | 14 +++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/flink-core/src/main/java/org/apache/flink/util/function/FunctionUtils.java b/flink-core/src/main/java/org/apache/flink/util/function/FunctionUtils.java
index 83846a6..b777308 100644
--- a/flink-core/src/main/java/org/apache/flink/util/function/FunctionUtils.java
+++ b/flink-core/src/main/java/org/apache/flink/util/function/FunctionUtils.java
@@ -34,6 +34,8 @@ public class FunctionUtils {
 
 	private static final Function<Object, Void> NULL_FN = ignored -> null;
 
+	private static final Consumer<Object> IGNORE_FN = ignored -> {};
+
 	/**
 	 * Function which returns {@code null} (type: Void).
 	 *
@@ -46,6 +48,17 @@ public class FunctionUtils {
 	}
 
 	/**
+	 * Consumer which ignores the input.
+	 *
+	 * @param <T> type of the input
+	 * @return Ignoring {@link Consumer}
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T> Consumer<T> ignoreFn() {
+		return (Consumer<T>) IGNORE_FN;
+	}
+
+	/**
 	 * Convert at {@link FunctionWithException} into a {@link Function}.
 	 *
 	 * @param functionWithException function with exception to convert into a function
diff --git a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
index 050b4de..dcf0fdd 100644
--- a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
+++ b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
@@ -20,15 +20,17 @@ package org.apache.flink.runtime.akka
 
 import java.io.IOException
 import java.net._
-import java.util.concurrent.{Callable, TimeUnit}
+import java.util.concurrent.{Callable, CompletableFuture, TimeUnit}
 
 import akka.actor._
 import akka.pattern.{ask => akkaAsk}
 import com.typesafe.config.{Config, ConfigFactory}
 import org.apache.flink.api.common.time.Time
 import org.apache.flink.configuration.{AkkaOptions, Configuration, IllegalConfigurationException, SecurityOptions}
+import org.apache.flink.runtime.concurrent.FutureUtils
 import org.apache.flink.runtime.net.SSLUtils
 import org.apache.flink.util.NetUtils
+import org.apache.flink.util.function.FunctionUtils
 import org.jboss.netty.channel.ChannelException
 import org.jboss.netty.logging.{InternalLoggerFactory, Slf4JLoggerFactory}
 import org.slf4j.{Logger, LoggerFactory}
@@ -852,5 +854,15 @@ object AkkaUtils {
       case f => f
     }
   }
+
+  /**
+    * Terminates the given [[ActorSystem]] and returns its termination future.
+    *
+    * @param actorSystem to terminate
+    * @return Termination future
+    */
+  def terminateActorSystem(actorSystem: ActorSystem): CompletableFuture[Void] = {
+    FutureUtils.toJava(actorSystem.terminate).thenAccept(FunctionUtils.ignoreFn())
+  }
 }
 


[flink] 07/08: [hotfix] Add MetricUtils#startMetricsActorSystem

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit c89df00736a0898a5ce6a3a32c1cd2b7bdf9e34a
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 14:46:28 2018 +0200

    [hotfix] Add MetricUtils#startMetricsActorSystem
    
    Single place where the metrics ActorSystem is instantiated.
---
 .../runtime/entrypoint/ClusterEntrypoint.java      |  9 +--------
 .../flink/runtime/metrics/util/MetricUtils.java    | 16 +++++++++++++++
 .../flink/runtime/minicluster/MiniCluster.java     |  9 ++-------
 .../runtime/taskexecutor/TaskManagerRunner.java    | 23 +---------------------
 4 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
index 07eef23..3c42bd9 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
@@ -95,7 +95,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import scala.concurrent.duration.FiniteDuration;
 
-import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
 import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FORK_JOIN_EXECUTOR;
 
 /**
@@ -282,13 +281,7 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 
 			// TODO: This is a temporary hack until we have ported the MetricQueryService to the new RpcEndpoint
 			// Start actor system for metric query service on any available port
-			metricQueryServiceActorSystem = BootstrapTools.startActorSystem(
-				configuration,
-				"metrics",
-				bindAddress,
-				0,
-				LOG,
-				FIXED_THREAD_POOL_EXECUTOR);
+			metricQueryServiceActorSystem = MetricUtils.startMetricsActorSystem(configuration, bindAddress, LOG);
 			metricRegistry.startQueryService(metricQueryServiceActorSystem, null);
 
 			archivedExecutionGraphStore = createSerializableExecutionGraphStore(configuration, commonRpcService.getScheduledExecutor());
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
index 3fd268a..76a7a13 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
@@ -18,8 +18,10 @@
 
 package org.apache.flink.runtime.metrics.util;
 
+import org.apache.flink.configuration.Configuration;
 import org.apache.flink.metrics.Gauge;
 import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.clusterframework.BootstrapTools;
 import org.apache.flink.runtime.io.network.NetworkEnvironment;
 import org.apache.flink.runtime.metrics.MetricRegistry;
 import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup;
@@ -27,6 +29,7 @@ import org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup;
 import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
 import org.apache.flink.util.Preconditions;
 
+import akka.actor.ActorSystem;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,12 +48,15 @@ import java.lang.management.MemoryMXBean;
 import java.lang.management.ThreadMXBean;
 import java.util.List;
 
+import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
+
 /**
  * Utility class to register pre-defined metric sets.
  */
 public class MetricUtils {
 	private static final Logger LOG = LoggerFactory.getLogger(MetricUtils.class);
 	private static final String METRIC_GROUP_STATUS_NAME = "Status";
+	private static final String METRICS = "flink-metrics";
 
 	private MetricUtils() {
 	}
@@ -102,6 +108,16 @@ public class MetricUtils {
 		instantiateCPUMetrics(jvm.addGroup("CPU"));
 	}
 
+	public static ActorSystem startMetricsActorSystem(Configuration configuration, String hostname, Logger logger) throws Exception {
+		return BootstrapTools.startActorSystem(
+			configuration,
+			METRICS,
+			hostname,
+			0,
+			logger,
+			FIXED_THREAD_POOL_EXECUTOR);
+	}
+
 	private static void instantiateNetworkMetrics(
 		MetricGroup metrics,
 		final NetworkEnvironment network) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
index e85e5fa..dbfdb42 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
@@ -32,7 +32,6 @@ import org.apache.flink.runtime.blob.BlobServer;
 import org.apache.flink.runtime.client.ClientUtils;
 import org.apache.flink.runtime.client.JobExecutionException;
 import org.apache.flink.runtime.client.JobStatusMessage;
-import org.apache.flink.runtime.clusterframework.BootstrapTools;
 import org.apache.flink.runtime.clusterframework.FlinkResourceManager;
 import org.apache.flink.runtime.clusterframework.types.ResourceID;
 import org.apache.flink.runtime.concurrent.FutureUtils;
@@ -97,7 +96,6 @@ import java.util.concurrent.CompletionStage;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
-import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
 import static org.apache.flink.util.Preconditions.checkNotNull;
 import static org.apache.flink.util.Preconditions.checkState;
 
@@ -252,13 +250,10 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 				commonRpcService = createRpcService(configuration, rpcTimeout, false, null);
 
 				// TODO: Temporary hack until the metric query service is ported to the RpcEndpoint
-				metricQueryServiceActorSystem = BootstrapTools.startActorSystem(
+				metricQueryServiceActorSystem = MetricUtils.startMetricsActorSystem(
 					configuration,
-					"metrics",
 					commonRpcService.getAddress(),
-					0,
-					LOG,
-					FIXED_THREAD_POOL_EXECUTOR);
+					LOG);
 				metricRegistry.startQueryService(metricQueryServiceActorSystem, null);
 
 				if (useSingleRpcService) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
index aff7557..f830ae1 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
@@ -27,7 +27,6 @@ import org.apache.flink.configuration.TaskManagerOptions;
 import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.runtime.akka.AkkaUtils;
 import org.apache.flink.runtime.blob.BlobCacheService;
-import org.apache.flink.runtime.clusterframework.BootstrapTools;
 import org.apache.flink.runtime.clusterframework.types.ResourceID;
 import org.apache.flink.runtime.concurrent.FutureUtils;
 import org.apache.flink.runtime.entrypoint.ClusterConfiguration;
@@ -74,7 +73,6 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 
-import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
 import static org.apache.flink.util.Preconditions.checkNotNull;
 
 /**
@@ -135,7 +133,7 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 			HighAvailabilityServicesUtils.AddressResolution.TRY_ADDRESS_RESOLUTION);
 
 		rpcService = createRpcService(configuration, highAvailabilityServices);
-		metricQueryServiceActorSystem = createMetricQueryServiceActorSystem(configuration, rpcService.getAddress());
+		metricQueryServiceActorSystem = MetricUtils.startMetricsActorSystem(configuration, rpcService.getAddress(), LOG);
 
 		HeartbeatServices heartbeatServices = HeartbeatServices.fromConfiguration(configuration);
 
@@ -429,25 +427,6 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 		return bindWithPort(configuration, taskManagerHostname, portRangeDefinition);
 	}
 
-	/**
-	 * Create a actor system service for the metric query service.
-	 *
-	 * @param configuration The configuration for the TaskManager.
-	 * @param hostname to bind the {@link ActorSystem} to
-	 */
-	public static ActorSystem createMetricQueryServiceActorSystem(
-			final Configuration configuration,
-			final String hostname) throws Exception {
-
-		return BootstrapTools.startActorSystem(
-			configuration,
-			"metrics",
-			hostname,
-			0,
-			LOG,
-			FIXED_THREAD_POOL_EXECUTOR);
-	}
-
 	private static RpcService bindWithPort(
 		Configuration configuration,
 		String taskManagerHostname,


[flink] 08/08: [FLINK-10247] Introduce port range option for Flink's metrics query service

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 9f593cd23d130b5a1266bd68ea5b34860c170c39
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 14:58:32 2018 +0200

    [FLINK-10247] Introduce port range option for Flink's metrics query service
    
    In order to make the port used for Flink's internal metrics query service configurable,
    this commits adds the metrics.internal.query-service.port config option. This option
    specifies a port range from which the metric query service picks a free one to bind to.
    Per default, a random port is picked.
    
    This closes #6759.
---
 docs/_includes/generated/metric_configuration.html |  5 +++
 .../apache/flink/configuration/MetricOptions.java  | 12 ++++++++
 .../runtime/clusterframework/BootstrapTools.java   | 36 +++++++++++++++++++++-
 .../flink/runtime/metrics/util/MetricUtils.java    |  8 +++--
 4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/docs/_includes/generated/metric_configuration.html b/docs/_includes/generated/metric_configuration.html
index 0fe9d0c..5f52abd 100644
--- a/docs/_includes/generated/metric_configuration.html
+++ b/docs/_includes/generated/metric_configuration.html
@@ -8,6 +8,11 @@
     </thead>
     <tbody>
         <tr>
+            <td><h5>metrics.internal.query-service.port</h5></td>
+            <td style="word-wrap: break-word;">"0"</td>
+            <td>The port range used for Flink's internal metric query service. Accepts a list of ports (“50100,50101”), ranges(“50100-50200”) or a combination of both. It is recommended to set a range of ports to avoid collisions when multiple Flink components are running on the same machine. Per default Flink will pick a random port.</td>
+        </tr>
+        <tr>
             <td><h5>metrics.latency.granularity</h5></td>
             <td style="word-wrap: break-word;">"subtask"</td>
             <td>Defines the granularity of latency metrics. Accepted values are:<ul><li>single - Track latency without differentiating between sources and subtasks.</li><li>operator - Track latency while differentiating between sources, but not subtasks.</li><li>subtask - Track latency while differentiating between sources and subtasks.</li></ul></td>
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/MetricOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/MetricOptions.java
index fc6b3c1..e76b7f2 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/MetricOptions.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/MetricOptions.java
@@ -130,6 +130,18 @@ public class MetricOptions {
 			.defaultValue(128)
 			.withDescription("Defines the number of measured latencies to maintain at each operator.");
 
+	/**
+	 * The default network port range for Flink's internal metric query service. The {@code "0"} means that
+	 * Flink searches for a free port.
+	 */
+	public static final ConfigOption<String> QUERY_SERVICE_PORT =
+		key("metrics.internal.query-service.port")
+		.defaultValue("0")
+		.withDescription("The port range used for Flink's internal metric query service. Accepts a list of ports " +
+			"(“50100,50101”), ranges(“50100-50200”) or a combination of both. It is recommended to set a range of " +
+			"ports to avoid collisions when multiple Flink components are running on the same machine. Per default " +
+			"Flink will pick a random port.");
+
 	private MetricOptions() {
 	}
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
index 462c687..00b6173 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
@@ -118,6 +118,34 @@ public class BootstrapTools {
 			String portRangeDefinition,
 			Logger logger,
 			@Nonnull ActorSystemExecutorMode executorMode) throws Exception {
+		return startActorSystem(
+			configuration,
+			AkkaUtils.getFlinkActorSystemName(),
+			listeningAddress,
+			portRangeDefinition,
+			logger,
+			executorMode);
+	}
+
+	/**
+	 * Starts an ActorSystem with the given configuration listening at the address/ports.
+	 *
+	 * @param configuration The Flink configuration
+	 * @param actorSystemName Name of the started {@link ActorSystem}
+	 * @param listeningAddress The address to listen at.
+	 * @param portRangeDefinition The port range to choose a port from.
+	 * @param logger The logger to output log information.
+	 * @param executorMode The executor mode of Akka actor system.
+	 * @return The ActorSystem which has been started
+	 * @throws Exception Thrown when actor system cannot be started in specified port range
+	 */
+	public static ActorSystem startActorSystem(
+			Configuration configuration,
+			String actorSystemName,
+			String listeningAddress,
+			String portRangeDefinition,
+			Logger logger,
+			@Nonnull ActorSystemExecutorMode executorMode) throws Exception {
 
 		// parse port range definition and create port iterator
 		Iterator<Integer> portsIterator;
@@ -143,7 +171,13 @@ public class BootstrapTools {
 			}
 
 			try {
-				return startActorSystem(configuration, listeningAddress, port, logger, executorMode);
+				return startActorSystem(
+					configuration,
+					actorSystemName,
+					listeningAddress,
+					port,
+					logger,
+					executorMode);
 			}
 			catch (Exception e) {
 				// we can continue to try if this contains a netty channel exception
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
index 76a7a13..39e5f44 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/metrics/util/MetricUtils.java
@@ -19,6 +19,7 @@
 package org.apache.flink.runtime.metrics.util;
 
 import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MetricOptions;
 import org.apache.flink.metrics.Gauge;
 import org.apache.flink.metrics.MetricGroup;
 import org.apache.flink.runtime.clusterframework.BootstrapTools;
@@ -56,7 +57,7 @@ import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSyst
 public class MetricUtils {
 	private static final Logger LOG = LoggerFactory.getLogger(MetricUtils.class);
 	private static final String METRIC_GROUP_STATUS_NAME = "Status";
-	private static final String METRICS = "flink-metrics";
+	private static final String METRICS_ACTOR_SYSTEM_NAME = "flink-metrics";
 
 	private MetricUtils() {
 	}
@@ -109,11 +110,12 @@ public class MetricUtils {
 	}
 
 	public static ActorSystem startMetricsActorSystem(Configuration configuration, String hostname, Logger logger) throws Exception {
+		final String portRange = configuration.getString(MetricOptions.QUERY_SERVICE_PORT);
 		return BootstrapTools.startActorSystem(
 			configuration,
-			METRICS,
+			METRICS_ACTOR_SYSTEM_NAME,
 			hostname,
-			0,
+			portRange,
 			logger,
 			FIXED_THREAD_POOL_EXECUTOR);
 	}


[flink] 06/08: [FLINK-10247] Start metrics ActorSystem under metrics

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit bb3eba40d68011be5e58136695f03df45a3b6d79
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Wed Oct 10 14:24:38 2018 +0200

    [FLINK-10247] Start metrics ActorSystem under metrics
---
 .../runtime/clusterframework/BootstrapTools.java   | 31 ++++++++++++++++++++--
 .../runtime/entrypoint/ClusterEntrypoint.java      |  1 +
 .../flink/runtime/minicluster/MiniCluster.java     |  8 +++++-
 .../runtime/taskexecutor/TaskManagerRunner.java    |  1 +
 .../org/apache/flink/runtime/akka/AkkaUtils.scala  | 19 +++++++++++--
 5 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
index 0e0d202..462c687 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
@@ -194,6 +194,33 @@ public class BootstrapTools {
 				int listeningPort,
 				Logger logger,
 				ActorSystemExecutorMode executorMode) throws Exception {
+		return startActorSystem(
+			configuration,
+			AkkaUtils.getFlinkActorSystemName(),
+			listeningAddress,
+			listeningPort,
+			logger,
+			executorMode);
+	}
+
+	/**
+	 * Starts an Actor System at a specific port.
+	 * @param configuration The Flink configuration.
+	 * @param actorSystemName Name of the started {@link ActorSystem}
+	 * @param listeningAddress The address to listen at.
+	 * @param listeningPort The port to listen at.
+	 * @param logger the logger to output log information.
+	 * @param executorMode The executor mode of Akka actor system.
+	 * @return The ActorSystem which has been started.
+	 * @throws Exception
+	 */
+	public static ActorSystem startActorSystem(
+		Configuration configuration,
+		String actorSystemName,
+		String listeningAddress,
+		int listeningPort,
+		Logger logger,
+		ActorSystemExecutorMode executorMode) throws Exception {
 
 		String hostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(listeningAddress, listeningPort);
 		logger.info("Trying to start actor system at {}", hostPortUrl);
@@ -207,7 +234,7 @@ public class BootstrapTools {
 
 			logger.debug("Using akka configuration\n {}", akkaConfig);
 
-			ActorSystem actorSystem = AkkaUtils.createActorSystem(akkaConfig);
+			ActorSystem actorSystem = AkkaUtils.createActorSystem(actorSystemName, akkaConfig);
 
 			logger.info("Actor system started at {}", AkkaUtils.getAddress(actorSystem));
 			return actorSystem;
@@ -217,7 +244,7 @@ public class BootstrapTools {
 				Throwable cause = t.getCause();
 				if (cause != null && t.getCause() instanceof BindException) {
 					throw new IOException("Unable to create ActorSystem at address " + hostPortUrl +
-							" : " + cause.getMessage(), t);
+						" : " + cause.getMessage(), t);
 				}
 			}
 			throw new Exception("Could not create actor system", t);
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
index 28443b5..07eef23 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
@@ -284,6 +284,7 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 			// Start actor system for metric query service on any available port
 			metricQueryServiceActorSystem = BootstrapTools.startActorSystem(
 				configuration,
+				"metrics",
 				bindAddress,
 				0,
 				LOG,
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
index f4d5501..e85e5fa 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java
@@ -252,7 +252,13 @@ public class MiniCluster implements JobExecutorService, AutoCloseableAsync {
 				commonRpcService = createRpcService(configuration, rpcTimeout, false, null);
 
 				// TODO: Temporary hack until the metric query service is ported to the RpcEndpoint
-				metricQueryServiceActorSystem = BootstrapTools.startActorSystem(configuration, commonRpcService.getAddress(), 0, LOG, FIXED_THREAD_POOL_EXECUTOR);
+				metricQueryServiceActorSystem = BootstrapTools.startActorSystem(
+					configuration,
+					"metrics",
+					commonRpcService.getAddress(),
+					0,
+					LOG,
+					FIXED_THREAD_POOL_EXECUTOR);
 				metricRegistry.startQueryService(metricQueryServiceActorSystem, null);
 
 				if (useSingleRpcService) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
index 80fb1ed..aff7557 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
@@ -441,6 +441,7 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 
 		return BootstrapTools.startActorSystem(
 			configuration,
+			"metrics",
 			hostname,
 			0,
 			LOG,
diff --git a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
index dba82f6..2b0c939 100644
--- a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
+++ b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
@@ -27,7 +27,6 @@ import akka.pattern.{ask => akkaAsk}
 import com.typesafe.config.{Config, ConfigFactory}
 import org.apache.flink.api.common.time.Time
 import org.apache.flink.configuration.{AkkaOptions, Configuration, IllegalConfigurationException, SecurityOptions}
-import org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode
 import org.apache.flink.runtime.concurrent.FutureUtils
 import org.apache.flink.runtime.net.SSLUtils
 import org.apache.flink.util.NetUtils
@@ -51,6 +50,12 @@ object AkkaUtils {
 
   val INF_TIMEOUT: FiniteDuration = 21474835 seconds
 
+  val FLINK_ACTOR_SYSTEM_NAME = "flink"
+
+  def getFlinkActorSystemName = {
+    FLINK_ACTOR_SYSTEM_NAME
+  }
+
   /**
    * Creates a local actor system without remoting.
    *
@@ -104,9 +109,19 @@ object AkkaUtils {
    * @return created actor system
    */
   def createActorSystem(akkaConfig: Config): ActorSystem = {
+    createActorSystem(FLINK_ACTOR_SYSTEM_NAME, akkaConfig)
+  }
+
+  /**
+    * Creates an actor system with the given akka config.
+    *
+    * @param akkaConfig configuration for the actor system
+    * @return created actor system
+    */
+  def createActorSystem(actorSystemName: String, akkaConfig: Config): ActorSystem = {
     // Initialize slf4j as logger of Akka's Netty instead of java.util.logging (FLINK-1650)
     InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory)
-    ActorSystem.create("flink", akkaConfig)
+    ActorSystem.create(actorSystemName, akkaConfig)
   }
 
   /**


[flink] 03/08: [FLINK-10247] Run MetricQueryService in separate ActorSystem

Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch release-1.6
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 1cdababc2826681bf2ecfb1b7261dad4bff4b2b9
Author: yangshimin <ya...@youzan.com>
AuthorDate: Fri Sep 21 14:53:27 2018 +0800

    [FLINK-10247] Run MetricQueryService in separate ActorSystem
    
    In order to avoid that the metric system interferes with Flink's cluster components,
    the MetricQueryService is now executed in a separate ActorSystem.
    
    [FLINK-10247][metric] Start new actor system in JobMananger and TaskManager
    
    An actor system dedicated for metric query service is started for each Cluster
    Entrypoint and TaskManager Runner. The actor system is a single thread executor
    with lowest priority. The metric query service path will be passed to Resource
    Manager and Dispatcher via MetricRegistry. This commit start the MetricQuery
    Service independent of main component Rpc Service and close it during shutdown.
    
    [FLINK-10247][metric]Pass the address of Metric Query Service actor system to TaskExecutor and fix up
    
    In order to making JobManager's metric query service communicate with Task executor's, JobManager should be
    aware of the address of TaskExecutor's MetricQueryService actor. This commit changes the constructor
    of TaskExecutor by passing the path of MetricQueryService actor and save it in an instance variable. Meanwhile,
    it changes the TaskExecutorGateway interface to make the address available to JobManager.
    
    Besides changes mentioned above, this commit also add an option to configure the port range of metric query
    service in JobManager started in a Yarn cluster.
    
    [FLINK-10247] Remove AkkaActorSystemService
    
    [FLINK-10247] Replace "" with null metricy query service path for TaskExecutor initialization
    
    [FLINK-10247] Decouple AkkaUtils and AkkaExecutorMode
    
    [FLINK-10247] Correct AkkaUtils#getSingleThreadExecutorConfig
    
    [FLINK-10247] Refactor Bootstrap#createActorSystem with dispatcher executor
    
    [FLINK-10247] Simplify metrics ActorSystem instantiation in TaskManagerRunner
---
 .../runtime/clusterframework/BootstrapTools.java   |  78 ++++++++++++++-
 .../runtime/entrypoint/ClusterEntrypoint.java      |  23 ++++-
 .../runtime/resourcemanager/ResourceManager.java   |  14 ++-
 .../runtime/rpc/akka/AkkaRpcServiceUtils.java      |   5 +-
 .../flink/runtime/taskexecutor/TaskExecutor.java   |  10 ++
 .../runtime/taskexecutor/TaskExecutorGateway.java  |   7 ++
 .../runtime/taskexecutor/TaskManagerRunner.java    |  44 ++++++++-
 .../org/apache/flink/runtime/akka/AkkaUtils.scala  | 106 ++++++++++++++++-----
 .../runtime/taskexecutor/TaskExecutorITCase.java   |   1 +
 .../runtime/taskexecutor/TaskExecutorTest.java     |  15 +++
 .../taskexecutor/TestingTaskExecutorGateway.java   |   5 +
 .../apache/flink/runtime/akka/AkkaUtilsTest.scala  |  28 +++++-
 12 files changed, 295 insertions(+), 41 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
index 56e4576..0e0d202 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/BootstrapTools.java
@@ -46,6 +46,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import java.io.File;
@@ -85,13 +86,38 @@ public class BootstrapTools {
 	 * @param portRangeDefinition The port range to choose a port from.
 	 * @param logger The logger to output log information.
 	 * @return The ActorSystem which has been started
-	 * @throws Exception
+	 * @throws Exception Thrown when actor system cannot be started in specified port range
+	 */
+	public static ActorSystem startActorSystem(
+		Configuration configuration,
+		String listeningAddress,
+		String portRangeDefinition,
+		Logger logger) throws Exception {
+		return startActorSystem(
+			configuration,
+			listeningAddress,
+			portRangeDefinition,
+			logger,
+			ActorSystemExecutorMode.FORK_JOIN_EXECUTOR);
+	}
+
+	/**
+	 * Starts an ActorSystem with the given configuration listening at the address/ports.
+	 *
+	 * @param configuration The Flink configuration
+	 * @param listeningAddress The address to listen at.
+	 * @param portRangeDefinition The port range to choose a port from.
+	 * @param logger The logger to output log information.
+	 * @param executorMode The executor mode of Akka actor system.
+	 * @return The ActorSystem which has been started
+	 * @throws Exception Thrown when actor system cannot be started in specified port range
 	 */
 	public static ActorSystem startActorSystem(
 			Configuration configuration,
 			String listeningAddress,
 			String portRangeDefinition,
-			Logger logger) throws Exception {
+			Logger logger,
+			@Nonnull ActorSystemExecutorMode executorMode) throws Exception {
 
 		// parse port range definition and create port iterator
 		Iterator<Integer> portsIterator;
@@ -117,7 +143,7 @@ public class BootstrapTools {
 			}
 
 			try {
-				return startActorSystem(configuration, listeningAddress, port, logger);
+				return startActorSystem(configuration, listeningAddress, port, logger, executorMode);
 			}
 			catch (Exception e) {
 				// we can continue to try if this contains a netty channel exception
@@ -136,10 +162,29 @@ public class BootstrapTools {
 
 	/**
 	 * Starts an Actor System at a specific port.
+	 *
+	 * @param configuration The Flink configuration.
+	 * @param listeningAddress The address to listen at.
+	 * @param listeningPort The port to listen at.
+	 * @param logger the logger to output log information.
+	 * @return The ActorSystem which has been started.
+	 * @throws Exception
+	 */
+	public static ActorSystem startActorSystem(
+		Configuration configuration,
+		String listeningAddress,
+		int listeningPort,
+		Logger logger) throws Exception {
+		return startActorSystem(configuration, listeningAddress, listeningPort, logger, ActorSystemExecutorMode.FORK_JOIN_EXECUTOR);
+	}
+
+	/**
+	 * Starts an Actor System at a specific port.
 	 * @param configuration The Flink configuration.
 	 * @param listeningAddress The address to listen at.
 	 * @param listeningPort The port to listen at.
 	 * @param logger the logger to output log information.
+	 * @param executorMode The executor mode of Akka actor system.
 	 * @return The ActorSystem which has been started.
 	 * @throws Exception
 	 */
@@ -147,7 +192,8 @@ public class BootstrapTools {
 				Configuration configuration,
 				String listeningAddress,
 				int listeningPort,
-				Logger logger) throws Exception {
+				Logger logger,
+				ActorSystemExecutorMode executorMode) throws Exception {
 
 		String hostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(listeningAddress, listeningPort);
 		logger.info("Trying to start actor system at {}", hostPortUrl);
@@ -155,7 +201,8 @@ public class BootstrapTools {
 		try {
 			Config akkaConfig = AkkaUtils.getAkkaConfig(
 				configuration,
-				new Some<>(new Tuple2<>(listeningAddress, listeningPort))
+				new Some<>(new Tuple2<>(listeningAddress, listeningPort)),
+				getExecutorConfigByExecutorMode(configuration, executorMode)
 			);
 
 			logger.debug("Using akka configuration\n {}", akkaConfig);
@@ -177,6 +224,17 @@ public class BootstrapTools {
 		}
 	}
 
+	private static Config getExecutorConfigByExecutorMode(Configuration configuration, ActorSystemExecutorMode executorMode) {
+		switch (executorMode) {
+			case FORK_JOIN_EXECUTOR:
+				return AkkaUtils.getForkJoinExecutorConfig(configuration);
+			case FIXED_THREAD_POOL_EXECUTOR:
+				return AkkaUtils.getThreadPoolExecutorConfig();
+			default:
+				throw new IllegalArgumentException(String.format("Unknown ActorSystemExecutorMode %s.", executorMode));
+		}
+	}
+
 	/**
 	 * Starts the web frontend.
 	 *
@@ -504,4 +562,14 @@ public class BootstrapTools {
 
 		return clonedConfiguration;
 	}
+
+	/**
+	 * Options to specify which executor to use in an {@link ActorSystem}.
+	 */
+	public enum ActorSystemExecutorMode {
+		/** Used by default, use dispatcher with fork-join-executor. **/
+		FORK_JOIN_EXECUTOR,
+		/** Use dispatcher with fixed thread pool executor. **/
+		FIXED_THREAD_POOL_EXECUTOR
+	}
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
index d7a864e..28443b5 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java
@@ -95,6 +95,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import scala.concurrent.duration.FiniteDuration;
 
+import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
+import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FORK_JOIN_EXECUTOR;
+
 /**
  * Base class for the Flink cluster entry points.
  *
@@ -154,6 +157,9 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 	private WebMonitorEndpoint<?> webMonitorEndpoint;
 
 	@GuardedBy("lock")
+	private ActorSystem metricQueryServiceActorSystem;
+
+	@GuardedBy("lock")
 	private ArchivedExecutionGraphStore archivedExecutionGraphStore;
 
 	@GuardedBy("lock")
@@ -275,9 +281,14 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 			metricRegistry = createMetricRegistry(configuration);
 
 			// TODO: This is a temporary hack until we have ported the MetricQueryService to the new RpcEndpoint
-			// start the MetricQueryService
-			final ActorSystem actorSystem = ((AkkaRpcService) commonRpcService).getActorSystem();
-			metricRegistry.startQueryService(actorSystem, null);
+			// Start actor system for metric query service on any available port
+			metricQueryServiceActorSystem = BootstrapTools.startActorSystem(
+				configuration,
+				bindAddress,
+				0,
+				LOG,
+				FIXED_THREAD_POOL_EXECUTOR);
+			metricRegistry.startQueryService(metricQueryServiceActorSystem, null);
 
 			archivedExecutionGraphStore = createSerializableExecutionGraphStore(configuration, commonRpcService.getScheduledExecutor());
 
@@ -392,7 +403,7 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 			Configuration configuration,
 			String bindAddress,
 			String portRange) throws Exception {
-		ActorSystem actorSystem = BootstrapTools.startActorSystem(configuration, bindAddress, portRange, LOG);
+		ActorSystem actorSystem = BootstrapTools.startActorSystem(configuration, bindAddress, portRange, LOG, FORK_JOIN_EXECUTOR);
 		FiniteDuration duration = AkkaUtils.getTimeout(configuration);
 		return new AkkaRpcService(actorSystem, Time.of(duration.length(), duration.unit()));
 	}
@@ -460,6 +471,10 @@ public abstract class ClusterEntrypoint implements FatalErrorHandler {
 				terminationFutures.add(metricRegistry.shutdown());
 			}
 
+			if (metricQueryServiceActorSystem != null) {
+				terminationFutures.add(AkkaUtils.terminateActorSystem(metricQueryServiceActorSystem));
+			}
+
 			if (commonRpcService != null) {
 				terminationFutures.add(commonRpcService.stopService());
 			}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
index ca3f02b..2fd8972 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
@@ -22,6 +22,7 @@ import org.apache.flink.annotation.VisibleForTesting;
 import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.time.Time;
 import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.runtime.akka.AkkaUtils;
 import org.apache.flink.runtime.blob.TransientBlobKey;
 import org.apache.flink.runtime.clusterframework.ApplicationStatus;
 import org.apache.flink.runtime.clusterframework.messages.InfoMessage;
@@ -47,7 +48,6 @@ import org.apache.flink.runtime.leaderelection.LeaderContender;
 import org.apache.flink.runtime.leaderelection.LeaderElectionService;
 import org.apache.flink.runtime.messages.Acknowledge;
 import org.apache.flink.runtime.metrics.MetricRegistry;
-import org.apache.flink.runtime.metrics.dump.MetricQueryService;
 import org.apache.flink.runtime.registration.RegistrationResponse;
 import org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException;
 import org.apache.flink.runtime.resourcemanager.exceptions.UnknownTaskExecutorException;
@@ -590,9 +590,15 @@ public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable>
 		for (Map.Entry<ResourceID, WorkerRegistration<WorkerType>> workerRegistrationEntry : taskExecutors.entrySet()) {
 			final ResourceID tmResourceId = workerRegistrationEntry.getKey();
 			final WorkerRegistration<WorkerType> workerRegistration = workerRegistrationEntry.getValue();
-			final String taskManagerAddress = workerRegistration.getTaskExecutorGateway().getAddress();
-			final String tmMetricQueryServicePath = taskManagerAddress.substring(0, taskManagerAddress.lastIndexOf('/') + 1) +
-				MetricQueryService.METRIC_QUERY_SERVICE_NAME + '_' + tmResourceId.getResourceIdString();
+			final TaskExecutorGateway taskExecutorGateway = workerRegistration.getTaskExecutorGateway();
+			String tmMetricQueryServicePath = null;
+			try {
+				tmMetricQueryServicePath =
+					taskExecutorGateway.getMetricQueryServiceAddress(AkkaUtils.getDefaultTimeout()).get();
+			} catch (Exception e) {
+				log.info("Fail to get task manager's metric query service path for worker: {}", taskExecutorGateway.getAddress());
+				continue;
+			}
 
 			metricQueryServicePaths.add(Tuple2.of(tmResourceId, tmMetricQueryServicePath));
 		}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcServiceUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcServiceUtils.java
index 3a62698..3ee7641 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcServiceUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rpc/akka/AkkaRpcServiceUtils.java
@@ -70,7 +70,10 @@ public class AkkaRpcServiceUtils {
 	 * @throws IOException      Thrown, if the actor system can not bind to the address
 	 * @throws Exception      Thrown is some other error occurs while creating akka actor system
 	 */
-	public static RpcService createRpcService(String hostname, int port, Configuration configuration) throws Exception {
+	public static RpcService createRpcService(
+		String hostname,
+		int port,
+		Configuration configuration) throws Exception {
 		LOG.info("Starting AkkaRpcService at {}.", NetUtils.unresolvedHostAndPortToNormalizedString(hostname, port));
 
 		final ActorSystem actorSystem;
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
index ae69e56..df6d0dd 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutor.java
@@ -157,6 +157,9 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 
 	private final BlobCacheService blobCacheService;
 
+	/** The path to metric query service on this Task Manager. */
+	private final String metricQueryServicePath;
+
 	// --------- TaskManager services --------
 
 	/** The connection information of this task manager. */
@@ -211,6 +214,7 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 			TaskManagerServices taskExecutorServices,
 			HeartbeatServices heartbeatServices,
 			TaskManagerMetricGroup taskManagerMetricGroup,
+			String metricQueryServicePath,
 			BlobCacheService blobCacheService,
 			FatalErrorHandler fatalErrorHandler) {
 
@@ -224,6 +228,7 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 		this.fatalErrorHandler = checkNotNull(fatalErrorHandler);
 		this.taskManagerMetricGroup = checkNotNull(taskManagerMetricGroup);
 		this.blobCacheService = checkNotNull(blobCacheService);
+		this.metricQueryServicePath = metricQueryServicePath;
 
 		this.taskSlotTable = taskExecutorServices.getTaskSlotTable();
 		this.jobManagerTable = taskExecutorServices.getJobManagerTable();
@@ -847,6 +852,11 @@ public class TaskExecutor extends RpcEndpoint implements TaskExecutorGateway {
 		}
 	}
 
+	@Override
+	public CompletableFuture<String> getMetricQueryServiceAddress(Time timeout) {
+		return CompletableFuture.completedFuture(metricQueryServicePath);
+	}
+
 	// ----------------------------------------------------------------------
 	// Disconnection RPCs
 	// ----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
index 4f79289..abbb979 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskExecutorGateway.java
@@ -195,4 +195,11 @@ public interface TaskExecutorGateway extends RpcGateway {
 	 * @return Future which is completed with the {@link TransientBlobKey} of the uploaded file.
 	 */
 	CompletableFuture<TransientBlobKey> requestFileUpload(FileType fileType, @RpcTimeout Time timeout);
+
+	/**
+	 * Returns the fully qualified address of Metric Query Service on the TaskManager.
+	 *
+	 * @return Future String with Fully qualified (RPC) address of Metric Query Service on the TaskManager.
+	 */
+	CompletableFuture<String> getMetricQueryServiceAddress(@RpcTimeout Time timeout);
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
index 42fe5bf..80fb1ed 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
@@ -27,6 +27,7 @@ import org.apache.flink.configuration.TaskManagerOptions;
 import org.apache.flink.core.fs.FileSystem;
 import org.apache.flink.runtime.akka.AkkaUtils;
 import org.apache.flink.runtime.blob.BlobCacheService;
+import org.apache.flink.runtime.clusterframework.BootstrapTools;
 import org.apache.flink.runtime.clusterframework.types.ResourceID;
 import org.apache.flink.runtime.concurrent.FutureUtils;
 import org.apache.flink.runtime.entrypoint.ClusterConfiguration;
@@ -43,7 +44,6 @@ import org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup;
 import org.apache.flink.runtime.metrics.util.MetricUtils;
 import org.apache.flink.runtime.rpc.FatalErrorHandler;
 import org.apache.flink.runtime.rpc.RpcService;
-import org.apache.flink.runtime.rpc.akka.AkkaRpcService;
 import org.apache.flink.runtime.rpc.akka.AkkaRpcServiceUtils;
 import org.apache.flink.runtime.security.SecurityConfiguration;
 import org.apache.flink.runtime.security.SecurityUtils;
@@ -74,6 +74,7 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import static org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode.FIXED_THREAD_POOL_EXECUTOR;
 import static org.apache.flink.util.Preconditions.checkNotNull;
 
 /**
@@ -101,6 +102,8 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 
 	private final RpcService rpcService;
 
+	private final ActorSystem metricQueryServiceActorSystem;
+
 	private final HighAvailabilityServices highAvailabilityServices;
 
 	private final MetricRegistryImpl metricRegistry;
@@ -132,14 +135,14 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 			HighAvailabilityServicesUtils.AddressResolution.TRY_ADDRESS_RESOLUTION);
 
 		rpcService = createRpcService(configuration, highAvailabilityServices);
+		metricQueryServiceActorSystem = createMetricQueryServiceActorSystem(configuration, rpcService.getAddress());
 
 		HeartbeatServices heartbeatServices = HeartbeatServices.fromConfiguration(configuration);
 
 		metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(configuration));
 
 		// TODO: Temporary hack until the MetricQueryService has been ported to RpcEndpoint
-		final ActorSystem actorSystem = ((AkkaRpcService) rpcService).getActorSystem();
-		metricRegistry.startQueryService(actorSystem, resourceId);
+		metricRegistry.startQueryService(metricQueryServiceActorSystem, resourceId);
 
 		blobCacheService = new BlobCacheService(
 			configuration, highAvailabilityServices.createBlobStore(), null
@@ -159,7 +162,7 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 		this.terminationFuture = new CompletableFuture<>();
 		this.shutdown = false;
 
-		MemoryLogger.startIfConfigured(LOG, configuration, actorSystem);
+		MemoryLogger.startIfConfigured(LOG, configuration, metricQueryServiceActorSystem);
 	}
 
 	// --------------------------------------------------------------------------------------------
@@ -214,6 +217,10 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 				exception = ExceptionUtils.firstOrSuppressed(e, exception);
 			}
 
+			if (metricQueryServiceActorSystem != null) {
+				terminationFutures.add(AkkaUtils.terminateActorSystem(metricQueryServiceActorSystem));
+			}
+
 			try {
 				highAvailabilityServices.close();
 			} catch (Exception e) {
@@ -373,6 +380,8 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 
 		TaskManagerConfiguration taskManagerConfiguration = TaskManagerConfiguration.fromConfiguration(configuration);
 
+		String metricQueryServicePath = metricRegistry.getMetricQueryServicePath();
+
 		return new TaskExecutor(
 			rpcService,
 			taskManagerConfiguration,
@@ -380,6 +389,7 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 			taskManagerServices,
 			heartbeatServices,
 			taskManagerMetricGroup,
+			metricQueryServicePath,
 			blobCacheService,
 			fatalErrorHandler);
 	}
@@ -416,6 +426,32 @@ public class TaskManagerRunner implements FatalErrorHandler, AutoCloseableAsync
 
 		final String portRangeDefinition = configuration.getString(TaskManagerOptions.RPC_PORT);
 
+		return bindWithPort(configuration, taskManagerHostname, portRangeDefinition);
+	}
+
+	/**
+	 * Create a actor system service for the metric query service.
+	 *
+	 * @param configuration The configuration for the TaskManager.
+	 * @param hostname to bind the {@link ActorSystem} to
+	 */
+	public static ActorSystem createMetricQueryServiceActorSystem(
+			final Configuration configuration,
+			final String hostname) throws Exception {
+
+		return BootstrapTools.startActorSystem(
+			configuration,
+			hostname,
+			0,
+			LOG,
+			FIXED_THREAD_POOL_EXECUTOR);
+	}
+
+	private static RpcService bindWithPort(
+		Configuration configuration,
+		String taskManagerHostname,
+		String portRangeDefinition) throws Exception{
+
 		// parse port range definition and create port iterator
 		Iterator<Integer> portsIterator;
 		try {
diff --git a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
index dcf0fdd..dba82f6 100644
--- a/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
+++ b/flink-runtime/src/main/scala/org/apache/flink/runtime/akka/AkkaUtils.scala
@@ -27,6 +27,7 @@ import akka.pattern.{ask => akkaAsk}
 import com.typesafe.config.{Config, ConfigFactory}
 import org.apache.flink.api.common.time.Time
 import org.apache.flink.configuration.{AkkaOptions, Configuration, IllegalConfigurationException, SecurityOptions}
+import org.apache.flink.runtime.clusterframework.BootstrapTools.ActorSystemExecutorMode
 import org.apache.flink.runtime.concurrent.FutureUtils
 import org.apache.flink.runtime.net.SSLUtils
 import org.apache.flink.util.NetUtils
@@ -119,7 +120,23 @@ object AkkaUtils {
   }
 
   /**
-    * Return a remote Akka config for the given configuration values.
+    * Returns a remote Akka config for the given configuration values.
+    *
+    * @param configuration containing the user provided configuration values
+    * @param hostname to bind against. If null, then the loopback interface is used
+    * @param port to bind against
+    * @param executorMode containing the user specified mode of executor
+    * @return A remote Akka config
+    */
+  def getAkkaConfig(configuration: Configuration,
+                    hostname: String,
+                    port: Int,
+                    executorConfig: Config): Config = {
+    getAkkaConfig(configuration, Some((hostname, port)), executorConfig)
+  }
+
+  /**
+    * Returns a remote Akka config for the given configuration values.
     *
     * @param configuration containing the user provided configuration values
     * @param hostname to bind against. If null, then the loopback interface is used
@@ -155,7 +172,25 @@ object AkkaUtils {
   @throws(classOf[UnknownHostException])
   def getAkkaConfig(configuration: Configuration,
                     externalAddress: Option[(String, Int)]): Config = {
-    val defaultConfig = getBasicAkkaConfig(configuration)
+    getAkkaConfig(configuration, externalAddress, getForkJoinExecutorConfig(configuration))
+  }
+
+  /**
+    * Creates an akka config with the provided configuration values. If the listening address is
+    * specified, then the actor system will listen on the respective address.
+    *
+    * @param configuration instance containing the user provided configuration values
+    * @param externalAddress optional tuple of bindAddress and port to be reachable at.
+    *                        If None is given, then an Akka config for local actor system
+    *                        will be returned
+    * @param executorConfig config defining the used executor by the default dispatcher
+    * @return Akka config
+    */
+  @throws(classOf[UnknownHostException])
+  def getAkkaConfig(configuration: Configuration,
+                    externalAddress: Option[(String, Int)],
+                    executorConfig: Config): Config = {
+    val defaultConfig = getBasicAkkaConfig(configuration).withFallback(executorConfig)
 
     externalAddress match {
 
@@ -207,24 +242,6 @@ object AkkaUtils {
     val supervisorStrategy = classOf[StoppingSupervisorWithoutLoggingActorKilledExceptionStrategy]
       .getCanonicalName
 
-    val forkJoinExecutorParallelismFactor =
-      configuration.getDouble(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_FACTOR)
-
-    val forkJoinExecutorParallelismMin =
-      configuration.getInteger(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_MIN)
-
-    val forkJoinExecutorParallelismMax =
-      configuration.getInteger(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_MAX)
-
-    val forkJoinExecutorConfig =
-      s"""
-         | fork-join-executor {
-         |   parallelism-factor = $forkJoinExecutorParallelismFactor
-         |   parallelism-min = $forkJoinExecutorParallelismMin
-         |   parallelism-max = $forkJoinExecutorParallelismMax
-         | }
-       """.stripMargin
-
     val config =
       s"""
         |akka {
@@ -251,8 +268,6 @@ object AkkaUtils {
         |
         |   default-dispatcher {
         |     throughput = $akkaThroughput
-        |
-        |   $forkJoinExecutorConfig
         |   }
         | }
         |}
@@ -261,6 +276,53 @@ object AkkaUtils {
     ConfigFactory.parseString(config)
   }
 
+  def getThreadPoolExecutorConfig: Config = {
+    val configString = s"""
+       |akka {
+       |  actor {
+       |    default-dispatcher {
+       |      executor = "thread-pool-executor"
+       |      thread-pool-executor {
+       |        core-pool-size-min = 2
+       |        core-pool-size-factor = 2.0
+       |        core-pool-size-max = 4
+       |      }
+       |    }
+       |  }
+       |}
+        """.
+      stripMargin
+
+    ConfigFactory.parseString(configString)
+  }
+
+  def getForkJoinExecutorConfig(configuration: Configuration): Config = {
+    val forkJoinExecutorParallelismFactor =
+      configuration.getDouble(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_FACTOR)
+
+    val forkJoinExecutorParallelismMin =
+      configuration.getInteger(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_MIN)
+
+    val forkJoinExecutorParallelismMax =
+      configuration.getInteger(AkkaOptions.FORK_JOIN_EXECUTOR_PARALLELISM_MAX)
+
+    val configString = s"""
+       |akka {
+       |  actor {
+       |    default-dispatcher {
+       |      executor = "fork-join-executor"
+       |      fork-join-executor {
+       |        parallelism-factor = $forkJoinExecutorParallelismFactor
+       |        parallelism-min = $forkJoinExecutorParallelismMin
+       |        parallelism-max = $forkJoinExecutorParallelismMax
+       |      }
+       |    }
+       |  }
+       |}""".stripMargin
+
+    ConfigFactory.parseString(configString)
+  }
+
   def testDispatcherConfig: Config = {
     val config =
       s"""
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorITCase.java
index 61cfde5..9890f94 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorITCase.java
@@ -164,6 +164,7 @@ public class TaskExecutorITCase extends TestLogger {
 			taskManagerServices,
 			heartbeatServices,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			new BlobCacheService(
 				configuration,
 				new VoidBlobStore(),
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
index 9c1f2f2..22256ee 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskExecutorTest.java
@@ -270,6 +270,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			heartbeatServices,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -360,6 +361,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			heartbeatServices,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -510,6 +512,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			heartbeatServices,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -588,6 +591,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -651,6 +655,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -773,6 +778,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -873,6 +879,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -988,6 +995,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1107,6 +1115,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			taskManagerMetricGroup,
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1222,6 +1231,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			heartbeatServicesMock,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1295,6 +1305,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			heartbeatServices,
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1351,6 +1362,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(1000L, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1443,6 +1455,7 @@ public class TaskExecutorTest extends TestLogger {
 			taskManagerServices,
 			new HeartbeatServices(heartbeatInterval, 10L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1550,6 +1563,7 @@ public class TaskExecutorTest extends TestLogger {
 				.build(),
 			new HeartbeatServices(heartbeatInterval, 1000L),
 			UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+			null,
 			dummyBlobCacheService,
 			testingFatalErrorHandler);
 
@@ -1692,6 +1706,7 @@ public class TaskExecutorTest extends TestLogger {
                 taskManagerServices,
                 new HeartbeatServices(1000L, 1000L),
                 UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(),
+                null,
                 dummyBlobCacheService,
                 testingFatalErrorHandler);
 	}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
index a9e9949..e86a95f 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TestingTaskExecutorGateway.java
@@ -150,6 +150,11 @@ public class TestingTaskExecutorGateway implements TaskExecutorGateway {
 	}
 
 	@Override
+	public CompletableFuture<String> getMetricQueryServiceAddress(Time timeout) {
+		return CompletableFuture.completedFuture(address);
+	}
+
+	@Override
 	public String getAddress() {
 		return address;
 	}
diff --git a/flink-runtime/src/test/scala/org/apache/flink/runtime/akka/AkkaUtilsTest.scala b/flink-runtime/src/test/scala/org/apache/flink/runtime/akka/AkkaUtilsTest.scala
index d02a554..e5c1668 100644
--- a/flink-runtime/src/test/scala/org/apache/flink/runtime/akka/AkkaUtilsTest.scala
+++ b/flink-runtime/src/test/scala/org/apache/flink/runtime/akka/AkkaUtilsTest.scala
@@ -18,7 +18,7 @@
 
 package org.apache.flink.runtime.akka
 
-import java.net.InetSocketAddress
+import java.net.{InetAddress, InetSocketAddress}
 
 import org.apache.flink.configuration.{AkkaOptions, Configuration, IllegalConfigurationException}
 import org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils.AddressResolution
@@ -167,4 +167,30 @@ class AkkaUtilsTest
     akkaConfig.getString("akka.remote.netty.tcp.hostname") should
       equal(NetUtils.unresolvedHostToNormalizedString(hostname))
   }
+
+  test("null hostname should go to localhost") {
+    val configure = AkkaUtils.getAkkaConfig(new Configuration(), Some((null, 1772)))
+
+    val hostname = configure.getString("akka.remote.netty.tcp.hostname")
+
+    InetAddress.getByName(hostname).isLoopbackAddress should be(true)
+  }
+
+  test("getAkkaConfig defaults to fork-join-executor") {
+    val akkaConfig = AkkaUtils.getAkkaConfig(new Configuration())
+
+    akkaConfig.getString("akka.actor.default-dispatcher.executor") should
+      equal("fork-join-executor")
+  }
+
+  test("getAkkaConfig respects executor config") {
+    val akkaConfig = AkkaUtils.getAkkaConfig(
+      new Configuration(),
+      "localhost",
+      1234,
+      AkkaUtils.getThreadPoolExecutorConfig)
+
+    akkaConfig.getString("akka.actor.default-dispatcher.executor") should
+      equal("thread-pool-executor")
+  }
 }