
# 修改连接 - UpdateLink
#### 功能介绍
修改连接接口。
#### 调用方法
请参见[如何调用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
PUT /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 | 连接名称。                                                                                                 |
   
#### 请求参数
表2请求Header参数 
| 参数           | 是否必选 | 参数类型   | 描述                                                                                                                                                       |
|:---|:---|:---|:---|
| X-Auth-Token | 是    | String | 用户Token，使用[Token认证](https://support.huaweicloud.com/api-dataartsstudio/dataartsstudio_02_0010.html)时必选。通过调用IAM服务的"获取用户Token"接口获取响应消息头中X-Subject-Token的值。 |
   
表3请求Body参数 
| 参数    | 是否必选 | 参数类型                                                 | 描述    |
|:---|:---|:---|:---|
| links | 是    | Array of [links] objects | 连接列表。 |
   
 表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 | 配置值。  |
   
#### 响应参数
**状态码：200**
表9响应Body参数 
| 参数                | 参数类型                                                                        | 描述                                          |
|:---|:---|:---|
| validation-result | Array of [validationResult] objects | 校验连接结果列表。如果更新连接失败，将返回失败原因。如果更新连接成功，返回空对象列表。 |
   
 表10validationResult 
| 参数         | 参数类型                                                                                | 描述           |
|:---|:---|:---|
| linkConfig | Array of [validationLinkConfig] objects | 创建或更新连接校验结果。 |
   
 表11validationLinkConfig 
| 参数      | 参数类型   | 描述                    |
|:---|:---|:---|
| message | String | 错误描述。                 |
| status  | String | 错误级别，如：ERROR、WARNING。 |
   
**状态码：500**
表12响应Body参数 
| 参数      | 参数类型   | 描述                    |
|:---|:---|:---|
| message | String | 错误描述。                 |
| status  | String | 错误级别，如：ERROR、WARNING。 |
   
#### 请求示例
修改一个名为mysql_link的数据连接。
```
PUT /v1.1/1551c7f6c808414d8e9f3c514a170f2e/clusters/6ec9a0a4-76be-4262-8697-e7af1fac7920/cdm/link/rdb_link
{
  "links" : [ {
    "link-config-values" : {
      "configs" : [ {
        "inputs" : [ {
          "name" : "linkConfig.databaseType",
          "value" : "MYSQL"
        }, {
          "name" : "linkConfig.host",
          "value" : "100.94.8.163"
        }, {
          "name" : "linkConfig.port",
          "value" : "3306"
        }, {
          "name" : "linkConfig.database",
          "value" : "DB_name"
        }, {
          "name" : "linkConfig.username",
          "value" : "username"
        }, {
          "name" : "linkConfig.password",
          "value" : "DB_password"
        }, {
          "name" : "linkConfig.fetchSize",
          "value" : "100000"
        }, {
          "name" : "linkConfig.usingNative",
          "value" : "false"
        } ],
        "name" : "linkConfig"
      } ]
    },
    "name" : "mysql_link",
    "creation-date" : 1496654788622,
    "connector-name" : "generic-jdbc-connector",
    "update-date" : 1496654788622,
    "enabled" : true
  } ]
}
```
#### 响应示例
**状态码：200**
OK。
```
{
  "validation-result" : [ { } ]
}
```
**状态码：500**
服务内部错误，具体返回错误码请参考错误码。
```
{
  "validation-result" : [ {
    "linkConfig" : [ {
      "message" : "Can''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''t connect to the database with given credentials: The authentication type 12 is not supported. Check that you have configured the pg_hba.conf file to include the client''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''s IP address or subnet, and that it is using an authentication scheme supported by the driver.",
      "status" : "ERROR"
    } ]
  } ]
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  修改一个名为mysql_link的数据连接。
  ```
  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.*;
  import java.util.List;
  import java.util.ArrayList;
  public class UpdateLinkSolution {
      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();
          UpdateLinkRequest request = new UpdateLinkRequest();
          request.withClusterId("{cluster_id}");
          request.withLinkName("{link_name}");
          CdmCreateAndUpdateLinkReq body = new CdmCreateAndUpdateLinkReq();
          List<Input> listConfigsInputs = new ArrayList<>();
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.databaseType")
                  .withValue("MYSQL")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.host")
                  .withValue("100.94.8.163")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.port")
                  .withValue("3306")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.database")
                  .withValue("DB_name")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.username")
                  .withValue("username")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.password")
                  .withValue("DB_password")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.fetchSize")
                  .withValue("100000")
          );
          listConfigsInputs.add(
              new Input()
                  .withName("linkConfig.usingNative")
                  .withValue("false")
          );
          List<Configs> listLinkConfigValuesConfigs = new ArrayList<>();
          listLinkConfigValuesConfigs.add(
              new Configs()
                  .withInputs(listConfigsInputs)
                  .withName("linkConfig")
          );
          LinksLinkconfigvalues linkConfigValuesLinks = new LinksLinkconfigvalues();
          linkConfigValuesLinks.withConfigs(listLinkConfigValuesConfigs);
          List<Links> listbodyLinks = new ArrayList<>();
          listbodyLinks.add(
              new Links()
                  .withLinkConfigValues(linkConfigValuesLinks)
                  .withName("mysql_link")
                  .withCreationDate(1496654788622L)
                  .withConnectorName("generic-jdbc-connector")
                  .withUpdateDate(1496654788622L)
                  .withEnabled(true)
          );
          body.withLinks(listbodyLinks);
          request.withBody(body);
          try {
              UpdateLinkResponse response = client.updateLink(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]
  修改一个名为mysql_link的数据连接。
  ```
  # 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 = UpdateLinkRequest()
          request.cluster_id = "{cluster_id}"
          request.link_name = "{link_name}"
          listInputsConfigs = [
              Input(
                  name="linkConfig.databaseType",
                  value="MYSQL"
              ),
              Input(
                  name="linkConfig.host",
                  value="100.94.8.163"
              ),
              Input(
                  name="linkConfig.port",
                  value="3306"
              ),
              Input(
                  name="linkConfig.database",
                  value="DB_name"
              ),
              Input(
                  name="linkConfig.username",
                  value="username"
              ),
              Input(
                  name="linkConfig.password",
                  value="DB_password"
              ),
              Input(
                  name="linkConfig.fetchSize",
                  value="100000"
              ),
              Input(
                  name="linkConfig.usingNative",
                  value="false"
              )
          ]
          listConfigsLinkConfigValues = [
              Configs(
                  inputs=listInputsConfigs,
                  name="linkConfig"
              )
          ]
          linkConfigValuesLinks = LinksLinkconfigvalues(
              configs=listConfigsLinkConfigValues
          )
          listLinksbody = [
              Links(
                  link_config_values=linkConfigValuesLinks,
                  name="mysql_link",
                  creation_date=1496654788622,
                  connector_name="generic-jdbc-connector",
                  update_date=1496654788622,
                  enabled=True
              )
          ]
          request.body = CdmCreateAndUpdateLinkReq(
              links=listLinksbody
          )
          response = client.update_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]
  修改一个名为mysql_link的数据连接。
  ```
  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.UpdateLinkRequest{}
  request.ClusterId = "{cluster_id}"
  request.LinkName = "{link_name}"
  valueInputs:= "MYSQL"
  var valueInputsInterface interface{} = valueInputs
  valueInputs1:= "100.94.8.163"
  var valueInputsInterface1 interface{} = valueInputs1
  valueInputs2:= "3306"
  var valueInputsInterface2 interface{} = valueInputs2
  valueInputs3:= "DB_name"
  var valueInputsInterface3 interface{} = valueInputs3
  valueInputs4:= "username"
  var valueInputsInterface4 interface{} = valueInputs4
  valueInputs5:= "DB_password"
  var valueInputsInterface5 interface{} = valueInputs5
  valueInputs6:= "100000"
  var valueInputsInterface6 interface{} = valueInputs6
  valueInputs7:= "false"
  var valueInputsInterface7 interface{} = valueInputs7
  var listInputsConfigs = []model.Input{
          {
              Name: "linkConfig.databaseType",
              Value: &valueInputsInterface,
          },
          {
              Name: "linkConfig.host",
              Value: &valueInputsInterface1,
          },
          {
              Name: "linkConfig.port",
              Value: &valueInputsInterface2,
          },
          {
              Name: "linkConfig.database",
              Value: &valueInputsInterface3,
          },
          {
              Name: "linkConfig.username",
              Value: &valueInputsInterface4,
          },
          {
              Name: "linkConfig.password",
              Value: &valueInputsInterface5,
          },
          {
              Name: "linkConfig.fetchSize",
              Value: &valueInputsInterface6,
          },
          {
              Name: "linkConfig.usingNative",
              Value: &valueInputsInterface7,
          },
      }
  var listConfigsLinkConfigValues = []model.Configs{
          {
              Inputs: listInputsConfigs,
              Name: "linkConfig",
          },
      }
  linkConfigValuesLinks := &model.LinksLinkconfigvalues{
  Configs: listConfigsLinkConfigValues,
  }
  creationDateLinks:= int64(1496654788622)
  updateDateLinks:= int64(1496654788622)
  enabledLinks:= true
  var listLinksbody = []model.Links{
          {
              LinkConfigValues: linkConfigValuesLinks,
              Name: "mysql_link",
              CreationDate: &creationDateLinks,
              ConnectorName: "generic-jdbc-connector",
              UpdateDate: &updateDateLinks,
              Enabled: &enabledLinks,
          },
      }
  request.Body = &model.CdmCreateAndUpdateLinkReq{
  Links: listLinksbody,
  }
  response, err := client.UpdateLink(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=UpdateLink)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述                    |
|:---|:---|
| 200 | OK。                   |
| 400 | 请求错误。                 |
| 401 | 鉴权失败。                 |
| 403 | 没有操作权限。               |
| 404 | 找不到资源。                |
| 500 | 服务内部错误，具体返回错误码请参考错误码。 |
| 503 | 服务不可用。                |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-dataartsstudio/ErrorCode.html)。
