T - type of the cluster idpublic abstract class ClusterClient<T> extends Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ClusterClient.LazyActorSystemLoader
Utility class to lazily instantiate an
ActorSystem. |
| Modifier and Type | Field and Description |
|---|---|
protected ActorSystemLoader |
actorSystemLoader
The actor system used to communicate with the JobManager.
|
protected org.apache.flink.configuration.Configuration |
flinkConfig
Configuration of the client.
|
protected org.apache.flink.runtime.highavailability.HighAvailabilityServices |
highAvailabilityServices
Service factory for high available.
|
protected org.apache.flink.api.common.JobExecutionResult |
lastJobExecutionResult
For interactive invocations, the job results are only available after the ContextEnvironment has
been run inside the user JAR.
|
protected org.slf4j.Logger |
log |
static int |
MAX_SLOTS_UNKNOWN
Value returned by
getMaxSlots() if the number of maximum slots is unknown. |
protected scala.concurrent.duration.FiniteDuration |
timeout
Timeout for futures.
|
| Constructor and Description |
|---|
ClusterClient(org.apache.flink.configuration.Configuration flinkConfig)
Creates a instance that submits the programs to the JobManager defined in the
configuration.
|
ClusterClient(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.runtime.highavailability.HighAvailabilityServices highAvailabilityServices,
boolean sharedHaServices)
Creates a instance that submits the programs to the JobManager defined in the
configuration.
|
ClusterClient(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.runtime.highavailability.HighAvailabilityServices highAvailabilityServices,
boolean sharedHaServices,
ActorSystemLoader actorSystemLoader) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(org.apache.flink.api.common.JobID jobId)
Cancels a job identified by the job id.
|
String |
cancelWithSavepoint(org.apache.flink.api.common.JobID jobId,
String savepointDirectory)
Cancels a job identified by the job id and triggers a savepoint.
|
org.apache.flink.runtime.client.JobListeningContext |
connectToJob(org.apache.flink.api.common.JobID jobID)
Reattaches to a running job with the given job id.
|
CompletableFuture<org.apache.flink.runtime.messages.Acknowledge> |
disposeSavepoint(String savepointPath) |
void |
endSession(org.apache.flink.api.common.JobID jobId)
Tells the JobManager to finish the session (job) defined by the given ID.
|
void |
endSessions(List<org.apache.flink.api.common.JobID> jobIds)
Tells the JobManager to finish the sessions (jobs) defined by the given IDs.
|
Map<String,org.apache.flink.util.OptionalFailure<Object>> |
getAccumulators(org.apache.flink.api.common.JobID jobID)
Requests and returns the accumulators for the given job identifier.
|
Map<String,org.apache.flink.util.OptionalFailure<Object>> |
getAccumulators(org.apache.flink.api.common.JobID jobID,
ClassLoader loader)
Requests and returns the accumulators for the given job identifier.
|
org.apache.flink.runtime.util.LeaderConnectionInfo |
getClusterConnectionInfo()
Gets the current cluster connection info (may change in case of a HA setup).
|
abstract T |
getClusterId()
Returns the cluster id identifying the cluster to which the client is connected.
|
abstract org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse |
getClusterStatus()
Returns the latest cluster status, with number of Taskmanagers and slots.
|
org.apache.flink.configuration.Configuration |
getFlinkConfiguration()
Return the Flink configuration object.
|
static org.apache.flink.runtime.jobgraph.JobGraph |
getJobGraph(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.optimizer.plan.FlinkPlan optPlan,
List<URL> jarFiles,
List<URL> classpaths,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings) |
static org.apache.flink.runtime.jobgraph.JobGraph |
getJobGraph(org.apache.flink.configuration.Configuration flinkConfig,
PackagedProgram prog,
org.apache.flink.optimizer.plan.FlinkPlan optPlan,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings) |
org.apache.flink.runtime.instance.ActorGateway |
getJobManagerGateway()
Returns the
ActorGateway of the current job manager leader using
the LeaderRetrievalService. |
CompletableFuture<org.apache.flink.runtime.jobgraph.JobStatus> |
getJobStatus(org.apache.flink.api.common.JobID jobId)
Requests the
JobStatus of the job with the given JobID. |
abstract int |
getMaxSlots()
The client may define an upper limit on the number of slots to use.
|
abstract List<String> |
getNewMessages()
May return new messages from the cluster.
|
static org.apache.flink.optimizer.plan.FlinkPlan |
getOptimizedPlan(org.apache.flink.optimizer.Optimizer compiler,
PackagedProgram prog,
int parallelism) |
static org.apache.flink.optimizer.plan.OptimizedPlan |
getOptimizedPlan(org.apache.flink.optimizer.Optimizer compiler,
org.apache.flink.api.common.Plan p,
int parallelism) |
static String |
getOptimizedPlanAsJson(org.apache.flink.optimizer.Optimizer compiler,
PackagedProgram prog,
int parallelism) |
boolean |
getPrintStatusDuringExecution() |
abstract String |
getWebInterfaceURL()
Returns an URL (as a string) to the JobManager web interface.
|
abstract boolean |
hasUserJarsInClassPath(List<URL> userJarFiles)
Returns true if the client already has the user jar and providing it again would
result in duplicate uploading of the jar.
|
boolean |
isDetached()
A flag to indicate whether this clients submits jobs detached.
|
CompletableFuture<Collection<org.apache.flink.runtime.client.JobStatusMessage>> |
listJobs()
Lists the currently running and finished jobs on the cluster.
|
protected void |
logAndSysout(String message)
Logs and prints to sysout if printing to stdout is enabled.
|
CompletableFuture<org.apache.flink.runtime.messages.Acknowledge> |
rescaleJob(org.apache.flink.api.common.JobID jobId,
int newParallelism)
Rescales the specified job such that it will have the new parallelism.
|
org.apache.flink.api.common.JobExecutionResult |
retrieveJob(org.apache.flink.api.common.JobID jobID)
Reattaches to a running from the supplied job id.
|
org.apache.flink.api.common.JobSubmissionResult |
run(org.apache.flink.optimizer.plan.FlinkPlan compiledPlan,
List<URL> libraries,
List<URL> classpaths,
ClassLoader classLoader) |
org.apache.flink.api.common.JobSubmissionResult |
run(org.apache.flink.optimizer.plan.FlinkPlan compiledPlan,
List<URL> libraries,
List<URL> classpaths,
ClassLoader classLoader,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings) |
org.apache.flink.api.common.JobExecutionResult |
run(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
Submits a JobGraph blocking.
|
org.apache.flink.api.common.JobSubmissionResult |
run(JobWithJars program,
int parallelism) |
org.apache.flink.api.common.JobSubmissionResult |
run(JobWithJars jobWithJars,
int parallelism,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings)
Runs a program on the Flink cluster to which this client is connected.
|
org.apache.flink.api.common.JobSubmissionResult |
run(PackagedProgram prog,
int parallelism)
General purpose method to run a user jar from the CliFrontend in either blocking or detached mode, depending
on whether
setDetached(true) or setDetached(false). |
org.apache.flink.api.common.JobSubmissionResult |
runDetached(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
Submits a JobGraph detached.
|
void |
setDetached(boolean isDetached)
Set the mode of this client (detached or blocking job execution).
|
void |
setPrintStatusDuringExecution(boolean print)
Configures whether the client should print progress updates during the execution to
System.out. |
void |
shutdown()
Shuts down the client.
|
void |
shutDownCluster() |
void |
stop(org.apache.flink.api.common.JobID jobId)
Stops a program on Flink cluster whose job-manager is configured in this client's configuration.
|
abstract org.apache.flink.api.common.JobSubmissionResult |
submitJob(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
Calls the subclasses' submitJob method.
|
CompletableFuture<String> |
triggerSavepoint(org.apache.flink.api.common.JobID jobId,
String savepointDirectory)
Triggers a savepoint for the job identified by the job id.
|
abstract void |
waitForClusterToBeReady()
Blocks until the client has determined that the cluster is ready for Job submission.
|
protected final org.slf4j.Logger log
protected final ActorSystemLoader actorSystemLoader
protected final org.apache.flink.configuration.Configuration flinkConfig
protected final scala.concurrent.duration.FiniteDuration timeout
protected final org.apache.flink.runtime.highavailability.HighAvailabilityServices highAvailabilityServices
protected org.apache.flink.api.common.JobExecutionResult lastJobExecutionResult
public static final int MAX_SLOTS_UNKNOWN
getMaxSlots() if the number of maximum slots is unknown.public ClusterClient(org.apache.flink.configuration.Configuration flinkConfig)
throws Exception
flinkConfig - The config used to obtain the job-manager's address, and used to configure the optimizer.Exception - we cannot create the high availability servicespublic ClusterClient(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.runtime.highavailability.HighAvailabilityServices highAvailabilityServices,
boolean sharedHaServices)
flinkConfig - The config used to obtain the job-manager's address, and used to configure the optimizer.highAvailabilityServices - HighAvailabilityServices to use for leader retrievalsharedHaServices - true if the HighAvailabilityServices are shared and must not be shut downpublic ClusterClient(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.runtime.highavailability.HighAvailabilityServices highAvailabilityServices,
boolean sharedHaServices,
ActorSystemLoader actorSystemLoader)
public void shutdown()
throws Exception
Exceptionpublic void setPrintStatusDuringExecution(boolean print)
System.out.
All updates are logged via the SLF4J loggers regardless of this setting.print - True to print updates to standard out during execution, false to not print them.public boolean getPrintStatusDuringExecution()
System.outpublic org.apache.flink.runtime.util.LeaderConnectionInfo getClusterConnectionInfo()
throws org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException
org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException - if the leader could not be retrievedpublic static String getOptimizedPlanAsJson(org.apache.flink.optimizer.Optimizer compiler, PackagedProgram prog, int parallelism) throws org.apache.flink.optimizer.CompilerException, ProgramInvocationException
org.apache.flink.optimizer.CompilerExceptionProgramInvocationExceptionpublic static org.apache.flink.optimizer.plan.FlinkPlan getOptimizedPlan(org.apache.flink.optimizer.Optimizer compiler,
PackagedProgram prog,
int parallelism)
throws org.apache.flink.optimizer.CompilerException,
ProgramInvocationException
org.apache.flink.optimizer.CompilerExceptionProgramInvocationExceptionpublic static org.apache.flink.optimizer.plan.OptimizedPlan getOptimizedPlan(org.apache.flink.optimizer.Optimizer compiler,
org.apache.flink.api.common.Plan p,
int parallelism)
throws org.apache.flink.optimizer.CompilerException
org.apache.flink.optimizer.CompilerExceptionpublic org.apache.flink.api.common.JobSubmissionResult run(PackagedProgram prog, int parallelism) throws ProgramInvocationException, ProgramMissingJobException
setDetached(true) or setDetached(false).prog - the packaged programparallelism - the parallelism to execute the contained Flink jobProgramMissingJobExceptionProgramInvocationExceptionpublic org.apache.flink.api.common.JobSubmissionResult run(JobWithJars program, int parallelism) throws ProgramInvocationException
ProgramInvocationExceptionpublic org.apache.flink.api.common.JobSubmissionResult run(JobWithJars jobWithJars, int parallelism, org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings) throws org.apache.flink.optimizer.CompilerException, ProgramInvocationException
jobWithJars - The program to be executed.parallelism - The default parallelism to use when running the program. The default parallelism is used
when the program does not set a parallelism by itself.org.apache.flink.optimizer.CompilerException - Thrown, if the compiler encounters an illegal situation.ProgramInvocationException - Thrown, if the program could not be instantiated from its jar file,
or if the submission failed. That might be either due to an I/O problem,
i.e. the job-manager is unreachable, or due to the fact that the
parallel execution failed.public org.apache.flink.api.common.JobSubmissionResult run(org.apache.flink.optimizer.plan.FlinkPlan compiledPlan,
List<URL> libraries,
List<URL> classpaths,
ClassLoader classLoader)
throws ProgramInvocationException
ProgramInvocationExceptionpublic org.apache.flink.api.common.JobSubmissionResult run(org.apache.flink.optimizer.plan.FlinkPlan compiledPlan,
List<URL> libraries,
List<URL> classpaths,
ClassLoader classLoader,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings)
throws ProgramInvocationException
ProgramInvocationExceptionpublic org.apache.flink.api.common.JobExecutionResult run(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
throws ProgramInvocationException
jobGraph - The JobGraphclassLoader - User code class loader to deserialize the results and errors (may contain custom classes).ProgramInvocationExceptionpublic org.apache.flink.api.common.JobSubmissionResult runDetached(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
throws ProgramInvocationException
jobGraph - The JobGraphclassLoader - User code class loader to deserialize the results and errors (may contain custom classes).ProgramInvocationExceptionpublic org.apache.flink.api.common.JobExecutionResult retrieveJob(org.apache.flink.api.common.JobID jobID)
throws org.apache.flink.runtime.client.JobExecutionException
jobID - The job id of the job to attach toorg.apache.flink.runtime.client.JobExecutionException - if an error occurs during monitoring the job executionpublic org.apache.flink.runtime.client.JobListeningContext connectToJob(org.apache.flink.api.common.JobID jobID)
throws org.apache.flink.runtime.client.JobExecutionException
jobID - The job id of the job to attach toorg.apache.flink.runtime.client.JobExecutionException - if an error occurs during monitoring the job executionpublic CompletableFuture<org.apache.flink.runtime.jobgraph.JobStatus> getJobStatus(org.apache.flink.api.common.JobID jobId)
JobStatus of the job with the given JobID.public void cancel(org.apache.flink.api.common.JobID jobId)
throws Exception
jobId - the job idException - In case an error occurred.public String cancelWithSavepoint(org.apache.flink.api.common.JobID jobId, @Nullable String savepointDirectory) throws Exception
jobId - the job idsavepointDirectory - directory the savepoint should be written toException - In case an error occurred.public void stop(org.apache.flink.api.common.JobID jobId)
throws Exception
jobId - the job ID of the streaming program to stopException - If the job ID is invalid (ie, is unknown or refers to a batch job) or if sending the stop signal
failed. That might be due to an I/O problem, ie, the job-manager is unreachable.public CompletableFuture<String> triggerSavepoint(org.apache.flink.api.common.JobID jobId, @Nullable String savepointDirectory) throws org.apache.flink.util.FlinkException
CheckpointingOptions.SAVEPOINT_DIRECTORY if it is null.jobId - job idsavepointDirectory - directory the savepoint should be written toorg.apache.flink.util.FlinkException - if no connection to the cluster could be establishedpublic CompletableFuture<org.apache.flink.runtime.messages.Acknowledge> disposeSavepoint(String savepointPath) throws org.apache.flink.util.FlinkException
org.apache.flink.util.FlinkExceptionpublic CompletableFuture<Collection<org.apache.flink.runtime.client.JobStatusMessage>> listJobs() throws Exception
Exception - if no connection to the cluster could be establishedpublic Map<String,org.apache.flink.util.OptionalFailure<Object>> getAccumulators(org.apache.flink.api.common.JobID jobID) throws Exception
jobID - The job identifier of a job.Exceptionpublic Map<String,org.apache.flink.util.OptionalFailure<Object>> getAccumulators(org.apache.flink.api.common.JobID jobID, ClassLoader loader) throws Exception
jobID - The job identifier of a job.loader - The class loader for deserializing the accumulator results.Exceptionpublic void endSession(org.apache.flink.api.common.JobID jobId)
throws Exception
jobId - The ID that identifies the session.Exceptionpublic void endSessions(List<org.apache.flink.api.common.JobID> jobIds) throws Exception
jobIds - The IDs that identify the sessions.Exceptionpublic static org.apache.flink.runtime.jobgraph.JobGraph getJobGraph(org.apache.flink.configuration.Configuration flinkConfig,
PackagedProgram prog,
org.apache.flink.optimizer.plan.FlinkPlan optPlan,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings)
throws ProgramInvocationException
ProgramInvocationExceptionpublic static org.apache.flink.runtime.jobgraph.JobGraph getJobGraph(org.apache.flink.configuration.Configuration flinkConfig,
org.apache.flink.optimizer.plan.FlinkPlan optPlan,
List<URL> jarFiles,
List<URL> classpaths,
org.apache.flink.runtime.jobgraph.SavepointRestoreSettings savepointSettings)
public org.apache.flink.runtime.instance.ActorGateway getJobManagerGateway()
throws org.apache.flink.util.FlinkException
ActorGateway of the current job manager leader using
the LeaderRetrievalService.Exceptionorg.apache.flink.util.FlinkExceptionprotected void logAndSysout(String message)
message - The message to log/printpublic abstract void waitForClusterToBeReady()
This is delayed until right before job submission to report any other errors first (e.g. invalid job definitions/errors in the user jar)
public abstract String getWebInterfaceURL()
public abstract org.apache.flink.runtime.clusterframework.messages.GetClusterStatusResponse getClusterStatus()
public abstract List<String> getNewMessages()
public abstract T getClusterId()
public void setDetached(boolean isDetached)
isDetached - If true, the client will submit programs detached via the run methodpublic boolean isDetached()
public org.apache.flink.configuration.Configuration getFlinkConfiguration()
public abstract int getMaxSlots()
MAX_SLOTS_UNKNOWN) if unknownpublic abstract boolean hasUserJarsInClassPath(List<URL> userJarFiles)
public abstract org.apache.flink.api.common.JobSubmissionResult submitJob(org.apache.flink.runtime.jobgraph.JobGraph jobGraph,
ClassLoader classLoader)
throws ProgramInvocationException
jobGraph - The JobGraph to be submittedProgramInvocationExceptionpublic CompletableFuture<org.apache.flink.runtime.messages.Acknowledge> rescaleJob(org.apache.flink.api.common.JobID jobId, int newParallelism)
jobId - specifying the job to modifynewParallelism - specifying the new parallelism of the rescaled jobpublic void shutDownCluster()
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.