You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by kk...@apache.org on 2020/05/29 07:18:19 UTC
[flink] branch release-1.10 updated: [FLINK-17744] Make
(Stream)ContextEnvironment#execute call JobListener#onJobExecuted
This is an automated email from the ASF dual-hosted git repository.
kkloudas pushed a commit to branch release-1.10
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/release-1.10 by this push:
new 01aa611 [FLINK-17744] Make (Stream)ContextEnvironment#execute call JobListener#onJobExecuted
01aa611 is described below
commit 01aa611e2096af1911ae63ba109810582e945d8c
Author: Echo Lee <13...@qq.com>
AuthorDate: Tue May 26 16:44:13 2020 +0800
[FLINK-17744] Make (Stream)ContextEnvironment#execute call JobListener#onJobExecuted
---
.../flink/client/program/ContextEnvironment.java | 27 +++++++++++++++++++++-
.../flink/api/java/ExecutionEnvironment.java | 7 ++++++
.../api/environment/StreamContextEnvironment.java | 23 +++++++++++++++++-
.../environment/StreamExecutionEnvironment.java | 7 ++++++
4 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/flink-clients/src/main/java/org/apache/flink/client/program/ContextEnvironment.java b/flink-clients/src/main/java/org/apache/flink/client/program/ContextEnvironment.java
index 824f4fb..6d5be1a 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/program/ContextEnvironment.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/program/ContextEnvironment.java
@@ -25,15 +25,21 @@ import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.DeploymentOptions;
import org.apache.flink.core.execution.DetachedJobExecutionResult;
import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.JobListener;
import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkRuntimeException;
import org.apache.flink.util.ShutdownHookUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
/**
* Execution Environment for remote execution with the Client.
*/
@@ -50,7 +56,26 @@ public class ContextEnvironment extends ExecutionEnvironment {
@Override
public JobExecutionResult execute(String jobName) throws Exception {
- JobClient jobClient = executeAsync(jobName);
+ final JobClient jobClient = executeAsync(jobName);
+ final List<JobListener> jobListeners = getJobListeners();
+
+ try {
+ final JobExecutionResult jobExecutionResult = getJobExecutionResult(jobClient);
+ jobListeners.forEach(jobListener ->
+ jobListener.onJobExecuted(jobExecutionResult, null));
+ return jobExecutionResult;
+ } catch (Throwable t) {
+ jobListeners.forEach(jobListener ->
+ jobListener.onJobExecuted(null, ExceptionUtils.stripExecutionException(t)));
+ ExceptionUtils.rethrowException(t);
+
+ // never reached, only make javac happy
+ return null;
+ }
+ }
+
+ private JobExecutionResult getJobExecutionResult(final JobClient jobClient) throws Exception {
+ checkNotNull(jobClient);
JobExecutionResult jobExecutionResult;
if (getConfiguration().getBoolean(DeploymentOptions.ATTACHED)) {
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java b/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java
index 1cd20f7..5703a9b 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/ExecutionEnvironment.java
@@ -216,6 +216,13 @@ public class ExecutionEnvironment {
}
/**
+ * Gets the config JobListeners.
+ */
+ protected List<JobListener> getJobListeners() {
+ return jobListeners;
+ }
+
+ /**
* Gets the parallelism with which operation are executed by default. Operations can
* individually override this value to use a specific parallelism via
* {@link Operator#setParallelism(int)}. Other operations may need to run with a different
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamContextEnvironment.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamContextEnvironment.java
index b4ecbbf..bb31628 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamContextEnvironment.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamContextEnvironment.java
@@ -24,12 +24,15 @@ import org.apache.flink.client.program.ContextEnvironment;
import org.apache.flink.configuration.DeploymentOptions;
import org.apache.flink.core.execution.DetachedJobExecutionResult;
import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.JobListener;
import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.ShutdownHookUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@@ -60,8 +63,26 @@ public class StreamContextEnvironment extends StreamExecutionEnvironment {
@Override
public JobExecutionResult execute(StreamGraph streamGraph) throws Exception {
- JobClient jobClient = executeAsync(streamGraph);
+ final JobClient jobClient = executeAsync(streamGraph);
+ final List<JobListener> jobListeners = getJobListeners();
+
+ try {
+ final JobExecutionResult jobExecutionResult = getJobExecutionResult(jobClient);
+ jobListeners.forEach(jobListener ->
+ jobListener.onJobExecuted(jobExecutionResult, null));
+ return jobExecutionResult;
+ } catch (Throwable t) {
+ jobListeners.forEach(jobListener ->
+ jobListener.onJobExecuted(null, ExceptionUtils.stripExecutionException(t)));
+ ExceptionUtils.rethrowException(t);
+
+ // never reached, only make javac happy
+ return null;
+ }
+ }
+ private JobExecutionResult getJobExecutionResult(final JobClient jobClient) throws Exception {
+ checkNotNull(jobClient);
JobExecutionResult jobExecutionResult;
if (getConfiguration().getBoolean(DeploymentOptions.ATTACHED)) {
CompletableFuture<JobExecutionResult> jobExecutionResultFuture =
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
index 0bff266..a8de8ac 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
@@ -237,6 +237,13 @@ public class StreamExecutionEnvironment {
}
/**
+ * Gets the config JobListeners.
+ */
+ protected List<JobListener> getJobListeners() {
+ return jobListeners;
+ }
+
+ /**
* Sets the parallelism for operations executed through this environment.
* Setting a parallelism of x here will cause all operators (such as map,
* batchReduce) to run with x parallel instances. This method overrides the