Search in sources :

Example 41 with JobClient

use of org.apache.flink.core.execution.JobClient 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 42 with JobClient

use of org.apache.flink.core.execution.JobClient in project zeppelin by apache.

the class JobManager method addJob.

public void addJob(InterpreterContext context, JobClient jobClient) {
    String paragraphId = context.getParagraphId();
    JobClient previousJobClient = this.jobs.put(paragraphId, jobClient);
    if (previousJobClient != null) {
        LOGGER.warn("There's another Job {} that is associated with paragraph {}", jobClient.getJobID(), paragraphId);
        return;
    }
    long checkInterval = Long.parseLong(properties.getProperty("zeppelin.flink.job.check_interval", "1000"));
    FlinkJobProgressPoller thread = new FlinkJobProgressPoller(flinkWebUrl, jobClient.getJobID(), context, checkInterval);
    thread.setName("JobProgressPoller-Thread-" + paragraphId);
    thread.start();
    this.jobProgressPollerMap.put(jobClient.getJobID(), thread);
}
Also used : JobClient(org.apache.flink.core.execution.JobClient)

Example 43 with JobClient

use of org.apache.flink.core.execution.JobClient in project zeppelin by apache.

the class JobManager method cancelJob.

public void cancelJob(InterpreterContext context) throws InterpreterException {
    LOGGER.info("Canceling job associated of paragraph: {}", context.getParagraphId());
    JobClient jobClient = this.jobs.get(context.getParagraphId());
    if (jobClient == null) {
        LOGGER.warn("Unable to remove Job from paragraph {} as no job associated to this paragraph", context.getParagraphId());
        return;
    }
    boolean cancelled = false;
    try {
        String savePointDir = context.getLocalProperties().get(SAVEPOINT_DIR);
        if (StringUtils.isBlank(savePointDir)) {
            LOGGER.info("Trying to cancel job of paragraph {}", context.getParagraphId());
            jobClient.cancel();
        } else {
            LOGGER.info("Trying to stop job of paragraph {} with save point dir: {}", context.getParagraphId(), savePointDir);
            try {
                String savePointPath = jobClient.stopWithSavepoint(true, savePointDir).get();
                Map<String, String> config = new HashMap<>();
                config.put(SAVEPOINT_PATH, savePointPath);
                context.getIntpEventClient().updateParagraphConfig(context.getNoteId(), context.getParagraphId(), config);
                LOGGER.info("Job {} of paragraph {} is stopped with save point path: {}", jobClient.getJobID(), context.getParagraphId(), savePointPath);
            } catch (Exception e) {
                LOGGER.warn("Fail to cancel job of paragraph {} with savepoint, try to cancel it without savepoint", context.getParagraphId(), e);
                jobClient.cancel();
            }
        }
        cancelled = true;
    } catch (Exception e) {
        String errorMessage = String.format("Fail to cancel job %s that is associated " + "with paragraph %s", jobClient.getJobID(), context.getParagraphId());
        LOGGER.warn(errorMessage, e);
        throw new InterpreterException(errorMessage, e);
    } finally {
        if (cancelled) {
            LOGGER.info("Cancelling is successful, remove the associated FlinkJobProgressPoller of paragraph: " + context.getParagraphId());
            FlinkJobProgressPoller jobProgressPoller = jobProgressPollerMap.remove(jobClient.getJobID());
            if (jobProgressPoller != null) {
                jobProgressPoller.cancel();
                jobProgressPoller.interrupt();
            }
            this.jobs.remove(context.getParagraphId());
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) JobClient(org.apache.flink.core.execution.JobClient) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 44 with JobClient

use of org.apache.flink.core.execution.JobClient in project zeppelin by apache.

the class JobManager method getJobProgress.

public int getJobProgress(String paragraphId) {
    JobClient jobClient = this.jobs.get(paragraphId);
    if (jobClient == null) {
        LOGGER.warn("Unable to get job progress for paragraph: " + paragraphId + ", because no job is associated with this paragraph");
        return 0;
    }
    FlinkJobProgressPoller jobProgressPoller = this.jobProgressPollerMap.get(jobClient.getJobID());
    if (jobProgressPoller == null) {
        LOGGER.warn("Unable to get job progress for paragraph: " + paragraphId + ", because no job progress is associated with this jobId: " + jobClient.getJobID());
        return 0;
    }
    return jobProgressPoller.getProgress();
}
Also used : JobClient(org.apache.flink.core.execution.JobClient)

Example 45 with JobClient

use of org.apache.flink.core.execution.JobClient in project zeppelin by apache.

the class Flink113Shims method executeMultipleInsertInto.

@Override
public boolean executeMultipleInsertInto(String jobName, Object tblEnv, InterpreterContext context) throws Exception {
    JobClient jobClient = statementSetMap.get(context.getParagraphId()).execute().getJobClient().get();
    while (!jobClient.getJobStatus().get().isTerminalState()) {
        LOGGER.debug("Wait for job to finish");
        Thread.sleep(1000 * 5);
    }
    if (jobClient.getJobStatus().get() == JobStatus.CANCELED) {
        context.out.write("Job is cancelled.\n");
        return false;
    }
    return true;
}
Also used : JobClient(org.apache.flink.core.execution.JobClient)

Aggregations

JobClient (org.apache.flink.core.execution.JobClient)70 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)36 Test (org.junit.Test)32 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)16 Configuration (org.apache.flink.configuration.Configuration)16 JobListener (org.apache.flink.core.execution.JobListener)14 ArrayList (java.util.ArrayList)12 List (java.util.List)10 JobID (org.apache.flink.api.common.JobID)10 ExecutionException (java.util.concurrent.ExecutionException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DEFAULT_COLLECT_DATA_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_COLLECT_DATA_TIMEOUT)8 DEFAULT_JOB_STATUS_CHANGE_TIMEOUT (org.apache.flink.connector.testframe.utils.ConnectorTestConstants.DEFAULT_JOB_STATUS_CHANGE_TIMEOUT)8 IOException (java.io.IOException)7 DisplayName (org.junit.jupiter.api.DisplayName)7 TestTemplate (org.junit.jupiter.api.TestTemplate)7 Iterator (java.util.Iterator)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)6 Preconditions.checkNotNull (org.apache.flink.util.Preconditions.checkNotNull)6