Skip to content

Commit

Permalink
docs: removed deprecated configuration section from README
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-jaeger authored Jan 22, 2025
1 parent e8aca0a commit 4c05ef6
Showing 1 changed file with 2 additions and 226 deletions.
228 changes: 2 additions & 226 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,231 +137,7 @@ Follow the documentation there. The directory also contains the config files for

.. installation-from-soruce-end
Getting Started
Configuration
===============
Check out the ``examples/dev_environment`` directory which contains configuration details or the (Administrator Guide)[https://grader-service.readthedocs.io/en/latest/admin/administrator.html].

.. TODO: completely outdated -> refer to config in dev environment instead + clean up configs there (only minimal config with lots of comments)
what is confusing about configs? write comments!
what parts can be omitted? should we set default values explicitly?
describe --show-config command -> does this even work?
.. running-start
Grader service uses RabbitMQ as a task broker to delegate grading tasks to separate worker instances.
Please follow their `tutorials <https://www.rabbitmq.com/docs/download>`_ on how to set up and run a RabbitMQ server on your host machine.
Our `helm` chart automatically deploys a RabbitMQ cluster when installing the grader service through the `RabbitMQ Kubernetes Operator <https://www.rabbitmq.com/docs/kubernetes/operator/operator-overview>`_.

Running grader service
--------------------------

To run the grader service you first have to register the service in JupyterHub as an unmanaged service in the config:

.. code-block:: python
c.JupyterHub.services.append(
{
'name': 'grader',
'url': 'http://127.0.0.1:4010',
'api_token': '<token>'
}
)
The api token can be generated in the jupyterhub control panel.
You can verify the config by running ``jupyterhub -f <config_file.py>`` and you should see the following error message: ::

Cannot connect to external service grader at http://127.0.0.1:4010. Is it running?

Specifying user roles
--------------------------

Since the JupyterHub is the only source of authentication for the service, it has to rely on the JupyterHub to provide all the necessary information for user groups.

Users have to be added to specific groups which maps the users to lectures and roles. They have to be separated by colons.

The config could look like this:

.. code-block:: python
## generic
c.JupyterHub.admin_access = True
c.Spawner.default_url = '/lab'
c.Spawner.cmd=["jupyter-labhub"]
## authenticator
c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'
c.Authenticator.allowed_users = {'user1', 'user2', 'user3', 'user4'}
c.Authenticator.admin_users = {'user1', 'user2', 'user3', 'user4'}
## spawner
c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner'
c.SimpleLocalProcessSpawner.home_dir_template = '/path/to/lab_dir/{username}'
c.JupyterHub.load_groups = {
"lect1:instructor": {'users': ["user1"]},
"lect1:tutor": {'users': ["user2"]},
"lect1:student": {'users': ["user3", "user4"]},
}
Here, ``user1`` is an instructor of the lecture with the code ``lect1`` and so on.

Starting the service
--------------------------

In order to start the grader service we have to provide a configuration file for it as well:

.. code-block:: python
import os
c.GraderService.service_host = "127.0.0.1"
# existing directory to use as the base directory for the grader service
service_dir = os.path.expanduser("<grader_service_dir>")
c.GraderService.grader_service_dir = service_dir
c.JupyterHubGroupAuthenticator.hub_api_url = "http://127.0.0.1:8081/hub/api"
c.LocalAutogradeExecutor.relative_input_path = "convert_in"
c.LocalAutogradeExecutor.relative_output_path = "convert_out"
The ``<token>`` has to be the same value as the JupyterHub service token specified earlier. The ``grader_service_dir`` directory has to be an existing directory with appropriate permissions to let the grader service read and write from it.

Alternatively, you can run ``grader-service --generate-config -f /path/to/grader_service_config.py`` to generate the skeleton for the config file that show all possible configuration options.

Furthermore the database must be initialized before we can start the service.
To do this navigate to the ``grader_service_dir`` that was specified and execute the following command: ::

grader-service-migrate

Then the grader service can be started by specifying the config file as such: ::

grader-service -f <grader_service_config.py>

When restarting the JupyterHub you should now see the following log message: ::

Adding external service grader at http://127.0.0.1:4010

Do not forget to set the log level to ``INFO`` in the JupyterHub config if you want to see this message.

The last thing we have to configure is the server-side of the JupyterLab plugin which also needs information where to access the endpoints of the service. This can be done in the ``jupyter_server_config.py`` file. When using the defaults from above we do not need to explicitly configure this but it would look like this:

.. code-block:: python
import os
c.GitService.git_access_token = os.environ.get("JUPYTERHUB_API_TOKEN")
c.GitService.git_remote_url = "http://127.0.0.1:4010/services/grader/git"
c.RequestService.url = "http://127.0.0.1:4010"
.. running-end
Using LTI3 Authenticator
=========================

In order to use the grader service with an LMS like Moodle, the groups first have to be added to the JupyterHub so the grader service gets the necessary information from the hub.

For this purpose, the `LTI 1.3 Authenticator <https://github.com/TU-Wien-dataLAB/lti13oauthenticator>`_ can be used so that users from the LMS can be added to the JupyterHub.

To automatically add the groups for the grader service from the LTI authenticator, the following `post auth hook <https://jupyterhub.readthedocs.io/en/stable/api/auth.html#jupyterhub.auth.Authenticator.post_auth_hook>`_ can be used.

.. code-block:: python
from jupyterhub import orm
import sqlalchemy
def post_auth_hook(authenticator, handler, authentication):
db: sqlalchemy.orm.session.Session = authenticator.db
log = authenticator.log
course_id = authentication["auth_state"]["course_id"].replace(" ","")
user_role = authentication["auth_state"]["user_role"]
user_name = authentication["name"]
# there are only Learner and Instructors
if user_role == "Learner":
user_role = "student"
elif user_role == "Instructor":
user_role = "instructor"
user_model: orm.User = orm.User.find(db, user_name)
if user_model is None:
user_model = orm.User()
user_model.name = user_name
db.add(user_model)
db.commit()
group_name = f"{course_id}:{user_role}"
group = orm.Group.find(db, group_name)
if group is None:
log.info(f"Creating group: '{group_name}'")
group = orm.Group()
group.name = group_name
db.add(group)
db.commit()
extra_grader_groups = [g for g in user_model.groups if g.name.startswith(f"{course_id}:") and g.name != group_name]
for g in extra_grader_groups:
log.info(f"Removing user from group: {g.name}")
g.users.remove(user_model)
db.commit()
if user_model not in group.users:
log.info(f"Adding user to group: {group.name}")
group.users.append(user_model)
db.commit()
return authentication
Make sure that the ``course_id`` does not contain any spaces or special characters!

Optional Configuration of JupyterLab >=3.4
==========================================

The grader labextension also uses the embedded cell toolbar of JupyterLab for further cell manipulation.
These optional features include:

* ``Run Cell``: This command simply run the current cell without advancing.

* ``Revert Cell``: In the conversion process new metadata is set to allow students to revert every answer cell to their original state.

* ``Show Hint``: Students can access a hint to a task if one is specified.

To access these commands buttons have to be added to the JupyterLab cell toolbar by editing the `overrides.json file <https://jupyterlab.readthedocs.io/en/stable/user/directories.html#overridesjson>`_.
We also recommend that all other built in cell toolbar buttons should be disabled in the config because they might enable unwanted cell manipulation by students.

A sample overrides.json file could look like this:

.. code-block:: json
{
"@jupyterlab/cell-toolbar-extension:plugin": {
"toolbar": [
{
"args": {},
"command": "notebookplugin:run-cell",
"disabled": false,
"rank": 501,
"name": "run-cell"
},
{
"args": {},
"command": "notebookplugin:revert-cell",
"disabled": false,
"rank": 502,
"name": "revert-cell"
},
{
"args": {},
"command": "notebookplugin:show-hint",
"disabled": false,
"rank": 503,
"name": "show-hint"
}
]
}
}

0 comments on commit 4c05ef6

Please sign in to comment.