בדף הזה מוסבר איך משתמשים ב-Datastream API כדי:
- יצירת פרופילי חיבור למסד נתונים של Oracle כמקור, למסד נתונים של MySQL כמקור, למסד נתונים של PostgreSQL כמקור, לארגון Salesforce כמקור, ליעד BigQuery וליעד Cloud Storage
- אחזור מידע על פרופילי חיבור, עדכון ומחיקה שלהם
- איך בודקים את המבנה של פרופילי חיבור למקור או ליעד
יש שתי דרכים להשתמש ב-Datastream API. אפשר לבצע קריאות ל-API בארכיטקטורת REST או להשתמש ב-Google Cloud CLI (CLI).
למידע כללי על שימוש ב-gcloud לניהול פרופילים של חיבורים ל-Datastream, אפשר ללחוץ על מסמכי Google Cloud SDK.
יצירת פרופיל חיבור למסד נתונים של Oracle כמקור
בדוגמת הקוד הבאה מוצגת בקשה ליצירת פרופיל חיבור למסד נתונים של Oracle באמצעות סוד ושיטת הקישוריות של רשימת היתרים של כתובות 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", "databaseService": "DATABASE" }, "secretManagerStoredPassword": "SECRET_MANAGER_RESOURCE", "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", "databaseService": "ORCL", }, "secretManagerStoredPassword": "projects/myProjectId/secrets/mySecret/versions/latest", "staticServiceIpConnectivity": {} }
בדוגמת הקוד הבאה מוצגת בקשה ליצירת פרופיל חיבור למסד נתונים של Oracle, ומוגדרת שיטת החיבור כחיבור פרטי (קישור בין רשתות VPC שכנות).
בשיטה הזו נוצר חיבור מאובטח בין Datastream לבין מסד הנתונים של המקור (באופן פנימי ב- Google Cloud, או עם מקורות חיצוניים שמחוברים דרך VPN או Interconnect). התקשורת הזו מתבצעת דרך חיבור של קישור בין רשתות שכנות (peering) של 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 כמקור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור למסד נתונים של 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 כמקור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור למסד נתונים של 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 ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור למסד נתונים של SQL Server כמקור
בדוגמת הקוד הבאה מוצגת בקשה ליצירת פרופיל חיבור למסד נתונים של SQL Server, ומוגדרת שיטת הקישוריות לשימוש בכתובות 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": {} }
gcloud
מידע נוסף על שימוש ב-gcloud ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור למקור Salesforce
בדוגמת הקוד הבאה מוצגת בקשה ליצירת פרופיל חיבור למופע של מקור Salesforce באמצעות שם משתמש וסיסמה כשיטת האימות.
REST
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" } } }
לדוגמה:
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" } } }
gcloud
מידע נוסף על שימוש ב-gcloud ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
בדוגמה הבאה מוצגת בקשה ליצירת פרופיל חיבור למופע של מקור Salesforce באמצעות פרטי כניסה של לקוח OAuth 2.0 כשיטת האימות.
REST
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" } } }
לדוגמה:
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" } } }
gcloud
מידע נוסף על שימוש ב-gcloud ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור למקור MongoDB
בדוגמה הבאה מוצגת בקשה ליצירת פרופיל חיבור למופע MongoDB של מקור באמצעות פורמט מחרוזת חיבור SRV.
REST
POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/ LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID { "displayName": "CONNECTION_PROFILE_NAME", "mongodbProfile": { "hostAddresses": [ { "hostname": "HOST_URI" } ], "username": "USERNAME", "password": "PASSWORD", "srvConnectionFormat": {} }, "staticServiceIpConnectivity": {} }
לדוגמה:
POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/ us-central1/connectionProfiles?connectionProfileId=mongodb-cp { "displayName": "mongodb-cp", "mongodbProfile": { "hostAddresses": [ { "hostname": "cluster85828.ebeek.mongodb.net" } ], "username": "Cluster85828", "password": "password", "srvConnectionFormat": {} }, "staticServiceIpConnectivity": {} }
gcloud
מידע נוסף על שימוש ב-gcloud ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
בדוגמת הקוד הבאה מוצגת בקשה ליצירת פרופיל חיבור למופע MongoDB של מקור באמצעות פורמט סטנדרטי של מחרוזת חיבור.
REST
POST https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/ LOCATION/connectionProfiles?connectionProfileId=CONNECTION_PROFILE_ID { "displayName": "CONNECTION_PROFILE_NAME", "mongodbProfile": { "hostAddresses": [ { "hostname": "HOST_IP", "port": "PORT_NUMBER" } ], "replica_set": "SET_ID", "username": "USERNAME", "password": "PASSWORD", "standardConnectionFormat": { "directConnection": false } }, "staticServiceIpConnectivity": {} }
לדוגמה:
POST https://datastream.googleapis.com/v1/projects/myProjectId/locations/ us-central1/connectionProfiles?connectionProfileId=mongodb-cp { "displayName": "mongodb-cp", "mongodbProfile": { "hostAddresses": [ { "hostname": "34.19.10.194", "port": "27017" } ], "replicaset": "rs0" "username": "root", "password": "password", "standardConnectionFormat": { "directConnection": false } }, "staticServiceIpConnectivity": {} }
gcloud
מידע נוסף על שימוש ב-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 ליצירת פרופילי חיבור זמין במסמכי התיעוד של Google Cloud SDK.
יצירת פרופיל חיבור ליעד ב-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 כדי לאחזר מידע על פרופיל החיבור זמין במסמכי התיעוד של Google Cloud SDK.
הצגת רשימה של פרופילי קישור
בדוגמה הבאה אפשר לראות בקשה לאחזור מידע על כל פרופילי החיבור.
REST
GET https://datastream.googleapis.com/v1/projects/PROJECT_ID/locations/ LOCATION/connectionProfiles
gcloud
מידע נוסף על שימוש ב-gcloud כדי לאחזר מידע על כל פרופילי החיבור זמין במסמכי Google Cloud SDK.
עדכון פרופיל קישור
בדוגמה הבאה מוצגת בקשה לשינוי שם המשתמש והסיסמה של פרופיל חיבור קיים למסד נתונים של מקור.
אם משתמשים בפרמטר updateMask בבקשה, רק השדות שמציינים צריכים להיכלל בגוף הבקשה (בדוגמה הזו, השדות username ו-password, שמיוצגים על ידי הדגלים oracle_profile.username ו-oracle_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" } }
הקוד הבא מציג בקשה לשינוי ההגדרה של קישוריות פרטית שהוקצתה לפרופיל חיבור. פרופיל החיבור הזה משתמש בשיטת הקישור בין רשתות שכנות (peering) של 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 כדי לעדכן את פרופיל החיבור זמין במסמכי התיעוד של Google Cloud SDK.
מחיקת פרופיל קישור
הקוד הבא מראה בקשה למחיקת פרופיל חיבור. אחרי שמוחקים את פרופיל החיבור, כל הסטרימינג שמשתמש בו ייכשל.
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 כדי למחוק את פרופיל החיבור זמין במסמכי Google Cloud SDK.
הבנת המבנה של מסד נתונים של מקור
אפשר להשתמש ב-discoverConnectionProfile API כדי לאחזר את רשימת הישויות (לדוגמה, סכימות וטבלאות) ממקור, ואת המטא-נתונים שמשויכים לישויות.
ה-API יכול לקבל כפרמטר מזהה של פרופיל חיבור קיים או הגדרה מלאה של אובייקט פרופיל חיבור. הפונקציה יכולה להחזיר רמה אחת (לדוגמה, כל הסכימות במסד נתונים או כל הטבלאות בסכימה), או את כל הישויות באופן רקורסיבי (לדוגמה, סכימות, טבלאות ועמודות).
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 כדי לגלות את המבנה של מסד הנתונים של המקור זמין במאמרי העזרה של Google Cloud SDK.
המאמרים הבאים
- איך משתמשים ב-Datastream API לניהול הזרמים
- איך משתמשים ב-Datastream API כדי לנהל הגדרות של קישוריות פרטית
- מידע נוסף על השימוש ב-Datastream API זמין במאמרי העזרה.