与将先前创建的工作流模板资源实例化的标准工作流不同,内嵌工作流使用 YAML 文件或嵌入式 WorkflowTemplate 定义来运行工作流。
。创建和运行内嵌工作流
请参阅使用 YAML 文件实例化工作流。
在使用任何请求数据之前,请先进行以下替换:
- project-id: Google Cloud 项目 ID
- region:集群区域,例如“us-central1”
- zoneUri:指定集群区域中的 zone(例如“us-central1-b”),或留空(“”)以使用 Dataproc 自动选择地区展示位置
- clusterName:集群名称
HTTP 方法和网址:
POST https://dataproc.googleapis.com/v1/projects/project-id /regions/region /workflowTemplates:instantiateInline
请求 JSON 正文:
{ "jobs": [ { "hadoopJob": { "mainJarFileUri": "file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar", "args": [ "teragen", "1000", "hdfs:///gen/" ] }, "stepId": "teragen" }, { "hadoopJob": { "mainJarFileUri": "file:///usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar", "args": [ "terasort", "hdfs:///gen/", "hdfs:///sort/" ] }, "stepId": "terasort", "prerequisiteStepIds": [ "teragen" ] } ], "placement": { "managedCluster": { "clusterName": "cluster-name ", "config": { "gceClusterConfig": { "zoneUri": "zone " } } } } }
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://dataproc.googleapis.com/v1/projects/project-id /regions/region /workflowTemplates:instantiateInline"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://dataproc.googleapis.com/v1/projects/project-id /regions/region /workflowTemplates:instantiateInline" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/project-id/regions/region/operations/2fbd0dad-...", "metadata": { "@type": "type.googleapis.com/google.cloud.dataproc.v1.WorkflowMetadata", "graph": { "nodes": [ { "stepId": "teragen", "state": "RUNNABLE" }, { "stepId": "terasort", "prerequisiteStepIds": [ "teragen" ], "state": "BLOCKED" } ] }, "state": "PENDING", "startTime": "2020-04-02T22:50:44.826Z" } }
目前,Google Cloud 控制台不支持创建内嵌工作流。您可以从 Dataproc 工作流页面查看工作流程模板和实例化的工作流。