Search in sources :

Example 1 with JobClient

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

the class StreamContextEnvironment method executeAsync.

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

Example 2 with JobClient

use of org.apache.flink.core.execution.JobClient 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;
    }
}
Also used : Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LoggerFactory(org.slf4j.LoggerFactory) PublicEvolving(org.apache.flink.annotation.PublicEvolving) PipelineExecutorServiceLoader(org.apache.flink.core.execution.PipelineExecutorServiceLoader) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) ShutdownHookUtil(org.apache.flink.util.ShutdownHookUtil) ArrayList(java.util.ArrayList) JobListener(org.apache.flink.core.execution.JobListener) StreamGraph(org.apache.flink.streaming.api.graph.StreamGraph) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) ObjectOutputStream(java.io.ObjectOutputStream) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) DetachedJobExecutionResult(org.apache.flink.core.execution.DetachedJobExecutionResult) Logger(org.slf4j.Logger) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) StreamExecutionEnvironmentFactory(org.apache.flink.streaming.api.environment.StreamExecutionEnvironmentFactory) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) IOException(java.io.IOException) JobClient(org.apache.flink.core.execution.JobClient) Serializable(java.io.Serializable) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TimeUnit(java.util.concurrent.TimeUnit) MapDifference(org.apache.flink.shaded.guava30.com.google.common.collect.MapDifference) Maps(org.apache.flink.shaded.guava30.com.google.common.collect.Maps) List(java.util.List) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) ConfigurationNotAllowedMessage(org.apache.flink.runtime.dispatcher.ConfigurationNotAllowedMessage) Internal(org.apache.flink.annotation.Internal) Collections(java.util.Collections) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) DetachedJobExecutionResult(org.apache.flink.core.execution.DetachedJobExecutionResult) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient)

Example 3 with JobClient

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

the class AbstractSessionClusterExecutor method execute.

@Override
public CompletableFuture<JobClient> execute(@Nonnull final Pipeline pipeline, @Nonnull final Configuration configuration, @Nonnull final ClassLoader userCodeClassloader) throws Exception {
    final JobGraph jobGraph = PipelineExecutorUtils.getJobGraph(pipeline, configuration);
    try (final ClusterDescriptor<ClusterID> clusterDescriptor = clusterClientFactory.createClusterDescriptor(configuration)) {
        final ClusterID clusterID = clusterClientFactory.getClusterId(configuration);
        checkState(clusterID != null);
        final ClusterClientProvider<ClusterID> clusterClientProvider = clusterDescriptor.retrieve(clusterID);
        ClusterClient<ClusterID> clusterClient = clusterClientProvider.getClusterClient();
        return clusterClient.submitJob(jobGraph).thenApplyAsync(FunctionUtils.uncheckedFunction(jobId -> {
            ClientUtils.waitUntilJobInitializationFinished(() -> clusterClient.getJobStatus(jobId).get(), () -> clusterClient.requestJobResult(jobId).get(), userCodeClassloader);
            return jobId;
        })).thenApplyAsync(jobID -> (JobClient) new ClusterClientJobClientAdapter<>(clusterClientProvider, jobID, userCodeClassloader)).whenCompleteAsync((ignored1, ignored2) -> clusterClient.close());
    }
}
Also used : Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) ClientUtils(org.apache.flink.client.ClientUtils) ClusterClientFactory(org.apache.flink.client.deployment.ClusterClientFactory) Pipeline(org.apache.flink.api.dag.Pipeline) Configuration(org.apache.flink.configuration.Configuration) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CompletableFuture(java.util.concurrent.CompletableFuture) PipelineExecutor(org.apache.flink.core.execution.PipelineExecutor) JobClient(org.apache.flink.core.execution.JobClient) ClusterClientJobClientAdapter(org.apache.flink.client.deployment.ClusterClientJobClientAdapter) ClusterDescriptor(org.apache.flink.client.deployment.ClusterDescriptor) ClusterClient(org.apache.flink.client.program.ClusterClient) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Internal(org.apache.flink.annotation.Internal) ClusterClientProvider(org.apache.flink.client.program.ClusterClientProvider) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Nonnull(javax.annotation.Nonnull) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobClient(org.apache.flink.core.execution.JobClient)

Example 4 with JobClient

use of org.apache.flink.core.execution.JobClient 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;
    }
}
Also used : DetachedJobExecutionResult(org.apache.flink.core.execution.DetachedJobExecutionResult) ExecutionEnvironmentFactory(org.apache.flink.api.java.ExecutionEnvironmentFactory) Logger(org.slf4j.Logger) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Configuration(org.apache.flink.configuration.Configuration) LoggerFactory(org.slf4j.LoggerFactory) PipelineExecutorServiceLoader(org.apache.flink.core.execution.PipelineExecutorServiceLoader) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) ShutdownHookUtil(org.apache.flink.util.ShutdownHookUtil) JobClient(org.apache.flink.core.execution.JobClient) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) JobListener(org.apache.flink.core.execution.JobListener) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) DetachedJobExecutionResult(org.apache.flink.core.execution.DetachedJobExecutionResult) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) JobListener(org.apache.flink.core.execution.JobListener) JobClient(org.apache.flink.core.execution.JobClient)

Example 5 with JobClient

use of org.apache.flink.core.execution.JobClient 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;
    }
}
Also used : CollectionInputFormat(org.apache.flink.api.java.io.CollectionInputFormat) PojoTypeInfo(org.apache.flink.api.java.typeutils.PojoTypeInfo) Arrays(java.util.Arrays) Tuple2(org.apache.flink.api.java.tuple.Tuple2) PipelineOptions(org.apache.flink.configuration.PipelineOptions) LoggerFactory(org.slf4j.LoggerFactory) ExceptionUtils(org.apache.flink.util.ExceptionUtils) FileInputFormat(org.apache.flink.api.common.io.FileInputFormat) DataSink(org.apache.flink.api.java.operators.DataSink) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) InstantiationUtil(org.apache.flink.util.InstantiationUtil) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) SplittableIterator(org.apache.flink.util.SplittableIterator) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) Path(org.apache.flink.core.fs.Path) Plan(org.apache.flink.api.common.Plan) PrimitiveInputFormat(org.apache.flink.api.java.io.PrimitiveInputFormat) InputFormat(org.apache.flink.api.common.io.InputFormat) Public(org.apache.flink.annotation.Public) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) DefaultExecutorServiceLoader(org.apache.flink.core.execution.DefaultExecutorServiceLoader) ValueTypeInfo(org.apache.flink.api.java.typeutils.ValueTypeInfo) PipelineExecutorFactory(org.apache.flink.core.execution.PipelineExecutorFactory) Collection(java.util.Collection) DistributedCacheEntry(org.apache.flink.api.common.cache.DistributedCache.DistributedCacheEntry) DistributedCache(org.apache.flink.api.common.cache.DistributedCache) Preconditions(org.apache.flink.util.Preconditions) Serializable(java.io.Serializable) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) List(java.util.List) TextValueInputFormat(org.apache.flink.api.java.io.TextValueInputFormat) TypeExtractor(org.apache.flink.api.java.typeutils.TypeExtractor) ResultTypeQueryable(org.apache.flink.api.java.typeutils.ResultTypeQueryable) DataSource(org.apache.flink.api.java.operators.DataSource) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) IteratorInputFormat(org.apache.flink.api.java.io.IteratorInputFormat) FlinkException(org.apache.flink.util.FlinkException) CsvReader(org.apache.flink.api.java.io.CsvReader) PublicEvolving(org.apache.flink.annotation.PublicEvolving) PipelineExecutorServiceLoader(org.apache.flink.core.execution.PipelineExecutorServiceLoader) CompletableFuture(java.util.concurrent.CompletableFuture) RestartStrategies(org.apache.flink.api.common.restartstrategy.RestartStrategies) PipelineExecutor(org.apache.flink.core.execution.PipelineExecutor) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) ReadableConfig(org.apache.flink.configuration.ReadableConfig) JobListener(org.apache.flink.core.execution.JobListener) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) RestOptions(org.apache.flink.configuration.RestOptions) DetachedJobExecutionResult(org.apache.flink.core.execution.DetachedJobExecutionResult) Serializer(com.esotericsoftware.kryo.Serializer) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ParallelIteratorInputFormat(org.apache.flink.api.java.io.ParallelIteratorInputFormat) Configuration(org.apache.flink.configuration.Configuration) JobClient(org.apache.flink.core.execution.JobClient) Operator(org.apache.flink.api.java.operators.Operator) TextInputFormat(org.apache.flink.api.java.io.TextInputFormat) StringValue(org.apache.flink.types.StringValue) NumberSequenceIterator(org.apache.flink.util.NumberSequenceIterator) Internal(org.apache.flink.annotation.Internal) PlanGenerator(org.apache.flink.api.java.utils.PlanGenerator) PipelineExecutorFactory(org.apache.flink.core.execution.PipelineExecutorFactory) Plan(org.apache.flink.api.common.Plan) JobClient(org.apache.flink.core.execution.JobClient) PublicEvolving(org.apache.flink.annotation.PublicEvolving)

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