use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class ExecutionEnvironment method registerCustomListeners.
private void registerCustomListeners(final ClassLoader classLoader, final List<String> listeners) {
for (String listener : listeners) {
try {
final JobListener jobListener = InstantiationUtil.instantiate(listener, JobListener.class, classLoader);
jobListeners.add(jobListener);
} catch (FlinkException e) {
throw new WrappingRuntimeException("Could not load JobListener : " + listener, e);
}
}
}
use of org.apache.flink.core.execution.JobListener in project zeppelin by apache.
the class FlinkSqlInterpreter method open.
@Override
public void open() throws InterpreterException {
this.sqlCommandParser = new SqlCommandParser(flinkInterpreter.getFlinkShims(), tbenv);
this.sqlSplitter = new SqlSplitter();
JobListener jobListener = new JobListener() {
@Override
public void onJobSubmitted(@Nullable JobClient jobClient, @Nullable Throwable throwable) {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
LOGGER.info("UnLock JobSubmitLock");
}
}
@Override
public void onJobExecuted(@Nullable JobExecutionResult jobExecutionResult, @Nullable Throwable throwable) {
}
};
flinkInterpreter.getExecutionEnvironment().getJavaEnv().registerJobListener(jobListener);
flinkInterpreter.getStreamExecutionEnvironment().getJavaEnv().registerJobListener(jobListener);
this.defaultSqlParallelism = flinkInterpreter.getDefaultSqlParallelism();
this.tableConfigOptions = flinkInterpreter.getFlinkShims().extractTableConfigOptions();
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class JobListenerITCase method testExecuteCallsJobListenerOnStreamingEnvironment.
@Test
public void testExecuteCallsJobListenerOnStreamingEnvironment() throws Exception {
AtomicReference<JobID> jobIdReference = new AtomicReference<>();
OneShotLatch submissionLatch = new OneShotLatch();
OneShotLatch executionLatch = 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) {
executionLatch.trigger();
}
});
env.fromElements(1, 2, 3, 4, 5).addSink(new DiscardingSink<>());
JobExecutionResult jobExecutionResult = env.execute();
submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
executionLatch.await(2000L, TimeUnit.MILLISECONDS);
assertThat(jobExecutionResult.getJobID(), is(jobIdReference.get()));
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class JobListenerITCase method testExecuteAsyncCallsJobListenerOnMainThreadOnBatchEnvironment.
@Test
public void testExecuteAsyncCallsJobListenerOnMainThreadOnBatchEnvironment() 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.executeAsync();
assertThat(Thread.currentThread(), is(threadReference.get()));
}
use of org.apache.flink.core.execution.JobListener in project flink by apache.
the class JobListenerITCase method testExecuteCallsJobListenerOnBatchEnvironment.
@Test
public void testExecuteCallsJobListenerOnBatchEnvironment() throws Exception {
AtomicReference<JobID> jobIdReference = new AtomicReference<>();
OneShotLatch submissionLatch = new OneShotLatch();
OneShotLatch executionLatch = new OneShotLatch();
ExecutionEnvironment env = new ExecutionEnvironment(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) {
executionLatch.trigger();
}
});
env.fromElements(1, 2, 3, 4, 5).output(new DiscardingOutputFormat<>());
JobExecutionResult jobExecutionResult = env.execute();
submissionLatch.await(2000L, TimeUnit.MILLISECONDS);
executionLatch.await(2000L, TimeUnit.MILLISECONDS);
assertThat(jobExecutionResult.getJobID(), is(jobIdReference.get()));
}
Aggregations