簡體   English   中英

我們如何使用Apache Airflow API創建Dataproc集群

[英]How we can create dataproc cluster using apache airflow API

我是Python和Airflow的新手,我已經使用pythonoperator在Python腳本中創建了4個任務。 第一個和第二個任務從GCP Bucket檢索zip文件,然后讀取數據,另一個任務是合並兩個文件數據。 現在,我需要再創建一個可以創建Dataproc Cluster任務。

我已經看過Airflow API ,但是沒有得到足夠的信息和線索。 有沒有可以幫助您的例子?

提前致謝!

有一個名為DataprocClusterCreateOperator的運算符,它將為您創建Dataproc集群。

在以下網址查看DataprocClusterCreateOperator的文檔: https: DataprocClusterCreateOperator

from airflow.contrib.operators import dataproc_operator

create_dataproc_cluster = dataproc_operator.DataprocClusterCreateOperator(
    task_id='create_dataproc_cluster',
    # Give the cluster a unique name by appending the date scheduled.
    # See https://airflow.apache.org/code.html#default-variables
    cluster_name='hadoop-cluster',
    num_workers=2,
    zone='europe-west1-b',
    master_machine_type='n1-standard-1',
    worker_machine_type='n1-standard-1',
    dag=dag)

是的,我們需要使用DataprocClusterCreateOperator。 首先,我們需要導入dataproc_operatror,然后還需要將所有參數與dag參數一起傳遞,否則會出現錯誤

from airflow.contrib.operators import dataproc_operator

create_dataproc_cluster = dataproc_operator.DataprocClusterCreateOperator(
    task_id='create_dataproc_cluster',
    project_id='trim-karma-248213',
    cluster_name='airflow-cluster',
    num_workers=2,
    zone='europe-west1-c',
    master_machine_type='n1-standard-1',
    worker_machine_type='n1-standard-1',
    dag=dag)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM