This is an automated email from the ASF dual-hosted git repository.
bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new cf0c495e5 [KYUUBI #4199] [DOC] Add REST API doc for POST /batches with
uploading resource
cf0c495e5 is described below
commit cf0c495e5cd3bda0a53b59d5f9f986f340e81fe8
Author: liangbowen <[email protected]>
AuthorDate: Mon Jan 30 10:48:24 2023 +0800
[KYUUBI #4199] [DOC] Add REST API doc for POST /batches with uploading
resource
### _Why are the changes needed?_
- add docs in REST API for POST /batches with uploading resource, which was
introduced in #4106 .
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including
negative and positive cases if possible
- [x] Add screenshots for manual tests if appropriate
- [ ] [Run
test](https://kyuubi.readthedocs.io/en/master/develop_tools/testing.html#running-tests)
locally before make a pull request

Closes #4199 from bowenliang123/rest-batchupload-doc.
Closes #4199
957249d4 [liangbowen] add doc for POST /batches (with uploading resource)
Authored-by: liangbowen <[email protected]>
Signed-off-by: liangbowen <[email protected]>
---
docs/client/rest/rest_api.md | 26 ++++++++++++++++++++++
.../kyuubi/server/api/v1/BatchesResource.scala | 4 ++++
2 files changed, 30 insertions(+)
diff --git a/docs/client/rest/rest_api.md b/docs/client/rest/rest_api.md
index b1c8edfea..d8872e792 100644
--- a/docs/client/rest/rest_api.md
+++ b/docs/client/rest/rest_api.md
@@ -357,6 +357,8 @@ Returns all the batches.
Create a new batch.
#### Request Body
+- Media type: `application-json`
+- JSON structure:
| Name | Description | Type
|
| :--------
|:---------------------------------------------------|:-----------------|
@@ -371,6 +373,30 @@ Create a new batch.
The created [Batch](#batch) object.
+### POST /batches (with uploading resource)
+
+Create a new batch with uploading resource file.
+
+Example of using `curl` command to send POST request to `/v1/batches` in
`multipart-formdata` media type with uploading resource file from local path.
+```shell
+curl --location --request POST 'http://localhost:10099/api/v1/batches' \
+--form
'batchRequest="{\"batchType\":\"SPARK\",\"className\":\"org.apache.spark.examples.SparkPi\",\"name\":\"Spark
Pi\"}";type=application/json' \
+--form 'resourceFile=@"/local_path/example.jar"'
+```
+
+#### Request Body
+- Media type: `multipart-formdata`
+- Request body structure in multiparts:
+
+| Name | Description
| Media Type |
+|:-------------|:-------------------------------------------------------------------------------------------------|:-----------------|
+| batchRequest | The batch request in JSON format as request body requried in
[POST /batches](#post-batches) | application/json |
+| resourceFile | The resource to upload and execute, which will be cached on
server and cleaned up after execution | File |
+
+#### Response Body
+
+The created [Batch](#batch) object.
+
### GET /batches/{batchId}
Returns the batch information.
diff --git
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/BatchesResource.scala
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/BatchesResource.scala
index 2c9c7535d..24f99a24c 100644
---
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/BatchesResource.scala
+++
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/BatchesResource.scala
@@ -178,6 +178,10 @@ private[v1] class BatchesResource extends
ApiRequestContext with Logging {
@FormDataParam("batchRequest") batchRequest: BatchRequest,
@FormDataParam("resourceFile") resourceFileInputStream: InputStream,
@FormDataParam("resourceFile") resourceFileMetadata:
FormDataContentDisposition): Batch = {
+ require(
+ batchRequest != null,
+ "batchRequest is required and please check the content type" +
+ " of batchRequest is application/json")
val tempFile = Utils.writeToTempFile(
resourceFileInputStream,
KyuubiApplicationManager.tempDirForUpload,