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

调整集群节点

功能介绍

创建集群后,扩容/缩容集群Core节点或者Task节点。MRS集群创建成功后不支持调整Master节点数量,即不支持扩缩容Master节点。该接口不兼容Sahara。处于running状态的集群才允许扩容/缩容,其他状态则不允许扩容/缩容。 集群状态和集群ID可参考查询集群列表接口获取。 本章节的接口只支持流式集群、分析集群和混合集群,不支持自定义集群。

接口约束

调用方法

请参见如何调用API

URI

PUT /v1.1/{project_id}/cluster_infos/{cluster_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

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

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

cluster_id

String

参数解释:

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

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

service_id

String

参数解释:

服务ID,为扩展接口,预留此参数。用户不需要配置。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

plan_id

String

参数解释:

套餐ID,为扩展接口,预留此参数。用户不需要配置。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

parameters

ClusterScalingParams object

参数解释:

请求参数集合。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

previous_values

Map<String,String>

参数解释:

扩展接口,预留此参数。用户不需要配置。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

表3 ClusterScalingParams

参数

是否必选

参数类型

描述

order_id

String

参数解释:

扩容/缩容时系统获取的订单号,用户不需要配置。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

scale_type

String

参数解释:

范围操作类型。

约束限制:

不涉及

取值范围:

  • scale_in:缩容

  • scale_out:扩容

默认取值:

不涉及

node_id

String

参数解释:

扩容/缩容时新增或者减少节点的ID标识,参数值固定为node_orderadd。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

node_group

String

参数解释:

扩容或缩容的节点组。

约束限制:

不涉及

取值范围:

  • core_node_default_group:表示Core节点组。

  • task_node_default_group:表示Task节点组。

默认取值:

core_node_default_group

skip_bootstrap_scripts

String

参数解释:

是否跳过引导操作。仅在创建集群时配置了引导操作且扩容时有意义,表示扩容时是否在新增节点上执行创建集群时指定的引导操作。

约束限制:

不涉及

取值范围:

  • true:跳过引导操作。

  • false:执行引导操作。

默认取值:

false

scale_without_start

Boolean

参数解释:

扩容后是否启动扩容节点上的组件。

约束限制:

不涉及

取值范围:

  • true:扩容后不启动组件。

  • false:扩容后启动组件。

默认取值:

不涉及

server_ids

Array of strings

参数解释:

缩容Task节点时指定待删除Task节点的ID列表。

约束限制:

  • 当scale_type为扩容时,该参数不生效。

  • 当scale_type为缩容且该参数不为空时,删除指定的Task节点。

  • 当scale_type为缩容且server_ids为空时,按照系统规则自动选择删除Task节点。

取值范围:

不涉及

默认取值:

不涉及

instances

Integer

参数解释:

扩容或缩容的节点数。

约束限制:

  • 扩容时的最大节点数为(500 - 集群Core/Task节点数)。例如,当前集群Core节点数为3,此处扩容的节点数必须小于等于497。

  • Core和Task节点总数最大值为500,如果用户需要的Core/Task节点数大于500,可以联系技术支持人员或者调用后台接口修改数据库。

-缩容时Core节点数大于3或者Task节点数大于0可以进行节点删除。例如,当前集群Core节点和Task节点数均为5,Core节点可缩容的节点数为2(5减去3),Task节点可缩容节点数为小于等于5。

取值范围:

≥1

默认取值:

不涉及

task_node_info

TaskNodeInfo object

参数解释:

Task节点规格。

约束限制:

  • 当Task节点个数为0时,使用该字段指定Task节点的规格。

  • 当Task节点个数大于0时,不能使用该字段。该字段为空时,不填即可,字段内含必填参数不可使用会传空值对象的置空按钮。

取值范围:

不涉及

默认取值:

不涉及

表4 TaskNodeInfo

参数

是否必选

参数类型

描述

node_size

String

参数解释:

Task节点的实例规格,例如:{ECS_FLAVOR_NAME}.linux.bigdata,{ECS_FLAVOR_NAME}可以为c3.4xlare.2等在MRS购买页可见的云服务器规格。实例规格详细说明请参见MRS所使用的弹性云服务器规格MRS所使用的裸金属服务器规格。该参数建议从MRS控制台的集群创建页面获取对应区域对应版本所支持的规格。

约束限制:

不涉及

取值范围:

不涉及

默认取值:

不涉及

data_volume_type

String

参数解释:

Task节点数据磁盘存储类别,目前支持SATA、SAS和SSD等。

约束限制:

不涉及

取值范围:

  • SATA:普通IO

  • SAS:高IO

  • SSD:超高IO

  • GPSSD:通用型SSD

默认取值:

不涉及

data_volume_count

Integer

参数解释:

Task节点数据磁盘存储数目。

约束限制:

不涉及

取值范围:

0-20

默认取值:

不涉及

data_volume_size

Integer

参数解释:

Task节点数据磁盘存储大小。传值只需填数字,不需要带单位GB。

约束限制:

不涉及

取值范围:

100-32000

默认取值:

不涉及

响应参数

状态码: 200

表5 响应Body参数

参数

参数类型

描述

result

String

参数解释:

操作结果。

约束限制:

  • succeeded:操作成功。

  • 操作失败时返回的错误码信息如错误码所示。

取值范围:

不涉及

默认取值:

不涉及

请求示例

  • 在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" : { }
    }

响应示例

状态码: 200

扩容/缩容集群Core节点或者Task节点成功。

{
  "result" : "succeeded"
}

SDK代码示例

SDK代码示例如下。

  • 在MRS集群中扩容1个core节点。

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_out"))
                .withNodeId("node_orderadd")
                .withNodeGroup("core_node_default_group")
                .withSkipBootstrapScripts("false")
                .withScaleWithoutStart(false)
                .withInstances(1);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 当Task节点个数大于零时,在MRS集群中扩容1个Task节点。

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_out"))
                .withNodeId("node_orderadd")
                .withNodeGroup("task_node_default_group")
                .withSkipBootstrapScripts("false")
                .withScaleWithoutStart(false)
                .withInstances(1);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 当Task节点个数等于零时,在MRS集群中扩容1个规格为s3.xlarge.2.linux.bigdata 的Task节点。

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            TaskNodeInfo taskNodeInfoParameters = new TaskNodeInfo();
            taskNodeInfoParameters.withNodeSize("s3.xlarge.2.linux.bigdata")
                .withDataVolumeType(TaskNodeInfo.DataVolumeTypeEnum.fromValue("SATA"))
                .withDataVolumeCount(2)
                .withDataVolumeSize(600);
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_out"))
                .withNodeId("node_orderadd")
                .withNodeGroup("task_node_default_group")
                .withScaleWithoutStart(false)
                .withInstances(1)
                .withTaskNodeInfo(taskNodeInfoParameters);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 在MRS集群中缩容1个Core节点。

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_in"))
                .withNodeId("node_orderadd")
                .withNodeGroup("core_node_default_group")
                .withInstances(1);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 在MRS集群中缩容1个Task节点

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_in"))
                .withNodeId("node_orderadd")
                .withNodeGroup("task_node_default_group")
                .withInstances(1);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 在MRS集群中缩容指定的Task节点。

     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
    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.v1.region.MrsRegion;
    import com.huaweicloud.sdk.mrs.v1.*;
    import com.huaweicloud.sdk.mrs.v1.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.util.HashMap;
    
    public class UpdateClusterScalingSolution {
    
        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();
            UpdateClusterScalingRequest request = new UpdateClusterScalingRequest();
            request.withClusterId("{cluster_id}");
            ClusterScalingReq body = new ClusterScalingReq();
            List<String> listParametersServerIds = new ArrayList<>();
            listParametersServerIds.add("c9573435-7814-4b2c-9131-ad78b814414c");
            listParametersServerIds.add("a4951009-6a0f-4e7b-9c81-9d4bd1f8c537");
            ClusterScalingParams parametersbody = new ClusterScalingParams();
            parametersbody.withOrderId("")
                .withScaleType(ClusterScalingParams.ScaleTypeEnum.fromValue("scale_in"))
                .withNodeId("node_orderadd")
                .withNodeGroup("task_node_default_group")
                .withServerIds(listParametersServerIds)
                .withInstances(2);
            body.withParameters(parametersbody);
            body.withPlanId("");
            body.withServiceId("");
            request.withBody(body);
            try {
                UpdateClusterScalingResponse response = client.updateClusterScaling(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());
            }
        }
    }
    
  • 在MRS集群中扩容1个core节点。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_out",
                node_id="node_orderadd",
                node_group="core_node_default_group",
                skip_bootstrap_scripts="false",
                scale_without_start=False,
                instances=1
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 当Task节点个数大于零时,在MRS集群中扩容1个Task节点。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_out",
                node_id="node_orderadd",
                node_group="task_node_default_group",
                skip_bootstrap_scripts="false",
                scale_without_start=False,
                instances=1
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 当Task节点个数等于零时,在MRS集群中扩容1个规格为s3.xlarge.2.linux.bigdata 的Task节点。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            taskNodeInfoParameters = TaskNodeInfo(
                node_size="s3.xlarge.2.linux.bigdata",
                data_volume_type="SATA",
                data_volume_count=2,
                data_volume_size=600
            )
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_out",
                node_id="node_orderadd",
                node_group="task_node_default_group",
                scale_without_start=False,
                instances=1,
                task_node_info=taskNodeInfoParameters
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 在MRS集群中缩容1个Core节点。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_in",
                node_id="node_orderadd",
                node_group="core_node_default_group",
                instances=1
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 在MRS集群中缩容1个Task节点

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_in",
                node_id="node_orderadd",
                node_group="task_node_default_group",
                instances=1
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 在MRS集群中缩容指定的Task节点。

     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
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkmrs.v1.region.mrs_region import MrsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkmrs.v1 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 = UpdateClusterScalingRequest()
            request.cluster_id = "{cluster_id}"
            listServerIdsParameters = [
                "c9573435-7814-4b2c-9131-ad78b814414c",
                "a4951009-6a0f-4e7b-9c81-9d4bd1f8c537"
            ]
            parametersbody = ClusterScalingParams(
                order_id="",
                scale_type="scale_in",
                node_id="node_orderadd",
                node_group="task_node_default_group",
                server_ids=listServerIdsParameters,
                instances=2
            )
            request.body = ClusterScalingReq(
                parameters=parametersbody,
                plan_id="",
                service_id=""
            )
            response = client.update_cluster_scaling(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 在MRS集群中扩容1个core节点。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	orderIdParameters:= ""
    	nodeGroupParameters:= "core_node_default_group"
    	skipBootstrapScriptsParameters:= "false"
    	scaleWithoutStartParameters:= false
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_OUT,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		SkipBootstrapScripts: &skipBootstrapScriptsParameters,
    		ScaleWithoutStart: &scaleWithoutStartParameters,
    		Instances: int32(1),
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 当Task节点个数大于零时,在MRS集群中扩容1个Task节点。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	orderIdParameters:= ""
    	nodeGroupParameters:= "task_node_default_group"
    	skipBootstrapScriptsParameters:= "false"
    	scaleWithoutStartParameters:= false
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_OUT,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		SkipBootstrapScripts: &skipBootstrapScriptsParameters,
    		ScaleWithoutStart: &scaleWithoutStartParameters,
    		Instances: int32(1),
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 当Task节点个数等于零时,在MRS集群中扩容1个规格为s3.xlarge.2.linux.bigdata 的Task节点。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	taskNodeInfoParameters := &model.TaskNodeInfo{
    		NodeSize: "s3.xlarge.2.linux.bigdata",
    		DataVolumeType: model.GetTaskNodeInfoDataVolumeTypeEnum().SATA,
    		DataVolumeCount: int32(2),
    		DataVolumeSize: int32(600),
    	}
    	orderIdParameters:= ""
    	nodeGroupParameters:= "task_node_default_group"
    	scaleWithoutStartParameters:= false
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_OUT,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		ScaleWithoutStart: &scaleWithoutStartParameters,
    		Instances: int32(1),
    		TaskNodeInfo: taskNodeInfoParameters,
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 在MRS集群中缩容1个Core节点。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	orderIdParameters:= ""
    	nodeGroupParameters:= "core_node_default_group"
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_IN,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		Instances: int32(1),
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 在MRS集群中缩容1个Task节点

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	orderIdParameters:= ""
    	nodeGroupParameters:= "task_node_default_group"
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_IN,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		Instances: int32(1),
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 在MRS集群中缩容指定的Task节点。

     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
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        mrs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/mrs/v1/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 := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := mrs.NewMrsClient(
            mrs.MrsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.UpdateClusterScalingRequest{}
    	request.ClusterId = "{cluster_id}"
    	var listServerIdsParameters = []string{
            "c9573435-7814-4b2c-9131-ad78b814414c",
    	    "a4951009-6a0f-4e7b-9c81-9d4bd1f8c537",
        }
    	orderIdParameters:= ""
    	nodeGroupParameters:= "task_node_default_group"
    	parametersbody := &model.ClusterScalingParams{
    		OrderId: &orderIdParameters,
    		ScaleType: model.GetClusterScalingParamsScaleTypeEnum().SCALE_IN,
    		NodeId: "node_orderadd",
    		NodeGroup: &nodeGroupParameters,
    		ServerIds: &listServerIdsParameters,
    		Instances: int32(2),
    	}
    	planIdClusterScalingReq:= ""
    	serviceIdClusterScalingReq:= ""
    	request.Body = &model.ClusterScalingReq{
    		Parameters: parametersbody,
    		PlanId: &planIdClusterScalingReq,
    		ServiceId: &serviceIdClusterScalingReq,
    	}
    	response, err := client.UpdateClusterScaling(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

扩容/缩容集群Core节点或者Task节点成功。

错误码

请参见错误码

相关文档