Starting a Spark Job
Function
This API is used to start a Spark job. It is asynchronous. It supports Spark Jar jobs, Python jobs, and SQL script jobs. After calling this API, the job will be submitted to the queue for execution. After the job ID is returned, you need to confirm whether the job was successfully started through the job status query API. For details about how to query the job status, see Querying the Status of a Spark Job.
Calling Method
For details, see Calling APIs.
URI
POST /v2/workspaces/{workspace_id}/spark-jobs
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| workspace_id | Yes | String | Definition: Workspace ID, used for resource isolation. This can be viewed on the workspace page of the console. Constraints: N/A Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition: User token. It is obtained by calling the Obtaining an IAM User Token API. Constraints: N/A Range: The value can contain a maximum of 65,534 characters, with no character type restrictions. Default Value: N/A |
| X-Client-Token | No | String | Definition: Service transaction ID, used for link tracking and preventing duplicate submissions. Constraints: N/A Range: UUID format, 36 characters. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Definition: Spark job name, used to identify the job. Constraints: N/A Range: The value can contain 1 to 128 characters, with no character type restrictions. Default Value: N/A |
| endpoint_name | Yes | String | Definition: Endpoint name, used to specify the Spark job execution environment. Constraints: N/A Range: 1 to 63 characters. Only lowercase letters, digits, and hyphens (-) are allowed. It must start with a lowercase letter and end with a lowercase letter or digit. Default Value: N/A |
| job_config | Yes | One of:
| Definition: Job configuration parameters, used to specify the Spark job type and execution parameters. The corresponding parameter structure is automatically selected based on the job type: SparkJarParameter for SPARK_JAR_JOB, SparkPyParameter for SPARK_PYTHON_JOB, and SparkSqlScriptParameter for SPARK_SQL_SCRIPTING_JOB. Constraints: N/A |
| catalog_name | No | String | Definition: Catalog name, used to specify the data catalog used by the job. Constraints: N/A Range: The value can contain a maximum of 128 characters, with no character type restrictions. Default Value: N/A |
| job_agency | No | String | Definition: Custom agency name, used for the job to operate OBS objects, dump logs, access DLI metadata, etc. Constraints: N/A Range: The value can contain 1 to 64 characters, with no character type restrictions. Default Value: N/A |
| resource_config | No | SparkResourceConfig object | Definition: Spark job resource configuration, used to configure the resource specifications and quantities for the Driver and Executor. Constraints: N/A |
| spark_config | No | Map<String,String> | Definition: User-defined Spark parameter configuration, used to optimize Spark job performance. The key in the map is the Spark configuration item name (for example, spark.executor.memory), and the value is the corresponding configuration value. Both key and value are strings, each with a maximum length of 1,024 characters. Constraints: A maximum of 100 parameters are supported. |
| image | No | SparkJobImageConfig object | Definition: Spark image configuration, used to specify the image information required for running the Spark job. Constraints: N/A |
| logging_config | No | SparkLoggingConfig object | Definition: Spark job logging configuration, used to configure the log levels for the Driver and Executor. Constraints: N/A |
| restore_strategy | No | SparkRestoreStrategy object | Definition: Job recovery policy configuration, used to define the retry mechanism and timeout control after a job failure. Constraints: N/A |
| labels | No | Array of SparkJobLabel objects | Definition: Job tag list, used to identify and categorize jobs. Constraints: The number of tags cannot exceed 16. |
| description | No | String | Definition: Spark job description, used to describe the purpose of the job. Constraints: N/A Range: The value can contain 1 to 512 characters, with no character type restrictions. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| main_class | No | String | Definition: Main class name, used to specify the entry class of the Spark Jar job. Constraints: N/A Range: The value can contain 1 to 512 characters, with no character type restrictions. Default Value: N/A |
| main_args | No | Array of strings | Definition: List of main class parameters, used to pass parameters to the entry class of the Spark Jar job. Multiple parameters are separated by spaces. Constraints: The number of parameters cannot exceed 100. |
| main_jar | No | String | Definition: Main Jar package path, used to specify the OBS path of the Jar package containing the main class of the Spark Jar job. Constraints: N/A Range: 1 to 512 characters, in OBS path format. Example: obs://bucket_name/path/to/jar.jar. Default Value: N/A |
| dependency_jars | No | Array of strings | Definition: List of dependent Jar packages, used to specify the OBS paths of Jar packages that the Spark job depends on. Constraints: The number of dependent Jar packages cannot exceed 100. |
| dependency_files | No | Array of strings | Definition: List of dependent files, used to specify the OBS paths of files that the Spark job depends on. Constraints: The number of dependent files cannot exceed 100. |
| dependency_archives | No | Array of strings | Definition: List of dependent archive packages, used to specify the OBS paths of archive packages that the Spark job depends on. Constraints: The number of dependent archive packages cannot exceed 100. |
| dependency_py_files | No | Array of strings | Definition: List of dependent Python files, used to specify the OBS paths of Python packages that the Spark job depends on. Constraints: The number of dependent Python files cannot exceed 100. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| main_python_file | Yes | String | Definition: Main Python file path, used to specify the OBS path of the main file for the Python Spark job. Constraints: N/A Range: 1 to 512 characters, in OBS path format. Example: obs://bucket/pyspark/pySpark_udf_python.py. Default Value: N/A |
| main_args | No | Array of strings | Definition: List of main file parameters, used to pass parameters to the Python Spark job. Multiple parameters are separated by spaces. Constraints: The number of parameters cannot exceed 100. |
| dependency_jars | No | Array of strings | Definition: List of dependent Jar packages, used to specify the OBS paths of Jar packages that the Spark job depends on. Constraints: The number of dependent Jar packages cannot exceed 100. |
| dependency_files | No | Array of strings | Definition: List of dependent files, used to specify the OBS paths of files that the Spark job depends on. Constraints: The number of dependent files cannot exceed 100. |
| dependency_archives | No | Array of strings | Definition: List of dependent archive packages, used to specify the OBS paths of archive packages that the Spark job depends on. Constraints: The number of dependent archive packages cannot exceed 100. |
| dependency_py_files | No | Array of strings | Definition: List of dependent Python files, used to specify the OBS paths of Python packages that the Spark job depends on. Constraints: The number of dependent Python files cannot exceed 100. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| sql_scripting_file | Yes | String | Definition: SQL script file path, used to specify the OBS path of the script file for the Spark SQL script job. Constraints: N/A Range: 1 to 512 characters, in OBS path format. Example: obs://bucket/sparksqlscript/script.sql. Default Value: N/A |
| sql_scripting_parameters | No | Array of SparkJobSqlScriptParameter objects | Definition: List of SQL script placeholder parameters, used to configure parameterized variables in the SQL script. Each element in the array is a SparkJobSqlScriptParameter object, which contains the key, value, and type information of the placeholder. Constraints: The number of placeholder parameters cannot exceed 16. |
| dependency_jars | No | Array of strings | Definition: List of dependent Jar packages, used to specify the OBS paths of Jar packages that the Spark job depends on. Constraints: The number of dependent Jar packages cannot exceed 100. |
| sql_scripting_result_to_obs | No | Boolean | Definition: Result write to OBS flag, used to control whether the execution result of the SQL script job is written to OBS. Constraints: N/A Range Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| driver_resource_spec | No | ResourceSpec object | Definition: Driver resource specification, used to configure resources such as CPU, memory, and disk for the Driver. Constraints: N/A |
| executor_number | No | Integer | Definition: Number of Executors, used to specify the maximum number of Executors for the Spark job. If the value is greater than 0, dynamic resource allocation is enabled (the minimum number of executors is 1, the initial number of executors is 1, and the maximum number of executors is the configured value). If the value is 0, this parameter does not take effect, meaning dynamic resource allocation is disabled. Constraints: N/A Range: 0 to 65,535. Default Value: N/A |
| executor_resource_spec | No | ResourceSpec object | Definition: Executor resource specification, used to configure resources such as CPU, memory, and disk for the Executor. Constraints: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| cpu | No | Integer | Definition: Number of CPU cores, in millicores, used to specify the CPU resources required for job execution. Constraints: N/A Range: 1000 to 48000 Default Value: 1000 |
| memory | No | Integer | Definition: Memory size, in MB. This parameter specifies the memory resources required for job execution. Constraints: N/A Range: 1024 to 393216 Default Value: 4096 |
| disk | No | Integer | Definition: Local disk size, used to specify the local disk resources for the Spark job Driver and Executor. Constraints: N/A Range: 0 to 994, in GB. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| image_id | Yes | String | Definition: Image ID, used to specify the image required for running the Spark job. This can be viewed on the image page of the console or obtained by calling the API for listing images. Constraints: N/A Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
| image_version_id | Yes | String | Definition: Image version ID, used to specify the image version required for running the Spark job. This can be viewed on the image version page of the console or obtained by calling the API for listing image versions. Constraints: N/A Range: 32 to 36 characters. Only letters, digits, and hyphens (-) are allowed. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| driver_root_logger_level | No | String | Definition: Driver root log level, used to control the overall log level of the Driver output. Constraints: N/A Range Default Value: INFO |
| driver_loggers_level_of_class | No | Array of SparkClassLoggerLevel objects | Definition: List of Driver class-level log configurations, used to configure the log levels for specified classes. Each element in the array is a SparkClassLoggerLevel object, which contains the class name and log level. Constraints: A maximum of 20 classes can be configured. |
| executor_root_logger_level | No | String | Definition: Executor root log level, used to control the overall log level of the Executor output. Constraints: N/A Range Default Value: INFO |
| executor_loggers_level_of_class | No | Array of SparkClassLoggerLevel objects | Definition: List of Executor class-level log configurations, used to configure the log levels for specified classes. Each element in the array is a SparkClassLoggerLevel object, which contains the class name and log level. Constraints: A maximum of 20 classes can be configured. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| logger_name | No | String | Definition: Log class name, used to specify the class name for which the log level needs to be configured. Constraints: N/A Range: The value can contain 1 to 256 characters, with no character type restrictions. Default Value: N/A |
| logger_level | No | String | Definition: Log level, used to control the verbosity of log output for the class. Constraints: N/A Range Default Value: INFO |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| max_retry | No | Integer | Definition: Maximum retry count, used to control the number of automatic retries after a job failure. If the configured value is greater than 0, failure retry is automatically enabled. If not configured or configured as 0, job failure retry is disabled. Constraints: N/A Range: 0 to 65535. Default Value: 0. |
| retry_delay | No | Integer | Definition: Retry interval, used to specify the time interval between each retry in the job failure retry mechanism, in seconds. Constraints: N/A Range: 1 to 3600. Default Value: 30. |
| queued_timeout | No | Integer | Definition: Queue timeout duration, used to specify the maximum time to wait for a job to start running after submission, in minutes. If the job has not started running after this time, the job fails. Constraints: N/A Range: 10 to 180 Default Value: 180 |
| running_timeout | No | Integer | Definition: Running timeout duration, used to specify the maximum runtime for the job, in minutes. If the job has not completed after this time, the job will be canceled and marked as running timeout. Constraints: N/A Range: 10 to 525600. Default Value: N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| key | Yes | String | Definition: Tag key, used to identify the unique key name of the tag. Constraints: N/A Range: The value can contain 1 to 128 characters, with no character type restrictions. Default Value: N/A |
| value | Yes | String | Definition: Tag value, used to identify the specific value of the tag. Constraints: N/A Range: The value can contain 1 to 512 characters, with no character type restrictions. Default Value: N/A |
Response Parameters
Status code: 201
| Parameter | Type | Description |
|---|---|---|
| job_id | String | Definition: Spark job ID, used to uniquely identify the started Spark job. Range: 1 to 64 characters. Only hexadecimal characters, hyphens (-), and underscores (_) are allowed. Example: 1ee7d9db-90ec-4b71-89b8-0de936dade77. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition: Error code, used to identify a specific error type. Range: 0 to 64 characters. |
| error_msg | String | Definition: Error description, used to explain the cause of an error. Range: 0 to 512 characters. |
| solution_msg | String | Definition: Solution description. Range: 0 to 4,096 characters. |
Example Requests
-
Start a Spark JAR job with the name spark-jar-job-example, endpoint spark-endpoint, job type SPARK_JAR_JOB, JAR path obs://bucket/path/job.jar, entry parameter --input obs://bucket/input --output obs://bucket/output, executor count 2, driver resources 2 vCPUs and 4 GB memory, and executor resources 2 vCPUs and 4 GB memory.
POST /v2/workspaces/{workspace_id}/spark-jobs { "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 } } } -
Start a Python job with the name python-job-example, endpoint spark-endpoint, job type SPARK_PYTHON_JOB, Python path obs://bucket/path/job.py, entry parameter --input-path obs://bucket/input, executor count 2, driver resources 2 vCPUs and 4 GB memory, and executor resources 2 vCPUs and 4 GB memory.
POST /v2/workspaces/{workspace_id}/spark-jobs { "name" : "python-job-example", "endpoint_name" : "spark-endpoint", "job_config" : { "type" : "SPARK_PYTHON_JOB", "main_python_file" : "obs://bucket/path/job.py", "main_args" : [ "--input-path", "obs://bucket/input" ] }, "resource_config" : { "executor_number" : 2, "driver_resource_spec" : { "cpu" : 2000, "memory" : 4096 }, "executor_resource_spec" : { "cpu" : 2000, "memory" : 4096 } } }
Example Responses
Status code: 201
{
"job_id" : "1ee7d9db-90ec-4b71-89b8-0de936dade77"
} Status code: 400
{
"error_code" : "AIDataLake.01011001",
"error_msg" : "Invalid parameter main_jar",
"solution_msg" : "Please check the input parameters according to the documentation(main_jar for jar job)."
} Status code: 401
{
"error_code" : "AIDataLake.01011003",
"error_msg" : "auth token not exists in header",
"solution_msg" : "Please check if auth token is included in the request header."
} Status code: 403
{
"error_code" : "AIDataLake.01011005",
"error_msg" : "current account has no permission",
"solution_msg" : "Please connect administrators to add permission."
} Status code: 500
{
"error_code" : "AIDataLake.01010001",
"error_msg" : "Internal system error",
"solution_msg" : "Contact operations for analysis."
} Status Codes
| Status Code | Description |
|---|---|
| 201 | Startup succeeded. |
| 400 | Invalid request parameter. |
| 401 | Authentication failed. |
| 403 | Insufficient permissions. |
| 500 | Internal server error. |
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