Skip to content

Add Phoebus alarm server (+ Kafka) and alarm logger (+ Elastic) roles - #101

Closed
ralphlange wants to merge 3 commits into
epics-training:mainfrom
ralphlange:alarm-handler
Closed

ralphlange wants to merge 3 commits into
epics-training:mainfrom
ralphlange:alarm-handler

Conversation

@ralphlange

@ralphlange ralphlange commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Adds the Phoebus alarm system to the Training-VM: the alarm server with Kafka, and the alarm logger with Elasticsearch.

Closes #100

New roles

All four run their service under systemd as its own system user, listen on localhost only, and end with a check that the service actually came up (skipped in containers).

  • kafka: Apache Kafka 4.3.2, single node in KRaft mode (no ZooKeeper). The download is checked against its SHA-512; automatic topic creation is off, as the Phoebus docs recommend. Has its own switch and tag.
  • phoebus_alarm: the alarm server (alarm-server), pulls in kafka. It creates its Accelerator, AcceleratorCommand and AcceleratorTalk topics at startup (Phoebus 6 always does; -create_topics is gone). /usr/local/bin/alarm-server wraps it for command-line use, e.g. -import/-export of configurations.
  • elasticsearch: Elasticsearch 8.19, single node, security disabled, following phoebus_services_elasticsearch of ansible-phoebus (everything under /opt/epics-tools/services/elasticsearch). Stays on 8.x, because Phoebus 6 uses the Elasticsearch 8 Java client. Additionally, the download is checked against its SHA-512, a version change removes the old release, and a failed start prints the status, journal and log. Has its own switch and tag.
  • phoebus_alarm_logger: the alarm logger (alarm-logger), pulls in elasticsearch and phoebus_alarm. Stores the alarm messages from Kafka in Elasticsearch and serves them to the Phoebus "Alarm Log" through its REST API on port 9000 (the client default). The final check waits until the REST API reports Elasticsearch as connected.

The alarm server and logger are already built by the phoebus role (its Maven build includes services/), so nothing new gets built.

Molecule tests

Functional tests for the service roles on x86_64 and aarch64. A new shared platform image (ansible/molecule/systemd/Dockerfile.j2) runs systemd as PID 1, so the roles run exactly as on a VM:

  • kafka: produces and consumes a message.
  • elasticsearch: indexes, searches and deletes a document.
  • phoebus_alarm_logger: builds Phoebus and tests the alarm system end to end: imports a configuration with a PV that never connects and follows the configuration and the resulting "Disconnected" alarm through Kafka and the logger into Elasticsearch and back out of the REST API.

Each scenario also checks service users and loopback-only listening, and passes the idempotence step. Details are in each scenario's molecule/README.md.

Other changes

  • playbook.yml: enabling phoebus_alarm or phoebus_alarm_logger also runs the phoebus role and installs the graphical desktop.
  • Alarm settings are role defaults: alarm_config_name (Accelerator), alarm_kafka_server (from the kafka role, localhost:9092) and alarm_logger_url (http://localhost:9000). The phoebus role uses the same names for its client preferences, so one setting in e.g. vars/local.yml configures client and services consistently.
  • phoebus role: preferences.ini points the client at the alarm server and configuration, and the Alarm Log at the alarm logger.
  • Molecule converges no longer load group_vars/all.yml, only the vars/arch (and where needed vars/os) files, as playbook.yml does.
  • New arch.elasticsearch token in vars/arch/*.yml; roles enabled in everything.yml and ci-phoebus-aa.yml, listed in local.yml.sample, documented in roles/README.md; CI workflows trigger on and run the new roles.

Notes

  • No alarm configuration is loaded: the Accelerator tree starts empty (fill it with the Alarm Tree GUI or alarm-server -import).
  • The alarm config logger (configuration history in git) is not part of this PR.

Testing

All CI checks pass: Molecule on x86_64 and aarch64; "Roles: Phoebus & AA" (with all role checks passing), "Roles: EPICS Modules", "Roles: oac-tree" and the VM image builds on Fedora, Ubuntu, Debian and Rocky (x86_64). Not tested: aarch64 in the QEMU role tests (manual-only); Molecule covers aarch64.

Developed with the assistance of generative AI.

@ralphlange
ralphlange requested a review from shroffk November 13, 2026 10:10
@ralphlange ralphlange self-assigned this Nov 13, 2026
@ralphlange ralphlange added ansible Related to the Ansible roles enhancement New feature or request labels Nov 13, 2026
@ralphlange

Copy link
Copy Markdown
Contributor Author

@shroffk: Should I add the alarm logger to this role or make it a separate one?

@shroffk

shroffk commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

I would do it as a seperate role
Let us use that as a test case for using the role from https://github.com/ControlSystemStudio/ansible-phoebus

So basically we would just need a playbook with the appropriate vars

@ralphlange

Copy link
Copy Markdown
Contributor Author

But there is no separate role for the alarm logger in that repo.

@shroffk

shroffk commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

good point, I think we should split these roles
especially since the logging adds the dependency to elastic

@ralphlange ralphlange changed the title Add Phoebus alarm server and Kafka roles Add Phoebus alarm server (+ Kafka) and alarm logger (+ Elastic) roles Nov 14, 2026
@ralphlange

Copy link
Copy Markdown
Contributor Author

Redone / reorganized / extended:

  • the new phoebus_alarm_logger role pulls the new elasticsearch role
  • proper Molecule / systemd tests run functional checks for everything

@ralphlange
ralphlange requested a review from jacomago November 15, 2026 14:23
@ralphlange
ralphlange marked this pull request as ready for review November 15, 2026 16:19
@ralphlange

Copy link
Copy Markdown
Contributor Author

@simon-ess: Are the molecule tests done in a reasonable way?

@jacomago jacomago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my docker comments:

  • Why are we adding the roles here instead of into the new galaxy namespace?
  • If the roles are to be generic rather than just for the training vm, we should probably not default with localhost and separate ports.

- name: Download Kafka {{ kafka_version }}
become: true
ansible.builtin.get_url:
url: "https://archive.apache.org/dist/kafka/{{ kafka_version }}/kafka_{{ kafka_scala_version }}-{{ kafka_version }}.tgz"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to maintain a manual deployment of kafka vs using docker? This is significantly more complex.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Training-VM I think the native install is the better choice overall, even though this role is longer than a docker run: one of the explicit goals of the Training-VM is to show installation from sources/downloads, avoiding docker.

For generic / real-world use, the best choice might be different.
(As the Galaxy roles are supposed to work in real-life and on the Training-VM, they need to clearly separate installation from configuration, giving at least from-source/system-packages/e3 as installation options while keeping the configuration parts common.)

@@ -0,0 +1,25 @@
# {{ ansible_managed }}
[Unit]
Description=Phoebus Alarm Server ({{ alarm_config_name }})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really am not a fan of maintaining all these systemd files etc over docker. I would rather start with as little to maintain as possible via docker and then move on to more optimized version with systemd sharing a jvm whatever thing.

@ralphlange ralphlange Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point, but for the alarm server and logger in particular, containers would add work rather than remove it here:

  • The phoebus role already builds both services from the same source tree and version as the client (Phoebus' Maven build includes services/). So client and services always match, and running them needs nothing beyond a JDK, which the VM already has.
  • With containers, we'd have to either build our own images from that build or pull upstream images and keep their versions in step with the client. Both are more to maintain than the unit files.
  • The unit files are short, run each service as its own system user, and give students the usual systemctl status / journalctl -u alarm-server to look at, which is also what they'll find at many facilities.

If we later want a shared-JVM or container setup for production use, that seems like a good fit for the ansible-phoebus / Galaxy roles, see my other comment.

@ralphlange

Copy link
Copy Markdown
Contributor Author

Other than my docker comments:

Thanks a lot for the review!

  • Why are we adding the roles here instead of into the new galaxy namespace?

ansible-phoebus currently has no alarm logger role (that's what started the split in this PR).
I am building these here first, where they're tested end to end in this repo's CI (Molecule on x86_64 and aarch64, plus the QEMU role tests on all four distros).
I'd be happy to move the roles into the Galaxy namespace once it's set up, and have the Training-VM consume them from there. Right now, ansible-phoebus is not in the required shape. Is there a plan or timeline for this?

  • If the roles are to be generic rather than just for the training vm, we should probably not default with localhost and separate ports.

This is partly addressed in 83f980a. The alarm settings are no longer in group_vars/all.yml. The Kafka address the alarm server uses is derived from the kafka role's kafka_listen_host/kafka_port instead of a hard-coded localhost:9092.

Binding to loopback is kept as the default on purpose: Kafka and Elasticsearch run without authentication on the Training-VM, so listening on all interfaces would be an unsafe default. Whoever needs a networked setup would set kafka_listen_host / elasticsearch_network_host explicitly.
If the roles move to be generic / on Galaxy, it would make sense to go over these defaults again.

Installs Apache Kafka (single node, KRaft mode, localhost only) and runs
the Phoebus alarm server 9built by the phoebus role) as systemd services.

The alarm server (Phoebus >= 6) creates and configures its Kafka topics;
automatic topic creation in Kafka is disabled.

- Apache Kafka (single node, KRaft mode, localhost only) as a systemd service,
  with its own kafka switch and tag; in_container role default
- alarm_config_name / alarm_kafka_server are defaults of the phoebus_alarm
  role (Kafka address derived from the kafka role's settings) and of the
  phoebus role, which now sets the client alarm preferences - same names,
  so one setting in a setup file configures client and server
- enabling phoebus_alarm also runs the phoebus role and installs graphics
- /usr/local/bin/alarm-server wrapper for -import/-export, Kafka tools on PATH
- after starting the services, wait for Kafka to accept connections and for
  the alarm server to create its configuration topic, then assert that both
  systemd services are still active/running - so CI catches an alarm server
  that starts but crashes (skipped in containers without systemd)
- enabled in everything.yml and ci-phoebus-aa.yml

A shared Molecule image definition (ansible/molecule/systemd/Dockerfile.j2)
runs systemd as PID 1 in a privileged container sharing the host's cgroup namespace,
so the roles run with in_container=false - exactly as on a VM.

Kafka scenario (in the molecule workflow matrix, x86_64 and aarch64)
that verifies the service runs as its own user, listens on loopback,
has its tools on the PATH, and can create a topic and deal with messages.
The tests are described in the scenario's README. Molecule converges load
only the arch variables, as playbook.yml does; everything else comes from
the roles' own defaults.

Developed with the assistance of generative AI.
Elasticsearch (single node, localhost only, security disabled) as a
systemd service - the storage of the Phoebus alarm logger. Follows the
phoebus_services_elasticsearch role of ControlSystemStudio/ansible-phoebus:

- one service root /opt/epics-tools/services/elasticsearch with release/
  (incl. its config/), data/, logs/ and run/, all owned by the service account
- elasticsearch.yml template and systemd unit (ES_HOME, DATA_DIR, LOG_DIR,
  PID_DIR, ES_JAVA_HOME, start limits); runs on the JDK of the java role
- version 8.19 (8.x matches the Elasticsearch client of Phoebus 6), 512M heap

In addition: the download is verified against Elastic's published
sha512 (new arch.elasticsearch token for the archive name),
a version change removes the old release first,
and after starting, the role waits for a usable cluster - showing
the service status, journal and log tail if Elasticsearch does not come
up. Own elasticsearch switch and tag; in_container role default.

Molecule scenario on the systemd platform (x86_64 and aarch64):
service running as its own user, loopback-only listeners, cluster health,
indexing and searching a document; described in the scenario's README.
The converge loads only the arch variables, as playbook.yml does.

Developed with the assistance of generative AI.
Runs the Phoebus alarm logger (built by the phoebus role) under systemd:
it stores the alarm system's messages from Kafka in Elasticsearch
and serves them to the Phoebus "Alarm Log" table through its REST API.
Modelled on the alarm logger part of ControlSystemStudio/ansible-phoebus.

- pulls in the elasticsearch and phoebus_alarm (alarm server, Kafka) roles;
  enabling it also runs the phoebus role and installs graphics
- REST API on port 9000 (the Phoebus client default): alarm_logger_url,
  a default of this role and of the phoebus role;
  set as Java system property, since the logger rejects unknown CLI options
- /usr/local/bin/alarm-logger wrapper
- after starting, the role waits for the REST API
  to report Elasticsearch as connected and asserts the service is running
- enabled in everything.yml and ci-phoebus-aa.yml (QEMU role tests)

Molecule scenario on the systemd platform (x86_64 and aarch64) that
builds Phoebus and tests the whole alarm system end to end: it imports
an alarm configuration with a PV that never connects and follows the
configuration and the resulting "Disconnected" alarm through Kafka and
the alarm logger into Elasticsearch and back out of the REST API;
described in the scenario's README.

closes epics-training#101

Developed with the assistance of generative AI.
@ralphlange
ralphlange deleted the alarm-handler branch November 18, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ansible Related to the Ansible roles enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add role for Alarm Handler

4 participants