Help Center/ Data Lake Insight/ API Reference/ Getting Started/ Creating and Using a Datasource Connection
Updated on 2024-11-04 GMT+08:00

Creating and Using a Datasource Connection

Scenario

This section describes how to create an enhanced datasource connection using an API.

Notes and Constraints

  • It takes 6 to 10 minutes to start a job using a new queue for the first time.
  • Before creating an enhanced datasource connection, you need to obtain the ID of the VPC and the network ID of the subnet where the service is located.

Involved APIs

Procedure

  1. Create an elastic resource pool named elastic_pool_dli.
    • API

      URI format: POST /v3/{project_id}/elastic-resource-pools

    • Example request
      • Description: Create an elastic resource pool named elastic_pool_dli in the project whose ID is 48cc2c48765f481480c7db940d6409d1.
      • Example URL: POST https://{endpoint}/v3/48cc2c48765f481480c7db940d6409d1/elastic-resource-pools
      • Body:
        {
          "elastic_resource_pool_name" : "elastic_pool_dli",
          "description" : "test",
          "cidr_in_vpc" : "172.16.0.0/14",
          "charging_mode" : "1",
          "max_cu" : 64,
          "min_cu" : 64
        }
    • Example response
      {
        "is_success": true,
        "message": ""
      }
  2. Create a queue named queue1 in the elastic resource pool.
    • API

      URI format: POST /v1.0/{project_id}/queues

    • Example request
      • Description: Create an elastic resource pool named queue1 in the project whose ID is 48cc2c48765f481480c7db940d6409d1.
      • Example URL: POST https://{endpoint}/v1.0/48cc2c48765f481480c7db940d6409d1/queues
      • Body:
        {
            "queue_name": "queue1",
            "queue_type": "sql",
            "description": "test",
            "cu_count": 16,
            "enterprise_project_id": "elastic_pool_dli"
        }
    • Example response
      {
        "is_success": true,
        "message": ""
      }
  3. Create an enhanced datasource connection.
    • API

      URI format: POST /v2.0/{project_id}/datasource/enhanced-connections

    • Example request
      • Description: Create an enhanced datasource connection named test1 in project 48cc2c48765f481480c7db940d6409d1.
      • Example URL: POST https://{endpoint}/v2.0/48cc2c48765f481480c7db940d6409d1/datasource/enhanced-connections
      • Body:
        {
          "name": "test1",
          "dest_vpc_id": "22094d8f-c310-4621-913d-4c4d655d8495",
          "dest_network_id": "78f2562a-36e4-4b39-95b9-f5aab22e1281",
          "elastic_resource_pools": "elastic_pool_dli",
          "hosts": [
            {
              "ip":"192.168.0.1",
              "name":"ecs-97f8-0001"
            },
            {
              "ip":"192.168.0.2", 
              "name":"ecs-97f8-0002"
            }
          ]
        }
    • Example response
      {
        "is_success": true,
        "message": "",
        "connection_id": "2a620c33-5609-40c9-affd-2b6453071b0f"
      }
  4. (Optional) If no queue is bound when you create an enhanced datasource connection, you can use the Binding a Queue API to bind a queue.
  5. Verify that the enhanced datasource connection is created successfully.
    • API

      URI format: GET /v2.0/{project_id}/datasource/enhanced-connections/{connection_id}

    • Example request
      • Description: Query an enhanced datasource connection whose ID is 2a620c33-5609-40c9-affd-2b6453071b0f in project 48cc2c48765f481480c7db940d6409d1.
      • Example URL: GET https://{endpoint}/v2.0/48cc2c48765f481480c7db940d6409d1/datasource/enhanced-connections/2a620c33-5609-40c9-affd-2b6453071b0f
      • Body:
        {}
    • Example response
      {
        "is_success": true,
        "message": "",
        "name": "test1",
        "id": "2a620c33-5609-40c9-affd-2b6453071b0f",
        "elastic_resource_pools": [
          {
            "status": "ACTIVE",
            "name": "elastic_pool_dli",
            "peer_id": "2a620c33-5609-40c9-affd-2b6453071b0f",
            "err_msg": "",
            "update_time": 1566889577861
          }
        ],
        "dest_vpc_id": "22094d8f-c310-4621-913d-4c4d655d8495",
        "dest_network_id": "78f2562a-36e4-4b39-95b9-f5aab22e1281",
        "isPrivis": true,
        "create_time": 1566888011125,
        "status": "ACTIVE",
        "hosts": [
          {
            "ip":"192.168.0.1",
            "name":"ecs-97f8-0001"
          },
          {
            "ip":"192.168.0.2", 
            "name":"ecs-97f8-0002"
          }
        ]
      }