Creating an Auto Scaling Policy
Function
This API is used to create a scheduled scaling policy for a deployed service. It is applicable to scenarios where the number of service instances needs to be automatically adjusted based on the service load or at a specified time. Before calling this API, ensure that the service has been deployed, a valid service ID has been obtained, and detailed scaling policy parameters, such as the scaling time, instance quantity range, and condition trigger, have been provided. After the creation, the system automatically adjusts the number of service instances based on the preset policy. This ensures the performance and availability of the service within the specified period. If the provided service ID is invalid, the parameter settings are incorrect, or the system resources are insufficient, an error message is displayed, prompting you to check the validity of the input data or contact technical support.
Debugging
You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
- If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
modelarts:service:createHpa
Read
service *
-
-
-
URI
POST /v2/{project_id}/services/{service_id}/deployments/{deployment_id}/hpa
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Project ID. For details, see Obtaining a Project ID and Name. Constraints N/A Range Project ID. Default Value N/A |
| service_id | Yes | String | Definition: Service ID, which can be obtained from the response body during service creation or by querying the service list. The service_id field indicates the service ID. Constraints N/A Range Service ID. Default Value N/A |
| deployment_id | Yes | String | Definition Deployment ID, which you can obtain from the response body when adding the deployment or by obtaining service deployments. The deployment_id field indicates the deployment ID. Constraints N/A Range Deployment ID. Default Value N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition User token. It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. For details about how to obtain the token, see Obtaining a User Token Through Password Authentication. Constraints N/A Range N/A Default Value N/A |
| Content-Type | Yes | String | Definition Message body type or format. Constraints N/A Range Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| type | Yes | String | Definition Auto scaling type. Range Constraints N/A Default Value N/A |
| target_resource_id | Yes | String | Definition ID of the target to which the auto scaling policy is bound. Range Instance group ID. Constraints N/A Default Value N/A |
| target_resource_type | Yes | String | Definition Type of the target to which the auto scaling policy is bound. Range Constraints N/A Default Value N/A |
| hpa_rules | Yes | Array of HpaRules objects | Definition Auto scaling rule. Constraints N/A |
| workspace_id | No | String | Definition Workspace ID. Range
Constraints N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | No | String | Definition Auto scaling rule name. Range The value contains 4 to 64 characters, including lowercase letters, digits, and hyphens (-). The value must start with a lowercase letter and cannot end with a hyphen (-). Constraints N/A Default Value N/A |
| id | No | String | Definition Auto scaling ID. Range The value can contain 4 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. Constraints N/A Default Value N/A |
| disable | No | Boolean | Definition Specifies whether to enable the auto scaling rule. Range Constraints N/A Default Value N/A |
| type | Yes | String | Definition Auto scaling type. Range Constraints N/A Default Value N/A |
| status | No | String | Definition Auto scaling type. Range Constraints N/A Default Value N/A |
| operate | No | String | Definition Auto scaling type. Range Constraints N/A Default Value N/A |
| schedule | Yes | String | Definition Cron expression for executing scheduled auto scaling. The value starts at a minute level and does not support seconds. Range N/A Constraints N/A Default Value N/A |
| target_replicas | Yes | Integer | Definition Number of target instances for auto scaling. Range The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number. Constraints N/A Default Value N/A |
| min_replicas | No | Integer | Definition Minimum number of instances for auto scaling. Range The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number. Constraints N/A Default Value N/A |
| max_replicas | No | Integer | Definition Maximum number of instances for auto scaling. Range The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number. Constraints N/A Default Value N/A |
| downscale_window | No | Integer | Definition Cooldown period for auto scale-out. Range The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number. Constraints N/A Default Value N/A |
| upscale_window | No | Integer | Definition Cooldown period for auto scale-in. Range The value ranges from 1 to 128. The API can receive floating-point numbers, and the backend automatically rounds down the number. Constraints N/A Default Value N/A |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| id | String | Definition Auto scaling policy ID. Range N/A |
| name | String | Definition Name of an auto scaling policy. Range N/A |
| target_resource_id | String | Definition ID of the target to which the auto scaling policy is bound. Range Instance group ID. |
| target_resource_type | String | Definition Type of the target to which the auto scaling policy is bound. Range |
| min_replicas | Integer | Definition Minimum number of instances for auto scaling. Range 1-128 |
| max_replicas | Integer | Definition Maximum number of instances for auto scaling. Range 1-128 |
| status | String | Definition Status of the auto scaling policy. Range |
| workspace_id | String | Definition Workspace ID. Range
|
| hpa_rules | Array of HpaRule objects | Definition Auto scaling rules. |
| Parameter | Type | Description |
|---|---|---|
| id | String | Definition Auto scaling rule ID. Range N/A |
| hpa_id | String | Definition ID of the policy associated with the auto scaling rule. Range N/A |
| name | String | Definition Auto scaling rule name. Range The value can contain 4 to 64 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. |
| type | String | Definition Auto scaling type. Range |
| schedule | String | Definition Cron expression for executing scheduled auto scaling. The value starts at a minute level and does not support seconds. Range N/A |
| target_replicas | Integer | Definition Number of target instances for auto scaling. Range 1 to 128 |
| disable | String | Definition Specifies whether to enable the auto scaling rule. Range |
| status | String | Definition Status of the auto scaling rule. Range |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Range: N/A. |
| error_msg | String | Definition: Error message. Range: N/A. |
Status code: 500
Example Requests
Create a rule. This API is used when no rule exists in the service.
POST https://{end_point}/v2/{project_id}/services/{service_id}/deployments/{deployment_id}/hpa
{
"type" : "CRON_HPA",
"target_resource_id" : "8a927efb-2e23-42e5-92ea-de86b4aba750",
"target_resource_type" : "GROUP",
"hpa_rules" : [ {
"name" : "test-rule1",
"disable" : false,
"type" : "CRON_HPA",
"schedule" : "22 9 * * ?",
"target_replicas" : 3
}, {
"name" : "test-rule2",
"disable" : true,
"type" : "CRON_HPA",
"schedule" : "0 0 * * ?",
"target_replicas" : 1
} ]
} Example Responses
Status code: 200
Response body for creating an auto scaling policy.
{
"hpa_rules" : [ {
"disable" : true,
"hpa_id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
"id" : "accba651-d3fd-4434-8254-61d30e9e1b45",
"name" : "test-rule2",
"schedule" : "0 0 * * ?",
"status" : "CREATING",
"target_replicas" : 1,
"type" : "CRON_HPA"
}, {
"disable" : false,
"hpa_id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
"id" : "7447626f-6c94-4ad7-a527-d3fa04706788",
"name" : "test-rule3",
"schedule" : "38 10 * * ?",
"status" : "CREATING",
"target_replicas" : 3,
"type" : "CRON_HPA"
} ],
"id" : "8521e55e-219f-4769-8a2f-08a78c02182e",
"name" : "cron-hpa-8a927efb-2e23-42e5-92ea-de86b4aba750",
"status" : "ACTIVE",
"target_resource_id" : "8a927efb-2e23-42e5-92ea-de86b4aba750",
"target_resource_type" : "GROUP"
} Status Codes
| Status Code | Description |
|---|---|
| 200 | Response body for creating an auto scaling policy. |
| 400 | Resource not found. |
| 500 | An exception occurs when the ModelArts OS API is called. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank 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