java - 无法使用 API 客户端库 (Java) 启动数据流模板,因为我收到无效参数异常

标签 java google-api google-cloud-dataflow google-cloud-pubsub

有趣的事实是,我能够从 Cloud shell 以及 Google OAuth2 Playground 控制台启动数据流模板。当我尝试使用具有相同详细信息集的 API 客户端库启动它时,我收到 400 Bad request 错误。

使用的网址:

GenericUrl URL = new GenericUrl("https://dataflow.googleapis.com/v1b3/projects/servicetesting-g-1575763471750/templates:launch?gcsPath=gs://dataflow-templates/latest/GCS_Text_to_Cloud_PubSub");

POST正文内容:

{
  "jobName":"st-txt-to-pubsub",
  "parameters":
  {
    "inputFilePattern":"gs://soa_global_storage/input/my_input.txt",
    "outputTopic":"projects/servicetesting-g-1575763471750/topics/Input_Topic_PUB"
  },
        "environment": { "zone": "us-central1" }
 }

异常(exception):

Exception in thread "main" com.google.api.client.http.HttpResponseException: 400 Bad Request
{
  "error": {
    "code": 400,
    "message": "The template parameters are invalid.",
    "errors": [
      {
        "message": "The template parameters are invalid.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

最佳答案

查看您的模板元数据,确保字段名称与您在 POST 正文中调用的字段名称相同。还要检查参数是否通过正则表达式测试。

正如其他人所说,您还必须将您的区域更正为 us-central1-a,或者您可以将其留空。

例如。适合您内容的元数据:

    {
  "description": "enter your description",
  "name": "template_name",
  "parameters": [
    {
      "name": "inputFilePattern",
      "helpText": "Bucket URI",
      "regexes":["^gs://.*"],
      "label": "input file pattern"
    },
    {
      "name": "outputTopic",
      "helpText": "lorem ipsum",
      "label": "Topic on Pub/sub",
    }
  ]
}

值得一提的是,您应该尝试使用控制台中的参数的模板。如果在那里不起作用,那么它在任何地方也不起作用。

关于java - 无法使用 API 客户端库 (Java) 启动数据流模板,因为我收到无效参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59601984/

相关文章:

javascript - Google 地方信息自动完成

google-cloud-platform - 我们可以将 webhook 与 Google PubSub 连接吗?

java - 数据流/ApacheBeam 将输入限制为前 X 数量?

javascript - Google Maps API 加载失败 ("' google' is undefined") in IE8

hadoop - 如何将 On Prem Hadoop 迁移到 GCP

java - 将 byte 或 int 转换为 bitset

java - 从列表中删除重复元素

java - HashMap<UUID,ArrayList<>>, arraylist 不会存储值

java - 使用 wsgen 实用程序生成 web 服务客户端类

api - Google Simple API key 停止工作