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

创建实例

功能介绍

创建实例。

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/instances/{instance_id}/clickhouse

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

租户在某一Region下的project ID。

获取方法请参见获取项目ID

instance_id

String

GaussDB(for MySQL)实例ID,严格匹配UUID规则。

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

通过调用IAM服务获取用户Token接口获取。

请求响应成功后在响应消息头中包含的“X-Subject-Token”的值即为Token值。

X-Language

String

请求语言类型。默认en-us。 取值范围:

  • en-us

  • zh-cn

表3 请求Body参数

参数

是否必选

参数类型

描述

name

String

ClickHouse实例名称。

  • 4位到64位之间

  • 必须以字母开头,可以包含字母、数字、中划线或下划线

  • 不能包含其他特殊字符

engine

ClickHouseEngineInfo object

引擎信息。

ha

ha object

部署信息。

flavor_id

String

节点规格ID,可通过“HTAP查询规格信息”获取。

db_root_pwd

String

root账户密码。

  • 8~32个字符

  • 包含大写字母、小写字母、数字或特殊字符(~ ! @ # / %^ * - _ = + ? ,)中的三种

az_mode

String

可用区类型。 取值范围:

  • single:单可用区

  • double:多可用区

volume

volume object

存储规格。

az_code

String

可用区码。

当ha中mode为Ha时,需要填写多个可用区,用"," 分隔。例如:cn-southwest-244b,cn-southwest-244a

time_zone

String

时区。默认为所属GaussDB(for MySQL)实例时区。

tags_info

tags_info object

标签值。

pay_info

pay_info object

支付信息。

表4 ClickHouseEngineInfo

参数

是否必选

参数类型

描述

type

String

数据库引擎类型,现在只支持click-house。

version

String

数据库版本,可通过“HTAP查询引擎信息”获取。 一位数的大版本号。

表5 ha

参数

是否必选

参数类型

描述

mode

String

部署模式。 取值范围:

  • Single:单机

  • Ha:主备

表6 volume

参数

是否必选

参数类型

描述

io_type

String

磁盘IO类型。 取值范围:

  • SSD:超高IO

  • ESSD:极速型SSD

capacity_in_gb

Integer

磁盘容量。取值范围:50GB~32000GB。

表7 tags_info

参数

是否必选

参数类型

描述

sys_tags

Array of sys_tags objects

系统标签。

表8 sys_tags

参数

是否必选

参数类型

描述

key

String

标签键。

value

String

标签值。

表9 pay_info

参数

是否必选

参数类型

描述

pay_model

String

计费模式,默认0。 取值范围:

  • 0:按需计费

  • 1:包周期

order_id

String

包周期计费ID。

period

Integer

包周期周期。

period_type

Integer

包周期周期类型。 取值范围:

  • 2:包月

  • 3:包年

is_auto_renew

Integer

包周期是否自动续费。 取值范围:

  • 1:自动续费

  • 0:不自动续费

响应参数

状态码: 202

表10 响应Body参数

参数

参数类型

描述

instance

CreateChInstanceInfo object

实例信息。

job_id

String

工作ID。

表11 CreateChInstanceInfo

参数

参数类型

描述

id

String

实例ID。

az_code

String

可用区。

az_mode

String

可用区模式。 取值范围:

  • single:单可用区

  • double:多可用区

name

String

实例名。

engine

ClickHouseEngineInfo object

引擎信息。

vpc_id

String

虚拟私有云ID。

security_group_id

String

安全组ID。

subnet_id

String

子网ID。

db_user

String

数据库用户。

port

Integer

数据库端口。取值范围:0~65535。

ha_mode

String

部署模式。 取值范围:

  • Single:单机

  • Ha:主备

pay_info

pay_info object

计费信息。

ssl_option

Boolean

SSL开关。

status

String

实例状态。 取值范围:

  • creating:创建

  • normal:正常

  • abnormal:异常

  • createfailed:创建失败

  • deleted:已删除

region

String

实例所在区。

tags_info

tags_info object

实例标签。

表12 ClickHouseEngineInfo

参数

参数类型

描述

type

String

数据库引擎类型,现在只支持click-house。

version

String

数据库版本,可通过“HTAP查询引擎信息”获取。 一位数的大版本号。

表13 pay_info

参数

参数类型

描述

pay_model

String

计费模式。默认0。 取值范围:

  • 0:按需计费

  • 1:包周期

order_id

String

包周期计费ID。

period

String

包周期周期。

period_type

String

包周期周期类型。 取值范围:

  • 2:包月

  • 3:包年

is_auto_renew

String

包周期是否自动续费。 取值范围:

  • 1:自动续费

  • 0:不自动续费

表14 tags_info

参数

参数类型

描述

tags

Array of tags objects

用户标签。

sys_tags

Array of sys_tags objects

系统标签。

表15 tags

参数

参数类型

描述

key

String

标签键。

value

String

标签值。

表16 sys_tags

参数

参数类型

描述

key

String

标签键。

value

String

标签值。

状态码: 400

表17 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误描述。

状态码: 500

表18 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误描述。

请求示例

创建ClickHouse实例

POST https://{endpoint}/v3/23a50154cf494ec9ad6883979a12db0a/instances/40dc4c5729f14aad893e2dcd5baf6a15in07/clickhouse

{
  "name" : "htap-cfd5",
  "engine" : {
    "type" : "click-house",
    "version" : "1"
  },
  "ha" : {
    "mode" : "Single"
  },
  "flavor_id" : "b44cfde6-d250-313c-8d7a-cd216f071658",
  "db_root_pwd" : "Rds_1234",
  "az_mode" : "single",
  "volume" : {
    "io_type" : "ESSD",
    "capacity_in_gb" : 40
  },
  "az_code" : "cn-southwest-244a",
  "time_zone" : "UTC+08:00",
  "tags_info" : {
    "sys_tags" : [ {
      "key" : "_sys_enterprise_project_id",
      "value" : "0"
    } ]
  }
}

响应示例

状态码: 202

Success.

{
    "instance": {
        "id": "2cdec02d8c4a4c88aecae08684dd8076in16",
        "az_code": "cn-southwest-244a",
        "az_mode": "double",
        "name": "htap-cfd5",
        "engine": {
            "type": "click-house",
            "version": "1"
        },
        "vpc_id": "467f1291-994f-4d3a-9db6-d4c563218df5",
        "security_group_id": "3dc780b1-9d92-4850-9b98-be248e1b5962",
        "subnet_id": "d99cd68c-0067-436d-869e-d32e902d0074",
        "db_user": "root",
        "port": null,
        "ha_mode": "Single"
        "pay_info": {
            "pay_model": "0",
            "order_id": null,
            "period": null,
            "period_type": null,
            "is_auto_renew": null,
        },
        "ssl_option": false,      
        "status": "creating",
        "region": "cn-southwest-244",
        "tags_info": {
            "tags": [],
            "sys_tags": [
                {
                    "key": "_sys_enterprise_project_id",
                    "value": "0"
                }
            ]
        }
    },
    "job_id": "76078f0b-5162-45c8-b95f-4c1afd37536c",
}

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
75
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.gaussdb.v3.region.GaussDBRegion;
import com.huaweicloud.sdk.gaussdb.v3.*;
import com.huaweicloud.sdk.gaussdb.v3.model.*;

import java.util.List;
import java.util.ArrayList;

public class CreateClickHouseInstanceSolution {

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

        GaussDBClient client = GaussDBClient.newBuilder()
                .withCredential(auth)
                .withRegion(GaussDBRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateClickHouseInstanceRequest request = new CreateClickHouseInstanceRequest();
        CreateChInstanceRequestBody body = new CreateChInstanceRequestBody();
        List<CreateChInstanceRequestBodyTagsInfoSysTags> listTagsInfoSysTags = new ArrayList<>();
        listTagsInfoSysTags.add(
            new CreateChInstanceRequestBodyTagsInfoSysTags()
                .withKey("_sys_enterprise_project_id")
                .withValue("0")
        );
        CreateChInstanceRequestBodyTagsInfo tagsInfobody = new CreateChInstanceRequestBodyTagsInfo();
        tagsInfobody.withSysTags(listTagsInfoSysTags);
        CreateChInstanceRequestBodyVolume volumebody = new CreateChInstanceRequestBodyVolume();
        volumebody.withIoType("ESSD")
            .withCapacityInGb(40);
        CreateChInstanceRequestBodyHa habody = new CreateChInstanceRequestBodyHa();
        habody.withMode("Single");
        ClickHouseEngineInfo enginebody = new ClickHouseEngineInfo();
        enginebody.withType("click-house")
            .withVersion("1");
        body.withTagsInfo(tagsInfobody);
        body.withTimeZone("UTC+08:00");
        body.withAzCode("cn-southwest-244a");
        body.withVolume(volumebody);
        body.withAzMode("single");
        body.withDbRootPwd("Rds_1234");
        body.withFlavorId("b44cfde6-d250-313c-8d7a-cd216f071658");
        body.withHa(habody);
        body.withEngine(enginebody);
        body.withName("htap-cfd5");
        request.withBody(body);
        try {
            CreateClickHouseInstanceResponse response = client.createClickHouseInstance(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
59
60
61
62
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkgaussdb.v3.region.gaussdb_region import GaussDBRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkgaussdb.v3 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 = GaussDBClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(GaussDBRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateClickHouseInstanceRequest()
        listSysTagsTagsInfo = [
            CreateChInstanceRequestBodyTagsInfoSysTags(
                key="_sys_enterprise_project_id",
                value="0"
            )
        ]
        tagsInfobody = CreateChInstanceRequestBodyTagsInfo(
            sys_tags=listSysTagsTagsInfo
        )
        volumebody = CreateChInstanceRequestBodyVolume(
            io_type="ESSD",
            capacity_in_gb=40
        )
        habody = CreateChInstanceRequestBodyHa(
            mode="Single"
        )
        enginebody = ClickHouseEngineInfo(
            type="click-house",
            version="1"
        )
        request.body = CreateChInstanceRequestBody(
            tags_info=tagsInfobody,
            time_zone="UTC+08:00",
            az_code="cn-southwest-244a",
            volume=volumebody,
            az_mode="single",
            db_root_pwd="Rds_1234",
            flavor_id="b44cfde6-d250-313c-8d7a-cd216f071658",
            ha=habody,
            engine=enginebody,
            name="htap-cfd5"
        )
        response = client.create_click_house_instance(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
66
67
68
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    gaussdb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/gaussdb/v3/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 := gaussdb.NewGaussDBClient(
        gaussdb.GaussDBClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateClickHouseInstanceRequest{}
	var listSysTagsTagsInfo = []model.CreateChInstanceRequestBodyTagsInfoSysTags{
        {
            Key: "_sys_enterprise_project_id",
            Value: "0",
        },
    }
	tagsInfobody := &model.CreateChInstanceRequestBodyTagsInfo{
		SysTags: listSysTagsTagsInfo,
	}
	volumebody := &model.CreateChInstanceRequestBodyVolume{
		IoType: "ESSD",
		CapacityInGb: int32(40),
	}
	habody := &model.CreateChInstanceRequestBodyHa{
		Mode: "Single",
	}
	enginebody := &model.ClickHouseEngineInfo{
		Type: "click-house",
		Version: "1",
	}
	timeZoneCreateChInstanceRequestBody:= "UTC+08:00"
	request.Body = &model.CreateChInstanceRequestBody{
		TagsInfo: tagsInfobody,
		TimeZone: &timeZoneCreateChInstanceRequestBody,
		AzCode: "cn-southwest-244a",
		Volume: volumebody,
		AzMode: "single",
		DbRootPwd: "Rds_1234",
		FlavorId: "b44cfde6-d250-313c-8d7a-cd216f071658",
		Ha: habody,
		Engine: enginebody,
		Name: "htap-cfd5",
	}
	response, err := client.CreateClickHouseInstance(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

202

Success.

400

Client error.

500

Server error.

错误码

请参见错误码

相关文档