Search in sources :

Example 1 with MiniClusterJobClient

use of org.apache.flink.runtime.minicluster.MiniClusterJobClient in project flink by apache.

the class PerJobMiniClusterFactory method submitJob.

/**
 * Starts a {@link MiniCluster} and submits a job.
 */
public CompletableFuture<JobClient> submitJob(JobGraph jobGraph, ClassLoader userCodeClassloader) throws Exception {
    MiniClusterConfiguration miniClusterConfig = getMiniClusterConfig(jobGraph.getMaximumParallelism());
    MiniCluster miniCluster = miniClusterFactory.apply(miniClusterConfig);
    miniCluster.start();
    return miniCluster.submitJob(jobGraph).thenApplyAsync(FunctionUtils.uncheckedFunction(submissionResult -> {
        org.apache.flink.client.ClientUtils.waitUntilJobInitializationFinished(() -> miniCluster.getJobStatus(submissionResult.getJobID()).get(), () -> miniCluster.requestJobResult(submissionResult.getJobID()).get(), userCodeClassloader);
        return submissionResult;
    })).thenApply(result -> new MiniClusterJobClient(result.getJobID(), miniCluster, userCodeClassloader, MiniClusterJobClient.JobFinalizationBehavior.SHUTDOWN_CLUSTER)).whenComplete((ignored, throwable) -> {
        if (throwable != null) {
            // We failed to create the JobClient and must shutdown to ensure
            // cleanup.
            shutDownCluster(miniCluster);
        }
    }).thenApply(Function.identity());
}
Also used : MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) Logger(org.slf4j.Logger) RpcServiceSharing(org.apache.flink.runtime.minicluster.RpcServiceSharing) Configuration(org.apache.flink.configuration.Configuration) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) JobClient(org.apache.flink.core.execution.JobClient) MathUtils(org.apache.flink.util.MathUtils) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) MiniClusterJobClient(org.apache.flink.runtime.minicluster.MiniClusterJobClient) FunctionUtils(org.apache.flink.util.function.FunctionUtils) ConfigConstants(org.apache.flink.configuration.ConfigConstants) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster) RestOptions(org.apache.flink.configuration.RestOptions) MiniClusterJobClient(org.apache.flink.runtime.minicluster.MiniClusterJobClient) MiniClusterConfiguration(org.apache.flink.runtime.minicluster.MiniClusterConfiguration) MiniCluster(org.apache.flink.runtime.minicluster.MiniCluster)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1 ConfigConstants (org.apache.flink.configuration.ConfigConstants)1 Configuration (org.apache.flink.configuration.Configuration)1 RestOptions (org.apache.flink.configuration.RestOptions)1 TaskManagerOptions (org.apache.flink.configuration.TaskManagerOptions)1 JobClient (org.apache.flink.core.execution.JobClient)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 MiniCluster (org.apache.flink.runtime.minicluster.MiniCluster)1 MiniClusterConfiguration (org.apache.flink.runtime.minicluster.MiniClusterConfiguration)1 MiniClusterJobClient (org.apache.flink.runtime.minicluster.MiniClusterJobClient)1 RpcServiceSharing (org.apache.flink.runtime.minicluster.RpcServiceSharing)1 MathUtils (org.apache.flink.util.MathUtils)1 FunctionUtils (org.apache.flink.util.function.FunctionUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1