연결 프로필 관리

개요

이 섹션에서는 다음을 위해 Datastream API를 사용하는 방법을 알아봅니다.

  • 소스 Oracle 데이터베이스, 소스 MySQL 데이터베이스, 소스 PostgreSQL 데이터베이스, BigQuery 대상, Cloud Storage 대상 위치의 연결 프로필 만들기
  • 연결 프로필에 대한 정보 검색, 업데이트, 삭제
  • 소스 또는 대상 연결 프로필의 구조 탐색

Datastream API는 두 가지 방법으로 사용될 수 있습니다. REST API 호출을 수행하거나 Google Cloud CLI(CLI)를 사용할 수 있습니다.

gcloud를 사용한 Datastream 연결 프로필 관리에 대한 자세한 내용은 Google Cloud SDK 문서를 클릭합니다.

소스 Oracle 데이터베이스의 연결 프로필 만들기

다음 코드는 Oracle 데이터베이스의 연결 프로필을 만들기 위한 요청을 보여주고 고정 IP 주소(IP 허용 목록)를 사용하는 연결 방법을 지정합니다.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "oracleProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "databaseService": "DATABASE"
  },
  "staticServiceIpConnectivity": {}
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myOracleCP
{
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "username": "admin",
    "password": "12345"
    "databaseService": "ORCL",
  },
  "staticServiceIpConnectivity": {}
}

다음 코드는 Oracle 데이터베이스의 연결 프로필 생성 요청을 보여주고 연결 방법을 비공개 연결(VPC 피어링)로 지정합니다.

이 방법은 Datastream과 소스 데이터베이스(내부적으로 Google Cloud 내 또는 VPN 또는 상호 연결을 통해 연결된 외부 소스) 간에 보안 연결을 설정합니다. 이 통신은 VPC 피어링 연결을 통해 이루어집니다.

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "oracleProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "databaseService": "DATABASE"
  },
  "privateConnectivity": {
    "privateConnection": "https://datastream.googleapis.com/v1/projects/
    PROJECT_ID/locations/LOCATION/privateConnections/
    [private-connectivity-configuration-id]"
  }
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myOracleVPCPeeringCP
{
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "username": "admin",
    "password": "12345"
    "databaseService": "ORCL",
  },
    "privateConnectivity": {
      "privateConnection": "https://datastream.googleapis.com/v1/projects/
       myProjectId/locations/us-central1/privateConnections/myPrivateConnection"
  }
}

연결 프로필을 만든 후 connectionProfiles/get 메서드를 호출하여 관련 정보를 확인할 수 있습니다. 다음과 비슷한 출력이 표시됩니다.

{
  "name": "projects/projectId/location/us-central1/connectionProfiles/myOracleVPCPeeringCP",
  "createTime": "2019-12-22T16:17:37.159786963Z",
  "updateTime": "2019-12-22T16:17:37.159786963Z",
  "displayName": "my Oracle database",
  "oracleProfile": {
    "hostname": "1.2.3.4",
    "port": 1521,
    "databaseService": "ORCL",
    "username": "admin"
  },
  "privateConnectivity": {
    "privateConnection": "https://datastream.googleapis.com/v1/projects/
     myProjectId/locations/us-central1/privateConnections/myPrivateConnection"
  }
}

gcloud

gcloud를 사용하여 소스 Oracle 데이터베이스의 연결 프로필을 만드는 방법에 대한 자세한 내용은 여기를 클릭하세요.

소스 MySQL 데이터베이스의 연결 프로필 만들기

다음 코드는 MySQL 데이터베이스의 연결 프로필을 만드는 요청을 보여주고 고정 IP 주소(IP 허용 목록)를 사용하는 연결 방법을 지정합니다.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "mysqlProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD"
  },
  "staticServiceIpConnectivity": {}
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=mysql-cp
{
  "displayName": "my MySQL database",
  "mysqlProfile": {
    "hostname": "1.2.3.4",
    "port": 3306,
    "username": "root",
    "password": "12345"
  },
  "staticServiceIpConnectivity": {}
}

gcloud

gcloud를 사용하여 소스 MySQL 데이터베이스의 연결 프로필을 만드는 방법에 대한 자세한 내용은 여기를 클릭하세요.

소스 PostgreSQL 데이터베이스의 연결 프로필 만들기

다음 코드는 PostgreSQL 데이터베이스의 연결 프로필을 만드는 요청을 보여줍니다.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "postgresqlProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "database": "DATABASE"
  },
  "staticServiceIpConnectivity": {}
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=postgres-cp
{
  "displayName": "my PostgreSQL database",
  "postgresqlProfile": {
    "hostname": "1.2.3.4",
    "database": "postgres",
    "port": 5432,
    "username": "root",
    "password": "12345"
  },
  "staticServiceIpConnectivity": {}
}

gcloud

gcloud를 사용하여 연결 프로필을 만드는 방법에 대한 자세한 내용은 여기를 클릭하세요.

소스 SQL Server 데이터베이스의 연결 프로필 만들기

다음 코드는 SQL 서버 데이터베이스의 연결 프로필을 만드는 요청을 보여주고 고정 IP 주소(IP 허용 목록)를 사용하는 연결 방법을 지정합니다.

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "[connection-profile-display-name]",
  "sqlserverProfile": {
    "hostname": "HOST_ID_ADDRESS",
    "port": PORT,
    "username": "USERNAME",
    "password": "PASSWORD",
    "database": "DATABASE"
  },
  "staticServiceIpConnectivity": {}
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=sqlserver-cp
{
  "displayName": "my SQL Server database",
  "mysqlProfile": {
    "hostname": "1.2.3.4",
    "port": 1433,
    "username": "root",
    "password": "12345"
    "database": "database1"
  },
  "staticServiceIpConnectivity": {}
}

Google Cloud CLI

gcloud를 사용하여 연결 프로필을 만드는 방법에 대한 자세한 내용은 Google Cloud SDK 문서를 참조하세요.

BigQuery 대상의 연결 프로필 만들기

다음 코드는 BigQuery 대상의 연결 프로필을 만드는 요청을 보여줍니다.

REST

POST https://datastream.googleapis.com/v1/projects/[project-id/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "connection-profile-display-name",
  "bigqueryProfile":  {}
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myBigqueryCP
{
  "displayName": "my BigQuery destination",
  "bigqueryProfile": {}
}

gcloud

gcloud를 사용하여 연결 프로필을 만드는 방법에 대한 자세한 내용은 여기를 클릭하세요.

Cloud Storage 대상의 연결 프로필 만들기

다음 코드는 Cloud Storage 버킷의 연결 프로필을 만드는 요청을 보여줍니다. Cloud Storage는 Datastream과 동일한 네트워크에 있으므로 특별한 연결이 필요하지 않습니다. 따라서 연결 방법을 지정하지 않습니다.

REST

POST https://datastream.googleapis.com/v1/projects/[project-id/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "connection-profile-display-name",
  "gcsProfile": {
    "bucketName": "bucket-name",
    "rootPath": "prefix-inside-bucket"
  }
}

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=myGcsCP
{
  "displayName": "my Cloud Storage bucket",
  "gcsProfile": {
    "bucketName": "myBucket",
    "rootPath": "prefix-inside-bucket"
  }
}

gcloud

gcloud을 사용하여 Cloud Storage의 연결 프로필을 만드는 방법에 대한 자세한 내용은 Cloud SDK 문서를 참조하세요.

연결 프로필 정보 가져오기

다음 코드는 생성된 소스 Oracle 데이터베이스, 소스 MySQL 데이터베이스, BigQuery 대상 또는 Cloud Storage 대상의 연결 프로필 정보를 검색하는 요청을 보여줍니다.

REST

GET https://datastream.googleapis.com/v1/projects/project-id/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID

예를 들면 다음과 같습니다.

GET https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP

gcloud

gcloud를 사용하여 연결 프로필에 대한 정보를 검색하는 방법에 대한 자세한 내용은 여기를 클릭하세요.

연결 프로필 나열

다음 코드는 모든 연결 프로필에 대한 정보를 검색하는 요청을 보여줍니다.

REST

GET https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles

gcloud

gcloud를 사용하여 모든 연결 프로필에 대한 정보를 검색하는 방법에 대한 자세한 내용은 여기를 클릭하세요.

연결 프로필 업데이트

다음 코드는 소스 데이터베이스에 대한 기존 연결 프로필의 사용자 이름과 비밀번호를 변경하는 요청을 보여줍니다.

요청에서 updateMask 매개변수를 사용하여 사용자가 지정하는 필드만 요청 본문에 포함해야 합니다. 이 예시에서는 usernamepassword 필드이며 각각 oracle_profile.usernameoracle_profile.password 플래그로 표현됩니다.

REST

PATCH https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID?
updateMask=oracle_profile.username,oracle_profile.password
{
  "oracleProfile": {
    "username": "USERNAME",
    "password": "PASSWORD"
  }
}

예를 들면 다음과 같습니다.

PATCH https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP?
updateMask=oracle_profile.username,oracle_profile.password
{
  "oracleProfile": {
    "username": "username",
    "password": "password"
  }
}

다음 코드는 연결 프로필에 할당된 비공개 연결 구성을 변경하는 요청을 보여줍니다. 이 연결 프로필은 VPC 피어링 네트워크 연결 방법을 사용합니다.

이 예시에서는 연결 프로필에 new_private_connection 구성을 할당합니다.

PATCH -d {\"private_connectivity\":{\"private_connection_name\":\
"https://datastream.googleapis.com/v1/
projects/PROJECT_ID/locations/LOCATION/privateConnections/
new_private_connection\"}}" -H "Authorization: Bearer $TOKEN" -H
"Content-Type: application/json" https://datastream.googleapis.com/v1/
projects/PROJECT_ID/locations/LOCATION/connectionProfiles/
CONNECTION_PROFILE_ID?update_mask=private_connectivity.private_connection_name

예를 들면 다음과 같습니다.

PATCH -d {\"private_connectivity\":{\"private_connection_name\":\
"https://datastream.googleapis.com/v1/
projects/myProjectId/locations/us-central1/privateConnections/
new_private_connection\"}}" -H "Authorization: Bearer $TOKEN" -H
"Content-Type: application/json"
https://datastream.googleapis.com/v1/projects/
myProjectId/locations/us-central1/connectionProfiles/
myOracleVPCPeeringCP?update_mask=private_connectivity.private_connection_name

gcloud

gcloud를 사용하여 연결 프로필을 업데이트하는 방법에 대한 자세한 내용은 여기를 클릭하세요.

연결 프로필 삭제

다음 코드는 연결 프로필을 삭제하는 요청을 보여줍니다. 연결 프로필이 삭제되면 해당 프로필을 사용하는 모든 스트림이 실패합니다.

REST

DELETE https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles/CONNECTION_PROFILE_ID

예를 들면 다음과 같습니다.

DELETE https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles/myOracleCP

gcloud

gcloud를 사용하여 연결 프로필을 삭제하는 방법에 대한 자세한 내용은 여기를 클릭하세요.

소스 데이터베이스의 구조 탐색

discoverConnectionProfile API를 사용하여 소스에서 항목 목록(예: 스키마 및 테이블) 및 항목과 연결된 메타데이터를 검색합니다.

API는 기존 연결 프로필의 ID 또는 전체 연결 프로필 객체 정의를 매개변수로 수신할 수 있습니다. 이 함수는 단일 수준을 반환하거나(예: 데이터베이스의 모든 스키마 또는 스키마의 모든 테이블) 모든 항목을 재귀적으로 반환할 수 있습니다(예: 스키마, 테이블, 열).

REST

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles:discoverConnectionProfile?CONNECTION_PROFILE_ID

예를 들면 다음과 같습니다.

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles:discoverConnectionProfile?myOracleCP

gcloud

gcloud를 사용하여 소스 데이터베이스의 구조를 탐색하는 방법에 대한 자세한 내용은 여기를 클릭하세요.