Skip to content

Commit fdb5a6a

Browse files
committed
Added GUIDE.MD for the rest api
1 parent daf9c79 commit fdb5a6a

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

JShellAPI/GUIDE.MD

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## Endpoints
2+
### Eval
3+
Everything works with sessions, the code is evaluated on a session which has a certain lifetime.
4+
```
5+
POST /eval/{id} body=code -> JShellResult
6+
POST /eval body=code -> JShellResultWithId
7+
POST /single-eval body=code -> JShellResult
8+
```
9+
- The first one takes an id, create a session from this id, or use an existing session if this id already exists.
10+
- The second one creates a new session each time, with a random id, and so it returns the generated id, in order to be reused.
11+
- The third one creates a session that can only be used once, not only that, but this session is called a one-time session and has lower timeout.
12+
#### Response
13+
In all three, a string containing code to be evaluated needs to be supplied, and a JShellResult will be returned containing the result :
14+
```java
15+
record JShellResult(
16+
SnippetStatus status,
17+
SnippetType type,
18+
int id,
19+
String source,
20+
String result,
21+
JShellExceptionResult exception,
22+
boolean stdoutOverflow,
23+
String stdout,
24+
List<String> errors){
25+
}
26+
enum SnippetStatus {
27+
VALID, RECOVERABLE_DEFINED, RECOVERABLE_NOT_DEFINED, REJECTED, ABORTED
28+
}
29+
enum SnippetType {
30+
ADDITION, MODIFICATION
31+
}
32+
record JShellExceptionResult(
33+
String exceptionClass,
34+
String exceptionMessage) {
35+
}
36+
record JShellResultWithId(
37+
String id,
38+
JShellResult result) {
39+
}
40+
```
41+
### Other endpoints
42+
```
43+
GET /snippets/{id} body=none -> List<String>
44+
DELETE /{id} body=none -> none
45+
```
46+
- The first one will retrieve all snippets of a given session
47+
- The second one will forcibly delete the given session
48+
### Errors
49+
if a problem happens, by default a 5XX error will be thrown, except in those cases :
50+
- Given [id](#Identifiers) is invalid : 400 Bad Request.
51+
- No session found with the given id : 404 Not Found.
52+
- An operation is already running on this session : 409 Conflict.
53+
- A session needs to be created, but the maximum number of session is already reached : 429 Too Many Requests.
54+
## Model
55+
Docker containers are used to encapsulate JShell evaluations.
56+
Each container is called a session, and can be reused assuming an identifier is used.
57+
The id of one-time sessions isn't shared.
58+
The endpoints may create, reuse or rarely delete sessions, deleting their related containers.
59+
### Timeouts
60+
Sessions have two timeouts, a per-eval timeout and a per-session timeout.
61+
#### Eval timeout
62+
This timeout is rather short, and limits the time an eval can last, in order for example to prevent infinite loops to use infinite CPU time.
63+
This timeout happens during the container itself, and so may be subject to security concern.
64+
#### Session timeout
65+
This timeout is rather long, unless for one-time session, and limits the lifetime of a session.
66+
It is reset each time an interaction is done with a session.
67+
Once the timeout happens, a session isn't deleted immediately, but rather after a certain time, when a session killer checks the dead sessions.
68+
When a session dies, the container is deleted.
69+
##### One-time session timeout
70+
A one-time session may have a timeout just a bit longer than an Eval timeout.
71+
### Identifiers
72+
The identifier must match the following regex :
73+
```regexp
74+
[a-zA-Z0-9][a-zA-Z0-9_.-]+
75+
```
76+
A random identifier is simply a random uuid.
77+
## Configuration
78+
Properties can be defined in resources/application.properties
79+
### jshellapi.regularSessionTimeoutSeconds
80+
The timeout of a regular session, in seconds, see [Session timeout](#Session-timeout).
81+
### jshellapi.oneTimeSessionTimeoutSeconds
82+
The timeout of a one-time session, in seconds, see [One-time session timeout](#One-time-session-timeout).
83+
### jshellapi.evalTimeoutSeconds
84+
The timeout of an evaluation, in seconds, see [Eval timeout](#Eval-timeout)
85+
### jshellapi.maxAliveSessions
86+
The maximum number of alive sessions, see [Errors](#Errors)
87+
### jshellapi.dockerMaxRamMegaBytes
88+
The maximum ram allocated per container, in megabytes.
89+
### jshellapi.dockerCPUsUsage
90+
The cpu configuration of each container, see [--cpus option of docker](https://docs.docker.com/config/containers/resource_constraints/#cpu).
91+
### jshellapi.schedulerSessionKillScanRate
92+
The rate at which the session killer will check and delete session, in seconds, see [Session timeout](#Session-timeout).

0 commit comments

Comments
 (0)