8000 Add Phoebus alarm server (+ Kafka) and alarm logger (+ Elastic) roles by ralphlange · Pull Request #101 · epics-training/training-vm · GitHub
[go: up one dir, main page]

Skip to content
Closed
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: 12 additions & 1 deletion .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ jobs:
# Don't let a failure on one architecture hide the result on the other
fail-fast: false
matrix:
role: ["initial_setup", "m_base", "phoebus", "archiver_appliance"]
# 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)
role:
- initial_setup
- m_base
- phoebus
- archiver_appliance
- kafka
- elasticsearch
- phoebus_alarm_logger
# The molecule platform image (ubuntu:22.04) is multi-arch, so each
# runner exercises the role natively on its own architecture
arch:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test-roles-phoebus-aa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- 'ansible/vars/ci-phoebus-aa.yml'
- 'ansible/requirements.yml'
- 'ansible/roles/phoebus/**'
- 'ansible/roles/phoebus_alarm/**'
- 'ansible/roles/kafka/**'
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/java/**'
- 'ansible/roles/archiver_appliance/**'
pull_request:
Expand All @@ -20,6 +24,10 @@ on:
- 'ansible/vars/ci-phoebus-aa.yml'
- 'ansible/requirements.yml'
- 'ansible/roles/phoebus/**'
- 'ansible/roles/phoebus_alarm/**'
- 'ansible/roles/kafka/**'
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/java/**'
- 'ansible/roles/archiver_appliance/**'
workflow_dispatch:
Expand Down
4 changes: 4 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ install_graphics: false
docker: true # for rootful this needs to happen before first reboot
catrust: false
phoebus: false
phoebus_alarm: false
phoebus_alarm_logger: false
kafka: false
elasticsearch: false
oac_tree: false
archiver_appliance: false
bluesky: false
Expand Down
31 changes: 31 additions & 0 deletions ansible/molecule/systemd/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Molecule platform image with systemd as PID 1
#
# Shared by the Molecule scenarios that test services (kafka, elasticsearch,
# phoebus_alarm_logger):
# 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
# platform definitions in the scenarios' molecule.yml.
FROM {{ item.image }}

ENV container=docker
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
systemd systemd-sysv dbus \
python3 python3-apt sudo ca-certificates \
git tar gzip unzip curl iproute2 procps \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Units that make no sense (or hang) in a container
RUN rm -f /lib/systemd/system/multi-user.target.wants/getty.target \
/lib/systemd/system/sysinit.target.wants/systemd-firstboot.service \
/lib/systemd/system/sysinit.target.wants/systemd-udevd.service \
/lib/systemd/system/sysinit.target.wants/sys-fs-fuse-connections.mount \
/lib/systemd/system/local-fs.target.wants/systemd-remount-fs.service \
&& systemctl mask systemd-logind.service getty.target console-getty.service

STOPSIGNAL SIGRTMIN+3
CMD ["/lib/systemd/systemd"]
34 changes: 32 additions & 2 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

- name: Decide if graphics should be installed
ansible.builtin.set_fact:
install_graphics: "{{ install_graphics | bool or phoebus | default(false) | bool or oac_tree | default(false) | bool }}"
install_graphics: "{{ install_graphics | bool or phoebus | default(false) | bool or phoebus_alarm | default(false) | bool or phoebus_alarm_logger | default(false) | bool or oac_tree | default(false) | bool }}"
tags: always

- name: Initial setup
Expand Down Expand Up @@ -143,12 +143,42 @@
include_role:
name: bluesky

# Also runs for phoebus_alarm(_logger): the Phoebus build produces the alarm services
- name: Phoebus
include_role:
name: phoebus
when: phoebus is defined and phoebus | bool
when: >-
(phoebus is defined and phoebus | bool) or
(phoebus_alarm is defined and phoebus_alarm | bool) or
(phoebus_alarm_logger is defined and phoebus_alarm_logger | bool)
tags: phoebus

- name: Kafka
include_role:
name: kafka
when: kafka is defined and kafka | bool
tags: kafka

# Pulls in the kafka role as a dependency
- name: Phoebus Alarm Server
include_role:
name: phoebus_alarm
when: phoebus_alarm is defined and phoebus_alarm | bool
tags: phoebus_alarm

- name: Elasticsearch
include_role:
name: elasticsearch
when: elasticsearch is defined and elasticsearch | bool
tags: elasticsearch

# Pulls in the elasticsearch and phoebus_alarm roles as dependencies
- name: Phoebus Alarm Logger
include_role:
name: phoebus_alarm_logger
when: phoebus_alarm_logger is defined and phoebus_alarm_logger | bool
tags: phoebus_alarm_logger

- name: OAC Tree
include_role:
name: oac_tree
Expand Down
31 changes: 31 additions & 0 deletions ansible/roles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ StreamDevice Device Support.
### phoebus
Control System Studio / Phoebus.

### phoebus_alarm
Phoebus alarm server as a systemd service.
It is built by the `phoebus` role, which is therefore always run
with this role; Kafka comes from the `kafka` role (a dependency).
The alarm configuration name (`alarm_config_name`, default `Accelerator`)
and Kafka address (`alarm_kafka_server`) are role defaults; the `phoebus`
role uses the same variable names for the client preferences, so setting
them once in a setup file configures client and server consistently.

### phoebus_alarm_logger
Phoebus alarm logger as a systemd service: stores the alarm system's
messages in Elasticsearch (`elasticsearch` role, a dependency) and serves
them to the Phoebus "Alarm Log" table through its REST API
(`alarm_logger_url`, default `http://localhost:9000`, shared with the
`phoebus` role's client preferences like the alarm server's settings).
Built by the `phoebus` role and pulls in `phoebus_alarm` (alarm server, Kafka).

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

Expand Down 10BC8 Expand Up @@ -64,6 +81,18 @@ The CALC (array and string calculation) module.
### m_sscan
The SSCAN (multi-dimensional scan record) module.

### kafka
Apache Kafka message broker (single node, KRaft mode, localhost only)
as a systemd service - the transport of the Phoebus alarm system.

### elasticsearch
Elasticsearch (single node, localhost only, security disabled)
as a systemd service - the storage of the Phoebus alarm logger.
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.

### docker
Installation of Docker or Podman to run containers.

Expand All @@ -89,6 +118,8 @@ unsupported architecture) and thereby provides:
(`x86_64-linux-gnu`, `aarch64-linux-gnu`).
- `arch.java`: architecture token used by the Adoptium/Temurin release assets
(`x64`, `aarch64`).
- `arch.elasticsearch`: architecture token used by the Elasticsearch release
archives (`x86_64`, `aarch64`).
- `is_x86_64` / `is_aarch64`: booleans, for gating a task that genuinely only
applies to one architecture.

Expand Down
52 changes: 52 additions & 0 deletions ansible/roles/elasticsearch/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# Defaults for Elasticsearch (single node, localhost only, no security)
#
# Follows the phoebus_services_elasticsearch role of
# 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).
#
# Stays on the 8.x line: Phoebus 6 uses the Elasticsearch 8 Java client,
# which is not supported against a 9.x server.

elasticsearch_version: "8.19.25"
# The download is verified against the .sha512 file Elastic publishes next to it
elasticsearch_url: "https://artifacts.elastic.co/downloads/elasticsearch/\
elasticsearch-{{ elasticsearch_version }}-linux-{{ arch.elasticsearch }}.tar.gz"

elasticsearch_root: "/opt/epics-tools/services/elasticsearch"
elasticsearch_account: elasticsearch

elasticsearch_release_dir: "{{ elasticsearch_root }}/release"
elasticsearch_conf_dir: "{{ elasticsearch_release_dir }}/config"
elasticsearch_data_dir: "{{ elasticsearch_root }}/data"
elasticsearch_logs_dir: "{{ elasticsearch_root }}/logs"
elasticsearch_run_dir: "{{ elasticsearch_root }}/run"

elasticsearch_cluster_name: "training-vm"
elasticsearch_node_name: "{{ ansible_facts['hostname'] }}"
elasticsearch_node_roles:
- master
- data
- ingest
# Only listen on localhost (training VM, no authentication)
elasticsearch_network_host: "127.0.0.1"
elasticsearch_http_port: 9200
elasticsearch_transport_port: 9300
elasticsearch_discovery_type: single-node
elasticsearch_seed_hosts: []
elasticsearch_initial_master_nodes: []
elasticsearch_xpack_security_enabled: false
elasticsearch_xpack_http_ssl_enabled: false
elasticsearch_xpack_transport_ssl_enabled: false

# Elasticsearch runs on the JDK installed by the java role
elasticsearch_java_home: "{{ java_home }}"
# Elasticsearch would otherwise size its heap to half of the RAM
elasticsearch_java_opts: "-Xms512m -Xmx512m"
elasticsearch_service_name: elasticsearch

# 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/elasticsearch/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Handlers for Elasticsearch

- name: Restart Elasticsearch service
become: true
when: not in_container
ansible.builtin.systemd_service:
name: "{{ elasticsearch_service_name }}"
state: restarted
daemon_reload: true
12 changes: 12 additions & 0 deletions ansible/roles/elasticsearch/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# galaxy_info is required by Molecule's prerun (role name check)
galaxy_info:
role_name: elasticsearch
namespace: epics
author: Ralph Lange
description: Elasticsearch (single node) for the Phoebus alarm logger
license: EPICS open license
min_ansible_version: "2.15"
# Elasticsearch runs on the JDK installed by the java role
dependencies:
- role: java
26 changes: 26 additions & 0 deletions ansible/roles/elasticsearch/molecule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Molecule tests for the elasticsearch role

Functional tests: the `default` scenario installs Elasticsearch (role
`elasticsearch`, which pulls in `java`) in an `ubuntu:22.04` container, then runs the
testinfra tests in `resources/tests/test_elasticsearch.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 services
really start.

| Test | Checks |
|---|---|
| `test_service_is_running_and_enabled` | the `elasticsearch` systemd service is running and enabled |
| `test_listens_on_localhost_only` | HTTP (9200) and transport (9300) ports are listening, on loopback addresses only |
| `test_runs_as_unprivileged_user` | the JVM runs as the `elasticsearch` user |
| `test_cluster_is_usable` | `/_cluster/health` reports cluster `training-vm` as green or yellow |
| `test_security_is_disabled` | the REST API answers without credentials, version 8.x |
| `test_index_and_search_a_document` | a document can be indexed, found by a search and deleted |

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

```bash
cd ansible/roles/elasticsearch
molecule test
```
42 changes: 42 additions & 0 deletions ansible/roles/elasticsearch/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:
elasticsearch-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: elasticsearch-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
21 changes: 21 additions & 0 deletions ansible/roles/elasticsearch/molecule/resources/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Converge
hosts: all
become: true

# Molecule runs the roles directly, bypassing playbook.yml, so the
# architecture variables (the arch dict, e.g. for the JDK download) 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:
Comment thread
ralphlange marked this conversation as resolved.
Resolved
- 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: elasticsearch
Loading
Loading
0