
# 创建编排规则 - CreateOrchestration
#### 功能介绍
创建编排规则
#### 调试
您可以在[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/ROMA/doc?api=CreateOrchestration)中调试该接口，支持自动认证鉴权。API Explorer可以自动生成SDK代码示例，并提供SDK代码示例调试功能。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-roma/roma_06_0018.html)。
#### URI
POST /v2/{project_id}/apic/instances/{instance_id}/orchestrations
表1路径参数 
| 参数          | 是否必选 | 参数类型   | 描述                                  |
|:---|:---|:---|:---|
| project_id  | 是    | String | 项目ID，获取方式请参见API参考的"附录 \> 获取项目ID"章节。 |
| instance_id | 是    | String | 实例ID                                |
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token。通过调用IAM服务获取用户Token接口获取（响应消息头中X-Subject-Token的值）。 |
   
表3请求Body参数 
| 参数                         | 是否必选 | 参数类型                                                                                      | 描述                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| orchestration_name         | 是    | String                                                                                    | 编排映射规则名称。 支持英文，数字，下划线，且只能以英文开头，3-64个字符，同一实例下不允许重名。                                                                                                                                                         |
| orchestration_strategy     | 是    | String                                                                                    | 编排策略，有以下几种策略类型： - list：列表； - hash：哈希； - range：区间； - hash_range: 哈希+区间； - none_value: 空值映射； - default: 默认值映射； - head_n: 截取前n项； - tail_n: 截取后n项； 当编排策略为list时，orchestration_map列表长度\*map_param_list长度不超过3000。 |
| orchestration_mapped_param | 否    | [OrchestrationMappedParam] object | 编排后的参数配置，isPreprocessing为false时必填。                                                                                                                                                                         |
| is_preprocessing           | 否    | Boolean                                                                                   | 是否为预处理策略，预处理策略只会生成临时参数作为后面参数编排规则的入参标记。当为预处理策略时，该编排规则不能作为除default之外的最后一个编排规则。                                                                                                                               |
| orchestration_map          | 否    | Array of [OrchestrationMap] objects       | 编排映射规则列表，列表长度范围为1-300。 编排映射规则的生效优先级与列表顺序保持一致，列表中靠前的配置匹配优先级较高。 映射规则不能重复，当orchestration_strategy=list时，map_param_list的列表也不能包含重复元素。                                                                           |
   
 表4OrchestrationMappedParam 
| 参数                    | 是否必选 | 参数类型   | 描述                                                           |
|:---|:---|:---|:---|
| mapped_param_name     | 是    | String | 编排后的请求参数名，只支持英文，数字，中划线，必须以英文开头，1-128个字符，不能与已有的参数重名，默认会透传到后端。 |
| mapped_param_type     | 是    | String | 编排后的参数类型，支持string和number。                                    |
| mapped_param_location | 是    | String | 编排后的参数位置，支持query和header。                                     |
   
 表5OrchestrationMap 
| 参数                 | 是否必选 | 参数类型                                                                                          | 描述                                                                                                           |
|:---|:---|:---|:---|
| map_param_list     | 否    | Array of strings                                                                              | 用于映射编排后参数的列表配置，当orchestration_strategy=list时必填，列表长度范围为0-3000。 列表的取值只支持英文，数字，中划线和下划线，1-128个字符。                |
| map_param_range    | 否    | [OrchestrationMapParamRange] object | 用于映射编排后参数的区间配置，当orchestration_strategy=range或hash_range时必填。                                                  |
| mapped_param_value | 否    | String                                                                                        | 编排后的参数取值，只支持英文和数字，1-128个字符。 当orchestration_strategy为hash、head_n、tail_n，或者is_preprocessing为false时，非必填，其他情况必填。 |
| intercept_length   | 否    | Integer                                                                                       | 截取长度，取值范围为1-100，当策略类型为head_n和tail_n时必填，当截取长度大于参数长度时，截取参数的结果为完整参数。                                            |
   
 表6OrchestrationMapParamRange 
| 参数          | 是否必选 | 参数类型   | 描述                                                                                             |
|:---|:---|:---|:---|
| range_start | 否    | String | 区间起始值。 为可以转换成integer的string，转换后的range_start的范围为0-9223372036854775807， range_start不大于range_end。 |
| range_end   | 否    | String | 区间终止值。 为可以转换成integer的string，转换后的range_end的范围为0-9223372036854775807， range_start不大于range_end。   |
   
#### 响应参数
**状态码：201**
表7响应Body参数 
| 参数                         | 参数类型                                                                                       | 描述                                                                                                                                                                                                         |
|:---|:---|:---|
| orchestration_name         | String                                                                                     | 编排映射规则名称。 支持英文，数字，下划线，且只能以英文开头，3-64个字符，同一实例下不允许重名。                                                                                                                                                         |
| orchestration_strategy     | String                                                                                     | 编排策略，有以下几种策略类型： - list：列表； - hash：哈希； - range：区间； - hash_range: 哈希+区间； - none_value: 空值映射； - default: 默认值映射； - head_n: 截取前n项； - tail_n: 截取后n项； 当编排策略为list时，orchestration_map列表长度\*map_param_list长度不超过3000。 |
| orchestration_mapped_param | [OrchestrationMappedParam] object | 编排后的参数配置，isPreprocessing为false时必填。                                                                                                                                                                         |
| is_preprocessing           | Boolean                                                                                    | 是否为预处理策略，预处理策略只会生成临时参数作为后面参数编排规则的入参标记。当为预处理策略时，该编排规则不能作为除default之外的最后一个编排规则。                                                                                                                               |
| orchestration_map          | Array of [OrchestrationMap] objects       | 编排映射规则列表，列表长度范围为1-300。 编排映射规则的生效优先级与列表顺序保持一致，列表中靠前的配置匹配优先级较高。 映射规则不能重复，当orchestration_strategy=list时，map_param_list的列表也不能包含重复元素。                                                                           |
| orchestration_id           | String                                                                                     | 编排规则编号。                                                                                                                                                                                                    |
| orchestration_create_time  | String                                                                                     | 编排规则创建时间。                                                                                                                                                                                                  |
| orchestration_update_time  | String                                                                                     | 编排规则更新时间。                                                                                                                                                                                                  |
   
 表8OrchestrationMappedParam 
| 参数                    | 参数类型   | 描述                                                           |
|:---|:---|:---|
| mapped_param_name     | String | 编排后的请求参数名，只支持英文，数字，中划线，必须以英文开头，1-128个字符，不能与已有的参数重名，默认会透传到后端。 |
| mapped_param_type     | String | 编排后的参数类型，支持string和number。                                    |
| mapped_param_location | String | 编排后的参数位置，支持query和header。                                     |
   
 表9OrchestrationMap 
| 参数                 | 参数类型                                                                                           | 描述                                                                                                           |
|:---|:---|:---|
| map_param_list     | Array of strings                                                                               | 用于映射编排后参数的列表配置，当orchestration_strategy=list时必填，列表长度范围为0-3000。 列表的取值只支持英文，数字，中划线和下划线，1-128个字符。                |
| map_param_range    | [OrchestrationMapParamRange] object | 用于映射编排后参数的区间配置，当orchestration_strategy=range或hash_range时必填。                                                  |
| mapped_param_value | String                                                                                         | 编排后的参数取值，只支持英文和数字，1-128个字符。 当orchestration_strategy为hash、head_n、tail_n，或者is_preprocessing为false时，非必填，其他情况必填。 |
| intercept_length   | Integer                                                                                        | 截取长度，取值范围为1-100，当策略类型为head_n和tail_n时必填，当截取长度大于参数长度时，截取参数的结果为完整参数。                                            |
   
 表10OrchestrationMapParamRange 
| 参数          | 参数类型   | 描述                                                                                             |
|:---|:---|:---|
| range_start | String | 区间起始值。 为可以转换成integer的string，转换后的range_start的范围为0-9223372036854775807， range_start不大于range_end。 |
| range_end   | String | 区间终止值。 为可以转换成integer的string，转换后的range_end的范围为0-9223372036854775807， range_start不大于range_end。   |
   
**状态码：400**
表11响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：401**
表12响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：403**
表13响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：404**
表14响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
**状态码：500**
表15响应Body参数 
| 参数         | 参数类型   | 描述   |
|:---|:---|:---|
| error_code | String | 错误码  |
| error_msg  | String | 错误描述 |
   
#### 请求示例
- 创建list策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_1",
    "orchestration_strategy" : "list",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "map_param_list" : [ "10001", "10002" ],
      "mapped_param_value" : "1"
    }, {
      "map_param_list" : [ "10003", "10004" ],
      "mapped_param_value" : "2"
    } ],
    "is_preprocessing" : false
  }
  ```
- 创建range策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_2",
    "orchestration_strategy" : "range",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "map_param_range" : {
        "range_start" : "1",
        "range_end" : "1000"
      },
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建hash策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_3",
    "orchestration_strategy" : "hash",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    }
  }
  ```
- 创建hash_range策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_4",
    "orchestration_strategy" : "hash_range",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "map_param_range" : {
        "range_start" : "1",
        "range_end" : "1000"
      },
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建none_value策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_5",
    "orchestration_strategy" : "none_value",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建default策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_6",
    "orchestration_strategy" : "default",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建head_n策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_7",
    "orchestration_strategy" : "head_n",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "intercept_length" : 10,
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建tail_n策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_8",
    "orchestration_strategy" : "tail_n",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "intercept_length" : 10,
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 创建tail_n预处理策略编排规则示例。
  ```
  {
    "orchestration_name" : "orchestration_demo_8",
    "orchestration_strategy" : "tail_n",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "intercept_length" : 10
    } ],
    "is_preprocessing" : true
  }
  ```
#### 响应示例
**状态码：201**
Created
- 示例 1
  ```
  {
    "orchestration_id" : "76545e81d9cb4424bf704ef2b0ac7600",
    "orchestration_name" : "orchestration_demo_1",
    "orchestration_create_time" : "2023-07-02T12:31:23.353Z",
    "orchestration_update_time" : "2023-07-02T13:31:23.353Z",
    "orchestration_strategy" : "list",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "map_param_list" : [ "10001", "10002" ],
      "mapped_param_value" : "1"
    }, {
      "map_param_list" : [ "10003", "10004" ],
      "mapped_param_value" : "2"
    } ]
  }
  ```
- 示例 2
  ```
  {
    "orchestration_id" : "yt655e81d9cb4424bf704ef2b0ac7600",
    "orchestration_name" : "orchestration_demo_2",
    "orchestration_create_time" : "2023-07-02T12:31:23.353Z",
    "orchestration_update_time" : "2023-07-02T13:31:23.353Z",
    "orchestration_strategy" : "range",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    },
    "orchestration_map" : [ {
      "map_param_range" : {
        "range_start" : "1",
        "range_end" : "1000"
      },
      "mapped_param_value" : "1"
    } ]
  }
  ```
- 示例 3
  ```
  {
    "orchestration_id" : "a7655e81d9cb4424bf704ef2b0ac7600",
    "orchestration_name" : "orchestration_demo_3",
    "orchestration_create_time" : "2023-07-02T12:31:23.353Z",
    "orchestration_update_time" : "2023-07-02T13:31:23.353Z",
    "orchestration_strategy" : "hash",
    "orchestration_mapped_param" : {
      "mapped_param_name" : "shared-tag",
      "mapped_param_type" : "number",
      "mapped_param_location" : "header"
    }
  }
  ```
**状态码：400**
Bad Request
```
{
  "error_code" : "APIG.2012",
  "error_msg" : "Invalid parameter value,parameterName:instance_id. Please refer to the support documentation"
}
```
**状态码：401**
Unauthorized
```
{
  "error_code" : "APIG.1002",
  "error_msg" : "Incorrect token or token resolution failed"
}
```
**状态码：403**
Forbidden
```
{
  "error_code" : "APIG.1005",
  "error_msg" : "No permissions to request this method"
}
```
**状态码：404**
Not Found
```
{
  "error_code" : "APIG.3030",
  "error_msg" : "The instance does not exist;id:f0fa1789-3b76-433b-a787-9892951c620ec"
}
```
**状态码：500**
Internal Server Error
```
{
  "error_code" : "APIG.9999",
  "error_msg" : "System error"
}
```
#### 状态码
| 状态码 | 描述                    |
|:---|:---|
| 201 | Created               |
| 400 | Bad Request           |
| 401 | Unauthorized          |
| 403 | Forbidden             |
| 404 | Not Found             |
| 500 | Internal Server Error |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-roma/ErrorCode.html)。
