【问题标题】:How we can create dataproc cluster using apache airflow API我们如何使用 apache 气流 API 创建 dataproc 集群
【发布时间】:2019-08-05 09:41:01
【问题描述】:

我是 Python 和 Airflow 的新手,我使用 pythonoperator 在我的 Python 脚本中创建了 4 个任务。第一个和第二个任务从GCP Bucket 检索 zip 文件,然后读取数据,另一个任务正在合并两个文件数据。现在我需要再创建一个可以创建的任务Dataproc Cluster

我见过Airflow API,但我没有得到足够的信息和线索。 有什么有用的例子吗?

提前致谢!

【问题讨论】:

    标签: python google-cloud-platform airflow google-cloud-dataproc


    【解决方案1】:

    有一个名为 DataprocClusterCreateOperator 的运算符将为您创建 Dataproc 集群。

    https://airflow.apache.org/_api/airflow/contrib/operators/dataproc_operator/index.html#module-airflow.contrib.operators.dataproc_operator查看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)
    

    【讨论】:

    【解决方案2】:

    是的,我们需要使用 DataprocClusterCreateOperator。首先我们需要导入dataproc_operator,然后我们还需要使用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)
    

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      相关资源
      最近更新 更多