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

集群添加组件

功能介绍

集群添加组件, 仅MRS 3.0.1以后的版本的自定义集群支持添加组件功能

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/clusters/{cluster_id}/components

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

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

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

cluster_id

String

参数解释:

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

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

components_install_mode

Array of ComponentInstallMode objects

参数解释:

组件模型详情。

约束限制:

不涉及

表3 ComponentInstallMode

参数

是否必选

参数类型

描述

component

String

参数解释:

组件名称。

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

node_groups

Array of AssignedNodeGroup objects

参数解释:

该组件的角色部署信息。

约束限制:

不涉及

component_user_password

String

参数解释:

配置组件用户密码,该密码用于ClickHouse组件机机用户连接使用。

约束限制:

不涉及

取值范围:

  • 密码长度应在8-26个字符之间

  • 不能与用户名或者倒序用户名相同

  • 必须包含如下4种字符的组合

  • 至少一个小写字母

  • 至少一个大写字母

  • 至少一个数字

  • 至少一个特殊字符:!@$%^-_=+[{}]:,./?

默认取值:

不涉及

component_default_password

String

参数解释:

配置组件default用户密码,该密码用于ClickHouse组件人机用户连接使用。

约束限制:

不涉及

取值范围:

  • 密码长度应在8-26个字符之间

  • 不能与用户名或者倒序用户名相同

  • 必须包含如下4种字符的组合

  • 至少一个小写字母

  • 至少一个大写字母

  • 至少一个数字

  • 至少一个特殊字符:!@$%^-_=+[{}]:,./?

默认取值:

不涉及

表4 AssignedNodeGroup

参数

是否必选

参数类型

描述

name

String

参数解释:

节点组名称。

约束限制:

不涉及

取值范围:

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

默认取值:

不涉及

assigned_roles

Array of strings

参数解释:

角色部署信息。可以指定节点组中部署的角色,该参数是一个字符串数组,每个字符串表示一个角色表达式。

角色表达式定义:

  • 当该角色在节点组所有节点部署时: {role name},如“DataNode”。

  • 当该角色在节点组指定下标节点部署时:{role name}:{index1},{index2}…,{indexN},如“NameNode:1,2”,下标从1开始计数。

可选的角色请参考MRS支持的角色与组件对应表

约束限制:

不能超过1000条。

响应参数

状态码: 200

表5 响应Body参数

参数

参数类型

描述

result

String

参数解释:

更新映射请求操作结果。

取值范围:

  • succeeded:操作成功

  • failed:操作失败

请求示例

  • 非安全集群添加请求添加ClickHouse组件

    v2/f77c10d14a544393a24e5f0bf53202b6/clusters/ff879d3a-e5d5-4485-a9b6-c673b52673fa/components
    
    {
      "components_install_mode" : [ {
        "component" : "ClickHouse",
        "node_groups" : [ {
          "name" : "master_node_default_group",
          "assigned_roles" : [ "ClickHouseServer:1,2" ]
        }, {
          "name" : "node_group_1",
          "assigned_roles" : [ "ClickHouseServer", "ClickHouseBalancer" ]
        } ],
        "component_user_password" : "*****",
        "component_default_password" : "*****"
      } ]
    }
  • 添加Hbase组件

    v2/f77c10d14a544393a24e5f0bf53202b6/clusters/ff879d3a-e5d5-4485-a9b6-c673b52673fa/components
    
    {
      "components_install_mode" : [ {
        "component" : "HBase",
        "node_groups" : [ {
          "name" : "master_node_default_group",
          "assigned_roles" : [ "RegionServer", "HMaster" ]
        } ]
      } ]
    }

响应示例

状态码: 200

请求处理结果

{
  "result" : "succeeded"
}

SDK代码示例

SDK代码示例如下。

  • 非安全集群添加请求添加ClickHouse组件

     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
    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 AddComponentSolution {
    
        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();
            AddComponentRequest request = new AddComponentRequest();
            AddComponentsReq body = new AddComponentsReq();
            List<String> listNodeGroupsAssignedRoles = new ArrayList<>();
            listNodeGroupsAssignedRoles.add("ClickHouseServer");
            listNodeGroupsAssignedRoles.add("ClickHouseBalancer");
            List<String> listNodeGroupsAssignedRoles1 = new ArrayList<>();
            listNodeGroupsAssignedRoles1.add("ClickHouseServer:1,2");
            List<AssignedNodeGroup> listComponentsInstallModeNodeGroups = new ArrayList<>();
            listComponentsInstallModeNodeGroups.add(
                new AssignedNodeGroup()
                    .withName("master_node_default_group")
                    .withAssignedRoles(listNodeGroupsAssignedRoles1)
            );
            listComponentsInstallModeNodeGroups.add(
                new AssignedNodeGroup()
                    .withName("node_group_1")
                    .withAssignedRoles(listNodeGroupsAssignedRoles)
            );
            List<ComponentInstallMode> listbodyComponentsInstallMode = new ArrayList<>();
            listbodyComponentsInstallMode.add(
                new ComponentInstallMode()
                    .withComponent("ClickHouse")
                    .withNodeGroups(listComponentsInstallModeNodeGroups)
                    .withComponentUserPassword("*****")
                    .withComponentDefaultPassword("*****")
            );
            body.withComponentsInstallMode(listbodyComponentsInstallMode);
            request.withBody(body);
            try {
                AddComponentResponse response = client.addComponent(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());
            }
        }
    }
    
  • 添加Hbase组件

     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
    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 AddComponentSolution {
    
        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();
            AddComponentRequest request = new AddComponentRequest();
            AddComponentsReq body = new AddComponentsReq();
            List<String> listNodeGroupsAssignedRoles = new ArrayList<>();
            listNodeGroupsAssignedRoles.add("RegionServer");
            listNodeGroupsAssignedRoles.add("HMaster");
            List<AssignedNodeGroup> listComponentsInstallModeNodeGroups = new ArrayList<>();
            listComponentsInstallModeNodeGroups.add(
                new AssignedNodeGroup()
                    .withName("master_node_default_group")
                    .withAssignedRoles(listNodeGroupsAssignedRoles)
            );
            List<ComponentInstallMode> listbodyComponentsInstallMode = new ArrayList<>();
            listbodyComponentsInstallMode.add(
                new ComponentInstallMode()
                    .withComponent("HBase")
                    .withNodeGroups(listComponentsInstallModeNodeGroups)
            );
            body.withComponentsInstallMode(listbodyComponentsInstallMode);
            request.withBody(body);
            try {
                AddComponentResponse response = client.addComponent(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());
            }
        }
    }
    
  • 非安全集群添加请求添加ClickHouse组件

     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
    # 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 = AddComponentRequest()
            listAssignedRolesNodeGroups = [
                "ClickHouseServer",
                "ClickHouseBalancer"
            ]
            listAssignedRolesNodeGroups1 = [
                "ClickHouseServer:1,2"
            ]
            listNodeGroupsComponentsInstallMode = [
                AssignedNodeGroup(
                    name="master_node_default_group",
                    assigned_roles=listAssignedRolesNodeGroups1
                ),
                AssignedNodeGroup(
                    name="node_group_1",
                    assigned_roles=listAssignedRolesNodeGroups
                )
            ]
            listComponentsInstallModebody = [
                ComponentInstallMode(
                    component="ClickHouse",
                    node_groups=listNodeGroupsComponentsInstallMode,
                    component_user_password="*****",
                    component_default_password="*****"
                )
            ]
            request.body = AddComponentsReq(
                components_install_mode=listComponentsInstallModebody
            )
            response = client.add_component(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 添加Hbase组件

     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.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 = AddComponentRequest()
            listAssignedRolesNodeGroups = [
                "RegionServer",
                "HMaster"
            ]
            listNodeGroupsComponentsInstallMode = [
                AssignedNodeGroup(
                    name="master_node_default_group",
                    assigned_roles=listAssignedRolesNodeGroups
                )
            ]
            listComponentsInstallModebody = [
                ComponentInstallMode(
                    component="HBase",
                    node_groups=listNodeGroupsComponentsInstallMode
                )
            ]
            request.body = AddComponentsReq(
                components_install_mode=listComponentsInstallModebody
            )
            response = client.add_component(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 非安全集群添加请求添加ClickHouse组件

     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
    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.AddComponentRequest{}
    	var listAssignedRolesNodeGroups = []string{
            "ClickHouseServer",
    	    "ClickHouseBalancer",
        }
    	var listAssignedRolesNodeGroups1 = []string{
            "ClickHouseServer:1,2",
        }
    	var listNodeGroupsComponentsInstallMode = []model.AssignedNodeGroup{
            {
                Name: "master_node_default_group",
                AssignedRoles: listAssignedRolesNodeGroups1,
            },
            {
                Name: "node_group_1",
                AssignedRoles: listAssignedRolesNodeGroups,
            },
        }
    	componentUserPasswordComponentsInstallMode:= "*****"
    	componentDefaultPasswordComponentsInstallMode:= "*****"
    	var listComponentsInstallModebody = []model.ComponentInstallMode{
            {
                Component: "ClickHouse",
                NodeGroups: listNodeGroupsComponentsInstallMode,
                ComponentUserPassword: &componentUserPasswordComponentsInstallMode,
                ComponentDefaultPassword: &componentDefaultPasswordComponentsInstallMode,
            },
        }
    	request.Body = &model.AddComponentsReq{
    		ComponentsInstallMode: listComponentsInstallModebody,
    	}
    	response, err := client.AddComponent(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 添加Hbase组件

     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/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.AddComponentRequest{}
    	var listAssignedRolesNodeGroups = []string{
            "RegionServer",
    	    "HMaster",
        }
    	var listNodeGroupsComponentsInstallMode = []model.AssignedNodeGroup{
            {
                Name: "master_node_default_group",
                AssignedRoles: listAssignedRolesNodeGroups,
            },
        }
    	var listComponentsInstallModebody = []model.ComponentInstallMode{
            {
                Component: "HBase",
                NodeGroups: listNodeGroupsComponentsInstallMode,
            },
        }
    	request.Body = &model.AddComponentsReq{
    		ComponentsInstallMode: listComponentsInstallModebody,
    	}
    	response, err := client.AddComponent(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

请求处理结果

错误码

请参见错误码

分享:

    相关文档

    相关产品