Repository navigation
Add Phoebus alarm server (+ Kafka) and alarm logger (+ Elastic) roles #101
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,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"] |
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 |
|---|---|---|
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
|
|
@@ -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. | ||
|
|
||
|
|
||
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,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 |
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,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 |
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,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 |
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,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 | ||
| ``` |
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,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
21
ansible/roles/elasticsearch/molecule/resources/converge.yml
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,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: | ||
| - 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 | ||
Oops, something went wrong.
Oops, something went wrong.
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.