
# 查询连接 - ShowLink
#### 功能介绍
查询连接接口。
#### 调用方法
请参见[如何调用API](https://support.huaweicloud.com/api-dataartsstudio/making_request.html)。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-dataartsstudio/abcd.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
GET /v1.1/{project_id}/clusters/{cluster_id}/cdm/link/{link_name}
表1路径参数 
| 参数         | 是否必选 | 参数类型   | 描述                                                                                                    |
|:---|:---|:---|:---|
| project_id | 是    | String | 项目ID，获取方法请参见[项目ID和账号ID](https://support.huaweicloud.com/api-dataartsstudio/projectid_accountid.html)。 |
| cluster_id | 是    | String | 集群ID，获取方法请参见[获取集群列表](https://support.huaweicloud.com/api-dataartsstudio/ListClusters.html)。           |
| link_name  | 是    | String | 连接名称。查询所有连接用all，查询单个连接输入连接名。                                                                          |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token，使用[Token认证](https://support.huaweicloud.com/api-dataartsstudio/dataartsstudio_02_0010.html)时必选。通过调用IAM服务的"获取用户Token"接口获取响应消息头中X-Subject-Token的值。 |
   
#### 响应参数
**状态码：200**
表3响应Body参数 
| 参数                  | 参数类型                                                | 描述                      |
|:---|:---|:---|
| links               | Array of [links] objects | 连接列表。                   |
| fromTo-unMapping    | String                                              | 表/文件迁移不支持哪些数据源迁移到哪些数据源。 |
| batchFromTo-mapping | String                                              | 整库迁移支持哪些数据源迁移到哪些数据源。    |
   
 表4links 
| 参数                 | 参数类型                                                                | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|:---|:---|:---|
| link-config-values | [link-config-values] object | 连接参数配置。                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| creation-user      | String                                                              | 创建连接的用户。                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| name               | String                                                              | 连接名称。只能包含数字、字母、中划线、下划线，且首字符不能是中划线，长度不能超过240个字符。                                                                                                                                                                                                                                                                                                                                                                                           |
| id                 | Integer                                                             | 连接ID。                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| creation-date      | Long                                                                | 创建连接的时间，单位：毫秒。                                                                                                                                                                                                                                                                                                                                                                                                                            |
| connector-name     | String                                                              | 连接器名称，对应的连接参数如下：generic-jdbc-connector：关系数据库连接。obs-connector：OBS连接。hdfs-connector：HDFS连接。hbase-connector：HBase连接、CloudTable连接。hive-connector：Hive连接。ftp-connector/sftp-connector：FTP/SFTP连接。mongodb-connector：MongoDB连接。redis-connector：Redis/DCS连接。kafka-connector：Kafka连接。dis-connector：DIS连接。elasticsearch-connector：Elasticsearch/云搜索服务连接。dli-connector：DLI连接。 http-connector：HTTP/HTTPS连接，该连接暂无连接参数。dms-kafka-connector：DMS Kafka连接。 |
| update-date        | Long                                                                | 更新连接的时间。                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| enabled            | Boolean                                                             | 是否激活连接，默认为"true"。                                                                                                                                                                                                                                                                                                                                                                                                                         |
| update-user        | String                                                              | 更新连接的用户。                                                                                                                                                                                                                                                                                                                                                                                                                                  |
   
 表5link-config-values 
| 参数               | 参数类型                                                            | 描述                      |
|:---|:---|:---|
| configs          | Array of [configs] objects         | 连接配置参数数据结构。             |
| extended-configs | [extended-configs] object | 扩展配置。扩展配置暂不对外开放，用户无需填写。 |
| validators       | Array of strings                                                | 校验器。校验器配置暂不对外开放，用户无需填写  |
   
 表6configs 
| 参数     | 参数类型                                                | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
|:---|:---|:---|
| inputs | Array of [Input] objects | 输入参数列表，列表中的每个参数为"name,value"结构。在"from-config-values"数据结构中，不同的源连接类型有不同的"inputs"参数列表，请参见[源端作业参数说明](https://support.huaweicloud.com/api-dataartsstudio/source_job_parameters.html)下的章节。在"to-config-values"数据结构中，不同的目的连接类型有不同的"inputs"参数列表，请参见[目的端作业参数说明](https://support.huaweicloud.com/api-dataartsstudio/destination_job_parameters.html)下面的子章节。在"driver-config-values"数据结构中，"inputs"具体参数请参见[作业任务参数说明](https://support.huaweicloud.com/api-dataartsstudio/job_parameter.html)。 |
| name   | String                                              | 配置名称：源端作业的配置名称为"fromJobConfig"。目的端作业的配置名称为"toJobConfig"，连接的配置名称固定为"linkConfig"。                                                                                                                                                                                                                                                                                                                                                                                                |
| id     | Integer                                             | 配置ID，由系统生成，用户无需填写。                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| type   | String                                              | 配置类型，由系统生成，用户无需填写。值为LINK或者JOB，如果是连接管理API，则为LINK；如果是作业管理API，则为JOB。                                                                                                                                                                                                                                                                                                                                                                                                              |
   
 表7Input 
| 参数    | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|
| name  | String | 参数名: - 如果是连接管理API，则以"linkConfig."开头，对于不同连接类型有不同的参数，具体可参见[连接参数说明](https://support.huaweicloud.com/api-dataartsstudio/link_parameter.html)下相应连接的参数说明。   - 如果是作业管理API，对于源端连接参数，则以"fromJobConfig."开头，具体可参见[源端作业参数说明](https://support.huaweicloud.com/api-dataartsstudio/source_job_parameters.html)下相应的源端参数说明；对于目的端连接参数，则以"toJobConfig."开头，具体可参见[目的端作业参数说明](https://support.huaweicloud.com/api-dataartsstudio/destination_job_parameters.html)下相应的目的端参数说明；对于作业任务参数，请参见[作业任务参数说明](https://support.huaweicloud.com/api-dataartsstudio/job_parameter.html)下相应的任务参数说明。    |
| value | Object | 参数值，参数名对应的值，必须填写为字符串。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| type  | String | 值类型，如STRING、INTEGER，由系统设定，用户无需填写。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
   
 表8extended-configs 
| 参数    | 参数类型   | 描述    |
|:---|:---|:---|
| name  | String | 配置名称。 |
| value | String | 配置值。  |
   
#### 请求示例
```
GET /v1.1/1551c7f6c808414d8e9f3c514a170f2e/clusters/6ec9a0a4-76be-4262-8697-e7af1fac7920/cdm/link/sftplink
```
#### 响应示例
**状态码：200**
OK。
```
{
  "links" : [ {
    "link-config-values" : {
      "configs" : [ {
        "inputs" : [ {
          "name" : "linkConfig.server",
          "type" : "STRING",
          "value" : "100.94.8.163"
        }, {
          "name" : "linkConfig.port",
          "type" : "INTEGER",
          "value" : 22
        }, {
          "name" : "linkConfig.username",
          "type" : "STRING",
          "value" : "root"
        }, {
          "name" : "linkConfig.password",
          "type" : "STRING",
          "value" : "Add password here"
        } ],
        "name" : "linkConfig"
      } ]
    },
    "creation-user" : "cdm",
    "name" : "sftp_link",
    "creation-date" : 1516674482640,
    "connector-name" : "sftp-connector",
    "update-date" : 1516674476022,
    "enabled" : true,
    "update-user" : "cdm"
  } ]
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  ```
  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.cdm.v1.region.CdmRegion;
  import com.huaweicloud.sdk.cdm.v1.*;
  import com.huaweicloud.sdk.cdm.v1.model.*;
  public class ShowLinkSolution {
      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");
          String projectId = "{project_id}";
          ICredential auth = new BasicCredentials()
                  .withProjectId(projectId)
                  .withAk(ak)
                  .withSk(sk);
          CdmClient client = CdmClient.newBuilder()
                  .withCredential(auth)
                  .withRegion(CdmRegion.valueOf("<YOUR REGION>"))
                  .build();
          ShowLinkRequest request = new ShowLinkRequest();
          request.withClusterId("{cluster_id}");
          request.withLinkName("{link_name}");
          try {
              ShowLinkResponse response = client.showLink(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());
          }
      }
  }
  ```
- [Python]
  ```
  # coding: utf-8
  import os
  from huaweicloudsdkcore.auth.credentials import BasicCredentials
  from huaweicloudsdkcdm.v1.region.cdm_region import CdmRegion
  from huaweicloudsdkcore.exceptions import exceptions
  from huaweicloudsdkcdm.v1 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"]
      projectId = "{project_id}"
      credentials = BasicCredentials(ak, sk, projectId)
      client = CdmClient.new_builder() \
          .with_credentials(credentials) \
          .with_region(CdmRegion.value_of("<YOUR REGION>")) \
          .build()
      try:
          request = ShowLinkRequest()
          request.cluster_id = "{cluster_id}"
          request.link_name = "{link_name}"
          response = client.show_link(request)
          print(response)
      except exceptions.ClientRequestException as e:
          print(e.status_code)
          print(e.request_id)
          print(e.error_code)
          print(e.error_msg)
  ```
- [Go]
  ```
  package main
  import (
  "fmt"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
      cdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1"
  "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/model"
      region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdm/v1/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")
      projectId := "{project_id}"
      auth, err := basic.NewCredentialsBuilder().
          WithAk(ak).
          WithSk(sk).
          WithProjectId(projectId).
          SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      hcClient, err := cdm.CdmClientBuilder().
           WithRegion(region.ValueOf("<YOUR REGION>")).
           WithCredential(auth).
           SafeBuild()
      if err != nil {
          fmt.Println(err)
          return
      }
      client := cdm.NewCdmClient(hcClient)
      request := &model.ShowLinkRequest{}
  request.ClusterId = "{cluster_id}"
  request.LinkName = "{link_name}"
  response, err := client.ShowLink(request)
  if err == nil {
          fmt.Printf("%+v\n", response)
      } else {
          fmt.Println(err)
      }
  }
  ```
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/CDM/sdk?api=ShowLink)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                    |
|:---|:---|
| 200 | OK。                   |
| 400 | 请求错误。                 |
| 401 | 鉴权失败。                 |
| 403 | 没有操作权限。               |
| 404 | 找不到资源。                |
| 500 | 服务内部错误，具体返回错误码请参考错误码。 |
| 503 | 服务不可用。                |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-dataartsstudio/ErrorCode.html)。
