במסמך הזה משתמשים ברכיבים הבאים של Google Cloud, והשימוש בהם כרוך בתשלום:
- Managed Service for Apache Spark
- Compute Engine
- Managed Airflow
בעזרת מחשבון העלויות אתם יכולים להעריך את העלויות בהתאם לשימוש הצפוי.
לפני שמתחילים
הגדרת הפרויקט
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Dataproc, Compute Engine, and Managed Airflow APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
יצירת תבנית של תהליך עבודה ב-Managed Service for Apache Spark
מעתיקים ומריצים את הפקודות הבאות בחלון טרמינל מקומי או ב-Cloud Shell כדי ליצור ולהגדיר תבנית של תהליך עבודה.
- יוצרים את תבנית תהליך העבודה
sparkpi.gcloud dataproc workflow-templates create sparkpi \ --region=us-central1 - מוסיפים את משימת Spark לתבנית תהליך העבודה
sparkpi. הדגל "compute"step-idמזהה את המשימה SparkPi.gcloud dataproc workflow-templates add-job spark \ --workflow-template=sparkpi \ --step-id=compute \ --class=org.apache.spark.examples.SparkPi \ --jars=file:///usr/lib/spark/examples/jars/spark-examples.jar \ --region=us-central1 \ -- 1000 - משתמשים באשכול עם צומת יחיד מנוהל כדי להריץ את תהליך העבודה. Managed Service for Apache Spark ייצור את האשכול, יריץ עליו את תהליך העבודה ואז ימחק את האשכול כשתהליך העבודה יסתיים.
gcloud dataproc workflow-templates set-managed-cluster sparkpi \ --cluster-name=sparkpi \ --single-node \ --region=us-central1 - מאשרים את יצירת התבנית של תהליך העבודה.
המסוף
לוחצים על השם של
sparkpiבדף Workflows של Managed Service for Apache Spark במסוף Google Cloud כדי לפתוח את הדף Workflow template details. לוחצים על השם של תבנית תהליך העבודה כדי לאשר את מאפייני התבנית שלsparkpi.
פקודת gcloud
מריצים את הפקודה הבאה:
gcloud dataproc workflow-templates describe sparkpi --region=us-central1
יצירה והעלאה של DAG ל-Cloud Storage
- יוצרים סביבת Managed Airflow או משתמשים בסביבה קיימת.
- הגדרה של משתני סביבה.
ממשק המשתמש של Airflow
- בסרגל הכלים, לוחצים על Admin (אדמין) > Variables (משתנים).
- לוחצים על יצירה.
- מזינים את הפרטים הבאים:
- מפתח:
project_id - Val: PROJECT_ID — מזהה הפרויקט ב- Google Cloud
- מפתח:
- לוחצים על Save.
פקודת gcloud
מזינים את הפקודות הבאות:
-
ENVIRONMENTהוא השם של סביבת Managed Airflow -
LOCATIONהוא האזור שבו נמצאת סביבת Managed Airflow -
PROJECT_IDהוא מזהה הפרויקט שמכיל את סביבת Managed Airflow
gcloud composer environments run ENVIRONMENT --location LOCATION variables set -- project_id PROJECT_ID - בסרגל הכלים, לוחצים על Admin (אדמין) > Variables (משתנים).
- מעתיקים את קוד ה-DAG הבא באופן מקומי לקובץ בשם "composer-dataproc-dag.py", שמשתמש ב-DataprocInstantiateWorkflowTemplateOperator.
Airflow 2
זרימת אוויר 1
- מעלים את ה-DAG לתיקיית הסביבה ב-Cloud Storage. אחרי שההעלאה מסתיימת, לוחצים על הקישור DAGs Folder בדף Managed Airflow Environment.
איך בודקים את הסטטוס של משימה
ממשק המשתמש של Airflow
- פותחים את ממשק האינטרנט של Airflow.
- בדף DAGs, לוחצים על שם ה-DAG (לדוגמה,
dataproc_workflow_dag). - בדף הפרטים של DAGs, לוחצים על Graph View.
- בודקים את הסטטוס:
- נכשל: המשימה מוקפת בתיבה אדומה.
אפשר גם להעביר את הסמן מעל המשימה ולחפש את הכיתוב State: Failed (מצב: נכשל).

- הצלחה: המשימה מוקפת בתיבה ירוקה.
אפשר גם להעביר את העכבר מעל המשימה ולבדוק אם מופיע State: Success.

- נכשל: המשימה מוקפת בתיבה אדומה.
אפשר גם להעביר את הסמן מעל המשימה ולחפש את הכיתוב State: Failed (מצב: נכשל).
המסוף
לוחצים על הכרטיסייה "תהליכי עבודה" כדי לראות את הסטטוס של תהליך העבודה.
פקודת gcloud
gcloud dataproc operations list \
--region=us-central1 \
--filter="labels.goog-dataproc-workflow-template-id=sparkpi"
הסרת המשאבים
כדי להימנע מחיובים בחשבון Google Cloud , אפשר למחוק את המשאבים שבהם השתמשתם במדריך הזה: