有趣的事实是,我能够从 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/