All Products
Search
Document Center

:CreateDataSource

更新時間:Aug 03, 2023

Adds a data source to DataWorks.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateDataSource

The operation that you want to perform. Set the value to CreateDataSource.

ProjectId Long Yes 1

The ID of the DataWorks workspace to which the data source belongs. You can call the ListProjects operation to obtain the ID.

Name String Yes abc

The name of the data source.

Description String No abc

The description of the data source.

DataSourceType String Yes rds

The type of the data source. Valid values:

  • odps
  • mysql
  • rds
  • oss
  • sqlserver
  • polardb
  • oracle
  • mongodb
  • emr
  • postgresql
  • analyticdb_for_mysql
  • hybriddb_for_postgresql
  • holo
SubType String No mysql

The subtype of the data source.

  • This parameter takes effect only if DataSourceType is set to rds.
  • If you set DataSourceType to rds, you can set this parameter to mysql, sqlserver, or postgresql.
EnvType Integer Yes 1

The environment in which the data source is used. Valid values: 0 and 1. The value 0 indicates the development environment. The value 1 indicates the production environment.

Content String Yes {"database":"dbname","instanceName":"instancename","password":"password","rdsOwnerId":"123","username":"username"}

The details of the data source. Examples of details of some common data sources:

  • odps

{
  "accessId": "xssssss",
  "accessKey": "xsaxsaxsa",
  "authType": 2,
  "endpoint": "http://service.odps.aliyun.com/api",
  "project": "xsaxsax",
  "tag": "public"
}
  • mysql

{
  "database": "xsaxsa",
  "instanceName": "rm-xsaxsa",
  "password": "xsaxsa",
  "rdsOwnerId": "xasxsa",
  "regionId": "cn-shanghai",
  "tag": "rds",
  "username": "xsaxsa"
}
  • rds

{
  "configType": 1,
  "tag": "rds",
  "database": "xsaxsa",
  "username": "xsaxsa",
  "password": "xssaxsa$32050",
  "instanceName": "rm-xsaxs",
  "rdsOwnerId": "11111111"
}
  • oss

{
  "accessId": "sssssxx",
  "accessKey": "xsaxaxsaxs",
  "bucket": "xsa-xs-xs",
  "endpoint": "http://oss-cn-shanghai.aliyuncs.com",
  "tag": "public"
}
  • sqlserver

{
  "jdbcUrl": "jdbc:sqlserver://xsaxsa-xsaxsa.database.xxx.cn:123;DatabaseName=xsxs-xsxs",
  "password": "sdasda$fs",
  "tag": "public",
  "username": "sxaxacdacdd"
}
  • polardb

{
  "clusterId": "pc-sdadsadsa",
  "database": "dsadsadsa",
  "ownerId": "121212122",
  "password": "sdasdafssa",
  "region": "cn-shanghai",
  "tag": "polardb",
  "username": "asdadsads"
}
  • redis

{    
"password": "xxxxxx",   
 "address":"[{\"host\":\"xxxxxxx.redis.rds.aliyuncs.com\",\"port\":6379}]",    
"tag": "public"
}
  • oracle

{
  "jdbcUrl": "jdbc:oracle:saaa:@xxxxx:1521:PROD",
  "password": "sxasaxsa",
  "tag": "public",
  "username": "sasfadfa"
}
  • mongodb

{
  "address": "[\"xsaxxsa.mongodb.rds.aliyuncs.com:3717\"]",
  "database": "admin",
  "password": "sadsda@",
  "tag": "public",
  "username": "dsadsadas"
}
  • emr

{
  "accessId": "xsaxsa",
  "emrClusterId": "C-dsads",
  "emrResourceQueueName": "default",
  "emrEndpoint": "emr.aliyuncs.com",
  "accessKey": "dsadsad",
  "emrUserId": "224833315798889783",
  "name": "sasdsadsa",
  "emrAccessMode": "simple",
  "region": "cn-shanghai",
  "authType": "2",
  "emrProjectId": "FP-sdadsad"
}
  • postgresql

{
  "jdbcUrl": "jdbc:postgresql://xxxx:1921/ssss",
  "password": "sdadsads",
  "tag": "public",
  "username": "sdsasda"
}
  • analyticdb_for_mysql

{
  "instanceId": "am-sadsada",
  "database": "xsxsx",
  "username": "xsxsa",
  "password": "asdadsa",
  "connectionString": "am-xssxsxs.ads.aliyuncs.com:3306"
}
  • hybriddb_for_postgresql

{
  "connectionString": "gp-xsaxsaxa-master.gpdbmaster.rds.aliyuncs.com",
  "database": "xsaxsaxas",
  "password": "xsaxsaxsa@11",
  "instanceId": "gp-xsaxsaxsa",
  "port": "541132",
  "ownerId": "xsaxsaxsas",
  "username": "sadsad"
}
  • holo

{
  "accessId": "xsaxsaxs",
  "accessKey": "xsaxsaxsa",
  "database": "xsaxsaxsa",
  "instanceId": "xsaxa",
  "tag": "aliyun"
}
  • kafka

{
  "instanceId": "xsax-cn-xsaxsa",
  "regionId": "cn-shanghai",
  "tag": "aliyun",
  "ownerId": "1212121212112"
}

Response parameters

Parameter Type Example Description
HttpStatusCode String 200

The HTTP status code.

Data Long 123

The data source ID.

RequestId String 0bc141151593763****

The request ID.

Success Boolean true

Indicates whether the request was successful.

Examples

Sample requests

http(s)://[Endpoint]/?Action=CreateDataSource
&ProjectId=1
&Name=abc
&Description=abc
&DataSourceType=rds
&SubType=mysql
&EnvType=1
&Content={"database":"dbname","instanceName":"instancename","password":"password","rdsOwnerId":"123","username":"username"}
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateDataSourceResponse>
    <HttpStatusCode>200</HttpStatusCode>
    <Data>123</Data>
    <RequestId>0bc141151593763****</RequestId>
    <Success>true</Success>
</CreateDataSourceResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "HttpStatusCode" : "200",
  "Data" : 123,
  "RequestId" : "0bc141151593763****",
  "Success" : true
}

Error codes

HTTP status code Error code Error message Description
400 Invalid.Tenant.ConnectionNotExists The connection does not exist. The specified data source does not exist.
400 Invalid.Tenant.ProjectNotExists The project does not exist. The specified workspace does not exist.
400 Invalid.Tenant.UserNotInProject The user is not in the project. The user is not added to the workspace.
400 ConnectionAlreadyExist The connection with envType %s and name %s already exists. The connection string already exists.
400 DataSource.CheckRamRoleFailure Failed to check the RAM role. AccountId %s. roleArn %s. The permissions on the data source failed to be verified.
400 DataSource.ConnectionStrProperty.PatternNotMatch The pattern value %s is invalid. The correct pattern is %s. The connection string properties of the data source do not match the specified rules.
400 Invalid.DataSource.DataSourceTypeNotSupport The dataSourceType %s and subType %s are not supported. The data source type is not supported.
400 MissingParam.ConnectionStr.Property You must specify property %s required by the data source connection string. The required properties of the connection string of the data source are not specified.
400 Invalid.DataSource.DataSourceTypeNotExist The data source type %s does not exist. The specified data source type does not exist.
403 Invalid.Tenant.UserIsNotProjectOwnerOrAdmin The user is not a project administrator or owner. The user is not the workspace owner or administrator.
403 Invalid.Tenant.UserNotInTenant The user is not in tenant. The user does not belong to the tenant.

For a list of error codes, see Service error codes.