演示部署
演示部署使用预定义的原始示例数据集提供简化的体验。它提供了一个端到端工作流,用于部署 Google Cloud Cortex Framework Dataform 流水线以进行编排,并使用抽样数据初始化相应的 BigQuery 数据集。运行 uv run cortex-demo 会为每个选定的源系统(sap 和 sfdc)创建原始、数据基础和数据产品数据集,在部署 SAP 时为 SAP 解决方案示例创建 cortex_demo_samples 数据集,并在预检期间创建 dataform_assertions 数据集(Dataform 会在流水线操作运行时使用断言视图填充该数据集)。
准备工作
在继续部署演示之前,请确保您已完成前提条件页面上列出的前提条件。
获取所需的 Identity and Access Management 角色
获取在目标 Google Cloud 项目中部署 Cortex Framework 内容所需的 Identity and Access Management (IAM) 权限。
目标项目的角色
如需获得部署 Cortex Framework 所需的权限,请让管理员向您授予目标项目的以下 IAM 角色:
- BigQuery Job User (
roles/bigquery.jobUser) - BigQuery Data Editor (
roles/bigquery.dataEditor) - Dataform Admin (
roles/dataform.admin) - Service Usage Consumer (
roles/serviceusage.serviceUsageConsumer)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
如需向用户授予请求的角色,请运行以下脚本:
# Grant BigQuery JobUser to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
--role="roles/bigquery.jobUser"
# Grant BigQuery DataEditor to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
--role="roles/bigquery.dataEditor"
# Grant Dataform Admin to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
--role="roles/dataform.admin"
# Grant Service Usage Consumer to the user
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_EMAIL" \
--role="roles/serviceusage.serviceUsageConsumer"
替换以下内容:
PROJECT_ID:您的目标 Google Cloud 项目 ID,例如:my-cortex-demo-project。USER_EMAIL:部署用户的邮箱,例如:analyst@example.com。
可选:服务账号 IAM 角色
只有在您传递 --create-workflow-configs(需要 --service-account)以创建一个版本配置、五个预定的 Dataform 工作流配置(hourly、daily、weekly、monthly 和 yearly,采用世界协调时间 [UTC])以及一个即时按需工作流运行时,才需要以下角色。为服务账号提供 --create-workflow-configs 可通过设置数据流水线的调度来简化部署后任务。您还可以使用三点状菜单在版本和时间安排标签页上手动触发 Dataform 中的任何工作流配置。
如需获得部署 Cortex Framework 演示版所需的权限,请让管理员向您授予自定义 Dataform 服务账号的以下 IAM 角色:
- Service Account Token Creator (
roles/iam.serviceAccountTokenCreator) - Service Account User (
roles/iam.serviceAccountUser)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
如需创建服务账号并授予必要的角色,请运行以下脚本:
export PROJECT_ID=PROJECT_ID
export USER_EMAIL=USER_EMAIL
export SERVICE_ACCOUNT_NAME=cortex-dataform
# Create the service account
gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME \
--description="Service account for Cortex Dataform execution" \
--display-name="Cortex Dataform Service Account" \
--project=$PROJECT_ID
# Wait for the service account to propagate (IAM eventual consistency)
sleep 10
# Grant BigQuery DataEditor to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID." \
--role="roles/bigquery.dataEditor"
# Grant BigQuery jobUser to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID." \
--role="roles/bigquery.jobUser"
# Grant Dataform Editor to the service account
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID." \
--role="roles/dataform.editor"
# Grant the user Service Account Token Creator and Service Account User roles on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
$SERVICE_ACCOUNT_NAME@$PROJECT_ID. \
--member="user:$USER_EMAIL" \
--role="roles/iam.serviceAccountTokenCreator" \
--project=$PROJECT_ID
gcloud iam service-accounts add-iam-policy-binding \
$SERVICE_ACCOUNT_NAME@$PROJECT_ID. \
--member="user:$USER_EMAIL" \
--role="roles/iam.serviceAccountUser" \
--project=$PROJECT_ID
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")
# Note: If the following commands fail with a "serviceAccount:service-$PROJECT_NUMBER@..."
# not found error, the default Dataform service agent has not yet been provisioned
# for the project. Run these commands after the initial `uv run cortex-*` invocation.
# Grant the Dataform Service Account the Token Creator role on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
$SERVICE_ACCOUNT_NAME@$PROJECT_ID. \
--member="serviceAccount:service-$PROJECT_NUMBER@gcp-sa-dataform." \
--role="roles/iam.serviceAccountTokenCreator" \
--project=$PROJECT_ID
# Grant the Dataform Service Account the Service Account User role on the Cortex service account
gcloud iam service-accounts add-iam-policy-binding \
$SERVICE_ACCOUNT_NAME@$PROJECT_ID. \
--member="serviceAccount:service-$PROJECT_NUMBER@gcp-sa-dataform." \
--role="roles/iam.serviceAccountUser" \
--project=$PROJECT_ID
替换以下内容:
PROJECT_ID:您的目标 Google Cloud 项目 ID,例如:my-cortex-demo-project。USER_EMAIL:部署用户的邮箱,例如:analyst@example.com。
部署
请按照以下步骤创建虚拟 Python 环境、同步依赖项并触发数据流水线。请记得使用 Cortex Framework uv 脚本构建数据资产并将其推送到 Google Cloud 项目,从而将本地配置转换为可伸缩的实时数据架构。如需了解详情,请参阅前提条件部分中的 uv 安装。
执行演示部署
运行以下命令以触发部署。此过程会执行以下操作:
- 确认已满足所有前提条件。
- 将示例数据加载到 BigQuery 数据集中,作为原始层以供演示。
- 构建 Dataform 流水线,以便通过 Cortex Framework 数据层处理抽样数据。
- 创建 Dataform 代码库和工作区,然后将编译后的工件与代码库同步。
- 可选:当您将
--create-workflow-configs与--service-account一起传递时,系统会提交并推送工作区,创建一个发布配置 (<repository_name>-release),创建五个预定的 Dataform 工作流配置(hourly、daily、weekly、monthly和yearly,采用世界协调时间 [UTC]),并立即触发按需运行。
运行 uv run cortex-demo 会收集匿名遥测数据(请参阅遥测以选择停用)。运行 uv run cortex-demo -h 或参阅 CLI 演示部署,了解所有可用标志。
对于使用默认值的演示部署(由于 --sources 默认为 all,--sap-version 默认为 s4,因此会同时部署 SAP S/4HANA 和 Salesforce 示例数据集),请运行以下命令(为 SAP ECC 传递 --sap-version ecc):
uv run cortex-demo --project-id=PROJECT_ID
替换以下内容:
PROJECT_ID:您的目标 Google Cloud 项目 ID,例如:my-cortex-demo-project。
如需仅部署 Salesforce 演示数据集和数据产品,请传递 --sources sfdc:
uv run cortex-demo --project-id=PROJECT_ID --sources sfdc
替换以下内容:
PROJECT_ID:您的目标 Google Cloud 项目 ID,例如:my-cortex-demo-project。
如需使用服务账号、五个预定工作流配置和即时按需运行进行演示部署,请运行以下命令:
export PROJECT_ID=PROJECT_ID
export SERVICE_ACCOUNT_NAME=cortex-dataform
uv run cortex-demo --project-id=$PROJECT_ID \
--service-account="$SERVICE_ACCOUNT_NAME@$PROJECT_ID." \
--create-workflow-configs
替换以下内容:
PROJECT_ID:您的目标 Google Cloud 项目 ID,例如:my-cortex-demo-project。
验证
部署完成后,验证并运行演示流水线:
- 打开 Dataform,选择
cortex-framework-demo代码库,然后打开demo工作区(点击已编译的图表以检查已编译的依赖项图表)。 使用以下任一选项执行 Dataform 操作:
- 选项 A - 手动运行(默认部署):在
demo工作区中,依次点击开始执行 > 执行操作 > 所有操作 > 开始执行,然后在工作流执行日志标签页中监控进度。 - 选项 B - 使用工作流时间表运行(使用
--create-workflow-configs部署时):在部署期间,系统会自动启动初始运行。如需手动触发另一次运行,请打开版本和时间安排,点击工作流配置旁边的三点状菜单,选择立即开始,然后在工作流执行日志标签页中监控进度。
- 选项 A - 手动运行(默认部署):在
前往 BigQuery 控制台,然后点击数据集以查看创建的数据集并验证其架构和示例行。根据您选择的
--sources标志,创建的数据集包括:cortex_demo_sap_s4_raw:示例原始 SAP 表(当--sources为all或sap且包含--sap-version s4时)。cortex_demo_sap_s4_data_foundation:经过 CDC 处理的 SAP 基础表。cortex_demo_sfdc_raw:原始 Salesforce SObject 表示例(当--sources为all或sfdc时)。cortex_demo_sfdc_data_foundation:一致的 Salesforce 数据基础表。cortex_demo_data_product:部署了 SAP 和 Salesforce 数据产品以供使用。cortex_demo_samples:适用于 SAP 的示例消费数据产品。dataform_assertions:已编译的 Dataform 数据质量断言视图(uv run cortex-demo会在部署预检期间创建数据集,Dataform 会在流水线操作运行时使用断言视图填充该数据集)。
可选:在 Knowledge Catalog 中注册演示数据产品
运行演示版 Dataform 流水线操作并验证演示版数据产品表是否已在 BigQuery 中具体化(在 cortex_demo_data_product 中,以及在部署 SAP 时在 cortex_demo_samples 中)后,您可以使用 uv run cortex-create-kc-data-products 在 Knowledge Catalog 中注册演示版数据产品。
由于 uv run cortex-demo 会在内存中构建其配置,而不会写入 config/config.yaml 文件,因此请完成以下步骤,以启用 Dataplex API、授予所需的 IAM 角色、创建演示配置文件并注册演示数据产品。
启用 Dataplex API 并授予所需角色
在目标Google Cloud 项目中启用 Dataplex API (dataplex.googleapis.com):
gcloud services enable dataplex.googleapis.com \
--project=PROJECT_ID
将 PROJECT_ID 替换为您的目标 Google Cloud项目 ID,例如 my-cortex-demo-project。
如需获得在 Knowledge Catalog 中注册和清理演示数据产品所需的权限,请让管理员向您授予目标项目的以下 IAM 角色:
- Dataplex Editor (
roles/dataplex.editor) - Dataplex Data Products Editor (
roles/dataplex.dataProductsEditor) - Dataplex Entry and EntryLink Owner (
roles/dataplex.entryOwner) - BigQuery Metadata Viewer (
roles/bigquery.metadataViewer) - BigQuery Data Viewer (
roles/bigquery.dataViewer)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
向运行 uv run cortex-create-kc-data-products 的主账号授予以下角色:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/dataplex.editor"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/dataplex.dataProductsEditor"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/dataplex.entryOwner"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/bigquery.metadataViewer"
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:USER_EMAIL" \
--role="roles/bigquery.dataViewer"
替换以下内容:
PROJECT_ID:您注册演示版 Knowledge Catalog 数据产品的 Google Cloud 项目 ID(或托管演示版数据集的项目 ID),例如my-cortex-demo-project。USER_EMAIL:运行uv run cortex-create-kc-data-products的主账号的邮箱,例如dana@example.com。
创建演示配置文件
根据 config/config.yaml.example 模板创建演示配置文件 (config/config-demo.yaml),以便 uv run cortex-create-kc-data-products 可以在不覆盖现有 config/config.yaml 文件的情况下发现演示数据集。更新 config/config-demo.yaml 中的项目 ID 属性、BigQuery 数据集 ID 以及 Dataform 代码库和工作区设置,使其与 uv run cortex-demo 的默认参数一致。
展开以下部分,查看复制模板和修改每个必填部分的分步说明:
创建和更新 config/config-demo.yaml 文件,以设置默认演示参数
在克隆的 Cortex Framework 代码库的根目录中,按照以下步骤创建 config/config-demo.yaml,并使其与 uv run cortex-demo 使用的默认参数(--sources all、--sap-version s4、--bigquery-location US、--dataform-region us-central1、--repository-name cortex-framework-demo 和 --workspace-name demo)保持一致。
-
将示例配置模板复制到专用演示文件:
cp config/config.yaml.example config/config-demo.yaml
-
打开
config/config-demo.yaml,并将所有活跃项目 ID 属性更新为目标 Google Cloud 项目 ID(PROJECT_ID,与--project-id标志匹配):buildEnvironment.buildProjectId:将YOUR_BUILD_PROJECT_ID替换为PROJECT_ID。data.datasets[].projectId:将YOUR_SOURCE_PROJECT_ID(在sap_raw和sfdc_raw上)以及YOUR_TARGET_PROJECT_ID(在sap_foundation、sfdc_foundation、product_target、samples_target和cortex_v6_compatibility_target上)替换为PROJECT_ID。deployment.targets[].targetSettings.repositoryProjectId:将YOUR_REPO_PROJECT_ID替换为PROJECT_ID。
除非您启用这些外部目录,否则请勿更改已停用的
data.modules.catalogs条目 (enabled: false) 下的占位符项目 ID。buildEnvironment: buildProjectId: PROJECT_ID
将
PROJECT_ID替换为您的目标 Google Cloud 项目 ID,例如my-cortex-demo-project。 -
在
data.datasets下,将datasetId值从模板默认值更新为与默认uv run cortex-demo数据集匹配:sap_raw:将cortex_sap_raw更改为cortex_demo_sap_s4_raw(默认值为--source-sap-raw-dataset-id)。sap_foundation:将cortex7_sap_data_foundation更改为cortex_demo_sap_s4_data_foundation(默认值为--target-sap-foundation-dataset-id)。sfdc_raw:将cortex_sfdc_raw更改为cortex_demo_sfdc_raw(默认值为--source-sfdc-raw-dataset-id)。sfdc_foundation:将cortex7_sfdc_data_foundation更改为cortex_demo_sfdc_data_foundation(默认值为--target-sfdc-foundation-dataset-id)。product_target:将cortex7_data_products更改为cortex_demo_data_product(默认值为--target-dp-dataset-id;请注意单数product)。samples_target:将cortex7_samples更改为cortex_demo_samples(默认值为--target-samples-dataset-id)。
在
data.datasets中保留cortex_v6_compatibility_target条目,以便对已停用的兼容性模块成功进行配置验证(所有cortex_v6_compatibility条目仍为enabled: false和syncToKc: false):datasets: - id: sap_raw projectId: PROJECT_ID datasetId: cortex_demo_sap_s4_raw - id: sap_foundation projectId: PROJECT_ID datasetId: cortex_demo_sap_s4_data_foundation - id: sfdc_raw projectId: PROJECT_ID datasetId: cortex_demo_sfdc_raw - id: sfdc_foundation projectId: PROJECT_ID datasetId: cortex_demo_sfdc_data_foundation - id: product_target projectId: PROJECT_ID datasetId: cortex_demo_data_product - id: samples_target projectId: PROJECT_ID datasetId: cortex_demo_samples - id: cortex_v6_compatibility_target projectId: PROJECT_ID datasetId: cortex_v6_compatibility
-
在
deployment.targets下,更新 Dataform 目标设置以匹配默认uv run cortex-demo参数:repositoryProjectId:将YOUR_REPO_PROJECT_ID替换为PROJECT_ID。repositoryRegion:保留us-central1(默认值为--dataform-region),或将其更新为与自定义区域匹配。repositoryName:将cortex-repository更改为cortex-framework-demo(默认值为--repository-name)。workspaceName:将dev更改为demo(默认值为--workspace-name)。
deployment: targets: - type: dataform enabled: true targetSettings: repositoryProjectId: PROJECT_ID repositoryRegion: us-central1 repositoryName: cortex-framework-demo workspaceName: demo
如果您将
--service-account传递给uv run cortex-demo,请取消注释targetSettings下的serviceAccount,并将其设置为您的服务账号邮箱。 -
可选:如果您想注册 SAP 解决方案示例,或者您替换了默认的
uv run cortex-demo标志,请调整config/config-demo.yaml:- 包含 SAP 解决方案示例。
如果包含 SAP,
uv run cortex-demo会将sap_sales_performance和sap_supplier_spend_analysis部署到cortex_demo_samples中,而config/config.yaml.example会将两者都设置为enabled: false。在data.modules.products下的两个条目上设置enabled: true以注册它们。 - 匹配自定义
--bigquery-location。 更新data.bigQueryLocation,使其与您传递给uv run cortex-demo的位置(默认值为US)相匹配。 - 匹配自定义
--sources值。如果您使用--sources sfdc进行了部署,请在data.modules.products下的 SAP 条目上设置enabled: false(或syncToKc: false),以免注册空数据产品。如果您使用--sources sap进行了部署,请停用 Salesforce 条目或在这些条目上设置syncToKc: false。 - 匹配
--sap-version ecc。将sap_raw和sap_foundation更新为cortex_demo_sap_ecc_raw和cortex_demo_sap_ecc_data_foundation,并在erp上设置moduleSettings.sapVersion: ecc。启用sap_general_ledger_items和sap_inventory_and_special_stocks,停用sap_universal_journal,并切换sap_accounts_receivable_insights和sap_financial_statements上的版本专用dependencyBindings,如config/config.yaml.example中的内嵌注释所示。 - 匹配自定义 Dataform 标志。如果您替换了
--dataform-region、--repository-name或--workspace-name,请更新deployment.targets下的repositoryRegion、repositoryName和workspaceName以进行匹配。
- 包含 SAP 解决方案示例。
如果包含 SAP,
注册并验证演示数据产品
将具体化的演示数据产品与 Knowledge Catalog 同步:
uv run cortex-create-kc-data-products \ --config config/config-demo.yaml \ --owner-email OWNER_EMAIL将
OWNER_EMAIL替换为在 Knowledge Catalog 中被指定为数据产品所有者的邮箱,例如dana@example.com。如需在单独的治理项目中注册所有演示数据产品,而不是在托管演示 BigQuery 数据集的项目中注册,请添加
--kc-project-id KC_PROJECT_ID,其中KC_PROJECT_ID是治理项目 ID。在 Google Cloud 控制台中,前往 Knowledge Catalog 数据产品页面:
在 Google Cloud 控制台工具栏中,点击资源选择器,然后选择目标项目。
点击已注册的演示数据产品,检查其商家说明、治理标签(包括
cortex_framework_created: "true")以及来自cortex_demo_data_product(和cortex_demo_samples,如果已启用)的关联 BigQuery 表。
如需详细了解治理标签、协调行为和生产自动化,请参阅Knowledge Catalog 集成和 uv run cortex-create-kc-data-products CLI 参考文档。
清理演示部署资源
成功部署演示后,您可以移除所用的 Google Cloud资源,以免产生持续费用。以下脚本会删除已创建的 BigQuery 数据集、Dataform 工作区、所有工作流和版本配置,以及 Dataform 代码库。如果找到,该脚本还会提示您选择是否删除 cortex-dataform 服务账号。如果您还在 Knowledge Catalog 中注册了演示数据产品,请按照可选:清理 Knowledge Catalog 演示数据产品中的说明将其移除。
展开以下部分,查看演示部署清理脚本:
演示部署清理脚本
在运行脚本之前,请将 PROJECT_ID 替换为您的目标 Google Cloud 项目 ID,例如 my-cortex-demo-project。此外,还要更新脚本顶部您使用 uv run cortex-demo 标志替换了默认值的任何变量(例如 --sap-version、--dataform-region、数据集 ID、--repository-name、--workspace-name 或 --service-account):
#!/bin/bash # Define variables using names from uv-run-cortex-demo.md PROJECT_ID="PROJECT_ID" SAP_VERSION="s4" DATAFORM_REGION="us-central1" SOURCE_SAP_RAW_DATASET_ID="cortex_demo_sap_s4_raw" TARGET_SAP_FOUNDATION_DATASET_ID="cortex_demo_sap_s4_data_foundation" if [[ "$SAP_VERSION" == "ecc" ]]; then SOURCE_SAP_RAW_DATASET_ID="cortex_demo_sap_ecc_raw" TARGET_SAP_FOUNDATION_DATASET_ID="cortex_demo_sap_ecc_data_foundation" fi SOURCE_SFDC_RAW_DATASET_ID="cortex_demo_sfdc_raw" TARGET_SFDC_FOUNDATION_DATASET_ID="cortex_demo_sfdc_data_foundation" TARGET_DP_DATASET_ID="cortex_demo_data_product" TARGET_SAMPLES_DATASET_ID="cortex_demo_samples" ASSERTIONS_DATASET_ID="dataform_assertions" REPOSITORY_NAME="cortex-framework-demo" WORKSPACE_NAME="demo" SERVICE_ACCOUNT_NAME="cortex-dataform" # Color codes for formatting status output GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' # No Color # Helper function to delete a resource and report status delete_resource() { local label=$1 local url=$2 local resource_type=$3 echo -n "${label}... " local temp_file=$(mktemp) local code=$(curl -s -o "${temp_file}" -w "%{http_code}" -X DELETE \ -H "Authorization: Bearer ${ACCESS_TOKEN}" \ "${url}") if [ "$code" -eq 200 ] || [ "$code" -eq 204 ]; then echo -e "${GREEN}ok${NC}" elif [ "$code" -eq 404 ]; then echo -e "${YELLOW}skipped, ${resource_type} not found${NC}" else echo -e "${RED}failed (HTTP ${code})${NC}" if [ -s "${temp_file}" ]; then echo " Error details:" sed 's/^/ /' "${temp_file}" fi fi rm -f "${temp_file}" } echo "Deleting BigQuery datasets..." for DATASET_ID in "${SOURCE_SAP_RAW_DATASET_ID}" \ "${TARGET_SAP_FOUNDATION_DATASET_ID}" \ "${SOURCE_SFDC_RAW_DATASET_ID}" \ "${TARGET_SFDC_FOUNDATION_DATASET_ID}" \ "${TARGET_DP_DATASET_ID}" \ "${TARGET_SAMPLES_DATASET_ID}" \ "${ASSERTIONS_DATASET_ID}"; do echo "deleting ${PROJECT_ID}:${DATASET_ID}" bq rm -r -f "${PROJECT_ID}:${DATASET_ID}" done ACCESS_TOKEN=$(gcloud auth print-access-token) delete_resource "Deleting Dataform workspace ${WORKSPACE_NAME}" \ "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/workspaces/${WORKSPACE_NAME}" \ "workspace" echo "Deleting Dataform workflow configurations..." WORKFLOW_CONFIGS_JSON=$(curl -s -H "Authorization: Bearer ${ACCESS_TOKEN}" \ "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/workflowConfigs") WORKFLOW_CONFIGS=$(echo "${WORKFLOW_CONFIGS_JSON}" | grep '"name":' | sed -E 's/.*"name": "([^"]+)".*/\1/') if [ -z "${WORKFLOW_CONFIGS}" ]; then echo -e " No workflow configurations found. ${YELLOW}skipped${NC}" else for config in ${WORKFLOW_CONFIGS}; do delete_resource " Deleting workflow config: ${config##*/}" \ "https://dataform.googleapis.com/v1beta1/${config}" \ "workflow config" done fi echo "Deleting Dataform release configurations..." RELEASE_CONFIGS_JSON=$(curl -s -H "Authorization: Bearer ${ACCESS_TOKEN}" \ "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}/releaseConfigs") RELEASE_CONFIGS=$(echo "${RELEASE_CONFIGS_JSON}" | grep '"name":' | sed -E 's/.*"name": "([^"]+)".*/\1/') if [ -z "${RELEASE_CONFIGS}" ]; then echo -e " No release configurations found. ${YELLOW}skipped${NC}" else for config in ${RELEASE_CONFIGS}; do delete_resource " Deleting release config: ${config##*/}" \ "https://dataform.googleapis.com/v1beta1/${config}" \ "release config" done fi delete_resource "Deleting Dataform repository ${REPOSITORY_NAME}" \ "https://dataform.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/${DATAFORM_REGION}/repositories/${REPOSITORY_NAME}?force=true" \ "repository" if gcloud iam service-accounts describe "${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}." --project="${PROJECT_ID}" >/dev/null 2>&1; then read -p "Do you want to delete the service account ${SERVICE_ACCOUNT_NAME}? (y/N): " -r if [[ "$REPLY" =~ ^[Yy]$ ]]; then echo -n "Deleting service account ${SERVICE_ACCOUNT_NAME}... " ERROR_MSG=$(gcloud iam service-accounts delete "${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}." --project="${PROJECT_ID}" --quiet 2>&1) EXIT_CODE=$? if [ ${EXIT_CODE} -eq 0 ]; then echo -e "${GREEN}ok${NC}" else echo -e "${RED}failed${NC}" echo " Error details:" echo "${ERROR_MSG}" | sed 's/^/ /' fi else echo -e "Deleting service account ${SERVICE_ACCOUNT_NAME}... ${YELLOW}skipped (user cancelled)${NC}" fi else echo -e "Deleting service account ${SERVICE_ACCOUNT_NAME}... ${YELLOW}skipped, service account not found${NC}" fi echo "Cortex Framework demo deployment cleanup complete."
可选:清理 Knowledge Catalog 演示数据产品
如果您在 Knowledge Catalog 中注册了演示数据产品,请运行以下独立脚本,删除所有由 Cortex Framework 管理的数据产品及其关联的数据资产。该脚本会过滤带有 cortex_framework_created: "true"(或旧版 cortex-framework-created: "true")所有权标签的数据产品,以便不修改客户管理的目录条目,并在删除任何资源之前提示确认。
使用在启用 Dataplex API 并授予所需角色中授予了 Knowledge Catalog 角色的主账号运行此脚本,包括 roles/dataplex.dataProductsEditor。您可以在删除演示版 BigQuery 数据集之前或之后运行此脚本。
展开以下部分,查看独立的 Knowledge Catalog 清理脚本:
Knowledge Catalog 演示数据产品清理脚本
调整以下清理脚本的配置值后,运行该脚本:
#!/bin/bash PROJECT_ID="PROJECT_ID" BIGQUERY_LOCATION="US" # Knowledge Catalog locations are lowercased (for example, "US" becomes "us"). KC_LOCATION=$(echo "${BIGQUERY_LOCATION}" | tr '[:upper:]' '[:lower:]') # Color codes for formatting status output GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' # No Color KC_ERR_FILE=$(mktemp) trap 'rm -f "${KC_ERR_FILE}"' EXIT KC_DATA_PRODUCTS=$(gcloud dataplex data-products list \ --project="${PROJECT_ID}" \ --location="${KC_LOCATION}" \ --filter='labels.cortex_framework_created="true" OR labels.cortex-framework-created="true"' \ --format="value(name)" \ --quiet 2>"${KC_ERR_FILE}") KC_LIST_EXIT_CODE=$? if [ ${KC_LIST_EXIT_CODE} -ne 0 ]; then if grep -qE "SERVICE_DISABLED|API \[dataplex\.googleapis\.com\] not enabled|has not been used in project" "${KC_ERR_FILE}"; then echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped, Dataplex API not enabled${NC}" else echo -e "Deleting Knowledge Catalog data products... ${RED}failed to list data products${NC}" if [ -s "${KC_ERR_FILE}" ]; then echo " Error details:" sed 's/^/ /' "${KC_ERR_FILE}" fi exit 1 fi elif [ -z "${KC_DATA_PRODUCTS}" ]; then echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped, no Cortex Framework data products found${NC}" else echo "Found Cortex Framework Knowledge Catalog data products in ${PROJECT_ID} (${KC_LOCATION}):" while IFS= read -r DP_NAME; do [ -n "${DP_NAME}" ] && echo " - ${DP_NAME##*/}" done <<< "${KC_DATA_PRODUCTS}" read -p "Do you want to delete these Knowledge Catalog data products and their linked assets? (y/N): " -r if [[ "$REPLY" =~ ^[Yy]$ ]]; then while IFS= read -r DP_NAME; do [ -z "${DP_NAME}" ] && continue DP_ID="${DP_NAME##*/}" # Remove linked data assets before deleting the data product ASSET_LIST_ERR=$(mktemp) DATA_ASSETS=$(gcloud dataplex data-products data-assets list \ --data-product="${DP_ID}" \ --project="${PROJECT_ID}" \ --location="${KC_LOCATION}" \ --format="value(name)" \ --quiet </dev/null 2>"${ASSET_LIST_ERR}") ASSET_LIST_EXIT=$? if [ ${ASSET_LIST_EXIT} -ne 0 ]; then echo -e "Listing data assets for ${DP_ID}... ${RED}failed${NC}" if [ -s "${ASSET_LIST_ERR}" ]; then echo " Error details:" sed 's/^/ /' "${ASSET_LIST_ERR}" fi rm -f "${ASSET_LIST_ERR}" continue fi rm -f "${ASSET_LIST_ERR}" ASSET_DELETE_FAILED=0 if [ -n "${DATA_ASSETS}" ]; then while IFS= read -r ASSET_NAME; do [ -z "${ASSET_NAME}" ] && continue ASSET_ID="${ASSET_NAME##*/}" echo -n " Deleting data asset ${ASSET_ID} from ${DP_ID}... " ERROR_MSG=$(gcloud dataplex data-products data-assets delete "${ASSET_ID}" \ --data-product="${DP_ID}" \ --project="${PROJECT_ID}" \ --location="${KC_LOCATION}" \ --quiet </dev/null 2>&1) if [ $? -eq 0 ]; then echo -e "${GREEN}ok${NC}" else ASSET_DELETE_FAILED=1 echo -e "${RED}failed${NC}" echo " Error details:" echo "${ERROR_MSG}" | sed 's/^/ /' fi done <<< "${DATA_ASSETS}" fi if [ ${ASSET_DELETE_FAILED} -ne 0 ]; then echo -e "Deleting Knowledge Catalog data product ${DP_ID}... ${YELLOW}skipped, failed to remove all linked assets${NC}" continue fi echo -n "Deleting Knowledge Catalog data product ${DP_ID}... " ERROR_MSG=$(gcloud dataplex data-products delete "${DP_ID}" \ --project="${PROJECT_ID}" \ --location="${KC_LOCATION}" \ --quiet </dev/null 2>&1) if [ $? -eq 0 ]; then echo -e "${GREEN}ok${NC}" else echo -e "${RED}failed${NC}" echo " Error details:" echo "${ERROR_MSG}" | sed 's/^/ /' fi done <<< "${KC_DATA_PRODUCTS}" else echo -e "Deleting Knowledge Catalog data products... ${YELLOW}skipped (user cancelled)${NC}" fi fi echo "Cortex Framework Knowledge Catalog demo cleanup complete."
替换以下内容:
PROJECT_ID:注册演示版 Knowledge Catalog 数据产品的 Google Cloud 项目 ID(您的演示版项目 ID,或者如果您传递了--kc-project-id,则为治理项目 ID),例如my-cortex-demo-project。
如果您在 config/config-demo.yaml 中使用了非默认位置,请同时更新脚本顶部的 BIGQUERY_LOCATION。
如果您为演示注册创建了 config/config-demo.yaml,还可以通过运行 rm -f config/config-demo.yaml 移除该本地配置文件。