Search in sources :

Example 1 with PipelineExecutorServiceLoader

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

the class StreamContextEnvironment method setAsContext.

// --------------------------------------------------------------------------------------------
public static void setAsContext(final PipelineExecutorServiceLoader executorServiceLoader, final Configuration configuration, final ClassLoader userCodeClassLoader, final boolean enforceSingleJobExecution, final boolean suppressSysout) {
    StreamExecutionEnvironmentFactory factory = conf -> {
        final List<String> errors = new ArrayList<>();
        final boolean allowConfigurations = configuration.getBoolean(DeploymentOptions.ALLOW_CLIENT_JOB_CONFIGURATIONS);
        if (!allowConfigurations && !conf.toMap().isEmpty()) {
            conf.toMap().forEach((k, v) -> errors.add(ConfigurationNotAllowedMessage.ofConfigurationKeyAndValue(k, v)));
        }
        Configuration mergedConfiguration = new Configuration();
        mergedConfiguration.addAll(configuration);
        mergedConfiguration.addAll(conf);
        return new StreamContextEnvironment(executorServiceLoader, mergedConfiguration, userCodeClassLoader, enforceSingleJobExecution, suppressSysout, allowConfigurations, errors);
    };
    initializeContextEnvironment(factory);
}
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) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) List(java.util.List) StreamExecutionEnvironmentFactory(org.apache.flink.streaming.api.environment.StreamExecutionEnvironmentFactory)

Example 2 with PipelineExecutorServiceLoader

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

the class ApplicationDispatcherBootstrap method runApplicationEntryPoint.

/**
 * Runs the user program entrypoint and completes the given {@code jobIdsFuture} with the {@link
 * JobID JobIDs} of the submitted jobs.
 *
 * <p>This should be executed in a separate thread (or task).
 */
private void runApplicationEntryPoint(final CompletableFuture<List<JobID>> jobIdsFuture, final Set<JobID> tolerateMissingResult, final DispatcherGateway dispatcherGateway, final ScheduledExecutor scheduledExecutor, final boolean enforceSingleJobExecution, final boolean submitFailedJobOnApplicationError) {
    if (submitFailedJobOnApplicationError && !enforceSingleJobExecution) {
        jobIdsFuture.completeExceptionally(new ApplicationExecutionException(String.format("Submission of failed job in case of an application error ('%s') is not supported in non-HA setups.", DeploymentOptions.SUBMIT_FAILED_JOB_ON_APPLICATION_ERROR.key())));
        return;
    }
    final List<JobID> applicationJobIds = new ArrayList<>(recoveredJobIds);
    try {
        final PipelineExecutorServiceLoader executorServiceLoader = new EmbeddedExecutorServiceLoader(applicationJobIds, dispatcherGateway, scheduledExecutor);
        ClientUtils.executeProgram(executorServiceLoader, configuration, application, enforceSingleJobExecution, true);
        if (applicationJobIds.isEmpty()) {
            jobIdsFuture.completeExceptionally(new ApplicationExecutionException("The application contains no execute() calls."));
        } else {
            jobIdsFuture.complete(applicationJobIds);
        }
    } catch (Throwable t) {
        // If we're running in a single job execution mode, it's safe to consider re-submission
        // of an already finished a success.
        final Optional<DuplicateJobSubmissionException> maybeDuplicate = ExceptionUtils.findThrowable(t, DuplicateJobSubmissionException.class);
        if (enforceSingleJobExecution && maybeDuplicate.isPresent() && maybeDuplicate.get().isGloballyTerminated()) {
            final JobID jobId = maybeDuplicate.get().getJobID();
            tolerateMissingResult.add(jobId);
            jobIdsFuture.complete(Collections.singletonList(jobId));
        } else if (submitFailedJobOnApplicationError && applicationJobIds.isEmpty()) {
            final JobID failedJobId = JobID.fromHexString(configuration.get(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID));
            dispatcherGateway.submitFailedJob(failedJobId, FAILED_JOB_NAME, t);
            jobIdsFuture.complete(Collections.singletonList(failedJobId));
        } else {
            jobIdsFuture.completeExceptionally(new ApplicationExecutionException("Could not execute application.", t));
        }
    }
}
Also used : PipelineExecutorServiceLoader(org.apache.flink.core.execution.PipelineExecutorServiceLoader) EmbeddedExecutorServiceLoader(org.apache.flink.client.deployment.application.executors.EmbeddedExecutorServiceLoader) Optional(java.util.Optional) ArrayList(java.util.ArrayList) JobID(org.apache.flink.api.common.JobID) DuplicateJobSubmissionException(org.apache.flink.runtime.client.DuplicateJobSubmissionException)

Example 3 with PipelineExecutorServiceLoader

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

the class DetachedApplicationRunner method tryExecuteJobs.

private List<JobID> tryExecuteJobs(final DispatcherGateway dispatcherGateway, final PackagedProgram program, final Configuration configuration) {
    configuration.set(DeploymentOptions.ATTACHED, false);
    final List<JobID> applicationJobIds = new ArrayList<>();
    final PipelineExecutorServiceLoader executorServiceLoader = new WebSubmissionExecutorServiceLoader(applicationJobIds, dispatcherGateway);
    try {
        ClientUtils.executeProgram(executorServiceLoader, configuration, program, enforceSingleJobExecution, true);
    } catch (ProgramInvocationException e) {
        LOG.warn("Could not execute application: ", e);
        throw new FlinkRuntimeException("Could not execute application.", e);
    }
    return applicationJobIds;
}
Also used : PipelineExecutorServiceLoader(org.apache.flink.core.execution.PipelineExecutorServiceLoader) ArrayList(java.util.ArrayList) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) WebSubmissionExecutorServiceLoader(org.apache.flink.client.deployment.application.executors.WebSubmissionExecutorServiceLoader) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) JobID(org.apache.flink.api.common.JobID)

Aggregations

ArrayList (java.util.ArrayList)3 PipelineExecutorServiceLoader (org.apache.flink.core.execution.PipelineExecutorServiceLoader)3 JobID (org.apache.flink.api.common.JobID)2 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Internal (org.apache.flink.annotation.Internal)1 PublicEvolving (org.apache.flink.annotation.PublicEvolving)1 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1 EmbeddedExecutorServiceLoader (org.apache.flink.client.deployment.application.executors.EmbeddedExecutorServiceLoader)1