华为云用户手册

  • 步骤1:构造规范请求 使用APP方式进行签名与认证,首先需要规范请求内容,然后再进行签名。客户端与API网关使用相同的请求规范,可以确保同一个HTTP请求的前后端得到相同的签名结果,从而完成身份校验。 HTTP请求规范伪代码如下: CanonicalRequest = HTTPRequestMethod + '\n' + CanonicalURI + '\n' + CanonicalQueryString + '\n' + CanonicalHeaders + '\n' + SignedHeaders + '\n' + HexEncode(Hash(RequestPayload)) 通过以下示例来说明规范请求的构造步骤。 假设原始请求如下: GET https://c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.com/app1?b=2&a=1 HTTP/1.1Host: c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.comX-Sdk-Date: 20191111T093443Z 构造HTTP请求方法(HTTPRequestMethod),以换行符结束。 HTTP请求方法,如GET、PUT、POST等。请求方法示例: GET 添加规范URI参数(CanonicalURI),以换行符结束。 释义: 规范URI,即请求资源路径,是URI的绝对路径部分的URI编码。 格式: 根据RFC 3986标准化URI路径,移除冗余和相对路径部分,路径中每个部分必须为URI编码。如果URI路径不以“/”结尾,则在尾部添加“/”。 举例: 示例中的URI:/app1,此时规范的URI编码为: GET/app1/ 计算签名时,URI必须以“/”结尾。发送请求时,可以不以“/”结尾。 添加规范查询字符串(CanonicalQueryString),以换行符结束。 释义: 查询字符串,即查询参数。如果没有查询参数,则为空字符串,即规范后的请求为空行。 格式: 规范查询字符串需要满足以下要求: 根据以下规则对每个参数名和值进行URI编码: 请勿对RFC 3986定义的任何非预留字符进行URI编码,这些字符包括:A-Z、a-z、0-9、-、_、.和~。 使用%XY对所有非预留字符进行百分比编码,其中X和Y为十六进制字符(0-9和A-F)。例如,空格字符必须编码为%20,扩展UTF-8字符必须采用“%XY%ZA%BC”格式。 对于每个参数,追加“URI编码的参数名称=URI编码的参数值”。如果没有参数值,则以空字符串代替,但不能省略“=”。 例如以下含有两个参数,其中第二个参数parm2的值为空。 parm1=value1&parm2= 按照字符代码以升序顺序对参数名进行排序。例如,以大写字母F开头的参数名排在以小写字母b开头的参数名之前。 以排序后的第一个参数名开始,构造规范查询字符串。 举例: 示例中包含两个可选参数:a、b GET/app1/a=1&b=2 添加规范消息头(CanonicalHeaders),以换行符结束。 释义: 规范消息头,即请求消息头列表。包括签名请求中的所有HTTP消息头列表。消息头必须包含X-Sdk-Date,用于校验签名时间,格式为ISO8601标准的UTC时间格式:YYYYMMDDTHHMMSSZ。如果API发布到非RELEASE环境时,需要增加自定义的环境名称。 客户端须注意本地时间与时钟服务器的同步,避免请求消息头X-Sdk-Date的值出现较大误差。 API网关除了校验时间格式外,还会校验该时间值与网关收到请求的时间差,如果时间差大于15分钟,API网关将拒绝请求。 格式: CanonicalHeaders由多个请求消息头共同组成,CanonicalHeadersEntry0 + CanonicalHeadersEntry1 + ...,其中每个请求消息头(CanonicalHeadersEntry)的格式为Lowercase(HeaderName) + ':' + Trimall(HeaderValue) + '\n' Lowercase表示将所有字符转换为小写字母的函数。 Trimall表示删除值前后的多余空格的函数。 最后一个请求消息头也会携带一个换行符。叠加规范中CanonicalHeaders自身携带的换行符,因此会出现一个空行。 消息头名称要保持唯一性,出现多个相同消息头名称时,无法完成认证。 举例: GET/app1/a=1&b=2host:c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.comx-sdk-date:20191111T093443Z 规范消息头需要满足以下要求: 将消息头名称转换为小写形式,并删除前导空格和尾随空格。 按照字符代码对消息头名称进行升序排序。 例如原始消息头为: Host: c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.com\nContent-Type: application/json;charset=utf8\nMy-header1: a b c \nX-Sdk-Date:20191111T093443Z\nMy-Header2: "a b c" \n 规范消息头为: content-type:application/json;charset=utf8\nhost:c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.com\nmy-header1:a b c\nmy-header2:"a b c"\nx-sdk-date:20191111T093443Z\n 添加用于签名的消息头声明(SignedHeaders),以换行符结束。 释义: 用于签名的请求消息头列表。通过添加此消息头,向API网关告知请求中哪些消息头是签名过程的一部分,以及在验证请求时API网关可以忽略哪些消息头。X-Sdk-date必须作为已签名的消息头。 格式: SignedHeaders = Lowercase(HeaderName0) + ';' + Lowercase(HeaderName1) + ";" + ... 已签名的消息头需要满足以下要求:将已签名的消息头名称转换为小写形式,按照字符代码对消息头进行排序,并使用“;”来分隔多个消息头。 Lowercase表示将所有字符转换为小写字母。 举例: 以下表示有两个消息头参与签名:host、x-sdk-date GET/app1/a=1&b=2host:c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.comx-sdk-date:20191111T093443Zhost;x-sdk-date 基于HTTP或HTTPS请求正文中的body体(RequestPayload),使用SHA-256哈希函数创建哈希值。 释义: 请求消息体。消息体需要做两层转换:HexEncode(Hash(RequestPayload)),其中Hash表示生成消息摘要的函数,当前支持SHA-256算法。HexEncode表示以小写字母形式返回摘要的Base-16编码的函数。例如,HexEncode("m") 返回值为“6d”而不是“6D”。输入的每一个字节都表示为两个十六进制字符。 计算RequestPayload的哈希值时,对于“RequestPayload==null”的场景,直接使用空字符串""来计算。 举例: 本示例为GET方法,body体为空。经过哈希处理的body(空字符串)如下: GET/app1/a=1&b=2host:c967a237-cd6c-470e-906f-a8655461897e.apigw.exampleRegion.comx-sdk-date:20191111T093443Zhost;x-sdk-datee3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 对构造好的规范请求进行哈希处理,算法与对RequestPayload哈希处理的算法相同。经过哈希处理的规范请求必须以小写十六进制字符串形式表示。 算法伪代码:Lowercase(HexEncode(Hash.SHA256(CanonicalRequest))) 经过哈希处理的规范请求示例: af71c5a7ef45310b8dc05ab15f7da50189ffa81a95cc284379ebaa5eb61155c0
  • 步骤2:创建待签字符串 对HTTP请求进行规范并取得请求的哈希值后,将其与签名算法、签名时间一起组成待签名字符串。 StringToSign = Algorithm + \n + RequestDateTime + \n + HashedCanonicalRequest 伪代码中参数说明如下。 Algorithm 签名算法。对于SHA 256,算法为SDK-HMAC-SHA256。 RequestDateTime 请求时间戳。与请求消息头X-Sdk-Date的值相同,格式为YYYYMMDDTHHMMSSZ。 HashedCanonicalRequest 经过哈希处理的规范请求。 上述例子得到的待签字符串为: SDK-HMAC-SHA25620191111T093443Zaf71c5a7ef45310b8dc05ab15f7da50189ffa81a95cc284379ebaa5eb61155c0
  • x-apigateway-cors 含义:API网关定义的API请求是否支持跨域,boolean类型。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-cors: true 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-cors 是 boolean 是否支持开启跨域请求的标识。 true:支持 false:不支持 开启跨域访问的API请求,响应会增加如下头域: 头 域名 称 头域值 描述 Access-Control-Max-Age 172800 预检响应最大缓存时间 单位:s Access-Control-Allow-Origin * 允许任何域。 Access-Control-Allow-Headers X-Sdk-Date,X-Sdk-Nonce,X-Proxy-Signed-Headers,X-Sdk-Content-Sha256,X-Forwarded-For,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range 正式请求允许的头域 Access-Control-Allow-Methods GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH 正式请求允许的方法 父主题: 扩展定义
  • x-apigateway-backend 含义:API网关定义的API后端服务定义。 作用域:Operation Object(2.0) 示例: paths: '/users/{userId}': get: produces: - "application/json" responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "backend endpoint type" 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-backend 是 String API后端服务定义 type 是 String 后端服务类型,支持HTTP、HTTP-VPC、FUNCTION、MOCK parameters 否 x-apigateway-backend.parameters 后端参数定义 httpEndpoints 否 x-apigateway-backend.httpEndpoints HTTP类型后端服务定义 httpVpcEndpoints 否 x-apigateway-backend.httpVpcEndpoints HTTP-VPC类型后端服务定义 functionEndpoints 否 x-apigateway-backend.functionEndpoints FUNCTION类型后端服务定义 mockEndpoints 否 x-apigateway-backend.mockEndpoints MOCK类型后端服务定义 父主题: x-apigateway-backend
  • x-apigateway-backend.parameters 含义:API网关定义的API后端参数定义。 作用域:x-apigateway-backend 示例: paths: '/users/{userId}': get: produces: - "application/json" parameters: - name: "X-Auth-Token" description: "认证token" type: "string" in: "header" required: true - name: "userId" description: "用户名" type: "string" in: "path" required: true responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "HTTP" parameters: - name: "userId" value: "userId" in: "query" origin: "REQUEST" description: "用户名" - name: "X-Invoke-User" value: "apigateway" in: "header" origin: "CONSTANT" description: "调用者" 表1 参数说明 参数 是否必选 类型 说明 name 是 String 参数名称,由字母、数字、下划线、连线、点组成,以字母开头,最长32字节 header位置的参数名称不区分大小写 value 是 String 参数值,当参数来源为REQUEST时,值为请求参数名称 in 是 String 参数位置,支持header、query、path origin 是 String 参数映射来源,支持REQUEST、CONSTANT description 否 String 参数含义描述 父主题: x-apigateway-backend
  • x-apigateway-backend.functionEndpoints 含义:API网关定义的FUNCTION类型API后端服务定义。 作用域:x-apigateway-backend 示例: paths: '/users/{userId}': get: produces: - "application/json" parameters: - name: "X-Auth-Token" description: "认证token" type: "string" in: "header" required: true responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "FUNCTION" functionEndpoints: version: "v1" function-urn: "" invocation-type: "synchronous" timeout: 30000 表1 参数说明 参数 是否必选 类型 说明 function-urn 是 String 函数URN地址 version 是 String 函数版本 invocation-type 是 String 函数调用类型,支持async、sync timeout 否 Number 函数超时时间,单位毫秒,缺省值为5000,取值范围为1 ~ 60000 父主题: x-apigateway-backend
  • x-apigateway-any-method 含义:API网关定义的API请求方法,用以匹配未指定定义的HTTP方法。 作用域:Path Item Object(2.0) 示例: paths: '/path': get: produces: - application/json responses: "200": description: "get response" x-apigateway-any-method: produces: - application/json responses: "200": description: "any response" 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-any-method 否 String API请求方法 父主题: 扩展定义
  • x-apigateway-backend.httpVpcEndpoints 含义:API网关定义的HTTP VPC类型API后端服务定义。 作用域:x-apigateway-backend 示例: paths: '/users/{userId}': get: produces: - "application/json" parameters: - name: "X-Auth-Token" description: "认证token" type: "string" in: "header" required: true responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "HTTP-VPC" httpVpcEndpoints: name: "vpc-test-1" scheme: "http" method: "GET" path: "/users" timeout: 30000 表1 参数说明 参数 是否必选 类型 说明 name 是 Array VPC通道名称 scheme 是 String 后端请求协议定义,支持http、https method 是 String 后端请求方法,支持GET、POST、PUT、DELETE、HEAD、OPTIONS、PATCH、ANY path 是 String 后端请求路径,支持路径变量 timeout 否 Number 后端请求超时时间,单位毫秒,缺省值为5000,取值范围为1 ~ 60000 父主题: x-apigateway-backend
  • x-apigateway-backend.mockEndpoints 含义:API网关定义的MOCK类型API后端服务定义。 作用域:x-apigateway-backend 示例: paths: '/users/{userId}': get: produces: - "application/json" parameters: - name: "X-Auth-Token" description: "认证token" type: "string" in: "header" required: true responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "MOCK" mockEndpoints: result-content: "mocked" 表1 参数说明 参数 是否必选 类型 说明 result-content 是 String MOCK返回结果 父主题: x-apigateway-backend
  • x-apigateway-ratelimit 含义:引用流控策略。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-ratelimit: 'customRatelimitName' 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-ratelimit 否 String 流控策略 父主题: 扩展定义
  • x-apigateway-backend-policies 含义:API网关定义的API后端策略。 作用域:Operation Object(2.0) 示例: paths: '/users/{userId}': get: produces: - "application/json" responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "backend endpoint type" x-apigateway-backend-policies: - type: "backend endpoint type" name: "backend policy name" conditions: - type: "equal/enum/pattern", value: "string", origin: "source/request_parameter", parameter_name: "string" 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-backend-policies 否 x-apigateway-backend-policies 策略后端 type 是 String 后端服务类型,支持HTTP、HTTP-VPC、FUNCTION、MOCK name 是 String 后端策略名称 parameters 否 x-apigateway-backend.parameters 后端参数定义 httpEndpoints 否 x-apigateway-backend.httpEndpoints HTTP类型服务定义 httpVpcEndpoints 否 x-apigateway-backend.httpVpcEndpoints HTTP-VPC类型服务定义 functionEndpoints 否 x-apigateway-backend.functionEndpoints FUNCTION类型服务定义 mockEndpoints 否 x-apigateway-backend.mockEndpoints MOCK类型服务定义 conditions 是 x-apigateway-backend-policies.conditions 策略条件数组 父主题: x-apigateway-backend-policies
  • x-apigateway-access-control 含义:引用访问控制策略。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-access-control: 'customAccessControlName' 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-access-control 否 String 访问控制策略 父主题: 扩展定义
  • 导入MOCK类型后端服务API 包含无认证的GET方法API定义,后端服务类型为MOCK。 Swagger示例: swagger: "2.0"info: title: "importMockEndpoint" description: "import apis" version: "1.0"host: "api.account.com"paths: '/mock': get: operationId: "mock" description: "mock test" schemes: - http responses: "200": description: "mock result" x-apigateway-request-type: "private" x-apigateway-cors: true x-apigateway-match-mode: "NORMAL" x-apigateway-backend: type: "MOCK" mockEndpoints: result-content: "{\"message\": \"mocked\"}"securityDefinitions: apig-auth-app: in: header name: Authorization type: apiKey x-apigateway-auth-type: AppSigv1 apig-auth-iam: in: header name: unused type: apiKey x-apigateway-auth-type: IAM 父主题: 导入API示例
  • x-apigateway-plugins 含义:API网关定义的API插件服务。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-plugins: ['Plugin_mock']x-apigateway-plugins 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-plugins 否 Array API所绑定的插件名列表。 父主题: 扩展定义
  • 导入HTTP类型后端服务API 包含IAM认证和请求参数编排的GET方法API定义,后端服务类型为HTTP。 Swagger示例: swagger: "2.0"info: title: "importHttpEndpoint10" description: "import apis" version: "1.0"host: "api.account.com"paths: '/http/{userId}': get: operationId: "getUser3" description: "get user by userId" security: - apig-auth-iam: [] schemes: - https parameters: - name: "test" description: "authorization token" type: "string" in: "header" required: true - name: "userId" description: "user id" type: "string" in: "path" required: true responses: "200": description: "user information" x-apigateway-request-type: "public" x-apigateway-cors: true x-apigateway-match-mode: "NORMAL" x-apigateway-backend: type: "HTTP" parameters: - name: "userId" value: "userId" in: "query" origin: "REQUEST" description: "user id" - name: "X-Invoke-User" value: "apigateway" in: "header" origin: "CONSTANT" description: "invoke user" httpEndpoints: address: "example.com" scheme: "http" method: "GET" path: "/users" timeout: 30000securityDefinitions: apig-auth-app: in: header name: Authorization type: apiKey x-apigateway-auth-type: AppSigv1 apig-auth-iam: in: header name: unused type: apiKey x-apigateway-auth-type: IAM 父主题: 导入API示例
  • x-apigateway-ratelimits 含义:流控策略名称与关联策略映射。 作用域:Swagger Object 示例: x-apigateway-ratelimits: customRatelimitName: api-limit: 200 app-limit: 200 user-limit: 200 ip-limit: 200 interval: 1 unit: second/minute/hour shared: true special: - type: APP limit: 100 instance: xxxxxxxxx 表1 参数说明 参数 是否必选 类型 说明 customRatelimitName 否 x-apigateway-ratelimits.policy 指定名称的流控策略。 要使用该策略,将x-apigateway-ratelimit属性值引用为该策略名称。 父主题: x-apigateway-ratelimits
  • x-apigateway-backend-policies.conditions 含义:API网关定义的API后端策略条件。 作用域:x-apigateway-backend-policies 示例: paths: '/users/{userId}': get: produces: - "application/json" responses: default: description: "default response" x-apigateway-request-type: "public" x-apigateway-backend: type: "backend endpoint type" x-apigateway-backend-policies: - type: "backend endpoint type" name: "backend policy name" conditions: - type: "equal/enum/pattern", value: "string", origin: "source/request_parameter", parameter_name: "string" 表1 参数说明 参数 是否必选 类型 说明 type 是 String 策略条件类型,支持equal、enum、pattern value 是 String 策略条件值 origin 是 String 策略条件输入来源,支持source、request parameter 否 String 策略条件输入来源为request时,请求入参的名称 父主题: x-apigateway-backend-policies
  • x-apigateway-access-controls 含义:访问控制策略名称与关联策略映射。 作用域:Swagger Object 示例: x-apigateway-access-controls: customAccessControlName: acl-type: "DENY" entity-type: "IP" value: 127.0.0.1,192.168.0.1/16 表1 参数说明 参数 是否必选 类型 说明 customAccessControlName 否 x-apigateway-access-controls.policy 指定名称的访问控制策略。 要使用该策略,将x-apigateway-access-control属性值引用为该策略名称。 父主题: x-apigateway-access-controls
  • 导入HTTP VPC类型后端服务API 包含APP认证和请求参数编排的ANY方法API定义,后端服务使用VPC通道。 Swagger示例: swagger: "2.0"info: title: "importHttpVpcEndpoint" description: "import apis" version: "1.0"host: "api.account.com"paths: '/http-vpc': x-apigateway-any-method: operationId: "userOperation" description: "user operation resource" security: - apig-auth-app: [] schemes: - https parameters: - name: "Authorization" description: "authorization signature" type: "string" in: "header" required: true responses: "default": description: "endpoint response" x-apigateway-request-type: "public" x-apigateway-cors: true x-apigateway-match-mode: "SWA" x-apigateway-backend: type: "HTTP-VPC" parameters: - name: "X-Invoke-User" value: "apigateway" in: "header" origin: "CONSTANT" description: "invoke user" httpVpcEndpoints: name: "userVpc" scheme: "http" method: "GET" path: "/users" timeout: 30000securityDefinitions: apig-auth-app: in: header name: Authorization type: apiKey x-apigateway-auth-type: AppSigv1 apig-auth-iam: in: header name: unused type: apiKey x-apigateway-auth-type: IAM 父主题: 导入API示例
  • x-apigateway-match-mode 含义:API网关定义的API请求URL的匹配模式,支持NORMAL和SWA。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-match-mode: 'SWA' 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-match-mode 是 String API匹配模式,支持SWA和NORMAL。 SWA:前缀匹配,如“/prefix/foo”和“/prefix/bar”都会被“/prefix ”匹配,但“/prefixpart”却不会被匹配。 NORMAL:绝对匹配。 父主题: 扩展定义
  • x-apigateway-request-type 含义:API网关定义的API请求类型,支持public和private。 作用域:Operation Object(2.0) 示例: paths: '/path': get: x-apigateway-request-type: 'public' 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-request-type 是 String API类型,支持public和private。 public:公开类型API,可以上架。 private:私有类型API,不会被上架。 父主题: 扩展定义
  • x-apigateway-auth-type 含义:基于Swagger的apiKey认证格式,定义API网关支持的特有认证方式。 作用域:Security Scheme Object(2.0) Swagger: securityDefinitions: apig-auth-app: in: header name: Authorization type: apiKey x-apigateway-auth-type: AppSigv1 apig-auth-iam: in: header name: unused type: apiKey x-apigateway-auth-type: IAM 表1 参数说明 参数 是否必选 类型 说明 x-apigateway-auth-type 是 String API网关认证方式,支持AppSigv1、IAM type 是 String 认证类型,仅支持apiKey name 是 String 用于认证的参数名称 in 是 String 仅支持header description 否 String 描述信息 父主题: 扩展定义
  • 响应示例 状态码: 200 查询作业exe对象详情成功。 { "job_execution" : { "id" : "632863d5-15d4-4691-9dc1-1a72340cb097", "create_at" : "1484240559176", "update_at" : "1484240559176", "tenant_id" : "3f99e3319a8943ceb15c584f3325d064", "job_id" : "632863d5-15d4-4691-9dc1-1a72340cb097", "job_name" : "hive_script", "start_time" : "1484240559176", "end_time" : null, "cluster_id" : "8b1d55f6-150e-45e2-8347-b2ca608d366b", "group_id" : "632863d5-15d4-4691-9dc1-1a72340cb097", "jar_path" : "s3a://jp-test1/program/Hivescript.sql", "input" : "s3a://jp-test1/input/", "output" : "s3a://jp-test1/output/", "job_log" : "s3a://jp-test1/joblogs/", "job_type" : "3", "file_action" : "", "arguments" : "wordcount", "hql" : null, "job_state" : "3", "job_final_status" : "1", "hive_script_path" : "s3a://jp-test1/program/Hivescript.sql", "create_by" : "3f99e3319a8943ceb15c584f3325d064", "finished_step" : "0", "job_main_id" : "", "job_step_id" : "", "postpone_at" : "1484240558705", "step_name" : "", "step_num" : "0", "task_num" : "0", "update_by" : "3f99e3319a8943ceb15c584f3325d064", "spend_time" : null, "step_seq" : "222", "progress" : "first progress" }}
  • 响应参数 状态码: 200 表2 响应Body参数 参数 参数类型 描述 job_execution JobExeResult object 作业详细信息。 表3 JobExeResult 参数 参数类型 描述 id String 作业ID。 create_at Long 作业创建时间,十三位时间戳。 update_at Long 作业更新时间,十三位时间戳。 tenant_id String 项目编号。获取方法,请参见获取项目ID。 job_id String 作业ID。 job_name String 作业名称。 start_time Long 作业执行开始时间,十三位时间戳。 end_time Long 作业执行结束时间,十三位时间戳。 cluster_id String 作业所属集群ID。 group_id String 作业执行组ID jar_path String 执行程序jar包或sql文件地址。 input String 数据输入地址。 output String 数据输出地址。 job_log String 作业日志存储地址 job_type Integer 作业类型码。 1:MapReduce 2:Spark 3:Hive Script 4:HiveSQL(当前不支持) 5:DistCp 6:Spark Script 7:Spark SQL(该接口当前不支持) file_action String 导入导出数据。 arguments String 程序执行的关键参数,该参数由用户程序内的函数指定, MRS 只负责参数的传入。该参数可为空。 hql String HQL脚本语句。 job_state Integer 作业状态编码: -1:Terminated表示已终止的作业状态 2:Running表示运行中的作业状态 3:Completed表示已完成的作业状态 4:Abnormal表示异常的作业状态 job_final_status Integer 作业最终状态码。 0:未完成 1:执行错误,终止执行 2:执行完成并且成功 3:已取消 hive_script_path String Hive脚本地址。 create_by String 创建作业的用户ID。 finished_step Integer 当前已完成的步骤数。 job_main_id String 作业主ID。 job_step_id String 作业步骤ID。 postpone_at Long 延迟时间,十三位时间戳。 step_name String 作业步骤名。 step_num Integer 步骤数量。 task_num Integer 任务数量。 update_by String 更新作业的用户ID。 spend_time Float 作业执行持续时间,单位:秒。 step_seq Integer 步骤序列号。 progress String 作业执行进度。
  • 操作步骤 接口相关信息 URI格式:POST /v2/{project_id}/clusters/{cluster_id}/job-executions/{job_execution_id}/kill 详情请参见终止作业。 请求示例 POST: https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions/{job_execution_id}/kill {endpoint}信息具体请参考终端节点。 {project_id}信息请通过获取项目ID获取。 {cluster_id}信息即创建集群成功后返回结果中的“cluster_id” 或参考获取集群ID获取。 {job_execution_id}信息即作业提交成功后返回结果中的“job_id”或参考获取作业ID获取。 Body:无 响应示例 无
  • 约束限制 集群已创建成功并处于“运行中”。 已获取待创建集群区域的项目ID,请参考获取项目ID获取。 已获取集群ID,即创建集群成功后返回结果中的“cluster_id” 或参考获取集群ID获取。 已获取作业ID,即作业提交成功后返回结果中的“job_id”或参考获取作业ID获取。 IAM用户已同步完成,可通过在集群详情页的“概览”页签,单击“IAM用户同步”右侧的“单击同步”进行IAM用户同步。 作业相关程序和输入文件已存放在OBS中。 该示例以新增MapReduce作业为例。
  • 操作步骤 接口相关信息 URI格式:POST /v2/{project_id}/clusters/{cluster_id}/job-executions 详情请参见新增并执行作业。 请求示例 POST: https://{endpoint}/v2/{project_id}/clusters/{cluster_id}/job-executions {endpoint}信息具体请参考终端节点。 {project_id}信息请通过获取项目ID获取。 {cluster_id}信息即创建集群成功后返回结果中的“cluster_id” 或参考获取集群ID获取。 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" }} 参数详细信息请参考新增并执行作业获取。 响应示例 { "job_submit_result":{ "job_id":"44b37a20-ffe8-42b1-b42b-78a5978d7e40", "state":"COMPLETE" }}
  • 调用API获取项目ID 项目ID可以通过调用查询指定条件下的项目信息API获取。 获取项目ID的接口为“GET https://{Endpoint}/v3/projects”,其中{Endpoint}为IAM的终端节点,具体请参考终端节点。 响应示例如下,其中projects下的“id”即为“name”所对应区域的项目ID。 { "projects": [ { "domain_id": "65382450e8f64ac0870cd180d14e684b", "is_domain": false, "parent_id": "65382450e8f64ac0870cd180d14e684b", "name": "region_id", "description": "", "links": { "next": null, "previous": null, "self": "https://www.example.com/v3/projects/a4a5d4098fb4474fa22cd05f897d6b99" }, "id": "a4a5d4098fb4474fa22cd05f897d6b99", "enabled": true } ], "links": { "next": null, "previous": null, "self": "https://www.example.com/v3/projects" }}
  • 状态码 状态码如表1所示。 表1 状态码 状态码 编码 状态说明 100 Continue 继续请求。 这个临时响应用来通知客户端,它的部分请求已经被服务器接收,且仍未被拒绝。 101 Switching Protocols 切换协议。只能切换到更高级的协议。 例如,切换到HTTPS的新版本协议。 200 OK 服务器已成功处理了请求。 201 Created 创建类的请求完全成功。 202 Accepted 已经接受请求,但未处理完成。 203 Non-Authoritative Information 非授权信息,请求成功。 204 NoContent 请求完全成功,同时HTTPS响应不包含响应体。 在响应OPTIONS方法的HTTPS请求时返回此状态码。 205 Reset Content 重置内容,服务器处理成功。 206 Partial Content 服务器成功处理了部分GET请求。 300 Multiple Choices 多种选择。请求的资源可包括多个位置,相应可返回一个资源特征与地址的列表用于用户终端(例如:浏览器)选择。 301 Moved Permanently 永久移动,请求的资源已被永久的移动到新的URI,返回信息会包括新的URI。 302 Found 资源被临时移动。 303 See Other 查看其它地址。 使用GET和POST请求查看。 304 Not Modified 所请求的资源未修改,服务器返回此状态码时,不会返回任何资源。 305 Use Proxy 所请求的资源必须通过代理访问。 306 Unused 已经被废弃的HTTPS状态码。 400 BadRequest 非法请求。 建议直接修改该请求,不要重试该请求。 401 Unauthorized 在客户端提供认证信息后,返回该状态码,表明服务端指出客户端所提供的认证信息不正确或非法。 402 Payment Required 保留请求。 403 Forbidden 请求被拒绝访问。 返回该状态码,表明请求能够到达服务端,且服务端能够理解用户请求,但是拒绝做更多的事情,因为该请求被设置为拒绝访问,建议直接修改该请求,不要重试该请求。 404 NotFound 所请求的资源不存在。 建议直接修改该请求,不要重试该请求。 405 MethodNotAllowed 请求中带有该资源不支持的方法。 建议直接修改该请求,不要重试该请求。 406 Not Acceptable 服务器无法根据客户端请求的内容特性完成请求。 407 Proxy Authentication Required 请求要求代理的身份认证,与401类似,但请求者应当使用代理进行授权。 408 Request Time-out 服务器等候请求时发生超时。 客户端可以随时再次提交该请求而无需进行任何更改。 409 Conflict 服务器在完成请求时发生冲突。 返回该状态码,表明客户端尝试创建的资源已经存在,或者由于冲突请求的更新操作不能被完成。 410 Gone 客户端请求的资源已经不存在。 返回该状态码,表明请求的资源已被永久删除。 411 Length Required 服务器无法处理客户端发送的不带Content-Length的请求信息。 412 Precondition Failed 未满足前提条件,服务器未满足请求者在请求中设置的其中一个前提条件。 413 Request Entity Too Large 由于请求的实体过大,服务器无法处理,因此拒绝请求。为防止客户端的连续请求,服务器可能会关闭连接。如果只是服务器暂时无法处理,则会包含一个Retry-After的响应信息。 414 Request-URI Too Large 请求的URI过长(URI通常为网址),服务器无法处理。 415 Unsupported Media Type 服务器无法处理请求附带的媒体格式。 416 Requested range not satisfiable 客户端请求的范围无效。 417 Expectation Failed 服务器无法满足Expect的请求头信息。 422 UnprocessableEntity 请求格式正确,但是由于含有语义错误,无法响应。 429 TooManyRequests 表明请求超出了客户端访问频率的限制或者服务端接收到多于它能处理的请求。建议客户端读取相应的Retry-After首部,然后等待该首部指出的时间后再重试。 500 InternalServerError 表明服务端能被请求访问到,但是不能理解用户的请求。 501 Not Implemented 服务器不支持请求的功能,无法完成请求。 502 Bad Gateway 充当网关或代理的服务器,从远端服务器接收到了一个无效的请求。 503 ServiceUnavailable 被请求的服务无效。 建议直接修改该请求,不要重试该请求。 504 ServerTimeout 请求在给定的时间内无法完成。客户端仅在为请求指定超时(Timeout)参数时会得到该响应。 505 HTTPS Version not supported 服务器不支持请求的HTTPS协议的版本,无法完成处理。 父主题: 附录
  • 请求示例 在MRS集群中扩容1个core节点。 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_out", "node_id" : "node_orderadd", "node_group" : "core_node_default_group", "instances" : "1", "skip_bootstrap_scripts" : false, "scale_without_start" : false }, "previous_values" : { }} 当Task节点个数大于零时,在MRS集群中扩容1个Task节点。 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_out", "node_id" : "node_orderadd", "node_group" : "task_node_default_group", "instances" : "1", "skip_bootstrap_scripts" : false, "scale_without_start" : false }, "previous_values" : { }} 当Task节点个数大于零时,在MRS集群中扩容1个规格为s3.xlarge.2.linux.bigdata 的Task节点。 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_out", "node_id" : "node_orderadd", "node_group" : "task_node_default_group", "task_node_info" : { "node_size" : "s3.xlarge.2.linux.bigdata", "data_volume_type" : "SATA", "data_volume_count" : 2, "data_volume_size" : 600 }, "instances" : "1", "scale_without_start" : false }, "previous_values" : { }} 在MRS集群中缩容1个Core节点。 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_in", "node_id" : "node_orderadd", "node_group" : "core_node_default_group", "instances" : "1" }, "previous_values" : { }} 在MRS集群中缩容1个Task节点 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_in", "node_id" : "node_orderadd", "node_group" : "task_node_default_group", "instances" : "1" }, "previous_values" : { }} 在MRS集群中缩容指定的Task节点。 PUT /v1.1/{project_id}/cluster_infos/{cluster_id}{ "service_id" : "", "plan_id" : "", "parameters" : { "order_id" : "", "scale_type" : "scale_in", "node_id" : "node_orderadd", "node_group" : "task_node_default_group", "instances" : "2", "server_ids" : [ "c9573435-7814-4b2c-9131-ad78b814414c", "a4951009-6a0f-4e7b-9c81-9d4bd1f8c537" ] }, "previous_values" : { }}
共100000条