Using the SparkJob API
Overview
This section describes how to call APIs to execute a Spark job, including starting the Spark job, querying the Spark job status, and querying Spark job details.
This process assumes that the end tenant has been authorized on the console to use AI DataLake and has created a workspace and a Spark 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: Spark endpoint name, which can be viewed on the endpoint management page of the console or obtained by referring to Listing All Endpoints.
Starting a Spark Job
Call the API for starting a Spark job to submit the Spark job and record the job ID returned by the API.
- Request example
POST /v2/workspaces/{workspace_id}/spark-jobs
{workspace_id}: Workspace ID, which is used for resource isolation.
- Request body:
{ "name" : "spark-jar-job-example", "endpoint_name" : "spark-endpoint", "job_config" : { "type" : "spark_jar_job", "main_class" : "com.example.SparkJobDriver", "main_jar" : "obs://bucket/path/job.jar", "main_args" : [ "--input", "obs://bucket/input", "--output", "obs://bucket/output" ] }, "resource_config" : { "executor_number" : 2, "driver_resource_spec" : { "cpu" : 2000, "memory" : 4096 }, "executor_resource_spec" : { "cpu" : 2000, "memory" : 4096 } } } - Response example:
{ "job_id": "1ee7d9db-90ec-xxxx-xxxx-0de936dade77" }
Querying the Status of a Spark Job
Call the API for obtaining the Spark job status. Wait until the job status changes to SUCCEED, indicating that the job execution is complete.
- Request example:
GET /v2/workspaces/{workspace_id}/spark-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 Spark Job.
- Response example:
{ "job_id": "1ee7d9db-90ec-xxxx-xxxx-0de936dade77", "state": "SUCCEED" }
Viewing Spark Job Details
Call the API for viewing Spark job details to view the complete configuration and execution result of a job.
- Request example:
GET /v2/workspaces/{workspace_id}/spark-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 Spark Job.
- Response example:
{ "job_id" : "1ee7d9db-90ec-xxxx-xxxx-0de936dade77", "client_token" : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "name" : "spark-jar-job-example", "endpoint_name" : "spark-endpoint", "state" : "SUCCEED", "job_config" : { "type" : "spark_jar_job", "main_class" : "com.example.SparkJobDriver", "main_jar" : "obs://bucket/path/job.jar", "main_args" : [ "--input", "obs://bucket/input", "--output", "obs://bucket/output" ] }, "resource_config" : { "executor_number" : 2, "driver_resource_spec" : { "cpu" : 2000, "memory" : 4096 }, "executor_resource_spec" : { "cpu" : 2000, "memory" : 4096 } }, "create_time" : 1698776400000, "start_time" : 1698776450000, "end_time" : 1698776700000, "create_user" : { "user_id" : "user123", "user_name" : "admin" }, "log_url" : "https://obs.example.com/logs/spark-job.log" }
Canceling Spark Job Execution
If a job needs to be terminated due to an execution exception, call the API for canceling Spark 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}/spark-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 Spark 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