Command-Line Interface
The command line can be used to
- submit jobs for execution,
- cancel a running job,
- provide information about a job,
- list running and waiting jobs,
- trigger and dispose savepoints, andA prerequisite to using the command line interface is that the Flinkmaster (JobManager) has been started (via
<flink-home>/bin/start-cluster.sh
) or that a YARN environment isavailable.
These examples about how to submit a job in CLI.
- Run example program with no arguments:
- Run example program with arguments for input and result files:
./bin/flink run ./examples/batch/WordCount.jar \
--input file:///home/user/hamlet.txt --output file:///home/user/wordcount_out
- Run example program with parallelism 16 and arguments for input and result files:
./bin/flink run -p 16 ./examples/batch/WordCount.jar \
--input file:///home/user/hamlet.txt --output file:///home/user/wordcount_out
- Run example program with flink log output disabled:
./bin/flink run -q ./examples/batch/WordCount.jar
- Run example program in detached mode:
./bin/flink run -d ./examples/batch/WordCount.jar
./bin/flink run -m myJMHost:8081 \
./examples/batch/WordCount.jar \
--input file:///home/user/hamlet.txt --output file:///home/user/wordcount_out
- Run example program with a specific class as an entry point:
./bin/flink run -c org.apache.flink.examples.java.wordcount.WordCount \
./examples/batch/WordCount.jar \
--input file:///home/user/hamlet.txt --output file:///home/user/wordcount_out
- Run example program using a per-job YARN cluster with 2 TaskManagers:
./bin/flink run -m yarn-cluster -yn 2 \
./examples/batch/WordCount.jar \
--input hdfs:///user/hamlet.txt --output hdfs:///user/wordcount_out
- Run Python Table program:
- Run Python Table program with pyFiles:
./bin/flink run -py examples/python/table/batch/word_count.py \
-pyfs file:///user.txt,hdfs:///$namenode_address/username.txt
- Run Python Table program with pyFiles and pyModule:
./bin/flink run -pym batch.word_count -pyfs examples/python/table/batch
- Run Python Table program with parallelism 16:
- Run Python Table program with flink log output disabled:
./bin/flink run -q -py examples/python/table/batch/word_count.py
- Run Python Table program in detached mode:
./bin/flink run -d -py examples/python/table/batch/word_count.py
- Run Python Table program on a specific JobManager:
./bin/flink run -m myJMHost:8081 \
-py examples/python/table/batch/word_count.py
- Run Python Table program using a with 2 TaskManagers:
-py examples/python/table/batch/word_count.py
These examples about how to manage a job in CLI.
- Display the optimized execution plan for the WordCount example program as JSON:
./bin/flink info ./examples/batch/WordCount.jar \
--input file:///home/user/hamlet.txt --output file:///home/user/wordcount_out
- List scheduled and running jobs (including their JobIDs):
./bin/flink list
- List scheduled jobs (including their JobIDs):
./bin/flink list -s
- List running jobs (including their JobIDs):
./bin/flink list -r
- List all existing jobs (including their JobIDs):
./bin/flink list -a
- List running Flink jobs inside Flink YARN session:
./bin/flink list -m yarn-cluster -yid <yarnApplicationID> -r
- Cancel a job:
- Cancel a job with a savepoint (deprecated; use “stop” instead):
- Gracefully stop a job with a savepoint (streaming jobs only):
./bin/flink stop [-p targetDirectory] [-d] <jobID>
Savepoints are controlled via the command line client:
Trigger a Savepoint
./bin/flink savepoint <jobId> [savepointDirectory]
This will trigger a savepoint for the job with ID jobId
, and returns the path of the created savepoint. You need this path to restore and dispose savepoints.
Furthermore, you can optionally specify a target file system directory to store the savepoint in. The directory needs to be accessible by the JobManager.
If you don’t specify a target directory, you need to have configured a default directory. Otherwise, triggering the savepoint will fail.
Trigger a Savepoint with YARN
./bin/flink savepoint <jobId> [savepointDirectory] -yid <yarnAppId>
Everything else is the same as described in the above Trigger a Savepoint section.
Stop
Use the stop
to gracefully stop a running streaming job with a savepoint.
./bin/flink stop [-p targetDirectory] [-d] <jobID>
A “stop” call is a more graceful way of stopping a running streaming job, as the “stop” signal flows fromsource to sink. When the user requests to stop a job, all sources will be requested to send the last checkpoint barrierthat will trigger a savepoint, and after the successful completion of that savepoint, they will finish by calling theircancel()
method. If the -d
flag is specified, then a MAX_WATERMARK
will be emitted before the last checkpointbarrier. This will result all registered event-time timers to fire, thus flushing out any state that is waiting fora specific watermark, e.g. windows. The job will keep running until all sources properly shut down. This allows the job to finish processing all in-flight data.
Cancel with a savepoint (deprecated)
You can atomically trigger a savepoint and cancel a job.
./bin/flink cancel -s [savepointDirectory] <jobID>
If no savepoint directory is configured, you need to configure a default savepoint directory for the Flink installation (see Savepoints).
The job will only be cancelled if the savepoint succeeds.
Note: Cancelling a job with savepoint is deprecated. Use "stop" instead.
Restore a savepoint
./bin/flink run -s <savepointPath> ...
By default, we try to match all savepoint state to the job being submitted. If you want to allow to skip savepoint state that cannot be restored with the new job you can set the allowNonRestoredState
flag. You need to allow this if you removed an operator from your program that was part of the program when the savepoint was triggered and you still want to use the savepoint.
./bin/flink run -s <savepointPath> -n ...
This is useful if your program dropped an operator that was part of the savepoint.
Dispose a savepoint
./bin/flink savepoint -d <savepointPath>
Disposes the savepoint at the given path. The savepoint path is returned by the savepoint trigger command.
If you use custom state instances (for example custom reducing state or RocksDB state), you have to specify the path to the program JAR with which the savepoint was triggered in order to dispose the savepoint with the user code class loader:
Otherwise, you will run into a ClassNotFoundException
.
Usage
The command line syntax is as follows: