-
Notifications
You must be signed in to change notification settings - Fork 5
Gt1180 apel loading validator #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tofu-rocketry
merged 5 commits into
apel:dev
from
rowan04:GT1180-apel-loading-validator
Feb 25, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
889154a
Update HTML and request/context variables for apel loader check
rowan04 750ec66
Add database loading check to monitoring validator
rowan04 bc8342e
Improve loader check exception handling, using specific exceptions
rowan04 b68391e
Fix changes identified in code review
rowan04 d6c2668
Add documentation for setting up a blackhole engined database
rowan04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| ## Steps to set up a blackhole database for local testing of the loading validator | ||
|
|
||
| As part of the validator app, records are sent to a local instance of the apel | ||
| loader class, to test if they load into an apel server database correctly. | ||
| This is important as some errors in a record won't be detected by the syntax | ||
| validator, but will still cause a record to fail to load. | ||
|
|
||
| These records are loaded into a database with blackhole engined tables - these | ||
| tables allow insert commands, but don't store any rows or data, as data is | ||
| discarded on write. This allows complete checking that a record can be | ||
| successfully loaded to a database, without having to deal with data being stored. | ||
|
|
||
| The local instance of the apel loader class is within `monitoring/views.py`, and | ||
| uses `monitoring/validatorSettings.py` to pull configuration settings from | ||
| `monitoring/settings.ini` about the blackhole validator database. | ||
|
|
||
| Steps to set up a blackhole-engined version of the apel server database: | ||
|
|
||
| 1. Ensure maraidb is started and enabled: | ||
| - `sudo su` | ||
| - `sudo systemctl start mariadb` | ||
| - `sudo systemctl enable mariadb` | ||
|
|
||
| 2. Login to mariadb with root: | ||
| - `mysql -u root -p` | ||
|
|
||
| 3. Install the blackhole plugin, and then verify it is installed: | ||
| - `INSTALL SONAME 'ha_blackhole';` | ||
| - `SHOW ENGINES;` (should be a row with BLACKHOLE and support as YES). | ||
|
|
||
| 4. Exit mariadb: | ||
| - `exit;` | ||
|
|
||
| 5. Set the global default storage engine to blackhole, so that when the database | ||
| schema gets applied, tables are created with the blackhole engine: | ||
| - find where your mariadb settings are stored (for me it was `/etc/my.cnf.d/`). | ||
| - either edit `server.cnf` or create a new `blackhole.cnf` file (what I did). | ||
| - in that file: | ||
| ``` | ||
| [mysqld] | ||
| default-storage-engine=BLACKHOLE | ||
| ``` | ||
| - This config setting means that any create table statements without an engine | ||
| defined will be set to a blackhole engine by default. | ||
|
|
||
| 6. Restart mariadb: | ||
| - `sudo systemctl restart mariadb` | ||
| - Running `SHOW ENGINES;` within mariadb at this point should show the Blackhole | ||
| row with support as DEFAULT; | ||
|
|
||
| 7. Create the database: | ||
| - `mysql -u root -p` | ||
| - `CREATE DATABASE validator_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;` | ||
| - `CREATE USER 'your_name'@'localhost' IDENTIFIED BY 'your_password';` | ||
| - `GRANT ALL PRIVILEGES ON validator_db.* TO 'your_name'@'localhost';` | ||
| - `FLUSH PRIVILEGES;` | ||
| - `exit;` | ||
|
|
||
| 8. Apply the apel server schema to the database: | ||
| - the schema is at https://github.com/apel/apel/blob/dev/schemas/server.sql. | ||
| - to do this step, I used my locally cloned version of apel as the | ||
| schema file path. | ||
| - `mysql -u root validator_db < path_to_apel/schemas/server.sql` | ||
|
|
||
| 9. Verify the schema applied correctly, and that the correct tables use a | ||
| blackhole engine: | ||
| - `mysql -u your_name -p` | ||
| - `SHOW DATABASES;` | ||
| - `USE validator_db;` | ||
| - `SHOW TABLES;` (check all tables are there) | ||
| - `SHOW TABLE STATUS;` (check that all tables either have a BLACKHOLE or | ||
| NULL engine) | ||
|
|
||
| 10. Populate settings.ini with the following, adding in the correct values: | ||
| - ``` | ||
| [db_validator] | ||
| backend=mysql | ||
| hostname=localhost | ||
| name=validator_db | ||
| password= | ||
| port=3306 | ||
| username= | ||
| ``` | ||
| - these config options are picked up by the `validatorSettings.py` file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """ | ||
| Settings for the validator app, part of the monitoring project. | ||
|
|
||
| These settings are for the apel modules, so they need to be kept separate | ||
| from Django's control. Because Django was having issues with some of | ||
| the defined configuration, such as the database engine. | ||
| """ | ||
|
|
||
| import configparser | ||
| import os | ||
| import sys | ||
|
|
||
| # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| try: | ||
| # Read configuration from the file | ||
| cp = configparser.ConfigParser(interpolation=None) | ||
| file_path = os.path.join(BASE_DIR, 'monitoring', 'settings.ini') | ||
| cp.read(file_path) | ||
|
|
||
| VALIDATOR_DB = { | ||
| 'ENGINE': cp.get('db_validator', 'backend'), | ||
| 'HOST': cp.get('db_validator', 'hostname'), | ||
| 'PORT': cp.get('db_validator', 'port'), | ||
| 'NAME': cp.get('db_validator', 'name'), | ||
| 'USER': cp.get('db_validator', 'username'), | ||
| 'PASSWORD': cp.get('db_validator', 'password'), | ||
| } | ||
|
|
||
| except (configparser.NoSectionError) as err: | ||
| print("Error in configuration file. Check that file exists first: %s" % err) | ||
| sys.exit(1) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| # Pin packages to support and work with py3.6. | ||
| apel | ||
| Django==3.2.25 | ||
| djangorestframework==3.15.1 | ||
| pytz==2025.2 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.