Verbindungsprofile verwalten

Auf dieser Seite erfahren Sie, wie Sie die Datastream API für folgende Aufgaben verwenden:

  • Verbindungsprofile für eine Oracle-Quelldatenbank, eine MySQL-Quelldatenbank, eine PostgreSQL-Quelldatenbank, eine Salesforce-Quellorganisation, ein BigQuery-Ziel und ein Cloud Storage-Ziel erstellen
  • Informationen zu Verbindungsprofilen abrufen, aktualisieren und löschen
  • Struktur der Quell- oder Zielverbindungsprofile ermitteln

Sie können die Datastream API auf zwei Arten verwenden. Sie können REST API-Aufrufe ausführen oder die Google Cloud CLI verwenden.

Allgemeine Informationen zur Verwendung von gcloud für die Verwaltung von Datastream-Verbindungsprofilen finden Sie in der Google Cloud SDK-Dokumentation.

Erstellen Sie ein Verbindungsprofil für eine Oracle-Quelldatenbank.

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Oracle-Datenbank und gibt als Verbindungsmethode die Verwendung statischer IP-Adressen (IP-Zulassungsliste) an.

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": {}
}

Beispiel:

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": {}
}

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Oracle-Datenbank und gibt die Verbindungsmethode als private Verbindung (VPC-Peering) an.

Diese Methode stellt eine sichere Verbindung zwischen Datastream und der Quelldatenbank her (intern in Google Cloudoder mit externen Quellen, die über VPN oder Interconnect verbunden sind). Diese Kommunikation erfolgt über eine VPC-Peering-Verbindung.

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]"
  }
}

Beispiel:

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"
  }
}

Nachdem das Verbindungsprofil erstellt wurde, können Sie mit der Methode connectionProfiles/get Informationen dazu aufrufen. Ihre Ausgabe sieht in etwa so aus:

{
  "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"
  }
}

Weitere Informationen zur Verwendung von gcloud zum Erstellen eines Verbindungsprofils für eine Oracle-Quelldatenbank finden Sie hier.

Verbindungsprofil für eine MySQL-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zur Erstellung eines Verbindungsprofils für eine MySQL-Datenbank und gibt als Verbindungsmethode die Verwendung statischer IP-Adressen (IP-Zulassungsliste) an.

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": {}
}

Beispiel:

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": {}
}

Weitere Informationen zum Erstellen eines Verbindungsprofils für eine MySQL-Quelldatenbank mit gcloud finden Sie hier.

Verbindungsprofil für eine PostgreSQL-Quellendatenbank erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine PostgreSQL-Datenbank.

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": {}
}

Beispiel:

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": {}
}

Weitere Informationen zur Verwendung von gcloud zum Erstellen von Verbindungsprofilen finden Sie hier.

Verbindungsprofil für eine SQL Server-Quelldatenbank erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine SQL Server-Datenbank und gibt als Verbindungsmethode die Verwendung statischer IP-Adressen (IP-Zulassungsliste) an.

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": {}
}

Beispiel:

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": {}
}

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für eine Salesforce-Quelle erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Salesforce-Quell-Instanz mit einem Nutzernamen und einem Passwort als Authentifizierungsmethode.

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "salesforceProfile": {
    "domain": "DOMAIN_NAME",
    "userCredentials": {
      "username": "USERNAME",
      "password": "PASSWORD",
      "securitytoken": "SECURITY_TOKEN"
    }
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=saleforce-cp
{
  "displayName": "My Salesforce connection profile",
  "salesforceProfile": {
    "domain": "domain.my.salesforce.com",
    "userCredentials": {
      "username": "mySalesforceUser",
      "password": "12345",
      "securitytoken": "C08120F510542FFB1C3640F57AF19E2D5D700556A25F7D665C3B428407709D8C"
    }
  }
}
  

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für eine Salesforce-Quell-Instanz mit OAuth 2.0-Clientanmeldedaten als Authentifizierungsmethode.

POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/
LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID
{
  "displayName": "CONNECTION_PROFILE_NAME",
  "salesforceProfile": {
    "domain": "DOMAIN_NAME",
    "oauth2ClientCredentials": {
      "clientId": "CLIENT_ID",
      "clientSecret": "CLIENT_SECRET"
    }
  }
}

Beispiel:

POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/
us-central1/connectionProfiles?connectionProfileId=saleforce-cp
{
  "displayName": "My Salesforce connection profile",
  "salesforceProfile": {
    "domain": "domain.my.salesforce.com",
    "oauth2ClientCredentials": {
      "clientId": "myClientId",
      "clientSecret": "projects/myProject/secrets/sf-client-secret"
    }
  }
}
  

Weitere Informationen zum Erstellen von Verbindungsprofilen mit gcloud finden Sie in der Google Cloud SDK-Dokumentation.

Verbindungsprofil für ein BigQuery-Ziel erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für ein BigQuery-Ziel.

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

Beispiel:

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

Weitere Informationen zur Verwendung von gcloud zum Erstellen von Verbindungsprofilen finden Sie hier.

Verbindungsprofil für ein Cloud Storage-Ziel erstellen

Der folgende Code zeigt eine Anfrage zum Erstellen eines Verbindungsprofils für einen Cloud Storage-Bucket. Da sich Cloud Storage im selben Netzwerk wie Datastream befindet, ist keine spezielle Verbindung erforderlich. Daher ist keine Verbindungsmethode angegeben.

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"
  }
}

Beispiel:

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"
  }
}

Weitere Informationen zum Erstellen eines Verbindungsprofils für Cloud Storage mit gcloud finden Sie in der Cloud SDK-Dokumentation.

Informationen zu einem Verbindungsprofil abrufen

Der folgende Code zeigt eine Anfrage zum Abrufen von Informationen zu einem Verbindungsprofil für eine Oracle-Quelldatenbank, eine MySQL-Quelldatenbank, ein BigQuery-Ziel oder ein Cloud Storage-Ziel, das erstellt wurde.

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

Beispiel:

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

Weitere Informationen zur Verwendung von gcloud zum Abrufen von Informationen zu einem Verbindungsprofil finden Sie hier.

Verbindungsprofile auflisten

Der folgende Code zeigt eine Anfrage zum Abrufen von Informationen zu allen Verbindungsprofilen.

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

Weitere Informationen zur Verwendung von gcloud zum Abrufen von Informationen zu allen Verbindungsprofilen finden Sie hier.

Verbindungsprofil aktualisieren

Der folgende Code zeigt eine Anfrage zum Ändern des Nutzernamens und des Passworts eines vorhandenen Verbindungsprofils für eine Quelldatenbank.

Bei Verwendung des Parameters updateMask in der Anfrage müssen nur die von Ihnen angegebenen Felder im Text der Anfrage enthalten sein (in diesem Beispiel die Felder username und password, dargestellt durch die Flags oracle_profile.username bzw. oracle_profile.password).

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"
  }
}

Beispiel:

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"
  }
}

Der folgende Code zeigt eine Anfrage zum Ändern der Konfiguration einer privaten Verbindung, die einem Verbindungsprofil zugewiesen ist. Dieses Verbindungsprofil verwendet die Netzwerkverbindungsmethode "VPC-Peering".

In diesem Beispiel weisen Sie dem Verbindungsprofil die Konfiguration new_private_connection zu.

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

Beispiel:

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

Weitere Informationen zur Verwendung von gcloud zum Aktualisieren Ihres Verbindungsprofils finden Sie hier.

Verbindungsprofil löschen

Der folgende Code zeigt eine Anfrage zum Löschen eines Verbindungsprofils. Nachdem das Verbindungsprofil gelöscht wurde, schlagen alle Streams fehl, die es verwenden.

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

Beispiel:

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

Weitere Informationen zur Verwendung von gcloud zum Löschen eines Verbindungsprofils finden Sie hier.

Struktur einer Quelldatenbank ermitteln

Mit der discoverConnectionProfile API können Sie die Liste der Entitäten (z. B. Schemas und Tabellen) aus einer Quelle sowie die mit den Entitäten verknüpften Metadaten abrufen.

Die API kann als Parameter entweder eine ID eines bestehenden Verbindungsprofils oder eine vollständige Objektdefinition des Verbindungsprofils erhalten. Die Funktion kann eine einzelne Ebene (z. B. alle Schemas in einer Datenbank oder alle Tabellen in einem Schema) oder alle Entitäten rekursiv (z. B. Schemas, Tabellen und Spalten) zurückgeben.

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

Beispiel:

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

Weitere Informationen zur Struktur Ihrer Quelldatenbank mit gcloud finden Sie hier.

Nächste Schritte