从Go应用程序创建Dataflow模板的作业

huangapple go评论154阅读模式
英文:

Create job from Dataflow template from Go app

问题

我正在尝试通过Go应用程序从现有模板启动一个Dataflow作业。

到目前为止,我已经引入了google.golang.org/api/dataflow/v1b3包,并使用作业信息创建了一个CreateJobFromTemplateRequest

现在,我该如何使用Compute Engine中的内置服务帐号凭据执行该请求呢?

英文:

I'm trying to launch a Dataflow job from an existing template, via a Go app.

So far, I've brought in google.golang.org/api/dataflow/v1b3 and created a CreateJobFromTemplateRequest with the job info.

How can I now execute that request using the built-in service account credentials in Compute Engine?

答案1

得分: 5

使用自动生成的Google Go API仅在为您要调用的服务开发了Google Go客户端库的情况下才推荐使用。目前还没有适用于Dataflow的客户端库。

要使用默认凭据从Go应用程序启动Dataflow模板:

ctx := context.Background()
oauthClient, err := google.DefaultClient(ctx, dataflow.CloudPlatformScope)

dataflowService, err := dataflow.New(oauthClient)

if err != nil {
  panic(err)
}

templateRequest := dataflow.CreateJobFromTemplateRequest{
  GcsPath: "在此处填写模板的GCS路径",
  JobName: "在此处选择一个唯一的作业名称",
  Parameters: map[string]string{
    "parameters": "用于作业的参数",
  },
}

result, err := dataflowService.Projects.Templates.Create("项目ID", &templateRequest).Do()

if err != nil {
  panic(err)
}
英文:

Using Auto-generated Google APIs for Go is only recommended if there is a Google Client Library for Go developed for the service you are calling. There is not a client library yet for Dataflow.

To launch a Dataflow template from a Go app using default credentials:

ctx := context.Background()
oauthClient, err := google.DefaultClient(ctx, dataflow.CloudPlatformScope)

dataflowService, err := dataflow.New(oauthClient)

if err != nil {
  panic(err)
}

templateRequest := dataflow.CreateJobFromTemplateRequest{
  GcsPath: "gcs path to template here",
  JobName: "choose a unique job name here",
  Parameters: map[string]string{
    "parameters": "for job",
  },
}

result, err := dataflowService.Projects.Templates.Create("project id", &templateRequest).Do()

if err != nil {
  panic(err)
}

huangapple
  • 本文由 发表于 2017年6月7日 01:22:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/44396155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定