更新时间:2024-08-12 GMT+08:00
分享

查看弹性伸缩策略

功能介绍

查看指定集群的所有的弹性伸缩策略信息。

接口约束

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/autoscaling-policy/{cluster_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目编号。获取方法,请参见获取项目ID

约束限制:

不涉及

取值范围:

只能由英文字母和数字组成,且长度为[1-64]个字符。

默认取值:

不涉及

cluster_id

String

参数解释:

集群ID。如果指定集群ID,则获取该集群做过补丁更新的最新版本元数据。获取方法,请参见获取集群ID

约束限制:

不涉及

取值范围:

只能由英文字母、数字以及“_”和“-”组成,且长度为[1-64]个字符。

默认取值:

不涉及

请求参数

响应参数

状态码: 200

表2 响应Body参数

参数

参数类型

描述

[数组元素]

Array of AutoScalingPolicyV2 objects

参数解释:

弹性伸缩策略列表。

表3 AutoScalingPolicyV2

参数

参数类型

描述

node_group_name

String

参数解释:

节点组名称。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

resource_pool_name

String

参数解释:

资源池名称。

约束限制:

当集群版本不支持按指定资源池进行弹性伸缩时,需要填写为default资源池。

取值范围:

只能由英文字母、数字以及“_”和“-”组成。

默认取值:

不涉及

auto_scaling_policy

AutoScalingPolicyInfo object

参数解释:

弹性伸缩规则。

约束限制:

不涉及

表4 AutoScalingPolicyInfo

参数

参数类型

描述

auto_scaling_enable

Boolean

参数解释:

当前自动伸缩规则是否开启。

约束限制:

不涉及

取值范围:

  • true:开启自动伸缩规则

  • false:不开启自动伸缩规则

默认取值:

不涉及

min_capacity

Integer

参数解释:

指定该节点组的最小保留节点数。

约束限制:

不涉及

取值范围:

0-500

默认取值:

不涉及

max_capacity

Integer

参数解释:

指定该节点组的最大节点数。

约束限制:

不涉及

取值范围:

0-500

默认取值:

不涉及

resources_plans

Array of ResourcesPlan objects

参数解释:

资源计划列表。若该参数为空表示不启用资源计划。

约束限制:

当启用弹性伸缩时,资源计划与自动伸缩规则需至少配置其中一种。不能超过5条。

rules

Array of Rule objects

参数解释:

自动伸缩的规则列表。

约束限制:

当启用弹性伸缩时,资源计划与自动伸缩规则需至少配置其中一种。不能超过10条。

tags

Array of Tag objects

参数解释:

弹性伸缩标签列表。

约束限制:

不能超过20条。

表5 ResourcesPlan

参数

参数类型

描述

period_type

String

参数解释:

资源计划的周期类型,当前只允许以下类型:daily。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

start_time

String

参数解释:

资源计划的起始时间,格式为“hour:minute”,表示时间在0:00-23:59之间。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

end_time

String

参数解释:

资源计划的结束时间,格式与“start_time”相同。

约束限制:

不早于start_time表示的时间,且与start_time间隔不小于30min。

取值范围:

不涉及

默认取值:

不涉及

min_capacity

Integer

参数解释:

资源计划内该节点组的最小保留节点数。

约束限制:

不涉及

取值范围:

0-500

默认取值:

不涉及

max_capacity

Integer

参数解释:

资源计划内该节点组的最大保留节点数。

约束限制:

不涉及

取值范围:

0-500

默认取值:

不涉及

effective_days

Array of strings

参数解释:

资源计划的生效日期,为空时代表每日,另外也可为以下返回值:

MONDAY(周一)、TUESDAY(周二)、WEDNESDAY(周三)、THURSDAY(周四)、FRIDAY(周五)、SATURDAY(周六)、SUNDAY(周日)

约束限制:

不涉及

表6 Rule

参数

参数类型

描述

name

String

参数解释:

弹性伸缩规则的名称。

约束限制:

不涉及

取值范围:

只能由英文字母、数字以及“_”和“-”组成,且长度为[1-64]个字符。

在一个节点组范围内,不允许重名。

默认取值:

不涉及

description

String

参数解释:

弹性伸缩规则的说明。

约束限制:

不涉及

取值范围:

长度为[0-1024]个字符。

默认取值:

不涉及

adjustment_type

String

参数解释:

弹性伸缩规则的调整类型。

约束限制:

不涉及

取值范围:

  • scale_out:扩容

  • scale_in:缩容

默认取值:

不涉及

cool_down_minutes

Integer

参数解释:

触发弹性伸缩规则后,该集群处于冷却状态(不再执行弹性伸缩操作)的时长,单位为分钟。

约束限制:

不涉及

取值范围:

0-10080。10080为一周的分钟数。

默认取值:

不涉及

scaling_adjustment

Integer

参数解释:

单次调整集群节点的个数。

约束限制:

不涉及

取值范围:

1-100

默认取值:

不涉及

trigger

Trigger object

参数解释:

描述该规则触发条件。

约束限制:

不涉及

表7 Trigger

参数

参数类型

描述

metric_name

String

参数解释:

指标名称。该触发条件会依据该名称对应指标的值来进行判断。详细指标名称内容请参见"弹性伸缩指标列表"

约束限制:

不涉及

取值范围:

取值范围请参见"弹性伸缩指标列表"

默认取值:

不涉及

metric_value

String

参数解释:

指标阈值。触发该条件的指标阈值,只允许输入整数或者带两位小数的数。

约束限制:

不涉及

取值范围:

只允许输入整数或者带两位小数的数。

默认取值:

不涉及

comparison_operator

String

参数解释:

指标判断逻辑运算符。

约束限制:

不涉及

取值范围:

  • LT:小于

  • GT:大于

  • LTOE:小于等于

  • GTOE:大于等于

默认取值:

不涉及

evaluation_periods

Integer

参数解释:

判断连续满足指标阈值的周期数(一个周期为5分钟)。

约束限制:

不涉及

取值范围:

1-288

默认取值:

不涉及

表8 Tag

参数

参数类型

描述

key

String

参数解释:

标签的键。

约束限制:

不涉及

取值范围:

  • 标签的key值可以包含任意语种字母、数字、空格和_.:=+-@,但首尾不能含有空格,不能以_sys_开头。

  • 同一资源的key值不能重复。

  • 最大长度128个unicode字符,不能为空字符串。

默认取值:

不涉及

value

String

参数解释:

标签的值。

约束限制:

不涉及

取值范围:

  • 标签的value值可以包含任意语种字母、数字、空格和_.:=+-@,但首尾不能含有空格,不能以_sys_开头。

  • 最大长度255个unicode字符,可以为空字符串。

默认取值:

不涉及

状态码: 400

表9 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码。

取值范围:

不涉及

error_msg

String

参数解释:

错误描述。

取值范围:

不涉及

请求示例

响应示例

状态码: 200

查看弹性伸缩策略成功

[ {
  "node_group_name" : "task_node_analysis_group",
  "resource_pool_name" : "default",
  "auto_scaling_policy" : {
    "auto_scaling_enable" : true,
    "min_capacity" : 0,
    "max_capacity" : 1,
    "resources_plans" : [ {
      "period_type" : "daily",
      "effective_days" : [ "SUNDAY" ],
      "start_time" : "12:00",
      "end_time" : "13:00",
      "min_capacity" : 2,
      "max_capacity" : 3
    } ],
    "rules" : [ {
      "name" : "default-expand-1",
      "description" : "",
      "adjustment_type" : "scale_out",
      "cool_down_minutes" : 5,
      "scaling_adjustment" : 1,
      "trigger" : {
        "metric_name" : "YARNAppRunning",
        "metric_value" : "100",
        "comparison_operator" : "GTOE",
        "evaluation_periods" : 1
      }
    } ]
  }
} ]

SDK代码示例

SDK代码示例如下。

 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
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.*;


public class ShowAutoScalingPolicySolution {

    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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        MrsClient client = MrsClient.newBuilder()
                .withCredential(auth)
                .withRegion(MrsRegion.valueOf("<YOUR REGION>"))
                .build();
        ShowAutoScalingPolicyRequest request = new ShowAutoScalingPolicyRequest();
        try {
            ShowAutoScalingPolicyResponse response = client.showAutoScalingPolicy(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());
        }
    }
}
 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
# 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"]

    credentials = BasicCredentials(ak, sk)

    client = MrsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(MrsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ShowAutoScalingPolicyRequest()
        response = client.show_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)
 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
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := mrs.NewMrsClient(
        mrs.MrsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ShowAutoScalingPolicyRequest{}
	response, err := client.ShowAutoScalingPolicy(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查看弹性伸缩策略成功

400

查看弹性伸缩策略失败

错误码

请参见错误码

相关文档