Updating an Auto Scaling Policy - UpdateAutoScalingPolicy
Function
This API is used to update the autoscaling policy configuration of a specified MRS cluster. It allows you to adjust the autoscaling rules and thresholds. It can be used in conjunction with the autoscaling policy query API to verify the update result.
Constraints
None
Debugging
You can debug this API in API Explorer, which supports automatic authentication and authorization. API Explorer can automatically generate sample SDK code and supports sample SDK code debugging.
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, no identity policy-based permissions are required for calling this API.
URI
PUT /v2/{project_id}/autoscaling-policy/{cluster_id}
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Project ID. For details about how to obtain the project ID, see Obtaining a Project ID. Constraints N/A Range The value must consist of 1 to 64 characters. Only letters and digits are allowed. Default Value N/A |
| cluster_id | Yes | String | Definition Cluster ID. For details about how to obtain the cluster ID, see Obtaining a Cluster ID. Constraints N/A Range The value can contain 1 to 64 characters, including only letters, digits, underscores (_), and hyphens (-). Default Value N/A |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| node_group_name | Yes | String | Definition Node group name. Constraints N/A Range Only letters, digits, and underscores (_) are allowed. Custom node group names must contain 3 to 14 characters. Default Value N/A |
| resource_pool_name | Yes | String | Definition Pool name. Constraints N/A Range This parameter is mandatory. If the cluster version does not support auto scaling for a specified resource pool, set this parameter to default. If this parameter is not default, the auto scaling policy of the specified resource pool is deleted. Default Value N/A |
| auto_scaling_policy | Yes | AutoScalingPolicyInfo object | Definition Auto scaling rule. For details about the parameters, see Table 3. Constraints N/A Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| auto_scaling_enable | No | Boolean | Definition Whether to enable the auto scaling rule. Constraints N/A Range
Default Value N/A |
| min_capacity | No | Integer | Definition Minimum number of nodes reserved for the node group. Constraints N/A Range 0-500 Default Value N/A |
| max_capacity | No | Integer | Definition Maximum number of nodes in the node group. Constraints N/A Range 0-500 Default Value N/A |
| resources_plans | No | Array of ResourcesPlan objects | Definition Resource plan list. For detailed parameter descriptions, see the parameter details list. If this parameter is left blank, the resource plan is disabled. Constraints When autoscaling is enabled, at least one of resource plans or autoscaling rules must be configured. A maximum of five resource plans are allowed. For details, see Table 4. Range N/A Default Value N/A |
| rules | No | Array of Rule objects | Definition Autoscaling rule list. For detailed parameter descriptions, see the parameter details list. Constraints When auto scaling is enabled, either a resource plan or an auto scaling rule must be configured. The number of records cannot exceed 10. For details, see Table 5. Range N/A Default Value N/A |
| tags | No | Array of Tag objects | Definition Autoscaling tag list. For detailed parameter descriptions, see the parameter details list. For details, see Table 7. Constraints The number of records cannot exceed 20. Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| period_type | Yes | String | Definition Period type of the resource plan. Currently, only daily configuration is supported. Constraints N/A Range daily: The resource plan is executed on a daily basis. Default Value N/A |
| start_time | Yes | String | Definition Start time of a resource plan. The value is in the format of hour:minute, indicating that the time ranges from 00:00 to 23:59. Constraints N/A Range 00:00–23:59 Default Value N/A |
| end_time | Yes | String | Definition End time of a resource plan. The format is the same as that of start_time. Constraints The value cannot be earlier than the start_time, and the interval between start_time and start_time cannot be less than 30 minutes. Range 00:00–23:59 Default Value N/A |
| min_capacity | Yes | Integer | Definition Minimum number of reserved nodes for this node group in the resource plan, measured in nodes. Constraints N/A Range 0~500 Default Value N/A |
| max_capacity | Yes | Integer | Definition Maximum number of reserved nodes for this node group in the resource plan, measured in nodes. Constraints N/A Range 0~500 Default Value N/A |
| effective_days | No | Array of strings | Definition The effective date of a resource plan. If this parameter is left blank, it indicates that the resource plan takes effect every day. The options are as follows: MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, and SUNDAY Constraints N/A Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Definition Name of an auto scaling rule. Constraints Rule names must be unique within a node group. Range The value can contain 1 to 64 characters, including only letters, digits, underscores (_), and hyphens (-). Default Value N/A |
| description | No | String | Definition Description about an auto scaling rule. Constraints N/A Range 0 to 1,024 characters. Default Value N/A |
| adjustment_type | Yes | String | Definition Adjustment type of an auto scaling rule. Constraints N/A Range
Default Value N/A |
| cool_down_minutes | Yes | Integer | Definition Cluster cooling time after an auto scaling rule is triggered, when no auto scaling operation is performed. The unit is minute. Constraints N/A Range The value ranges from 0 to 10080. 10080 indicates the number of minutes in a week. Default Value N/A |
| scaling_adjustment | Yes | Integer | Definition Number of cluster nodes to adjust in a single operation, measured in nodes. Constraints N/A Range 1-100 Default Value N/A |
| trigger | Yes | Trigger object | Definition The condition for triggering a rule. For details, see Table 6. Constraints N/A Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| metric_name | Yes | String | Definition Metric name. This triggering condition makes a judgment according to the value of the metric. Constraints N/A Range For details about the value range, see Auto scaling metrics. Default Value N/A |
| metric_value | Yes | String | Definition Metric threshold to trigger a rule. The value must be an integer or a number with two decimal places. Constraints N/A Range Only integers or numbers with two decimal places are allowed. Default Value N/A |
| comparison_operator | No | String | Definition Metric judgment logic operator. Constraints N/A Range
Default Value N/A |
| evaluation_periods | Yes | Integer | Definition Number of consecutive five-minute periods, during which a metric threshold is reached Constraints N/A Range 1~288 Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| key | Yes | String | Definition Tag key. Constraints The tag key of a resource must be unique. Range
Default Value N/A |
| value | Yes | String | Definition Tag value. Constraints N/A Range
Default Value N/A |
Response Parameters
Status code: 202
Autoscaling policy updated successfully.
None
Example Request
Update an auto scaling policy, set the number of node groups in node_group_1 to 0 to 5, and configure two scaling rules. If the value of YARNAppRunning is greater than or equal to 75 for one 5-minute period, add one Task node. If the value of YARNAppRunning is less than or equal to 25 for one 5-minute period, stop one Task node. The cooling duration is 20 minutes, and the aaa=bbb label is added to the involved nodes.
/v2/{project_id}/autoscaling-policy/{cluster_id}
{
"node_group_name" : "ttt",
"auto_scaling_policy" : {
"auto_scaling_enable" : true,
"min_capacity" : 0,
"max_capacity" : 5,
"rules" : [ {
"name" : "default-expand-1",
"adjustment_type" : "scale_out",
"cool_down_minutes" : 20,
"scaling_adjustment" : 1,
"trigger" : {
"metric_name" : "YARNAppRunning",
"metric_value" : "75",
"comparison_operator" : "GT",
"evaluation_periods" : 1
}
}, {
"name" : "default-shrink-1",
"adjustment_type" : "scale_in",
"cool_down_minutes" : 20,
"scaling_adjustment" : 1,
"trigger" : {
"metric_name" : "YARNAppRunning",
"metric_value" : "25",
"comparison_operator" : "LT",
"evaluation_periods" : 1
}
} ],
"resources_plans" : [ {
"period_type" : "daily",
"start_time" : "06:00",
"end_time" : "20:00",
"min_capacity" : "0",
"max_capacity" : "2",
"effective_days" : null
} ],
"tags" : [ {
"key" : "aaa",
"value" : "bbb"
} ]
},
"resource_pool_name" : "default"
} Example Response
None
SDK Sample Code
The SDK sample code is as follows.
Update an autoscaling policy. Configure the node group node_group_1 with a node count range of 0–5, and configure two scaling rules. If YARNAppRunning is greater than or equal to 75 for one consecutive five-minute period, add one Task node. If YARNAppRunning is less than or equal to 25 for one consecutive five-minute period, terminate one Task node. The cooldown period for both rules is 20 minutes. Nodes launched under this policy are tagged with aaa=bbb.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.mrs.v2.region.MrsRegion; import com.huaweicloud.sdk.mrs.v2.*; import com.huaweicloud.sdk.mrs.v2.model.*; import java.util.List; import java.util.ArrayList; public class UpdateAutoScalingPolicySolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); MrsClient client = MrsClient.newBuilder() .withCredential(auth) .withRegion(MrsRegion.valueOf("<YOUR REGION>")) .build(); UpdateAutoScalingPolicyRequest request = new UpdateAutoScalingPolicyRequest(); request.withClusterId("{cluster_id}"); AutoScalingPolicyV2 body = new AutoScalingPolicyV2(); List<Tag> listAutoScalingPolicyTags = new ArrayList<>(); listAutoScalingPolicyTags.add( new Tag() .withKey("aaa") .withValue("bbb") ); Trigger triggerRules = new Trigger(); triggerRules.withMetricName("YARNAppRunning") .withMetricValue("25") .withComparisonOperator("LT") .withEvaluationPeriods(1); Trigger triggerRules1 = new Trigger(); triggerRules1.withMetricName("YARNAppRunning") .withMetricValue("75") .withComparisonOperator("GT") .withEvaluationPeriods(1); List<Rule> listAutoScalingPolicyRules = new ArrayList<>(); listAutoScalingPolicyRules.add( new Rule() .withName("default-expand-1") .withAdjustmentType(Rule.AdjustmentTypeEnum.fromValue("scale_out")) .withCoolDownMinutes(20) .withScalingAdjustment(1) .withTrigger(triggerRules1) ); listAutoScalingPolicyRules.add( new Rule() .withName("default-shrink-1") .withAdjustmentType(Rule.AdjustmentTypeEnum.fromValue("scale_in")) .withCoolDownMinutes(20) .withScalingAdjustment(1) .withTrigger(triggerRules) ); List<ResourcesPlan> listAutoScalingPolicyResourcesPlans = new ArrayList<>(); listAutoScalingPolicyResourcesPlans.add( new ResourcesPlan() .withPeriodType("daily") .withStartTime("06:00") .withEndTime("20:00") .withMinCapacity(0) .withMaxCapacity(2) ); AutoScalingPolicyInfo autoScalingPolicybody = new AutoScalingPolicyInfo(); autoScalingPolicybody.withAutoScalingEnable(true) .withMinCapacity(0) .withMaxCapacity(5) .withResourcesPlans(listAutoScalingPolicyResourcesPlans) .withRules(listAutoScalingPolicyRules) .withTags(listAutoScalingPolicyTags); body.withAutoScalingPolicy(autoScalingPolicybody); body.withResourcePoolName("default"); body.withNodeGroupName("ttt"); request.withBody(body); try { UpdateAutoScalingPolicyResponse response = client.updateAutoScalingPolicy(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Update an autoscaling policy. Configure the node group node_group_1 with a node count range of 0–5, and configure two scaling rules. If YARNAppRunning is greater than or equal to 75 for one consecutive five-minute period, add one Task node. If YARNAppRunning is less than or equal to 25 for one consecutive five-minute period, terminate one Task node. The cooldown period for both rules is 20 minutes. Nodes launched under this policy are tagged with aaa=bbb.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkmrs.v2.region.mrs_region import MrsRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkmrs.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = MrsClient.new_builder() \ .with_credentials(credentials) \ .with_region(MrsRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateAutoScalingPolicyRequest() request.cluster_id = "{cluster_id}" listTagsAutoScalingPolicy = [ Tag( key="aaa", value="bbb" ) ] triggerRules = Trigger( metric_name="YARNAppRunning", metric_value="25", comparison_operator="LT", evaluation_periods=1 ) triggerRules1 = Trigger( metric_name="YARNAppRunning", metric_value="75", comparison_operator="GT", evaluation_periods=1 ) listRulesAutoScalingPolicy = [ Rule( name="default-expand-1", adjustment_type="scale_out", cool_down_minutes=20, scaling_adjustment=1, trigger=triggerRules1 ), Rule( name="default-shrink-1", adjustment_type="scale_in", cool_down_minutes=20, scaling_adjustment=1, trigger=triggerRules ) ] listResourcesPlansAutoScalingPolicy = [ ResourcesPlan( period_type="daily", start_time="06:00", end_time="20:00", min_capacity=0, max_capacity=2 ) ] autoScalingPolicybody = AutoScalingPolicyInfo( auto_scaling_enable=True, min_capacity=0, max_capacity=5, resources_plans=listResourcesPlansAutoScalingPolicy, rules=listRulesAutoScalingPolicy, tags=listTagsAutoScalingPolicy ) request.body = AutoScalingPolicyV2( auto_scaling_policy=autoScalingPolicybody, resource_pool_name="default", node_group_name="ttt" ) response = client.update_auto_scaling_policy(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Update an autoscaling policy. Configure the node group node_group_1 with a node count range of 0–5, and configure two scaling rules. If YARNAppRunning is greater than or equal to 75 for one consecutive five-minute period, add one Task node. If YARNAppRunning is less than or equal to 25 for one consecutive five-minute period, terminate one Task node. The cooldown period for both rules is 20 minutes. Nodes launched under this policy are tagged with aaa=bbb.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth, err := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := mrs.MrsClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := mrs.NewMrsClient(hcClient) request := &model.UpdateAutoScalingPolicyRequest{} request.ClusterId = "{cluster_id}" var listTagsAutoScalingPolicy = []model.Tag{ { Key: "aaa", Value: "bbb", }, } comparisonOperatorTrigger:= "LT" triggerRules := &model.Trigger{ MetricName: "YARNAppRunning", MetricValue: "25", ComparisonOperator: &comparisonOperatorTrigger, EvaluationPeriods: int32(1), } comparisonOperatorTrigger1:= "GT" triggerRules1 := &model.Trigger{ MetricName: "YARNAppRunning", MetricValue: "75", ComparisonOperator: &comparisonOperatorTrigger1, EvaluationPeriods: int32(1), } var listRulesAutoScalingPolicy = []model.Rule{ { Name: "default-expand-1", AdjustmentType: model.GetRuleAdjustmentTypeEnum().SCALE_OUT, CoolDownMinutes: int32(20), ScalingAdjustment: int32(1), Trigger: triggerRules1, }, { Name: "default-shrink-1", AdjustmentType: model.GetRuleAdjustmentTypeEnum().SCALE_IN, CoolDownMinutes: int32(20), ScalingAdjustment: int32(1), Trigger: triggerRules, }, } var listResourcesPlansAutoScalingPolicy = []model.ResourcesPlan{ { PeriodType: "daily", StartTime: "06:00", EndTime: "20:00", MinCapacity: int32(0), MaxCapacity: int32(2), }, } autoScalingEnableAutoScalingPolicy:= true minCapacityAutoScalingPolicy:= int32(0) maxCapacityAutoScalingPolicy:= int32(5) autoScalingPolicybody := &model.AutoScalingPolicyInfo{ AutoScalingEnable: &autoScalingEnableAutoScalingPolicy, MinCapacity: &minCapacityAutoScalingPolicy, MaxCapacity: &maxCapacityAutoScalingPolicy, ResourcesPlans: &listResourcesPlansAutoScalingPolicy, Rules: &listRulesAutoScalingPolicy, Tags: &listTagsAutoScalingPolicy, } request.Body = &model.AutoScalingPolicyV2{ AutoScalingPolicy: autoScalingPolicybody, ResourcePoolName: "default", NodeGroupName: "ttt", } response, err := client.UpdateAutoScalingPolicy(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
For details, see Status Codes.
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank 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