Search in sources :

Example 11 with JobListener

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);
        }
    }
}
Also used : WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) JobListener(org.apache.flink.core.execution.JobListener) FlinkException(org.apache.flink.util.FlinkException)

Example 12 with JobListener

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();
}
Also used : SqlSplitter(org.apache.zeppelin.interpreter.util.SqlSplitter) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) SqlCommandParser(org.apache.zeppelin.flink.sql.SqlCommandParser) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) Nullable(javax.annotation.Nullable)

Example 13 with JobListener

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()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 14 with JobListener

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()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

Example 15 with JobListener

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()));
}
Also used : JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

JobListener (org.apache.flink.core.execution.JobListener)16 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)14 JobClient (org.apache.flink.core.execution.JobClient)14 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Test (org.junit.Test)8 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)6 List (java.util.List)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Configuration (org.apache.flink.configuration.Configuration)5 DeploymentOptions (org.apache.flink.configuration.DeploymentOptions)5 DetachedJobExecutionResult (org.apache.flink.core.execution.DetachedJobExecutionResult)5 PipelineExecutorServiceLoader (org.apache.flink.core.execution.PipelineExecutorServiceLoader)5 ExceptionUtils (org.apache.flink.util.ExceptionUtils)5 FlinkException (org.apache.flink.util.FlinkException)5 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)5 WrappingRuntimeException (org.apache.flink.util.WrappingRuntimeException)5 Serializable (java.io.Serializable)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4