更新时间:2022-12-14 GMT+08:00
新增并执行作业
功能介绍
在MRS集群中新增并提交一个作业。
- 需要先在集群详情页的“概览”页签,单击“IAM用户同步”右侧的“单击同步”进行IAM用户同步,然后再通过该接口提交作业。
URI
请求参数
参数名 |
是否必选 |
参数类型 |
说明 |
---|---|---|---|
job_type |
是 |
String |
作业类型。
说明:
只有包含Spark、Hive和Flink组件的集群才能新增Spark、Hive和Flink类型的作业。 |
job_name |
是 |
String |
作业名称,只能由字母、数字、中划线和下划线组成,并且长度为1~64个字符。
说明:
不同作业的名称允许相同,但不建议设置相同。 |
arguments |
否 |
Array of strings |
程序执行的关键参数,该参数由用户程序内的函数指定,MRS只负责参数的传入。 最多为150000字符,不能包含;|&>'<$!\\特殊字符,可为空。
说明:
|
properties |
否 |
Map<String,String> |
程序系统参数。 最多为2048字符,不能包含><|'`&!\特殊字符,可为空。 |
响应参数
状态码: 200
参数名 |
参数类型 |
说明 |
---|---|---|
job_submit_result |
JobSubmitResult object |
作业执行结果,详细参数说明请参考表4。 |
参数名 |
参数类型 |
说明 |
---|---|---|
job_id |
String |
作业ID。 |
state |
String |
作业提交状态。
|
状态码: 500
参数名 |
参数类型 |
说明 |
---|---|---|
error_code |
String |
错误码。 |
error_msg |
String |
错误描述。 |
请求示例
所有示例中涉及的OBS路径、样例文件及终端节点和AKSK,请提前准备并在提交请求时根据实际情况替换。
- MapReduce作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "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" } }
- SparkSubmit作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"SparkSubmitTest", "job_type":"SparkSubmit", "arguments":[ "--master", "yarn", "--deploy-mode", "cluster", "--py-files", "obs://obs-test/a.py", "--conf", "spark.yarn.appMasterEnv.PYTHONPATH=/tmp:$PYTHONPATH", "--conf", "spark.yarn.appMasterEnv.aaa=aaaa", "--conf", "spark.executorEnv.aaa=executoraaa", "--properties-file", "obs://obs-test/test-spark.conf", "obs://obs-test/pi.py", "100000" ], "properties":{ "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- HiveScript作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"HiveScriptTest", "job_type":"HiveScript", "arguments":[ "obs://obs-test/sql/test_script.sql" ], "properties":{ "fs.obs.endpoint":"obs endpoint", "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- HiveSql作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name" : "HiveSqlTest", "job_type" : "HiveSql", "arguments" : [ "DROP TABLE IF EXISTS src_wordcount;\ncreate external table src_wordcount(line string) row format delimited fields terminated by \"\\n\" stored as textfile location \"obs://donotdel-gxc/input/\";\ninsert into src_wordcount values(\"v1\")" ], "properties" : { "fs.obs.endpoint" : "obs endpoint", "fs.obs.access.key" : "xxx", "fs.obs.secret.key" : "yyy" } }
- DistCp作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"DistCpTest", "job_type":"DistCp", "arguments":[ "obs://obs-test/DistcpJob/", "/user/test/sparksql/" ], "properties":{ "fs.obs.endpoint":"obs endpoint", "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- SparkScript作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"SparkScriptTest", "job_type":"SparkScript", "arguments":[ "op-key1", "op-value1", "op-key2", "op-value2", "obs://obs-test/sql/test_script.sql" ], "properties":{ "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- SparkSql作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"SparkSqlTest", "job_type":"SparkSql", "arguments":[ "op-key1", "op-value1", "op-key2", "op-value2", "create table student_info3 (id string,name string,gender string,age int,addr string);" ], "properties":{ "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- Flink作业请求示例:
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name":"FlinkTest", "job_type":"Flink", "arguments":[ "run", "-d", "-ynm", "testExcutorejobhdfsbatch", "-m", "yarn-cluster", "hdfs://test/examples/batch/WordCount.jar" ], "properties":{ "fs.obs.endpoint":"obs endpoint", "fs.obs.access.key":"xxx", "fs.obs.secret.key":"yyy" } }
- SparkPython作业请求示例(该类型作业将转换为SparkSubmit类型提交,MRS控制台界面的作业类型展示为SparkSubmit,通过接口查询作业列表信息时作业类型请选择SparkSubmit。)
POST https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions { "job_name" : "SparkPythonTest", "job_type" : "SparkPython", "arguments" : [ "--master", "yarn", "--deploy-mode", "cluster", "--py-files", "obs://obs-test/a.py", "--conf", "spark.yarn.appMasterEnv.PYTHONPATH=/tmp:$PYTHONPATH", "--conf", "spark.yarn.appMasterEnv.aaa=aaaa", "--conf", "spark.executorEnv.aaa=executoraaa", "--properties-file", "obs://obs-test/test-spark.conf", "obs://obs-test/pi.py", "100000" ], "properties" : { "fs.obs.access.key" : "xxx", "fs.obs.secret.key" : "yyy" } }
响应示例
状态码: 200
- 成功示例
{ "job_submit_result":{ "job_id":"44b37a20-ffe8-42b1-b42b-78a5978d7e40", "state":"COMPLETE" } }
状态码: 500
- 失败示例
{ "error_msg":"不能提交Hive相关作业", "error_code":"0168" }
状态码
状态码请参见状态码。
错误码
请参见错误码。
父主题: 作业对象接口