Updated on 2024-08-29 GMT+08:00

Creating a Job

Scenario

This API is used to add and submit a job in an MRS cluster. For details on how to call APIs, see Making an API Request.

Constraints

  • A cluster has been created and is in the Running state.
  • You have obtained the project ID of the region where the cluster is to be created. For details, see Obtaining a Project ID.
  • You have obtained the cluster ID, that is, the value of cluster_id in the command output returned after the cluster is successfully created. For details about how to obtain the cluster ID, see Obtaining a Cluster ID.
  • IAM users have been synchronized. On the Overview tab page of the cluster details page, click Click to synchronize on the right of IAM User Sync to synchronize IAM users.
  • The job-related programs and input files have been stored in OBS.
  • In this example, a MapReduce job is added.

Procedure

  • API

    URI format: POST /v2/{project_id}/clusters/{cluster_id}/job-executions

    For details, see Adding and Executing a Job.

  • Example request

    POST: https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions

    • For details about {endpoint}, see Endpoints.
    • For details about {project_id}, see Obtaining a Project ID.
    • {cluster_id} indicates the value of cluster_id in the command output returned after the cluster is successfully created. You can also obtain the value of cluster_id by referring to Obtaining a Cluster ID.
    Request body:
    {
        "job_name":"MapReduceTest",
        "job_type":"MapReduce",
        "arguments":[
            "obs://obs-test/program/hadoop-mapreduce-examples-x.x.x.jar",
            "wordcount",
            "obs://obs-test/input/",
            "obs://obs-test/job/mapreduce/output"
        ],
        "properties":{
            "fs.obs.endpoint":"obs endpoint",
            "fs.obs.access.key":"xxx",
            "fs.obs.secret.key":"yyy"
        }
    }

    For details about the parameters, see Adding and Executing a Job.

  • Example response
    {
      "job_submit_result":{
          "job_id":"44b37a20-ffe8-42b1-b42b-78a5978d7e40",
          "state":"COMPLETE"
      }
    }