use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class StreamContextEnvironment method execute.
@Override
public JobExecutionResult execute(StreamGraph streamGraph) throws Exception {
checkNotAllowedConfigurations();
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;
}
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class ContextEnvironment method execute.
@Override
public JobExecutionResult execute(String jobName) throws Exception {
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;
}
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class ExecutionEnvironment method executeAsync.
/**
* Triggers the program execution asynchronously. The environment will execute all parts of the
* program that have resulted in a "sink" operation. Sink operations are for example printing
* results ({@link DataSet#print()}, writing results (e.g. {@link DataSet#writeAsText(String)},
* {@link DataSet#write(org.apache.flink.api.common.io.FileOutputFormat, String)}, or other
* generic data sinks created with {@link
* DataSet#output(org.apache.flink.api.common.io.OutputFormat)}.
*
* <p>The program execution will be logged and displayed with the given job name.
*
* @return A {@link JobClient} that can be used to communicate with the submitted job, completed
* on submission succeeded.
* @throws Exception Thrown, if the program submission fails.
*/
@PublicEvolving
public JobClient executeAsync(String jobName) throws Exception {
checkNotNull(configuration.get(DeploymentOptions.TARGET), "No execution.target specified in your configuration file.");
final Plan plan = createProgramPlan(jobName);
final PipelineExecutorFactory executorFactory = executorServiceLoader.getExecutorFactory(configuration);
checkNotNull(executorFactory, "Cannot find compatible factory for specified execution.target (=%s)", configuration.get(DeploymentOptions.TARGET));
CompletableFuture<JobClient> jobClientFuture = executorFactory.getExecutor(configuration).execute(plan, configuration, userClassloader);
try {
JobClient jobClient = jobClientFuture.get();
jobListeners.forEach(jobListener -> jobListener.onJobSubmitted(jobClient, null));
return jobClient;
} catch (Throwable t) {
jobListeners.forEach(jobListener -> jobListener.onJobSubmitted(null, t));
ExceptionUtils.rethrow(t);
// make javac happy, this code path will not be reached
return null;
}
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class JobListenerITCase method testExecuteCallsJobListenerOnMainThreadOnBatchEnvironment.
@Test
public void testExecuteCallsJobListenerOnMainThreadOnBatchEnvironment() throws Exception {
AtomicReference<Thread> threadReference = new AtomicReference<>();
ExecutionEnvironment env = new ExecutionEnvironment(getClientConfiguration());
env.registerJobListener(new JobListener() {
@Override
public void onJobSubmitted(JobClient jobClient, Throwable t) {
threadReference.set(Thread.currentThread());
}
@Override
public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
}
});
env.fromElements(1, 2, 3, 4, 5).output(new DiscardingOutputFormat<>());
env.execute();
assertThat(Thread.currentThread(), is(threadReference.get()));
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnStreamingEnvironment.
@Test
public void testExecuteAsyncCallsJobListenerOnStreamingEnvironment() throws Exception {
AtomicReference<JobID> jobIdReference = new AtomicReference<>();
OneShotLatch submissionLatch = new OneShotLatch();
StreamExecutionEnvironment env = new StreamExecutionEnvironment(getClientConfiguration());
env.registerJobListener(new JobListener() {
@Override
public void onJobSubmitted(JobClient jobClient, Throwable t) {
jobIdReference.set(jobClient.getJobID());
submissionLatch.trigger();
}
@Override
public void onJobExecuted(JobExecutionResult jobExecutionResult, Throwable throwable) {
}
});
env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());
JobClient jobClient = env.executeAsync();
submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
// when executing asynchronously we don't get an "executed" callback
assertThat(jobClient.getJobID(), is(jobIdReference.get()));
}
Aggregations