Flink Rest API错误:请求与预期的格式JarRunRequestBody不匹配

时间:2019-01-24 13:42:46

标签: apache google-cloud-platform apache-flink

尝试使用下面的rest api远程运行flink作业,但抛出错误

curl -X POST -H 'Content-Type: application/json' --data '
{
    "type": "object",
    "id": "urn:jsonschema:org:apache:flink:runtime:webmonitor:handlers:JarRunRequestBody",
    "properties": {
    "programArgsList" : {
      "type" : "array",
      "items" : [
        "input-kafka-server": "****",
        "input-kafka-topics": "****",
        "input-job-name": "****"

    }
  }
}
' http://x.x.x.x:8081/jars/810ac968-5d5f-450d-aafc-22655238d617.jar/run

{“错误”:[[请求与预期格式的JarRunRequestBody不匹配。“]}

谢谢。

2 个答案:

答案 0 :(得分:0)

您发现here的jar运行处理程序的请求正文的描述是jar运行消息的JSON schema specification。您只需要在properties中指定,而无需在"type""id"字段中指定。因此,您的请求应如下所示:

curl -X POST -H 'Content-Type: application/json' --data '
{
  "programArgsList" : [
    "--input-kafka-server",
    "value-input-kafka-server",
    "--input-kafka-topics",
    "value-kafka-topics",
    "input-job-name",
    "value-job-name"
  ]
}
' http://x.x.x.x:8081/jars/810ac968-5d5f-450d-aafc-22655238d617.jar/run

答案 1 :(得分:0)

如果有人正在寻找Python代码以通过REST API提交Flink作业。

import json

url = base_url + "/jars/" + jar_id + "/run"
    myheader = {'content-type': 'application/json'}
    mydata = {
        "programArgsList": [
                            "--input-kafka-server", "value-input-kafka-server",
                            "--input-kafka-topics", "value-kafka-topics",
                            "--input-job-name","value-job-name"
                            ],
        "parallelism": 30
    }
    x = requests.post(url, data=json.dumps(mydata), headers=myheader)