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 Managed Service untuk Apache Spark.
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
yang diperlukan kecuali kolom
id, dan juga harus mengecualikan kolomversiondan semua kolom khusus output. Dalam contoh alur kerja berikut, daftarprerequisiteStepIdsdi langkahterasortmemastikan langkahterasorthanya akan dimulai setelah langkahteragenberhasil diselesaikan.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
Membuat instance alur kerja menggunakan file YAML dengan Penempatan Zona Otomatis Managed Service untuk Apache Spark
- Tentukan template alur kerja Anda dalam file YAML. File YAML ini sama dengan file YAML sebelumnya, kecuali kolom
zoneUriditetapkan ke string kosong ('') untuk memungkinkan Managed Service for Apache Spark 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 a
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 pertama-tama diekspor sebagai file YAML, lalu YAML diedit, dan kemudian file YAML yang diedit diimpor untuk memperbarui template.
Ekspor template alur kerja ke file YAML. Selama operasi ekspor, kolom
iddanversion, serta semua kolom khusus output difilter dari output dan tidak muncul di file YAML yang diekspor. Anda dapat meneruskan WorkflowTemplategcloud dataproc workflow-templates export TEMPLATE_ID or TEMPLATE_NAME \ --destination=TEMPLATE_YAML \ --region=REGION
idatau 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 khusus output, yang difilter dari file YAML saat template diekspor, tidak diizinkan dalam file YAML yang diimpor.Impor template alur kerja yang diperbarui file YAML:
Anda dapat meneruskan WorkflowTemplategcloud dataproc workflow-templates import TEMPLATE_ID or TEMPLATE_NAME \ --source=TEMPLATE_YAML \ --region=REGION
idatau 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 akan dibuat.