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

查询数据连接列表

功能介绍

查询数据连接列表

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/data-connectors

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID

表2 Query参数

参数

是否必选

参数类型

描述

connector_id

String

连接ID

source_type

String

数据源类别

connector_name

String

数据连接名称

limit

Integer

每页返回的资源个数

offset

Integer

分页查询起始偏移量

available

Boolean

数据连接是否有效

请求参数

响应参数

状态码: 200

表3 响应Body参数

参数

参数类型

描述

total_count

Integer

数据连接总数

data_connectors

Array of DataConnectorDetail objects

数据连接详情列表

表4 DataConnectorDetail

参数

参数类型

描述

connector_name

String

数据连接名称。

source_type

String

数据连接类型。

  • RDS_POSTGRES:RDS服务PostgreSQL数据库

  • RDS_MYSQL:RDS服务MySQL数据库

  • gaussdb-mysql:云数据库GaussDB(for MySQL)

source_info

String

数据源信息,为json格式,不同数据连接有不同的信息,各数据源的source_info请求内容可参见示例。

connector_id

String

数据连接ID

create_time

Long

创建时间

last_update_time

Long

最后更新时间

create_by

String

创建用户ID

create_user

String

创建用户名称

tenant_id

String

租户ID

last_update_by

String

最后更新用户ID

status

Integer

数据连接状态:

  • -1:已删除

  • 0:正常

  • -2:异常

  • 1:使用中

used_clusters

String

使用集群

encrypt_type

Integer

加密类型

请求示例

响应示例

状态码: 200

查询数据连接列表成功

{
  "total_count" : 1,
  "data_connectors" : [ {
    "connector_id" : "7d169c6c-ab50-4a56-a5d2-240ca20aabda",
    "connector_name" : "test",
    "create_time" : 1681270961,
    "source_type" : "RDS_MYSQL",
    "source_info" : "{\"rds_instance_id\":\"3ce1ae8af8cd43b2bcbd18b7541bb8b0in01\",\"jdbc_url\":\"jdbc:mysql://192.XXX.XXX.XXX:3306/test?socketTimeout=60000\",\"db_name\":\"test\",\"user_name\":\"root\",\"driver_path\":\"mrs-public/dirvers/mysql-connector-java-5.1.47.jar\"}",
    "last_update_time" : 1681270961,
    "create_by" : "148c89d603e048b291f5940935b38f46",
    "create_user" : "xxx",
    "tenant_id" : "xxxxe662a7e24cc99bfc858c4558dbf6",
    "last_update_by" : "148c89d603e048b291f5940935b38f46",
    "status" : 0,
    "encrypt_type" : 2
  } ]
}

SDK代码示例

SDK代码示例如下。

 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
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.*;


public class ListDataConnectorSolution {

    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();
        ListDataConnectorRequest request = new ListDataConnectorRequest();
        request.withConnectorId("<connector_id>");
        request.withSourceType("<source_type>");
        request.withConnectorName("<connector_name>");
        request.withLimit(<limit>);
        request.withOffset(<offset>);
        request.withAvailable(<available>);
        try {
            ListDataConnectorResponse response = client.listDataConnector(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
# coding: utf-8

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.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

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

    try:
        request = ListDataConnectorRequest()
        request.connector_id = "<connector_id>"
        request.source_type = "<source_type>"
        request.connector_name = "<connector_name>"
        request.limit = <limit>
        request.offset = <offset>
        request.available = <Available>
        response = client.list_data_connector(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
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.ListDataConnectorRequest{}
	connectorIdRequest:= "<connector_id>"
	request.ConnectorId = &connectorIdRequest
	sourceTypeRequest:= "<source_type>"
	request.SourceType = &sourceTypeRequest
	connectorNameRequest:= "<connector_name>"
	request.ConnectorName = &connectorNameRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	offsetRequest:= int32(<offset>)
	request.Offset = &offsetRequest
	availableRequest:= <available>
	request.Available = &availableRequest
	response, err := client.ListDataConnector(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

查询数据连接列表成功

错误码

请参见错误码

分享:

    相关文档

    相关产品