Commit 2feb4614 authored by Romain Reuillon's avatar Romain Reuillon

[REST] enh: complete rest api doc

parent 5493b9de
......@@ -29,7 +29,7 @@ The API of exposes the following routes to submit and manage executions:
@li{@b{GET /job/:id/state} - return the state of a mole execution. It has the following parameters:
@ul
@li{@b{id} - the id of the mole execution}
When successful, it returns a structure the state:
When successful, it returns a structure representing the state:
@ul
@li{@b{state} - the state of the execution, it can be running, finished or failed}
When running the other fields are:
......@@ -49,6 +49,30 @@ The API of exposes the following routes to submit and manage executions:
@li{@b{id} - the id of the mole execution}
@li{@b{path}} - the path of the file to download}
}
@li{@b{PROPFIND /job/:id/workDirectory/:file} - get info of a file or a directory from the server. It has the following parameters:
@ul
@li{@b{id} - the id of the mole execution}
@li{@b{path}} - the path of the file to download}
@li{@b{last}} - this parameter is optional - an integer to list only the last n files.
When successful, it returns a listing of the directory, that look like this:
@hl.plain("""
{
"entries" : [ {
"name" : "Pi.oms",
"size" : 909,
"modified" : 1584980668517,
"type" : "file"
} ],
"modified" : 1584980668517,
"type" : "directory"
""")
The fields contains the following info:
@ul
@li{@b{name}} - the name of the file
@li{@b{type}} - the type of the file. It can be (directory or file)
@li{@b{modified}} - the date of the last modification of this file
@li{@b{size}} - mentioned only for the entry of type "file". It contains the size of the file.
}
@li{@b{DELETE /job/:id} - cancel and remove an execution from the server. It has the following parameters:
@ul
@li{@b{id} - the id of the mole execution}
......@@ -94,7 +118,6 @@ val pi = Val[Double]
val piAvg = Val[Double]
val piMed = Val[Double]
val testFile = Val[File]
// Define the model task that computes an estimation of pi
val model =
......@@ -113,28 +136,48 @@ val model =
outputs += pi
)
Replication(
evaluation = model,
seed = seed,
replications = 100,
aggregation = Seq(pi aggregate average as piAvg, pi aggregate median as piMed)
) hook display
) hook display hook (workDirectory / "result.json", format = JSONOutputFormat())
[reuillon:/tmp/pi] $$ tar -cvzf pi.tgz *
""")
Submit the job:
@plain("""
[reuillon:/tmp/pi] 1m59s $ curl -X POST -F 'script=Pi.oms' -F 'workDirectory=@/tmp/pi.tgz' http://localhost:8080/job
[reuillon:/tmp/pi] $ curl -X POST -F 'script=Pi.oms' -F 'workDirectory=@/tmp/pi.tgz' http://localhost:8080/job
{
"id" : "160ba693-199c-48e8-9ee1-6a1f9ac66e62"
}[reuillon:/tmp/pi] 3m12s $ curl -X GET http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/state
}[reuillon:/tmp/pi] $ curl -X GET http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/state
{
"state" : "finished"
}[reuillon:/tmp/pi] 4m5s $ curl -X GET http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/output
}[reuillon:/tmp/pi] $ curl -X GET http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/output
piAvg,piMed
3.1415440000000006,3.1416
[reuillon:/tmp/pi] $ curl -X PROPFIND http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/workDirectory/
{
"entries" : [ {
"name" : "result.json",
"size" : 43,
"modified" : 1584981433544,
"type" : "file"
}, {
"name" : "Pi.oms",
"size" : 869,
"modified" : 1584981429072,
"type" : "file"
} ],
"modified" : 1584981433540,
"type" : "directory"
}[reuillon:/tmp/pi] $ curl -X GET http://localhost:8080/job/160ba693-199c-48e8-9ee1-6a1f9ac66e62/workDirectory/result.json -O -J && gunzip result.json.gz && cat result.json
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 50 0 50 0 0 4166 0 --:--:-- --:--:-- --:--:-- 4166
curl: Saved to filename 'result.json.gz'
{"piAvg":3.1415440000000006,"piMed":3.1416}
""")
......
......@@ -145,16 +145,21 @@ trait RESTAPI extends ScalatraServlet
else {
val gzOs = response.getOutputStream.toGZ
if (file.isDirectory) {
val os = new TarOutputStream(gzOs)
contentType = "application/octet-stream"
response.setHeader("Content-Disposition", "attachment; filename=" + "archive.tgz")
os.archive(file)
os.close
}
else {
file.copy(gzOs)
try {
if (file.isDirectory) {
val os = new TarOutputStream(gzOs)
contentType = "application/octet-stream"
response.setHeader("Content-Disposition", "attachment; filename=" + "archive.tgz")
os.archive(file)
os.close
}
else {
contentType = "application/octet-stream"
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName + ".gz")
file.copy(gzOs)
}
}
finally gzOs.flushClose
Ok()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment