Using the FlinkJob API
Overview
This section describes how to execute a Flink job by calling APIs, including starting a Flink job, querying the job status, and querying the details of a Flink job.
This process assumes that the end tenant has been authorized on the console to use AI DataLake and has created a workspace and a Flink endpoint. For how to call this API, see Calling an API.
Prerequisites
- workspace_id: Workspace ID, which can be viewed on the workspace management page of the console.
- endpoint_name: Flink endpoint name, which can be viewed on the endpoint management page of the console or obtained by referring to Listing All Endpoints.
Starting a Flink Job
Call the API for starting a Flink job to submit the Flink job and record the job ID returned by the API.
- Request example
POST /v2/workspaces/{workspace_id}/flink-jobs
{workspace_id}: Workspace ID, which is used for resource isolation.
- Request body:
{ "name": "flink-job-test", "endpoint_name": "flink-test", "execution_mode": "STREAMING", "resource_config": { "parallelism": 1, "jobmanager_resource_spec": { "cpu": 500, "memory": 1024, "disk": 30 }, "taskmanager_resource_spec": { "cpu": 500, "memory": 1024, "disk": 30 } }, "job_config": { "type": "FLINK_JAR_JOB", "main_jar": "obs://infotest/flink/jars/WindowJoin.jar", "main_class": "org.apache.flink.streaming.examples.join.WindowJoin", "main_args": [ "--output", "/tmp/result.txt" ] }, "logging_config": { "root_logger_level": "INFO" }, "flink_config": { "taskmanager.memory.framework.heap.size": "64mb", "taskmanager.memory.framework.off-heap.size": "64mb", "taskmanager.memory.managed.fraction": "0.2", "taskmanager.memory.network.min": "32mb", "taskmanager.memory.network.max": "64mb" } } - Response example:
{ "job_id": "019fa293-6a76-xxxx-xxxx-10e8fc29bba9" }
Querying the Status of a Flink Job
Call the API for obtaining the Flink job status. Wait until the job status changes to SUCCEED, indicating that the job execution is complete.
- Request example:
GET /v2/workspaces/{workspace_id}/flink-jobs/{job_id}/state
- {workspace_id}: Workspace ID, which is used for resource isolation.
- {job_id}: Value of job_id in the response for Starting a Flink Job.
- Response example:
{ "job_id": "019fa293-6a76-xxxx-xxxx-10e8fc29bba9", "state": "SUCCEED" }
Querying Flink Job Details
Call the API for viewing Flink job details to view the complete configuration and execution result of a job.
- Request example:
GET /v2/workspaces/{workspace_id}/flink-jobs/{job_id}
- {workspace_id}: Workspace ID, which is used for resource isolation.
- {job_id}: Value of job_id in the response for Starting a Flink Job.
- Response example:
{ "job_id": "019fa293-6a76-xxxx-xxxx-10e8fc29bba9", "client_token": "019fa293-6a76-xxxx-xxxx-1fdfa6b993a4", "name": "flink-job-test", "endpoint_name": "flink-test", "status": { "state": "SUCCEED" }, "job_agency": "ai_datalake_alpha_admin_trust", "obs_bucket_name": "ai4db", "job_config": { "type": "FLINK_JAR_JOB", "main_jar": "obs://infotest/flink/jars/WindowJoin.jar", "main_class": "org.apache.flink.streaming.examples.join.WindowJoin", "main_args": [ "--output", "/tmp/result.txt" ] }, "resource_config": { "parallelism": 1, "jobmanager_resource_spec": { "cpu": 500, "memory": 1024, "disk": 30 }, "taskmanager_resource_spec": { "cpu": 500, "memory": 1024, "disk": 30 } }, "flink_config": { "high-availability.storageDir": "obs://ai4db/AIDataLake/Workspace_57fd5733-20b4-xxxx-xxxx-c6e7f39b1891/Flink/Endpoint_bd0f32d1-25aa-461e-xxxx-78daa554dd5c/jobs/ha/019fa293-6a76-xxxx-xxxx-10e8fc29bba9", "taskmanager.memory.framework.off-heap.size": "64mb", "taskmanager.memory.network.max": "64mb", "execution.checkpointing.savepoint-dir": "obs://ai4db/AIDataLake/Workspace_57fd5733-20b4-xxxx-xxxx-c6e7f39b1891/Flink/Endpoint_bd0f32d1-25aa-461e-xxxx-78daa554dd5c/jobs/savepoint/019fa293-6a76-xxxx-xxxx-10e8fc29bba9", "taskmanager.memory.network.min": "32mb", "taskmanager.memory.framework.heap.size": "64mb", "taskmanager.memory.managed.fraction": "0.2", "execution.checkpointing.num-retained": "6", "execution.checkpointing.dir": "obs://ai4db/AIDataLake/Workspace_57fd5733-20b4-xxxx-xxxx-c6e7f39b1891/Flink/Endpoint_bd0f32d1-25aa-461e-xxxx-78daa554dd5c/jobs/checkpoint/019fa293-6a76-xxxx-xxxx-10e8fc29bba9" }, "execution_mode": "STREAMING", "restore_strategy": { "restore_type": "NONE" }, "logging_config": { "root_logger_level": "INFO" }, "metric": { "total_memory": 1948, "total_cpu": 900, "total_disk": -1 }, "create_time": 1785138997878, "create_user": { "user_id": "019e19fb78887b57bxxxxxxxxcd5a002", "user_name": "aid_developer03" }, "update_time": 1785138997878, "update_user": { "user_id": "019e19fb78887b57bxxxxxxxxcd5a002", "user_name": "aid_developer03" }, "log_url": "obs://ai4db/AIDataLake/Workspace_57fd5733-20b4-xxxx-xxxx-c6e7f39b1891/Flink/Endpoint_bd0f32d1-25aa-461e-xxxx-78daa554dd5c/jobs/log/019fa293-6a76-7a9f-xxxx-10e8fc29bba9", "description": "", "start_time": 1785139107050, "end_time": 0 }
Canceling Flink Job Execution
If a job needs to be terminated due to an execution exception, call the API for canceling Flink jobs to cancel the job that is being executed. Only jobs in the QUEUED or RUNNING state can be canceled.
- Request example:
POST /v2/workspaces/{workspace_id}/flink-jobs/{job_id}/cancel
- {workspace_id}: Workspace ID, which is used for resource isolation.
- {job_id}: Value of job_id in the response for Starting a Flink Job.
- Example response: No response body. HTTP status code 204 indicates that the cancellation is successful.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot