使用工作建構工具執行管道
本快速入門導覽課程說明如何使用 Dataflow 工作建立工具執行 Dataflow 工作。工作建構工具提供視覺化的使用者介面,可讓您在 Google Cloud 控制台中建構及執行 Dataflow pipeline,完全不需要編寫程式碼。
在本快速入門導覽課程中,您將範例 pipeline 載入工作建立工具、執行工作,並確認工作已建立輸出內容。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataflow, Compute Engine, Cloud Logging, Cloud Storage, Google Cloud Storage JSON, and Resource Manager APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataflow, Compute Engine, Cloud Logging, Cloud Storage, Google Cloud Storage JSON, and Resource Manager APIs.
- 建立 Cloud Storage bucket:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
- For Name your bucket, enter a unique bucket name. Don't include sensitive information in the bucket name, because the bucket namespace is global and publicly visible.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
In the Replication settings section, click Configure to configure settings for the replication job.
The Configure cross-bucket replication pane appears.
- To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
- To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
- Click Done.
-
In the Choose how to store your data section, do the following:
- In the Set a default class section, select the following: Standard.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
In the Choose how to protect object data section, do the
following:
- Select any of the options under Data protection that you
want to set for your bucket.
- To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
- To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
- To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
- To enable Object Retention Lock, click the Enable object retention checkbox.
- To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
- To choose how your object data will be encrypted, expand the Data encryption section (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
- Click Create.
如要完成本快速入門導覽中的步驟,使用者帳戶必須具備 Dataflow 管理員角色和服務帳戶使用者角色。Compute Engine 預設服務帳戶必須具備 Dataflow 工作者角色。 如要在 Google Cloud 控制台中新增必要角色,請按照下列步驟操作:
- 前往身分與存取權管理頁面。
前往「IAM」頁面 - 選取專案。
- 在包含您使用者帳戶的資料列中,按一下 「Edit principal」(編輯主體)。
- 按一下「新增其他角色」 ,然後在下拉式清單中選取「Dataflow 管理員」。
- 按一下「Add another role」(新增其他角色) ,然後在下拉式清單中選取「Service Account User」(服務帳戶使用者)。
- 按一下 [儲存]。
- 在包含 Compute Engine 預設服務帳戶的資料列中,按一下 「Edit principal」(編輯主體)。
- 按一下「新增其他角色」 ,然後在下拉式清單中選取「Dataflow Worker」。
- 按一下「新增其他角色」 ,然後在下拉式清單中選取「Storage 物件管理員」。
按一下 [儲存]。
如要進一步瞭解如何授予角色,請參閱「使用控制台授予 IAM 角色」。
- 前往身分與存取權管理頁面。
- 根據預設,每個新專案一開始都會具備預設網路。如果專案的預設網路已停用或刪除,您必須在專案中建立網路,並為使用者帳戶指派Compute 網路使用者角色 (
roles/compute.networkUser
)。
載入範例管道
在這個步驟中,您會載入範例管道,計算莎士比亞《李爾王》的字數。
前往 Google Cloud 控制台的「Jobs」(工作) 頁面。
按一下「利用範本建立工作」
。按一下「工作建構工具」。
按一下「載入」。
按一下「字數統計」。工作建構工具會填入管道的圖示。
工作建構工具會為每個管道步驟顯示一張卡片,其中指定該步驟的設定參數。舉例來說,第一個步驟是從 Cloud Storage 讀取文字檔案。來源資料的位置會預先填入「文字位置」方塊。
設定輸出位置
在這個步驟中,您會指定管道寫入輸出的 Cloud Storage bucket。
找出名為「New sink」(新水槽) 的資訊卡。你可能需要捲動畫面。
在「文字位置」方塊中,按一下「瀏覽」。
選取您在「事前準備」中建立的 Cloud Storage bucket 名稱。
按一下「查看子資源」
。在「檔案名稱」方塊中輸入
words
。按一下 [選取]。
執行工作
按一下「Run job」(執行工作)。工作建構工具會建立 Dataflow 工作,然後前往工作圖表。工作開始後,工作圖會顯示管道的圖形表示法,類似於工作建構工具中顯示的管道。管道的每個步驟執行時,工作圖表中的狀態都會更新。
「Job info」(工作資訊) 面板會顯示工作的整體狀態。如果工作順利完成,「工作狀態」欄位會更新為 Succeeded
。
檢查工作輸出內容
工作完成後,請按照下列步驟查看管道的輸出內容:
在 Google Cloud 控制台,前往「Cloud Storage bucket」頁面。
在 bucket 清單中,按一下您在「事前準備」中建立的 bucket 名稱。
按一下名為
words-00000-of-00001
的檔案。在「物件詳細資料」頁面中,按一下已驗證的網址,即可查看管道輸出內容。
輸出內容應如下所示:
brother: 20
deeper: 1
wrinkles: 1
'alack: 1
territory: 1
dismiss'd: 1
[....]
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
刪除專案
如要避免付費,最簡單的方法就是刪除您為快速入門導覽課程建立的 Google Cloud 專案。
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
刪除個別資源
如要保留您在本快速入門中使用的 Google Cloud 專案,請刪除 Cloud Storage bucket:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click the checkbox for the bucket that you want to delete.
- To delete the bucket, click Delete, and then follow the instructions.