This service provides a queue system for jobs. It handles receiving jobs from various sources and sending jobs to taskgrader servers. It was made for use with the taskgrader but can work with any program using JSON to describe jobs and results.
- Platforms send jobs through the API
api.php
- Grading servers poll the queue through
poll.php
- Tasks whose tags can be handled by a given server are sent to this server
- Grading server executes the job then sends back the results through
sendresults.php
- Platforms get the results through the API
## Installation
- install composer and run
composer install
- In the
www
folder, copyconfig.inc.php.template
toconfig.inc.php
and edit it to suit your needs. - Execute
install.sh
in the root folder, it will set up the database and create the graderqueue certificate. - Create keys for the platforms and the servers using
clientcert.sh
in thecerts
folder. - Add platforms and servers to the database in the tables
platforms
andservers
. - Configure your web server to point to the
www
folder; for Apache2 and Nginx, you can use the example config files in theexamples
folder. - Secure or disable access to
interface.php
with your favorite method, for instance with thehtaccess
file in theexamples
folder.
The file config.inc.php
contains various configuration options.
The script cron.php
needs to be executed regularly to delete old tasks and
send warnings to the admin.
Once the database is set up, platforms, servers, server types and tags need to be configured.
Platforms send jobs through the API. They need to be registered first in the table platforms
:
id
andname
are internal identifiers (name is also the key id used in token communication)public_key
is the public key of the platform (used in token communications)return_url
is the url where the result of the evaluation will be sentrestrict_paths
means, if not empty, that the jobs sent by this platform will have access restricted to these paths during their executionforce_tag
means, if not-1
, that the tag with this id will be added to all jobs sent by this platform
Platforms need to call the API with their request encoded in a token, passed in a post variable name token
. This token (jwt) has the following characteristics:
- it is encrypted (JWE) with the following parameters (all names are standard):
- algorithm:
RSA-OAEP-256
- encoding:
A256CBC-HS512
- compression:
DEF
- key id: the configuration option
$CFG_key_name
ofwww/config.inc.php
- algorithm:
- its payload is a signed token (JWS) with the following parameters:
- algorithm:
RS512
- key id: the sql field
platforms.name
- algorithm:
The jws token can be verified with the platform public key (platforms.public_key
) and the jwe can be decrypted with $CFG_private_key
of www/config.inc.php
.
Tokens used in the communication with the platform's return url are one the exact same principle.
Servers poll the graderqueue for jobs, execute them, then send back the results. They need to be registered as well in the table servers
:
id
andname
are internal identifiersssl_serial
andssl_dn
are the serial and issuer DN of the client SSL certificate used by the platformwakeup_url
is an URL to call to wake-up the server: if this server hasn't been polling for a minute and the graderqueue has a job for it, it will call the URLtype
is the type of the servermax_concurrent_jobs
is the maximum number of concurrent jobs this server is allowed to ask for
Servers need to access the graderqueue through HTTPS, using a client SSL
certificate issued by the platform. The script certs/clientcert.sh
easily
creates such a certificate.
Tags are capabilities of a server. If a job is assigned tags, then only servers who can handle these tags will be given the job.
They're defined in the table tags
; the id
is the internal identifier, and
the name
is the name of the tag used by platforms when sending jobs.
A server type corresponds to a set of tags: servers of this type can handle all tags of this set (and only these tags).
Their name is defined in the table server_types
, and the tags which can be
handled are defined with pairs in the table type_tags
.
The API at api.php
is made for platforms to send jobs and request the
results. It needs to be access through HTTPS with a client SSL certificate, and
parameters must be sent in a POST request.
Note that the interface uses an extra parameter, token
, allowing it to bypass
the SSL client certificate validation (thus why the interface needs to be
secured in some way).
test
request allows a platform to test the connection and authentication. No
parameters.
sendjob
request allows a platform to send a job directly with the JSON data. Parameters:
request
:'sendjob'
jobdata
: (JSON) data of the job to be executedjobname
: (string) name for the jobpriority
: (integer) priority of the job in the queuetags
: (comma-separated list of strings) tags associated with the job
sendsolution
request allows a platform to send the parameters of a job; the
JSON data of that job will in that case be generated with standard parameters
by the API. It is mainly meant for use by the interface. Parameters:
request
:'sendsolution'
jobname
: (string) name for the jobpriority
: (integer) priority of the job in the queuetags
: (comma-separated list of strings) tags associated with the jobsolfile
orsolpath
orsolcontent
: solution, either as an uploaded file (solfile
), as a path local to the grading server (solpath
) or directly as the content of the solution (solcontent
)taskpath
: (string) path to the problemmemlimit
: (integer) memory limit for the execution of the solutiontimelimit
: (integer) time limit for the execution of the solutionlang
: (string) language of the solution
getjob
requests allows a platform to fetch the status of a job. Parameters:
request
:'getjob'
jobid
: (integer) the ID of the job
It returns a JSON array corresponding to the contents of the table for that job.
Users can access a simple interface at interface.php
; this interface allows
to send jobs, check the current status of servers and of jobs.
The folder graderserver
contains an implementation of a grading server using
this graderqueue. It was made for use with the
taskgrader, but can be used with
any program accepting the job on its standard input and sending back the
results on its standard output.
Before using it, you need to edit config.py
, using the template from
config.py.template
, and supply the client SSL certificate for this server.
The command server.py -s
will launch it in server-mode: it will daemonize and
listen on UDP for wake-up signals from the graderqueue.
Once configured, you can execute server.py -t
to test the connection and
authentication to the graderqueue.
The command-line argument --testbehavior
allows to use graderserver as a test
server for graderqueue, by simulating various behaviors an erroneous server may
have. It accepts an integer to select which test behavior to apply:
0
: behave normally (default)1
: accept a job, then poll for a new one immediately without sending back any results2
: accept a job, then wait for 60 seconds before starting the evaluation; allows to test behavior on jobs with a timeout shorter than 60 seconds3
: accept a job, then report a fatal error while sending results4
: accept a job, then report a temporary error while sending results5
: accept a job, then send back erroneous results6
: accept a job, then use /bin/cat as taskgrader, effectively sending job JSON as a dummy result JSON