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.
- Tentukan template alur kerja Anda dalam file YAML. File YAML harus menyertakan semua kolom
WorkflowTemplate
wajib diisi, kecuali kolom
id
, dan juga harus mengecualikan kolomversion
dan semua kolom hanya output. Dalam contoh alur kerja berikut, daftarprerequisiteStepIds
di langkahterasort
memastikan langkahterasort
hanya akan dimulai setelah langkahteragen
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
- 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
- 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: ''
- 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.
Ekspor template alur kerja ke file YAML. Selama operasi ekspor, kolom
id
danversion
, serta semua kolom hanya output difilter dari output dan tidak muncul dalam file YAML yang diekspor. Anda dapat meneruskan WorkflowTemplategcloud dataproc workflow-templates export TEMPLATE_ID or TEMPLATE_NAME \ --destination=TEMPLATE_YAML \ --region=REGION
id
atau resource template yang sepenuhnya memenuhi syaratname
("projects/PROJECT_ID/regions/REGION/workflowTemplates/TEMPLATE_ID") ke perintah.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.Impor file YAML template alur kerja yang diperbarui:
Anda dapat meneruskan WorkflowTemplategcloud dataproc workflow-templates import TEMPLATE_ID or TEMPLATE_NAME \ --source=TEMPLATE_YAML \ --region=REGION
id
atau resource template yang sepenuhnya memenuhi syaratname
("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.