Menggunakan file YAML dengan alur kerja

Anda dapat menentukan template alur kerja dalam file YAML, lalu membuat instance template untuk menjalankan alur kerja. Anda juga dapat mengimpor dan mengekspor file YAML template alur kerja untuk membuat dan memperbarui resource template alur kerja Dataproc.

Menjalankan alur kerja menggunakan file YAML

Untuk menjalankan alur kerja tanpa membuat resource template alur kerja terlebih dahulu, gunakan perintah gcloud dataproc workflow-templates instantiate-from-file.

  1. Tentukan template alur kerja Anda dalam file YAML. File YAML harus menyertakan semua kolom WorkflowTemplate wajib diisi, kecuali kolom id, dan juga harus mengecualikan kolom version dan semua kolom hanya output. Dalam contoh alur kerja berikut, daftar prerequisiteStepIds di langkah terasort memastikan langkah terasort hanya akan dimulai setelah langkah teragen selesai dengan berhasil.
    jobs:
    - hadoopJob:
        args:
        - teragen
        - '1000'
        - hdfs:///gen/
        mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar
      stepId: teragen
    - hadoopJob:
        args:
        - terasort
        - hdfs:///gen/
        - hdfs:///sort/
        mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar
      stepId: terasort
      prerequisiteStepIds:
        - teragen
    placement:
      managedCluster:
        clusterName: my-managed-cluster
        config:
          gceClusterConfig:
            zoneUri: us-central1-a
    
  2. Jalankan alur kerja:
    gcloud dataproc workflow-templates instantiate-from-file \
        --file=TEMPLATE_YAML \
        --region=REGION
    

Buat instance alur kerja menggunakan file YAML dengan Penempatan Zona Otomatis Dataproc

  1. Tentukan template alur kerja Anda dalam file YAML. File YAML ini sama dengan file YAML sebelumnya, kecuali kolom zoneUri ditetapkan ke string kosong ('') untuk mengizinkan Dataproc Penempatan Zona Otomatis memilih zona untuk cluster.
    jobs:
    - hadoopJob:
        args:
        - teragen
        - '1000'
        - hdfs:///gen/
        mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar
      stepId: teragen
    - hadoopJob:
        args:
        - terasort
        - hdfs:///gen/
        - hdfs:///sort/
        mainJarFileUri: file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar
      stepId: terasort
      prerequisiteStepIds:
        - teragen
    placement:
      managedCluster:
        clusterName: my-managed-cluster
        config:
          gceClusterConfig:
            zoneUri: ''
    
  2. Jalankan alur kerja. Saat menggunakan Penempatan Otomatis, Anda harus meneruskan region ke perintah gcloud.
    gcloud dataproc workflow-templates instantiate-from-file \
        --file=TEMPLATE_YAML \
        --region=REGION
    

Mengimpor dan mengekspor file YAML template alur kerja

Anda dapat mengimpor dan mengekspor file YAML template alur kerja. Biasanya, template alur kerja diekspor terlebih dahulu sebagai file YAML, lalu YAML diedit, dan kemudian file YAML yang telah diedit diimpor untuk memperbarui template.

  1. Ekspor template alur kerja ke file YAML. Selama operasi ekspor, kolom id dan version, serta semua kolom hanya output difilter dari output dan tidak muncul dalam file YAML yang diekspor.

    gcloud dataproc workflow-templates export TEMPLATE_ID or TEMPLATE_NAME \
        --destination=TEMPLATE_YAML \
        --region=REGION
    
    Anda dapat meneruskan WorkflowTemplate id atau resource template yang sepenuhnya memenuhi syarat name ("projects/PROJECT_ID/regions/REGION/workflowTemplates/TEMPLATE_ID") ke perintah.

  2. Edit file YAML secara lokal. Perhatikan bahwa kolom id, version, dan hanya output, yang difilter dari file YAML saat template diekspor, tidak diizinkan dalam file YAML yang diimpor.

  3. Impor file YAML template alur kerja yang diperbarui:

    gcloud dataproc workflow-templates import TEMPLATE_ID or TEMPLATE_NAME \
        --source=TEMPLATE_YAML \
        --region=REGION
    
    Anda dapat meneruskan WorkflowTemplate id atau resource template yang sepenuhnya memenuhi syarat name ("projects/PROJECT_ID/regions/region/workflowTemplates/TEMPLATE_ID") ke perintah. Resource template dengan nama template yang sama akan ditimpa (diperbarui) dan nomor versinya akan bertambah. Jika template dengan nama template yang sama tidak ada, template tersebut akan dibuat.