我试图通过REST API调用数据流模板,然而,当在体内被指定的参数,一个INVALID_ARGUMENT引发错误。在除去参数字段,它工作正常不过。我试图同时加入JavaScript和Python的,但得到完全相同的错误。
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
def invoke_dataflow_job():
credentials = GoogleCredentials.get_application_default()
service = build('dataflow', 'v1b3', credentials=credentials)
TEMPLATE_LOCATION = 'gs://xxx';
PROJECT_ID = 'xxx';
JOB_NAME = 'xxx';
LOCATION = 'europe-west1';
ZONE = 'europe-west1-b';
TEMP_LOCATION = 'xxx';
BODY = {
'jobName': JOB_NAME,
'gcsPath': TEMPLATE_LOCATION,
'parameters': {
'messageToPrint': 'Blue sky'
},
'environment': {
'tempLocation': TEMP_LOCATION,
'zone': ZONE,
}
}
request = service.projects().locations().templates().create(projectId=PROJECT_ID, location=LOCATION, body=BODY)
response = request.execute()
return response
是否REST API支持的参数传递?纵观example代码,相信它应该。
有什么建议么?
错误信息:
The workflow could not be created. Causes: (4adc3dbfd180d8a2): Found unexpected parameters: ['messageToPrint' (perhaps you meant 'userAgent')]
更新1:
样品DOFN:
public static class BuildPathFn extends DoFn<String, Void> {
private static final long serialVersionUID = -2815123956194177539L;
private final ValueProvider<String> baseDir;
private final ValueProvider<String> year;
private final ValueProvider<String> month;
private final ValueProvider<String> day;
private final ValueProvider<String> hour;
private final ValueProvider<String> filePattern;
public BuildPathFn (ValueProvider<String> baseDir, ValueProvider<String> year,
ValueProvider<String> month, ValueProvider<String> day,
ValueProvider<String> hour, ValueProvider<String> filePattern) {
this.baseDir = baseDir;
this.year = year;
this.month = month;
this.day = day;
this.hour = hour;
this.filePattern = filePattern;
}
@ProcessElement
public void processElement(@Element String element, OutputReceiver<Void> receiver) {
try {
String path = baseDir.get() + "/" + year.get() + "/" + month.get() + "/" + day.get() + "/" + hour.get() + "/" + filePattern.get();
LOG.info("BuildPathFn >> Path: {}", path);
} catch (Exception e) {
LOG.error("BuildPathFn >> Exception: {}", e.getMessage());
}
}
}
运行时的输出:
BuildPathFn >> Path: true/true/true/true/true/true
用于构建模板MVN命令的一部分:
".... --baseDir --year --month --day --hour --filePattern"
该代码是好的,它是传递参数的正确方法。请记住,选择需要的模板作为ValueProvider来定义。当staging模板不通过要在运行时需要解决的任何参数。然后选项值应在说明书中与代码invoking模板时已经(即,使用parameters
请求主体内部)进行评估。