Search in sources :

Example 46 with JobClient

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

the class Flink114Shims 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)

Example 47 with JobClient

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

the class TableEnvironmentImpl method executeInternal.

private TableResultInternal executeInternal(List<Transformation<?>> transformations, List<String> sinkIdentifierNames) {
    final String defaultJobName = "insert-into_" + String.join(",", sinkIdentifierNames);
    Pipeline pipeline = execEnv.createPipeline(transformations, tableConfig.getConfiguration(), defaultJobName);
    try {
        JobClient jobClient = execEnv.executeAsync(pipeline);
        final List<Column> columns = new ArrayList<>();
        Long[] affectedRowCounts = new Long[transformations.size()];
        for (int i = 0; i < transformations.size(); ++i) {
            // use sink identifier name as field name
            columns.add(Column.physical(sinkIdentifierNames.get(i), DataTypes.BIGINT()));
            affectedRowCounts[i] = -1L;
        }
        return TableResultImpl.builder().jobClient(jobClient).resultKind(ResultKind.SUCCESS_WITH_CONTENT).schema(ResolvedSchema.of(columns)).resultProvider(new InsertResultProvider(affectedRowCounts).setJobClient(jobClient)).build();
    } catch (Exception e) {
        throw new TableException("Failed to execute sql", e);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) Column(org.apache.flink.table.catalog.Column) ArrayList(java.util.ArrayList) JobClient(org.apache.flink.core.execution.JobClient) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) TableAlreadyExistException(org.apache.flink.table.catalog.exceptions.TableAlreadyExistException) TableException(org.apache.flink.table.api.TableException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) DatabaseNotEmptyException(org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException) DatabaseAlreadyExistException(org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException) SqlParserException(org.apache.flink.table.api.SqlParserException) ValidationException(org.apache.flink.table.api.ValidationException) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) Pipeline(org.apache.flink.api.dag.Pipeline)

Example 48 with JobClient

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

the class ContextEnvironment method executeAsync.

@Override
public JobClient executeAsync(String jobName) throws Exception {
    validateAllowedExecution();
    final JobClient jobClient = super.executeAsync(jobName);
    if (!suppressSysout) {
        System.out.println("Job has been submitted with JobID " + jobClient.getJobID());
    }
    LOG.info("Job has been submitted with JobID {}", jobClient.getJobID());
    return jobClient;
}
Also used : JobClient(org.apache.flink.core.execution.JobClient)

Example 49 with JobClient

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

the class AdaptiveSchedulerITCase method testStopWithSavepointNoError.

@Test
public void testStopWithSavepointNoError() throws Exception {
    StreamExecutionEnvironment env = getEnvWithSource(StopWithSavepointTestBehavior.NO_FAILURE);
    DummySource.resetForParallelism(PARALLELISM);
    JobClient client = env.executeAsync();
    DummySource.awaitRunning();
    final File savepointDirectory = tempFolder.newFolder("savepoint");
    final String savepoint = client.stopWithSavepoint(false, savepointDirectory.getAbsolutePath(), SavepointFormatType.CANONICAL).get();
    assertThat(savepoint, containsString(savepointDirectory.getAbsolutePath()));
    assertThat(client.getJobStatus().get(), is(JobStatus.FINISHED));
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JobClient(org.apache.flink.core.execution.JobClient) File(java.io.File) Test(org.junit.Test)

Example 50 with JobClient

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

the class AdaptiveSchedulerITCase method testStopWithSavepointFailOnStop.

@Test
public void testStopWithSavepointFailOnStop() throws Exception {
    StreamExecutionEnvironment env = getEnvWithSource(StopWithSavepointTestBehavior.FAIL_ON_CHECKPOINT_COMPLETE);
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 0L));
    DummySource.resetForParallelism(PARALLELISM);
    JobClient client = env.executeAsync();
    DummySource.awaitRunning();
    try {
        client.stopWithSavepoint(false, tempFolder.newFolder("savepoint").getAbsolutePath(), SavepointFormatType.CANONICAL).get();
        fail("Expect exception");
    } catch (ExecutionException e) {
        assertThat(e, containsCause(FlinkException.class));
    }
    // expect job to run again (maybe restart)
    CommonTestUtils.waitUntilCondition(() -> client.getJobStatus().get() == JobStatus.RUNNING, Deadline.fromNow(Duration.of(1, ChronoUnit.MINUTES)));
}
Also used : StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) ExecutionException(java.util.concurrent.ExecutionException) JobClient(org.apache.flink.core.execution.JobClient) Test(org.junit.Test)

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