简体   繁体   English

如何在谷歌数据流中获取现有作业的“templateLocation”参数值

[英]How to Get the "templateLocation" parameter value of an existing Job in google dataflow

I have a list of an existing jobs running in a google dataflow.我有一个在谷歌数据流中运行的现有作业列表。 I would like to list the jobs running for last x number of days and would like to recycle those programmatically.我想列出最近 x 天运行的作业,并想以编程方式回收这些作业。 To achieve this I need the name of the template used for a particular job.为此,我需要用于特定作业的模板名称。 We can easily get this information from Console in a Job Info view.我们可以在作业信息视图中轻松地从控制台获取此信息。 However i would like to know if there is any way to get this info from Gcloud command or from a API.但是我想知道是否有任何方法可以从 Gcloud 命令或 API 获取此信息。

Your early response will be appreciated.您的早期反应将不胜感激。

Thanks Sarang谢谢萨朗

- Solution 1: - 解决方案 1:

You can use GCloud sdk and a shell script to achieve your need:您可以使用GCloud sdkshell脚本来满足您的需求:

https://cloud.google.com/sdk/gcloud/reference/dataflow/jobs/list https://cloud.google.com/sdk/gcloud/reference/dataflow/jobs/list

Filter jobs with the given name:过滤具有给定名称的作业:

gcloud dataflow jobs list --filter="name=my-wordcount"

List jobs with from a given region:列出来自给定区域的作业:


gcloud dataflow jobs list --region="europe-west1"

List jobs created this year:列出今年创造的工作:

gcloud dataflow jobs list --created-after=2018-01-01

List jobs created more than a week ago:列出一周多前创建的工作:

gcloud dataflow jobs list --created-before=-P1W

Many filters and parameters are proposed to apply your use case.建议使用许多过滤器和参数来应用您的用例。

- Solution 2 - 解决方案 2

You can use the rest api for Dataflow jobs:您可以将rest api 用于Dataflow作业:

https://cloud.google.com/dataflow/docs/reference/rest https://cloud.google.com/dataflow/docs/reference/rest

Example:例子:

GET /v1b3/projects/{projectId}/locations/{location}/jobs
List the jobs of a project.

There is no direct way of getting the template location and name.没有直接获取模板位置和名称的方法。 To achieve above requirement I have defined the pattern for the template name and job name and based on the defined pattern, while recycling the job, template name has been computed and passed on to the API call.为实现上述要求,我定义了模板名称和作业名称的模式,并基于定义的模式,在回收作业时,模板名称已被计算并传递给 API 调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM