Creating a Connection

Function

This API is used to create a connection. The supported connection types include DWS, DLI, SparkSQL, Hive, RDS, and CloudTable.

URI

  • URI format

    POST /v1/{project_id}/connections

  • Parameter description
    Table 1 URI parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

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

Request Message

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

workspace

No

String

Workspace ID.

  • If this parameter is not set, data in the default workspace is queried by default.
  • If you need to query data in other workspaces, this header must be carried.
Table 3 Connection parameter description

Parameter

Mandatory

Type

Description

name

Yes

String

Name of the connection. The name consists of a maximum of 100 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed. The connection name must be unique.

type

Yes

String

Connection type. The options are as follows:

  • DWS
  • DLI
  • SparkSQL
  • HIVE
  • RDS
  • CloudTable

config

No

Map<String,String>

Connection configuration item. The configuration item varies with the connection type. You do not need to set the config parameter for the DLI connection. For other types of connections, see the description of connection configuration items.

description

No

String

The description contains a maximum of 255 characters.

Table 4 DWS connection parameters

Parameter

Mandatory

Type

Description

clusterName

No

String

DWS cluster name.

Perform the following operations to obtain the DWS cluster name:

  1. Log in to the management console.
  2. Click Data Warehouse Service and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster management list.

By default, this parameter is left blank.

ip

No

String

IP address for accessing the DWS cluster.

Perform the following operations to obtain the DWS access address:

  1. Log in to the management console.
  2. Click Data Warehouse Service and select Cluster Management from the list on the left.
  3. Click the cluster name. The basic information page of the cluster is displayed.

You can obtain the private network IP address on the Database Attribute tab. If there are multiple IP addresses, select the first IP address.

By default, this parameter is left blank.

port

No

String

Port for accessing the DWS cluster.

Perform the following operations to obtain the DWS access port:

  1. Log in to the management console.
  2. Click Data Warehouse Service and select Cluster Management from the list on the left.
  3. Click the cluster name. The basic information page of the cluster is displayed.

You can obtain the port information on the Database Attribute tab.

For example, 8000. By default, this parameter is left blank.

userName

Yes

String

Username of the database. The username is required for creating the DWS cluster.

password

Yes

String

Password for accessing the database. The password is required for creating the DWS cluster.

sslEnable

Yes

boolean

Specifies whether to enable the SSL connection.

kmsKey

Yes

String

Name of the KMS key.

Perform the following operations to obtain the key:

  1. Log in to the management console.
  2. Click Key Management Service and select Key Management Service from the list on the left.

You can obtain the key name from the key list.

agentName

Yes

String

Name of the CDM cluster.

Perform the following operations to obtain the CDM cluster name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster list.

Table 5 Spark SQL connection parameters

Parameter

Mandatory

Type

Description

clusterName

Yes

String

MRS cluster name.

Perform the following operations to obtain the MRS cluster name:

  1. Log in to the management console.
  2. Click MapReduce Service and select Active Clusters from the list on the left.

You can obtain the cluster name from the active clusters, such as mrsCluster1.

connectionMethod

Yes

String

Method to connect.

  • agent: connected through an agent.
  • direct: connected directly.

userName

No

String

Username of the MRS cluster. This parameter is mandatory when connectionMethod is set to agent.

password

No

String

Password for accessing the MRS cluster. This parameter is mandatory when connectionMethod is set to agent.

agentName

No

String

Name of the CDM cluster. This parameter is mandatory when connectionMethod is set to agent.

Perform the following operations to obtain the CDM cluster name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster list.

kmsKey

No

String

Name of the KMS key. This parameter is mandatory when connectionMethod is set to agent.

Perform the following operations to obtain the key:

  1. Log in to the management console.
  2. Click Key Management Service and select Key Management Service from the list on the left.

You can obtain the key name from the key list.

Table 6 Hive connection parameters

Parameter

Mandatory

Type

Description

clusterName

Yes

String

Name of the MRS cluster. For example, mrsCluster1

connectionMethod

Yes

String

Method to connect.

  • agent: connected through an agent.
  • direct: connected directly.

userName

No

String

Username of the MRS cluster. This parameter is mandatory when connectionMethod is set to agent.

password

No

String

Password for accessing the MRS cluster. This parameter is mandatory when connectionMethod is set to agent.

agentName

No

String

Name of the CDM cluster. This parameter is mandatory when connectionMethod is set to agent.

Perform the following operations to obtain the CDM cluster name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster list.

kmsKey

No

String

Name of the KMS key. This parameter is mandatory when connectionMethod is set to agent.

Perform the following operations to obtain the key:

  1. Log in to the management console.
  2. Click Key Management Service and select Key Management Service from the list on the left.

You can obtain the key name from the key list.

Table 7 RDS connection parameters

Parameter

Mandatory

Type

Description

ip

Yes

String

Address for accessing RDS.

Perform the following operations to obtain the RDS access address:

  1. Log in to the management console.
  2. Click Relational Database Service and select Instance Management from the list on the left.
  3. Click the name of an instance. The basic information page of the instance is displayed.

You can obtain the IP address on the Connection Information tab.

port

Yes

String

Port for accessing RDS.

Perform the following operations to obtain the RDS access port:

  1. Log in to the management console.
  2. Click Relational Database Service and select Instance Management from the list on the left.
  3. Click the name of an instance. The basic information page of the instance is displayed.

You can obtain the database port number on the Connection Information tab.

userName

Yes

String

Username of the database. The username is required for creating the cluster.

password

Yes

String

Password for accessing the database. The password is required for creating the cluster.

kmsKey

Yes

String

Name of the KMS key.

Perform the following operations to obtain the key:

  1. Log in to the management console.
  2. Click Key Management Service and select Key Management Service from the list on the left.

You can obtain the key name from the key list.

agentName

Yes

String

Name of the CDM cluster.

Perform the following operations to obtain the CDM cluster name:

  1. Log in to the management console.
  2. Click Cloud Data Migration and select Cluster Management from the list on the left.

You can obtain the cluster name from the cluster list.

driverName

Yes

String

Name of the driver.

  • com.mysql.jdbc.Driver
  • org.postgresql.Driver

driverPath

Yes

String

Path of the driver on OBS.

CloudTable connection parameters

Parameter

Mandatory

Type

Description

clusterName

Yes

String

Name of the CloudTable cluster.

Perform the following operations to obtain the cluster name:

  1. Log in to the management console.
  2. Click CloudTable Service and select Cluster Mode from the list on the left.

You can obtain the cluster name from the cluster list.

Response Message

None.

Example

Create a connection.

  • Request
    POST /v1/b384b9e9ab9b4ee8994c8633aabc9505/connections
    {
        "name":"connection1",
        "type":"DWS",
        "config":{
    	    "clusterName":"test",
    	    "userName":"dbadmin",
                "password":"test1234",
    	    "kmsKey":"cdm-dlf",		
    	    "agentName":"cdm-donotdelete",		
    	    "sslEnable":false
        }
    }
    
  • Success response

    HTTP status code 204

  • Failure response

    HTTP status code 400

    {
        "error_code":"DLF.6309",
        "error_msg":"The name already exists."
    }

Status Codes

For details about status codes, see Status Codes.