Help Center/
MapReduce Service/
Developer Guide (LTS)/
Flink Development Guide (Security Mode)/
Developing a Flink Application/
PyFlink Sample Program/
Using Python to Submit a Common Flink Job
Updated on 2024-08-10 GMT+08:00
Using Python to Submit a Common Flink Job
- Obtain pyflink-kafka.py and insertData2kafka.sql from the sample project flink-examples/pyflink-example/pyflink-kafka.
- Package the prepared Python virtual environment by referring to Preparing for Development and Operating Environment and obtain the venv.zip file.
zip -q -r venv.zip venv/
- Log in to the active management node as the root user and upload venv.zip, pyflink-kafka.py, and insertData2kafka.sql files obtained in 1and 2 to the client environment.
- Per-job: Upload the preceding files to Client installation directory/Flink/flink.
- yarn-application: Upload the preceding files and the flink-connector-kafka-Actual version number.jar package to Client installation directory/Flink/flink/yarnship.
- Change the specific_jars path in pyflink-kafka.py.
- per-job: Change the path to the actual path of the SQL file, for example, file:///Client installation directory/Flink/flink/lib/flink-connector-kafka-Actual version number.jar.
- yarn-application: Change to file://"+os.getcwd()+"/../../../../yarnship/flink-connector-kafka-Actual version number.jar.
- Change file_path in pyflink-kafka.py.
- per-job: Change the path to the actual path of the SQL file. For example: Client installation directory/Flink/flink/insertData2kafka.sql
- yarn-application: Change the path to os.getcwd () + "/../../../../yarnship/insertData2kafka.sql"
- Run the following command to specify the running environment:
export PYFLINK_CLIENT_EXECUTABLE=venv.zip/venv/bin/python3
- Run the following command to run the program:
- Per-job:
./bin/flink run --detached -t yarn-per-job -Dyarn.application.name=py_kafka -pyarch venv.zip -pyexec venv.zip/venv/bin/python3 -py pyflink-kafka.py
Execution result:
- yarn-application
./bin/flink run-application --detached -t yarn-application -Dyarn.application.name=py_kafka -Dyarn.ship-files=/opt/client/Flink/flink/yarnship/ -pyarch yarnship/venv.zip -pyexec venv.zip/venv/bin/python3 -pyclientexec venv.zip/venv/bin/python3 -pyfs yarnship -pym pyflink-kafka
Execution result:
- Per-job:
Parent topic: PyFlink Sample Program
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot