8000 Add Olog electronic logbook: mongodb, phoebus_olog and phoebus_olog_webclient roles by ralphlange · Pull Request #104 · epics-training/training-vm · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ jobs:
# Don't let a failure on one architecture hide the result on the other
fail-fast: false
matrix:
# kafka, elasticsearch and phoebus_alarm_logger run in a container
# with systemd (ansible/molecule/systemd) and test the services
# functionally; phoebus_alarm_logger builds Phoebus and covers the
# whole alarm system (Kafka, alarm server, Elasticsearch, logger)
# kafka, elasticsearch, phoebus_alarm_logger, mongodb, phoebus_olog
# and phoebus_olog_webclient run in a container with systemd
# (ansible/molecule/systemd) and test the services functionally;
# phoebus_alarm_logger builds Phoebus and covers the whole alarm
# system (Kafka, alarm server, Elasticsearch, logger),
# phoebus_olog(_webclient) the logbook (Elasticsearch, MongoDB, Olog)
role:
- initial_setup
- m_base
Expand All @@ -31,6 +33,9 @@ jobs:
- kafka
- elasticsearch
- phoebus_alarm_logger
- mongodb
- phoebus_olog
- phoebus_olog_webclient
# The molecule platform image (ubuntu:22.04) is multi-arch, so each
# runner exercises the role natively on its own architecture
arch:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-roles-phoebus-aa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ on:
- 'ansible/roles/kafka/**'
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/mongodb/**'
- 'ansible/roles/phoebus_olog/**'
- 'ansible/roles/phoebus_olog_webclient/**'
- 'ansible/roles/java/**'
- 'ansible/roles/archiver_appliance/**'
pull_request:
Expand All @@ -28,6 +31,9 @@ on:
- 'ansible/roles/kafka/**'
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/mongodb/**'
- 'ansible/roles/phoebus_olog/**'
- 'ansible/roles/phoebus_olog_webclient/**'
- 'ansible/roles/java/**'
- 'ansible/roles/archiver_appliance/**'
workflow_dispatch:
Expand Down
3 changes: 3 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ phoebus_alarm: false
phoebus_alarm_logger: false
kafka: false
elasticsearch: false
mongodb: false
phoebus_olog: false
phoebus_olog_webclient: false
oac_tree: false
archiver_appliance: false
bluesky: false
Expand Down
2 changes: 1 addition & 1 deletion ansible/molecule/systemd/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Molecule platform image with systemd as PID 1
#
# Shared by the Molecule scenarios that test services (kafka, elasticsearch,
# phoebus_alarm_logger):
# mongodb, phoebus_alarm_logger, phoebus_olog, phoebus_olog_webclient):
# with a real systemd the roles run with in_container=false, i.e. exactly as on a VM,
# and the tests can check that the services are actually running and working.
# Needs a privileged container sharing the host's cgroup namespace - see the
Expand Down
20 changes: 20 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@
when: phoebus_alarm_logger is defined and phoebus_alarm_logger | bool
tags: phoebus_alarm_logger

- name: MongoDB
include_role:
name: mongodb
when: mongodb is defined and mongodb | bool
tags: mongodb

# Pulls in the elasticsearch and mongodb roles as dependencies
- name: Olog
include_role:
name: phoebus_olog
when: phoebus_olog is defined and phoebus_olog | bool
tags: phoebus_olog

# Pulls in the phoebus_olog role as a dependency
- name: Olog Web Client
include_role:
name: phoebus_olog_webclient
when: phoebus_olog_webclient is defined and phoebus_olog_webclient | bool
tags: phoebus_olog_webclient

- name: OAC Tree
include_role:
name: oac_tree
Expand Down
34 changes: 34 additions & 0 deletions ansible/roles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ them to the Phoebus "Alarm Log" table through its REST API
`phoebus` role's client preferences like the alarm server's settings).
Built by the `phoebus` role and pulls in `phoebus_alarm` (alarm server, Kafka).

### phoebus_olog
Olog electronic logbook service (REST API) as a systemd service:
built with Maven from its release tar (Maven from the `phoebus` role), log entries
stored in Elasticsearch (`elasticsearch` role), attachments in MongoDB
(`mongodb` role), both dependencies.
Plain HTTP at `olog_url` (default `http://localhost:4180/Olog`, shared with
the `phoebus` role's client preferences like the alarm system's settings),
HTTPS with Olog's self-signed certificate on port 4181. Built-in accounts `user`/`userPass` and
`admin`/`adminPass`. When enabled, the `phoebus` role configures the Phoebus
logbook to use Olog (default logbook `operations`).
Follows `phoebus_services_phoebus_olog` of
[ansible-phoebus](https://github.com/ControlSystemStudio/ansible-phoebus).

### phoebus_olog_webclient
Olog web client, built from its release tar with Node.js (installed by the role) and served as a
systemd service at `olog_webclient_url` (default `http://localhost:3000`,
shared with the `phoebus_olog` and `phoebus` roles; linked on the
Training-VM homepage).
Pulls in `phoebus_olog`. Follows `phoebus_services_phoebus_olog_webclient`
of [ansible-phoebus](https://github.com/ControlSystemStudio/ansible-phoebus),
but builds once at install time instead of at every service start.

### archiver_appliance
Minimal install of the EPICS Archiver Appliance.

Expand Down Expand Up @@ -97,6 +119,14 @@ Follows `phoebus_services_elasticsearch` of
[ansible-phoebus](https://github.com/ControlSystemStudio/ansible-phoebus):
everything under `/opt/epics-tools/services/elasticsearch` (`release/`
with its `config/`, `data/`, `logs/`, `run/`), owned by the service account.
Also the storage of Olog's log entries.

### mongodb
MongoDB (single node, localhost only, no authentication)
as a systemd service - the attachment storage of Olog.
Installed from MongoDB's generic release archive (Ubuntu builds on the
Debian family, RHEL builds on the Red Hat family), everything under
`/opt/epics-tools/services/mongodb`.

### docker
Installation of Docker or Podman to run containers.
Expand Down Expand Up @@ -125,6 +155,10 @@ unsupported architecture) and thereby provides:
(`x64`, `aarch64`).
- `arch.elasticsearch`: architecture token used by the Elasticsearch release
archives (`x86_64`, `aarch64`).
- `arch.mongodb`: architecture token used by the MongoDB release archives
(`x86_64`, `aarch64`).
- `arch.nodejs`: architecture token used by the Node.js release archives
(`x64`, `arm64`).
- `is_x86_64` / `is_aarch64`: booleans, for gating a task that genuinely only
applies to one architecture.

Expand Down
3 changes: 2 additions & 1 deletion ansible/roles/elasticsearch/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# https://github.com/ControlSystemStudio/ansible-phoebus:
# one service root with release/, data/, logs/ and run/, all owned by the
# service account; the configuration lives in release/config.
# Used by the Phoebus alarm logger (phoebus_alarm_logger role).
# Used by the Phoebus alarm logger (phoebus_alarm_logger role) and Olog
# (phoebus_olog role).
#
# Stays on the 8.x line: Phoebus 6 uses the Elasticsearch 8 Java client,
# which is not supported against a 9.x server.
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/elasticsearch/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ galaxy_info:
role_name: elasticsearch
namespace: epics
author: Ralph Lange
description: Elasticsearch (single node) for the Phoebus alarm logger
description: Elasticsearch (single node) for the Phoebus alarm logger and Olog
license: EPICS open license
min_ansible_version: "2.15"
# Elasticsearch runs on the JDK installed by the java role
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# {{ ansible_managed }}
[Unit]
Description=Elasticsearch (single node) for the Phoebus alarm logger
Description=Elasticsearch (single node) for the Phoebus alarm logger and Olog
Documentation=https://www.elastic.co
Wants=network-online.target
After=network-online.target
Expand Down
52 changes: 52 additions & 0 deletions ansible/roles/mongodb/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# Defaults for MongoDB (single node, localhost only, no authentication)
#
# Modelled on the phoebus_services_mongodb role of
# https://github.com/ControlSystemStudio/ansible-phoebus:
# one service root with data/, logs/ and run/, owned by the service account.
# Used by Olog (phoebus_olog role) to store the log entry attachments.
#
# Unlike ansible-phoebus (MongoDB's RPM repository, RHEL x86_64 only), this
# installs the generic release archive, which MongoDB publishes per distro
# family for x86_64 and aarch64: one install method for all distros of the
# training VM. Debian has no aarch64 build - its Debian family uses the
# Ubuntu builds (same glibc/OpenSSL 3/libcurl 4 baseline).

mongodb_version: "8.0.38"

# Distro build of the release archive (see https://www.mongodb.com/try/download)
mongodb_target: >-
{%- if is_debian -%}
{{ 'ubuntu2204' if (ansible_facts['distribution'] == 'Ubuntu'
and ansible_facts['distribution_major_version'] | int < 24)
else 'ubuntu2404' }}
{%- elif ansible_facts['distribution'] != 'Fedora'
and ansible_facts['distribution_major_version'] | int >= 10 -%}
rhel10
{%- else -%}
rhel93
{%- endif -%}

mongodb_archive: "mongodb-linux-{{ arch.mongodb }}-{{ mongodb_target }}-{{ mongodb_version }}.tgz"
# The download is verified against the .sha256 file MongoDB publishes next to it
mongodb_url: "https://fastdl.mongodb.org/linux/{{ mongodb_archive }}"

mongodb_root: "/opt/epics-tools/services/mongodb"
mongodb_account: mongodb

mongodb_release_dir: "{{ mongodb_root }}/release"
mongodb_data_dir: "{{ mongodb_root }}/data"
mongodb_logs_dir: "{{ mongodb_root }}/logs"
mongodb_conf_file: "{{ mongodb_root }}/mongod.conf"

# Only listen on localhost (training VM, no authentication)
mongodb_bind_ip: "127.0.0.1"
mongodb_port: 27017
# WiredTiger would otherwise take half of the RAM (minus 1 GB) as its cache
mongodb_cache_size_gb: 0.25

mongodb_service_name: mongodb

# Set to true when running in a container without systemd: the service is
# then installed and configured, but not started
in_container: false
10 changes: 10 additions & 0 deletions ansible/roles/mongodb/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Handlers for MongoDB

- name: Restart MongoDB service
become: true
when: not in_container
ansible.builtin.systemd_service:
name: "{{ mongodb_service_name }}"
state: restarted
daemon_reload: true
10 changes: 10 additions & 0 deletions ansible/roles/mongodb/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# galaxy_info is required by Molecule's prerun (role name check)
galaxy_info:
role_name: mongodb
namespace: epics
author: Ralph Lange
description: MongoDB (single node) for the Olog attachments
license: EPICS open license
min_ansible_version: "2.15"
dependencies: []
25 changes: 25 additions & 0 deletions ansible/roles/mongodb/molecule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Molecule tests for the mongodb role

Functional tests: the `default` scenario installs MongoDB (role `mongodb`)
in an `ubuntu:22.04` container, then runs the testinfra tests in
`resources/tests/test_mongodb.py`.
The container runs systemd as PID 1 (privileged, host cgroup namespace;
image definition shared in `ansible/molecule/systemd/Dockerfile.j2`), so the
role runs with `in_container: false`, exactly as on a VM, and the service
really starts.

| Test | Checks |
|---|---|
| `test_service_is_running_and_enabled` | the `mongodb` systemd service is running and enabled |
| `test_listens_on_localhost_only` | port 27017 is listening, on loopback addresses only |
| `test_runs_as_unprivileged_user` | `mongod` runs as the `mongodb` user |
| `test_server_version` | the installed server is version 8.0.x |
| `test_answers_hello_command` | the server answers a `hello` command (sent with a minimal wire protocol client, as the release has no shell) as a writable primary |

CI runs the scenario on x86_64 and aarch64 (`.github/workflows/molecule.yml`).
To run it locally (needs Docker):

```bash
cd ansible/roles/mongodb
molecule test
```
42 changes: 42 additions & 0 deletions ansible/roles/mongodb/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
dependency:
name: galaxy
lint: |
set -e
yamllint .
ansible-lint
flake8
provisioner:
name: ansible
playbooks:
converge: ../resources/converge.yml
inventory:
host_vars:
mongodb-systemd:
# Real systemd in the container: run the services as on a VM
in_container: false
group_vars:
all:

scenario:
name: default
verifier:
name: testinfra
directory: ../resources/tests/
driver:
name: docker
# Container with systemd as PID 1 (shared image definition in ansible/molecule/systemd)
platforms:
- name: mongodb-systemd
image: ubuntu:22.04
# relative to the scenario directory
dockerfile: ../../../../molecule/systemd/Dockerfile.j2
pre_build_image: false
command: /lib/systemd/systemd
privileged: true
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
33 changes: 33 additions & 0 deletions ansible/roles/mongodb/molecule/resources/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Converge
hosts: all
become: true

# Molecule runs the roles directly, bypassing playbook.yml, so the OS and
# architecture variables the roles rely on have to be loaded here too.
# Same first-found logic as playbook.yml's pre_tasks. Everything else
# comes from the roles' own defaults.
pre_tasks:
- name: Load OS-specific variables with fallback
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_facts['distribution'] }}_\
{{ ansible_facts['distribution_major_version'] }}.yml"
- "{{ ansible_facts['distribution'] }}.yml"
- "{{ ansible_facts['os_family'] }}.yml"
- "default.yml"
paths:
- "{{ playbook_dir }}/../../../../vars/os"

- name: Load architecture-specific variables with fallback
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_facts['architecture'] }}.yml"
- "default.yml"
paths:
- "{{ playbook_dir }}/../../../../vars/arch"

roles:
- role: mongodb
Loading
0