Updated on 2024-04-18 GMT+08:00

Creating a Cluster (V2)

Function

This API is used to create a cluster. The cluster must run in a VPC. Before creating a cluster, you need to create a VPC and obtain the VPC and subnet IDs.

This API is an asynchronous API. It takes 10 to 15 minutes to create a cluster.

Call Method

For details, see Calling APIs.

URI

1
POST /v2/{project_id}/clusters
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the ID, see Obtaining Project ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

cluster

No

V2CreateCluster object

Request for creating a cluster

Table 3 V2CreateCluster

Parameter

Mandatory

Type

Description

name

Yes

String

Cluster name, which must be unique. The cluster name must contain 4 to 64 characters, which must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed.

flavor

Yes

String

Cluster flavor name For details about node flavors, see Data Warehouse Flavors.

num_cn

Yes

Integer

Number of CNs in the cluster. The value ranges from 2 to the number of cluster nodes. The maximum value is 20 and the default value is 3.

num_node

Yes

Integer

Number of cluster nodes. For a cluster, the value ranges from 3 to 256. For a hybrid data warehouse (standalone), the value is 1.

db_name

Yes

String

Username of the administrator. The username must meet the following requirements:

  • Consists of only lowercase letters, digits, or underscores.

  • Starts with a lowercase letter or an underscore.

  • Contains 6 to 64 characters.

  • Cannot be a keyword of the GaussDB(DWS) database.

db_password

Yes

String

Password of the administrator, which must meet the following requirements:

  • Contains 12 to 32 characters.
  • Contains at least three types of the following characters: uppercase letters, lowercase letters, digits, and special characters (~!?, .:;-_(){}[]/<>@# %^&*+|\=).
  • Cannot be the same as the username or the username written in reverse order.

db_port

Yes

Integer

Cluster database port. The value ranges from 8000 to 30000. The default value is 8000.

dss_pool_id

No

String

DSS storage pool ID.

availability_zones

Yes

Array of String

List of AZs. For details, see Regions and Endpoints.

NOTE:

Currently, only three AZs can be selected for a multi-AZ cluster.

tags

No

Array of Tags objects

Tags

vpc_id

Yes

String

VPC ID, which is used for configuring cluster network.

subnet_id

Yes

String

Subnet ID, which is used for configuring cluster network.

security_group_id

No

String

ID of a security group, which is used for configuring cluster network.

public_ip

No

PublicIp object

Public IP address. If the parameter is not specified, public connection is not used by default.

datastore_version

Yes

String

Cluster version

master_key_id

No

String

Key pair ID.

master_key_name

No

String

Key name.

crypt_algorithm

No

String

Encryption algorithm

volume

No

Volume object

Disk information

enterprise_project_id

No

String

Enterprise project. The default enterprise project ID is 0.

Table 4 Tags

Parameter

Mandatory

Type

Description

key

Yes

String

Key. A tag key can contain a maximum of 128 Unicode characters, which cannot be null. The first and last characters cannot be spaces. Only letters, digits, hyphens (-), and underscores (_) are allowed. It cannot contain the following characters: =*<>\,|/

value

Yes

String

Value. A tag value can contain a maximum of 255 characters, which can be an empty string. It cannot start or end with a space. Only letters, digits, hyphens (-), and underscores (_) are allowed. It cannot contain the following characters: =*<>\,|/

Table 5 PublicIp

Parameter

Mandatory

Type

Description

public_bind_type

Yes

String

Binding type of an EIP. The value can be one of the following:

  • auto_assign

  • not_use

  • bind_existing

eip_id

No

String

EIP ID

Table 6 Volume

Parameter

Mandatory

Type

Description

volume

No

String

Disk name. The options are as follows:

  • SSD: Ultra-high I/O
  • High I/O (SAS)
  • Common I/O (SATA)

capacity

No

Integer

Disk capacity

Response Parameters

Status code: 200

Table 7 Response body parameter

Parameter

Type

Description

cluster

Cluster object

Cluster object

Table 8 Cluster

Parameter

Type

Description

id

String

Cluster ID

Example Request

Create a multi-AZ data warehouse cluster with the following specifications: cluster version 8.2.1, AZs az1, az2, and az3, node flavor dws.m1.xlarge.ultrahigh, three nodes, SSD disk with 100 GB capacity, database port 8000, and public IP address, security Group ID, Subnet ID, VPC ID are as follows:

POST https://{Endpoint}/v2/89cd04f168b84af6be287f71730fdb4b/clusters

{
  "cluster" : {
    "flavor" : "dws.m1.xlarge.ultrahigh",
    "num_node" : 3,
    "subnet_id" : "374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
    "security_group_id" : "dc3ec145-9029-4b39-b5a3-ace5a01f772b",
    "vpc_id" : "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
    "db_port" : 8000,
    "datastore_version" : "8.2.1",
    "availability_zones" : [ "az1", "az2", "az3" ],
    "name" : "dws-1",
    "num_cn": 3,
    "db_name" : "dbadmin",
    "db_password" : "Passw0rd!",
    "public_ip" : {
      "public_bind_type" : "auto_assign",
      "eip_id" : ""
    },
    "volume":{
      "volume":"SSD",
      "capacity":100
    },
    "enterprise_project_id" : "aca4e50a-266f-4786-827c-f8d6cc3fbada"
  }
}

Example Response

Status code: 200

The cluster has been successfully created.

{
  "cluster" : {
    "id" : "7d85f602-a948-4a30-afd4-e84f47471c15"
  }
}

SDK Sample Code

The sample code is as follows:

 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
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.dws.v2.region.DwsRegion;
import com.huaweicloud.sdk.dws.v2.*;
import com.huaweicloud.sdk.dws.v2.model.*;

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

public class CreateClusterV2Solution {

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

        DwsClient client = DwsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DwsRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateClusterV2Request request = new CreateClusterV2Request();
        V2CreateClusterReq body = new V2CreateClusterReq();
        PublicIp publicIpCluster = new PublicIp();
        publicIpCluster.withPublicBindType("auto_assign")
            .withEipId("");
        List<String> listClusterAvailabilityZones = new ArrayList<>();
        listClusterAvailabilityZones.add("az1");
        listClusterAvailabilityZones.add("az2");
        V2CreateCluster clusterbody = new V2CreateCluster();
        clusterbody.withName("dws-1")
            .withFlavor("dws.m1.xlarge.ultrahigh")
            .withNumNode(3)
            .withDbName("dbadmin")
            .withDbPassword("Passw0rd!")
            .withDbPort(8000)
            .withAvailabilityZones(listClusterAvailabilityZones)
            .withVpcId("85b20d7e-9eb7-4b2a-98f3-3c8843ea3574")
            .withSubnetId("374eca02-cfc4-4de7-8ab5-dbebf7d9a720")
            .withSecurityGroupId("dc3ec145-9029-4b39-b5a3-ace5a01f772b")
            .withPublicIp(publicIpCluster)
            .withDatastoreVersion("8.2.1")
            .withEnterpriseProjectId("aca4e50a-266f-4786-827c-f8d6cc3fbada");
        body.withCluster(clusterbody);
        request.withBody(body);
        try {
            CreateClusterV2Response response = client.createClusterV2(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdws.v2.region.dws_region import DwsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdws.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.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

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

    try:
        request = CreateClusterV2Request()
        publicIpCluster = PublicIp(
            public_bind_type="auto_assign",
            eip_id=""
        )
        listAvailabilityZonesCluster = [
            "az1",
            "az2"
        ]
        clusterbody = V2CreateCluster(
            name="dws-1",
            flavor="dws.m1.xlarge.ultrahigh",
            num_node=3,
            db_name="dbadmin",
            db_password="Passw0rd!",
            db_port=8000,
            availability_zones=listAvailabilityZonesCluster,
            vpc_id="85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
            subnet_id="374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
            security_group_id="dc3ec145-9029-4b39-b5a3-ace5a01f772b",
            public_ip=publicIpCluster,
            datastore_version="8.2.1",
            enterprise_project_id="aca4e50a-266f-4786-827c-f8d6cc3fbada"
        )
        request.body = V2CreateClusterReq(
            cluster=clusterbody
        )
        response = client.create_cluster_v2(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
package main

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

    request := &model.CreateClusterV2Request{}
	eipIdPublicIp:= ""
	publicIpCluster := &model.PublicIp{
		PublicBindType: "auto_assign",
		EipId: &eipIdPublicIp,
	}
	var listAvailabilityZonesCluster = []string{
        "az1",
	    "az2",
    }
	securityGroupIdCluster:= "dc3ec145-9029-4b39-b5a3-ace5a01f772b"
	enterpriseProjectIdCluster:= "aca4e50a-266f-4786-827c-f8d6cc3fbada"
	clusterbody := &model.V2CreateCluster{
		Name: "dws-1",
		Flavor: "dws.m1.xlarge.ultrahigh",
		NumNode: int32(3),
		DbName: "dbadmin",
		DbPassword: "Passw0rd!",
		DbPort: int32(8000),
		AvailabilityZones: listAvailabilityZonesCluster,
		VpcId: "85b20d7e-9eb7-4b2a-98f3-3c8843ea3574",
		SubnetId: "374eca02-cfc4-4de7-8ab5-dbebf7d9a720",
		SecurityGroupId: &securityGroupIdCluster,
		PublicIp: publicIpCluster,
		DatastoreVersion: "8.2.1",
		EnterpriseProjectId: &enterpriseProjectIdCluster,
	}
	request.Body = &model.V2CreateClusterReq{
		Cluster: clusterbody,
	}
	response, err := client.CreateClusterV2(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For more SDK sample codes of programming languages, visit API Explorer and click the Sample Code tab. Example codes can be automatically generated.

Status Code

Status Code

Description

200

The cluster has been successfully created.

400

Request error.

401

Authentication failed.

403

You do not have required permissions.

500

Internal server error

503

Service unavailable.