
org.apache.flink.client.program.MiniClusterClient Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.client.program;
import org.apache.flink.api.common.JobID;
import org.apache.flink.api.common.JobStatus;
import org.apache.flink.api.common.JobSubmissionResult;
import org.apache.flink.api.common.accumulators.AccumulatorHelper;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.execution.CheckpointType;
import org.apache.flink.core.execution.SavepointFormatType;
import org.apache.flink.runtime.client.JobStatusMessage;
import org.apache.flink.runtime.executiongraph.AccessExecutionGraph;
import org.apache.flink.runtime.jobgraph.IntermediateDataSetID;
import org.apache.flink.runtime.jobgraph.JobGraph;
import org.apache.flink.runtime.jobgraph.OperatorID;
import org.apache.flink.runtime.jobmaster.JobResult;
import org.apache.flink.runtime.messages.Acknowledge;
import org.apache.flink.runtime.minicluster.MiniCluster;
import org.apache.flink.runtime.operators.coordination.CoordinationRequest;
import org.apache.flink.runtime.operators.coordination.CoordinationResponse;
import org.apache.flink.util.AbstractID;
import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.SerializedValue;
import org.apache.flink.util.concurrent.FutureUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
/** Client to interact with a {@link MiniCluster}. */
public class MiniClusterClient implements ClusterClient {
private static final Logger LOG = LoggerFactory.getLogger(MiniClusterClient.class);
private final MiniCluster miniCluster;
private final Configuration configuration;
public MiniClusterClient(
@Nonnull Configuration configuration, @Nonnull MiniCluster miniCluster) {
this.configuration = configuration;
this.miniCluster = miniCluster;
}
@Override
public Configuration getFlinkConfiguration() {
return new Configuration(configuration);
}
@Override
public CompletableFuture submitJob(@Nonnull JobGraph jobGraph) {
return miniCluster.submitJob(jobGraph).thenApply(JobSubmissionResult::getJobID);
}
@Override
public CompletableFuture requestJobResult(@Nonnull JobID jobId) {
return miniCluster.requestJobResult(jobId);
}
@Override
public CompletableFuture cancel(JobID jobId) {
return miniCluster.cancelJob(jobId);
}
@Override
public CompletableFuture cancelWithSavepoint(
JobID jobId, @Nullable String savepointDirectory, SavepointFormatType formatType) {
return miniCluster.triggerSavepoint(jobId, savepointDirectory, true, formatType);
}
@Override
public CompletableFuture stopWithSavepoint(
JobID jobId,
boolean advanceToEndOfEventTime,
@Nullable String savepointDirectory,
SavepointFormatType formatType) {
return miniCluster.stopWithSavepoint(
jobId, savepointDirectory, advanceToEndOfEventTime, formatType);
}
@Override
public CompletableFuture stopWithDetachedSavepoint(
JobID jobId,
boolean advanceToEndOfEventTime,
@Nullable String savepointDirectory,
SavepointFormatType formatType) {
return miniCluster.stopWithDetachedSavepoint(
jobId, savepointDirectory, advanceToEndOfEventTime, formatType);
}
@Override
public CompletableFuture triggerSavepoint(
JobID jobId, @Nullable String savepointDirectory, SavepointFormatType formatType) {
return miniCluster.triggerSavepoint(jobId, savepointDirectory, false, formatType);
}
@Override
public CompletableFuture triggerCheckpoint(JobID jobId, CheckpointType checkpointType) {
return miniCluster.triggerCheckpoint(jobId, checkpointType);
}
@Override
public CompletableFuture triggerDetachedSavepoint(
JobID jobId, @Nullable String savepointDirectory, SavepointFormatType formatType) {
return miniCluster.triggerDetachedSavepoint(jobId, savepointDirectory, false, formatType);
}
@Override
public CompletableFuture disposeSavepoint(String savepointPath) {
return miniCluster.disposeSavepoint(savepointPath);
}
@Override
public CompletableFuture> listJobs() {
return miniCluster.listJobs();
}
@Override
public CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy