Skip to content

Latest commit

 

History

History
518 lines (382 loc) · 7.48 KB

API.md

File metadata and controls

518 lines (382 loc) · 7.48 KB

API Reference

Data Model

User

Fields

Field Type Comment
id string mongo generated
username string unique, indexed
password string bcrypt encrypted
type int

User types:

Type Code
ROOT 0
ADMIN 100
USER 200
WORKER 300

Dataset

Field Type Comment
id string mongo generated
name string unique, indexed
time int time limit
memory int memory limit
cpu int cpu limit
data string input data

CARPCase

Field Type Comment
id string mongo generated
user User reference, indexed
dataset Dataset reference, indexed
archive binary original zip
status int
submitTime date
judgeTime date
judgeWorker User
timedout bool
stdout string
outOverflow bool stdout exceeds limit
stderr string
errOverflow bool stderr exceeds limit
time double running time including docker overhead
exitcode int
path string carp result
valid bool is result valid
cost int path cost
reason string invalid reason

Status codes:

Status Code Comment
WAITING 0
QUEUED 1 sent to worker
RUNNING 2
FINISHED 3

REST API

Exception Handling

  • All exceptions will result in non-200 status code with body of json format containing further details. A typical response looks like:
{
  "timestamp": "2018-10-29T04:46:26.091+0000",
  "status": 403,
  "error": "Forbidden",
  "message": "Not logged in!",
  "path": "/api/judge/all"
}
  • All responses with 200 status DO NOT include information like the example above.

Admin

System

Dataset

Add dataset

POST /api/admin/dataset/add

Request body:

{
  "name" : "small-1",
  "time" : 10,
  "memory" : 256,
  "cpu" : 1,
  "data" : "NAME : small-1\nVERTICES : 12..."
}

Allowed user types: ROOT, ADMIN

Response:

{
  "id": "Object id of the added dataset"
}

Judge

Query by User and Dataset

GET /api/admin/judge/query?user={USER_NAME}&dataset={DATASET_NAME}

Allowed user types: ROOT, ADMIN

Response:

[
    {
        "id": "5bea74b2e47f881914f10123",
        "status": 0,
        "submitTime": "2018-11-13T06:52:34.028+0000",
        "judgeTime": null,
        "timedout": false,
        "outOverflow": false,
        "errOverflow": false,
        "time": 0,
        "exitcode": 0,
        "valid": false,
        "cost": 0,
        "reason": null,
        "userId": "5be908eea6d72a185426a6ca",
        "datasetId": "5be908ffa6d72a185426a781",
        "workerName": null
    }
]
Download Archive

GET /api/admin/judge/archive?cid={CASE_ID}

Allowed user types: ROOT, ADMIN

Response:

zip archive
Get Output

GET /api/admin/judge/output?cid={CASE_ID}

Allowed user types: ROOT, ADMIN

Response:

{
  "exitcode": 0,
  "stdout": "...",
  "stderr": "..."
}
Rejudge

POST /api/admin/judge/rejudge

Request body:

{
  "cid" : "xxx"
}

Allowed user types: ROOT, ADMIN

Response:

ok

User

Add user

POST /api/admin/user/add

Request body:

{
  "username": "user",
  "password": "pass",
  "type": 300
}

Allowed user types:

  • ROOT: ADMIN, WORKER, USER
  • ADMIN: USER

Response:

{
  "id": "Object id of the added user"
}
Change password for user

POST /api/admin/user/change/password

Request body:

{
  "username": "user",
  "password": "pass"
}

Allowed user types:

  • ROOT: ADMIN, WORKER, USER
  • ADMIN: USER

Response:

done

Dataset

Query all datasets

GET /api/dataset/all

Allowed user types: ROOT, ADMIN, USER

Response:

{
  "datasets": [
    {
      "id": "5bd5fb0a044caa567486134d",
      "name": "gdb10",
      "time": 10,
      "memory": 256,
      "cpu": 1
    }
  ]
}

Judge

Query all for logged in user

GET /api/judge/get?page={PAGE}&size={SIZE}

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "baseCases": [
        {
            "id": "5bdacbaea6d72a1b48b63784",
            "status": 3,
            "submitTime": "2018-11-01T09:47:26.263+0000",
            "judgeTime": "2018-11-01T09:47:25.511+0000",
            "timedout": false,
            "outOverflow": false,
            "errOverflow": false,
            "time": 12.249048709869385,
            "exitcode": 0,
            "valid": true,
            "cost": 0,
            "reason": null,
            "datasetId": "5bd7ddbca6d72a2e908da716",
            "userId": "5bd7d6d6a6d72a2e908da712",
            "workerName": "judge"
        }
    ],
    "total": 1
}

Page start from 0. Ordered by submitTime desc.

Query by case id

GET /api/judge/query?cid={CASE_ID}

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "id": "5bd5fbce044caa567486134e",
    "status": 3,
    "submitTime": "2018-10-28T18:11:26.103+0000",
    "judgeTime": "2018-10-28T18:11:36.646+0000",
    "timedout": false,
    "outOverflow": false,
    "errOverflow": false,
    "time": 10.630940437316895,
    "exitcode": 0,
    "valid": false,
    "cost": 0,
    "reason": null,
    "datasetId": "5bd5fb0a044caa567486134d",
    "userId": "5bd5fb02044caa5674861349",
    "workerName": "judge"
}
Query leaderboard for dataset

GET /api/judge/top?dataset={DATASET_ID}

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "baseCases": [
        {
            "userName": "root",
            "datasetId": "5bd602c4044caa5464b356e0",
            "submitTime": "2018-10-28T18:41:08.775+0000",
            "time": 9.969951629638672,
            "cost": 0
        }
    ]
}

Each user appears only once, order by cost asc, time asc, submitTime asc.

Query self best for dataset

GET /api/judge/best?dataset={DATASET_ID}

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "baseCases": [
        {
            "userName": "root",
            "datasetId": "5bd602c4044caa5464b356e0",
            "submitTime": "2018-10-28T18:41:08.775+0000",
            "time": 9.969951629638672,
            "cost": 0
        }
    ]
}
Get remaining submit time

GET /api/judge/remain

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "remain": 6,
    "total": 10
}
Get queue length

Get /api/judge/queue

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "length": 2
}
Submit data for judging

POST /api/judge/submit

Request body:

{
  "dataset": "5bd5fb0a044caa567486134d",
  "data": "Base64 encoded zip"
}

Allowed user types: ROOT, ADMIN, USER

Response:

{
    "cid": "5bd6a0170a44aa105c5927e9",
    "remain": 6
}

Login & Logout

Login

POST /api/login

Request body:

{
    "username": "user",
    "password": "123"
}

Response:

{
    "uid": "5bd5fb0a044caa567486134c",
    "type": 200
}

Logout before login again.

Logout

POST /api/logout

Response:

{
    "uid": "5bd5fb0a044caa567486134c"
}

User

Get info for logged in user

GET /api/user/info

Allowed user types: ROOT, ADMIN, WORKER, USER

Response:

{
    "uid": "5bd5fb0a044caa567486134c",
    "username": "user",
    "type": 200
}
Change password for logged in user

POST /api/user/change/password

Request body:

{
    "old": "111",
    "new": "123"
}

Allowed user types: ROOT, ADMIN, WORKER, USER

Response:

{
    "uid": "5bd6ffd10a44aa129c547ff5"
}

Status of 200 means success. Otherwise exception is thrown.