~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to doc/dev/architecture.rst

  • Committer: William Grant
  • Date: 2010-02-25 07:34:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225073450-zcl8ev5hlyhbszeu
Activate the Storm C extensions if possible. Moar speed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
186
186
very large.
187
187
 
188
188
 
189
 
.. ref-python-console
 
189
.. _ref-python-console:
190
190
 
191
191
Python Console
192
192
==============
193
193
 
194
194
IVLE provides a web based programming console, exposing similar features to 
195
 
Python's command line console. It is built around python script 
196
 
:file:`services/python-console` which opens up a socket to which `JSON`_ 
197
 
encoded chat requests can be made. A new console is typically from launched on 
198
 
demand by the web client to the HTTP API, which in turn calls the wrapper 
199
 
class :class:`ivle.console.Console` to start a new console in the user's jail.
 
195
Python's command line console. It is built around the
 
196
:file:`services/python-console` script, which opens up a socket on a random
 
197
port to which `JSON`_ encoded chat requests can be made.
 
198
 
 
199
A new console is typically launched on demand by the web client to the HTTP
 
200
API, which in turn calls the wrapper class :class:`ivle.console.Console` to
 
201
start a new console in the user's jail.
 
202
 
 
203
Subsequent requests from the same in-browser console connect to the existing
 
204
console process. This is achieved by storing a string on the client which
 
205
identifies the server address and port. The client then makes requests
 
206
through the load balancer, sending this string through to an arbitrary slave
 
207
which forwards the request to the identified console.
 
208
 
 
209
This means that all slaves need access to all ports on every other slave.
200
210
 
201
211
.. _JSON: http://json.org
202
212
 
203
213
 
204
 
.. _ref-usermgt-server:
 
214
.. _ref-usrmgt-server:
205
215
 
206
216
User Management Server
207
217
======================
215
225
* Creating group Subversion repositories.
216
226
* Rebuilding Subversion authorization files. 
217
227
 
218
 
Communication with the Server is done using the `Chat Protocol <ref-chat>`_.  
219
 
To prevent unauthorized use, communication with the User Management Server 
220
 
requires that a *shared secret* be used to communicate with the server.  This 
221
 
secret is stored in the `magic` variable in the `[usrmgt]` section of 
222
 
:file:`/etc/ivle/ivle.conf`.
 
228
Communication with the Server is done using the :ref:`Chat Protocol
 
229
<ref-chat>`.  To prevent unauthorized use, communication with the User
 
230
Management Server requires that a *shared secret* be used to communicate with
 
231
the server.  This secret is stored in the `magic` variable in the `[usrmgt]`
 
232
section of :file:`/etc/ivle/ivle.conf`.
223
233
 
224
234
The User Management Server is called almost exclusively from the 
225
235
:mod:`ivle.webapp.userservice` module.
231
241
Chat Protocol
232
242
=============
233
243
 
234
 
**Chat** is our JSON_-based client/server communication protocol used in 
235
 
communicating to `Python Console <ref-python-console>`_ processes and `User 
236
 
Management Server <ref-usrmgt-server>`_.  Since it is JSON-based it can be 
237
 
called from either Python or JavaScript.
 
244
**Chat** is our JSON_-based client/server communication protocol used in
 
245
communicating to :ref:`Python Console <ref-python-console>` processes and
 
246
:ref:`User Management Server <ref-usrmgt-server>`.  Since it is JSON-based it
 
247
can be called from either Python or JavaScript.
238
248
 
239
249
Protocol
240
250
--------
300
310
 
301
311
Each user is allocated a Subversion repository when their :ref:`Jail 
302
312
<ref-jail>` is created by the :ref:`User Management Server 
303
 
<ref-usermgt-server>`. Repository are stored in the location specified by 
304
 
``[paths] [[svn]] repo_path`` in :file:`/etc/ivle/ivle.conf` (by default 
 
313
<ref-usrmgt-server>`. Repository are stored in the location specified by 
 
314
``paths/svn/repo_path`` in :file:`/etc/ivle/ivle.conf` (by default 
305
315
:file:`/var/lib/ivle/svn/repositories/`). User repositories are stored in the 
306
316
:samp:`users/{USERNAME}/` subdirectory and group repositories in 
307
317
:samp:`groups/{SUBJECT}_{YEAR}_{SEMESTER}_{GROUP}`.
320
330
These repositories are served by Apache using ``mod_dav_svn`` allowing access 
321
331
over Subversion's WebDAV HTTP or HTTPS backends. Users are authenticated using 
322
332
a randomly generated key which is stored in the database and is made available 
323
 
to each user inside their Jail (``svn_pass`` property inside 
 
333
to each user inside their jail (``svn_pass`` property inside 
324
334
:file:`/home/.ivle.conf`). This key is automatically provided when doing 
325
 
Subversion actions, but can be manually entered when accessing a users 
 
335
Subversion actions, but can be manually entered when accessing a user's 
326
336
repository from an external Subversion client such as with :samp:`svn checkout 
327
337
{svn_addr}/users/{USERNAME}/ workspace`.
328
338
 
329
 
Repository permissions for ``AuthzSVNAccessFILE`` are automatically generated 
330
 
and placed in the file located at ``[paths] [[svn]] conf`` for user 
331
 
repositories and ``[paths] [[svn]] group_conf`` for group repositories. User 
332
 
authentication keys for ``AuthUserFile`` are stored in the file located at 
333
 
``[path] [[svn]] auth_ivle``. These will be regenerated each time user or 
334
 
group repository settings change.
 
339
Repository permissions for ``AuthzSVNAccessFile`` are automatically generated 
 
340
and placed in the file specified by the ``paths/svn/conf`` config option
 
341
(usually ``/var/lib/ivle/svn/svn.conf``) for user repositories and the
 
342
``paths/svn/group_conf`` option for group repositories (usually
 
343
``/var/lib/ivle/svn/svn-group.conf``). User authentication keys for
 
344
``AuthUserFile`` are stored in the file specified by ``paths/svn/auth_ivle``,
 
345
usually ``/var/lib/ivle/svn/ivle.auth``. These will be regenerated each time
 
346
user or group repository settings change.
335
347
 
336
348
 
337
349
Worksheets
338
350
==========
339
351
 
 
352
Worksheets provide a way for users to be able to attempt a set of coding 
 
353
exercises along with accompanying instructions. In the past worksheets were 
 
354
created directly using an XML format, but this has been deprecated in favour 
 
355
of being generated automatically from reStructuredText.
 
356
 
 
357
Worksheets are now stored in the database as a :class:`Worksheet` object (see 
 
358
:file:`ivle/database.py`).  This allows them to be treated with the same 
 
359
access permissions available to other objects and lays down the ground work 
 
360
for providing versioned worksheets.
 
361
 
 
362
 
 
363
Exercises
 
364
---------
 
365
 
 
366
When users submit an exercise, the user's solution is tested against a series 
 
367
of test cases which can be used to check if a solution is acceptable. Almost 
 
368
all the behavior for exercises is contained within 
 
369
:file:`ivle/webapp/tutorial/test/TestFramework.py`.
 
370
 
 
371
.. note::
 
372
    The TestFramework module is one of the oldest and most complicated in 
 
373
    IVLE, largely taken directly from the IVLE prototype. As such it has a 
 
374
    design that doesn't quite match the current architecture of IVLE, such as 
 
375
    using slightly different terminology and having a few testing facilities 
 
376
    that are untested or untested. It requires a substantial rewrite and 
 
377
    comprehensive test suite to be developed.
 
378
 
 
379
At the top level exists the :class:`Exercise` object (known as ``TestSuite`` 
 
380
in :file:`TestFramework.py`). This object encompasses the entire collection of 
 
381
tests for a given exercise and details such as the exercise name, provided 
 
382
solution and any "include code" (Python code available for all test cases, but 
 
383
not the user's submission).
 
384
 
 
385
Each exercise may contain one or more :class:`TestSuite` objects (known as 
 
386
``TestCase`` in :file:`TestFramework.py`. A test suite is a collection of 
 
387
tests that run with some sort of common input - be that stdin contents, a 
 
388
virtual file system configuration (presently disabled), inputs to particular 
 
389
function or defining the contents of one or more variables. A test suite will 
 
390
typically run until the first test case fails, but can be configured to 
 
391
continue running test cases even after one has failed. Exceptions raised by 
 
392
submitted code will typically cause the test to fail except if it is marked as 
 
393
an "allowed exception".
 
394
 
 
395
Individual units to be tested (something that can pass or fail) are contained 
 
396
within :class:`TestCase` objects (known as ``TestCaseParts`` in 
 
397
:file:`TestFramework.py`). A test case can test the value of source code text, 
 
398
the function return value (Will be ``None`` for scripts), stdout contents, 
 
399
stderr contents, name of any raised exception and contents of the virtual file 
 
400
system (presently disabled) of code submitted by users. These checks are 
 
401
contained in a :class:`TestCasePart`. In addition, a normalisation function or 
 
402
custom comparison function can be used instead of comparing the raw values 
 
403
directly.  By default, the value of each check will be ignored unless 
 
404
overidden by a test case part.
 
405
 
340
406
Database
341
407
========
342
408
 
343
 
..  TODO: Not yet merged
344
 
    Object Publishing
345
 
    =================
 
409
 
 
410
Object Publishing
 
411
=================
 
412
 
 
413
URLs are resolved with a small IVLE-specific object publishing framework --
 
414
that is, resolution is implemented as traversal through an object graph. The
 
415
framework lives in :mod:`ivle.webapp.publisher`, and has an extensive test
 
416
suite.
 
417
 
 
418
This object graph is constructed by the dispatcher. Any plugin class deriving
 
419
from ViewPlugin will be searched for ``forward_routes``, ``reverse_routes``
 
420
and ``views`` sequences. Everything is class-based -- an object's routes
 
421
and views are determined by its class.
 
422
 
 
423
Forward routes handle resolution of URLs to objects. Given a source object
 
424
and some path segments, the route must calculate the next object.
 
425
A forward route is a tuple of ``(source class, intermediate path segments,
 
426
function, number of subsequent path segments to consume)``, or simply a
 
427
reference to a decorated function (see :mod:`ivle.webapp.admin.publishing`
 
428
for decoration examples). The function must return the next object in the
 
429
path.
 
430
 
 
431
A reverse route handles URL generation for an object. Given just an object,
 
432
it must return a tuple of ``(previous object, intermediate path segments)``.
 
433
This creates a chain of objects and path segments until the root is reached.
 
434
Due to IVLE's lack of a utility framework, reverse routes at the root of the
 
435
URL space need to refer to the root object with the magical
 
436
:mod:`ivle.webapp.publisher.ROOT`. 
 
437
 
 
438
Views are registered with a tuple of ``(source class, intermediate path segments,
 
439
view class)``.
 
440
 
 
441
In all of the above, "intermediate path segments" can either be a single
 
442
segment string, or a sequence of multiple strings representing multiple
 
443
segments.
 
444
 
 
445
.. note::
 
446
   While many applications prefer a pattern matching mechanism, this did not
 
447
   work out well for IVLE. Our deep URL structure and multitude of nested
 
448
   objects with lots of views meant that match patterns had to be repeated
 
449
   tediously, and views required many lines of code to turn a match into a
 
450
   context object. It also made URL generation very difficult.
 
451
 
 
452
   The simple object publishing framework allows views to be registered with
 
453
   just one line of code, getting their context object for free. URL
 
454
   generation now comes at a cost of approximately one line of code per class,
 
455
   and breadcrumbs are easy too. The reduced code duplication also improves
 
456
   robustness.