修改连接
功能介绍
修改连接接口。
调用方法
请参见如何调用API。
URI
PUT /v1.1/{project_id}/clusters/{cluster_id}/cdm/link/{link_name}
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,获取方法请参见项目ID和账号ID |
cluster_id |
是 |
String |
集群ID |
link_name |
是 |
String |
连接名称 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
links |
是 |
Array of links objects |
连接列表,请参见links数据结构说明 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
link-config-values |
是 |
link-config-values object |
连接参数配置,请参见link-config-values参数说明。 |
creation-user |
否 |
String |
创建连接的用户 |
name |
是 |
String |
连接名称 |
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:DMSKafka连接 |
update-date |
否 |
Long |
更新连接的时间 |
enabled |
否 |
Boolean |
是否激活连接,默认为“true”。 |
update-user |
否 |
String |
更新连接的用户 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
configs |
是 |
Array of configs objects |
连接配置参数数据结构,请参见configs参数说明。 |
extended-configs |
否 |
extended-configs object |
扩展配置,请参见extended-configs参数说明。 |
validators |
否 |
Array of strings |
校验器 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
inputs |
是 |
Array of Input objects |
输入参数列表,列表中的每个参数为“name,value”结构,请参考inputs数据结构参数说明。在“from-config-values”数据结构中,不同的源连接类型有不同的“inputs”参数列表,请参见源端作业参数说明下的章节。在“to-config-values”数据结构中,不同的目的连接类型有不同的“inputs”参数列表,请参见目的端作业参数说明下面的子章节。在“driver-config-values”数据结构中,“inputs”具体参数请参见作业任务参数说明。 |
name |
是 |
String |
配置名称:源端作业的配置名称为“fromJobConfig”。目的端作业的配置名称为“toJobConfig”,连接的配置名称固定为“linkConfig”。 |
id |
否 |
Integer |
配置ID,由系统生成,用户无需填写。 |
type |
否 |
String |
配置类型,由系统生成,用户无需填写。值为LINK或者JOB,如果是连接管理API,则为LINK;如果是作业管理API,则为JOB。 |
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
validation-result |
Array of validationResult objects |
校验结构:如果创建连接失败,返回失败原因,请参见validation-result参数说明。如果创建成功,返回空列表。 |
参数 |
参数类型 |
描述 |
---|---|---|
linkConfig |
Array of validationLinkConfig objects |
创建或更新连接校验结果,请参见linkConfig参数说明。 |
参数 |
参数类型 |
描述 |
---|---|---|
message |
String |
错误描述 |
status |
String |
ERROR,WARNING 枚举值:
|
状态码: 500
参数 |
参数类型 |
描述 |
---|---|---|
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代码示例如下。
修改一个名为mysql_link的数据连接。
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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()); } } } |
修改一个名为mysql_link的数据连接。
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# coding: utf-8 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 = __import__('os').getenv("CLOUD_SDK_AK") sk = __import__('os').getenv("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) |
修改一个名为mysql_link的数据连接。
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
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 := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := cdm.NewcdmClient( cdm.cdmClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateLinkRequest{} request.ClusterId = "{cluster_id}" request.LinkName = "{link_name}" var listInputsConfigs = []model.Input{ { 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", }, } 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的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK |
400 |
请求错误 |
401 |
鉴权失败 |
403 |
没有操作权限 |
404 |
找不到资源 |
500 |
服务内部错误,具体返回错误码请参考错误码 |
503 |
服务不可用 |
错误码
请参见错误码。