Skip to content

A possible implementation for managing non-python agents #320

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
64fe132
A possible implementation for managing non-python agents
Feb 24, 2023
3bb7842
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 24, 2023
feab97f
Fix reference to removed variable
Feb 24, 2023
e1fbd11
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Mar 6, 2023
455df18
Merge pull request #321 from simonsobs/pre-commit-ci-update-config
BrianJKoopman Mar 7, 2023
92371ff
Separate blocks for each registered operation (#312)
jlashner Mar 8, 2023
6bfd154
Add importlib_metadata dependency for ocs-agent-cli
BrianJKoopman Mar 15, 2023
91c51d5
Merge pull request #323 from simonsobs/koopman/importlib-metadata-dep
BrianJKoopman Mar 15, 2023
919b966
Use procsettitle to have ocs-agent-cli rename itself
mhasself Apr 12, 2023
d6e95ec
Merge pull request #325 from simonsobs/set-title
BrianJKoopman Apr 12, 2023
ff41bb8
Fix readthedocs builds (#328)
BrianJKoopman May 10, 2023
0a0404d
Improve test/development portability (#319)
cnweaver May 11, 2023
93cc8b2
Revist address_root != "observatory" (#327)
mhasself May 16, 2023
5edbde1
Cast tuple param before type check
BrianJKoopman May 22, 2023
4b9fd3f
Merge pull request #332 from simonsobs/koopman/issue-274
BrianJKoopman May 23, 2023
e7d331f
Support direct start calls with params to param decorated Tasks/Proce…
BrianJKoopman May 24, 2023
003260a
Replace pytest-docker-compose with pytest-docker plugin
BrianJKoopman Aug 9, 2023
befdda6
Merge pull request #342 from simonsobs/koopman/replace-pytest-docker-…
BrianJKoopman Aug 9, 2023
4222f53
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jul 31, 2023
c8d1fc5
Merge pull request #340 from simonsobs/pre-commit-ci-update-config
BrianJKoopman Aug 9, 2023
cf39d9c
systemd service file: add RestartSec=10s
mhasself Aug 18, 2023
4a981c5
Merge pull request #344 from simonsobs/hm-service-robustness
BrianJKoopman Aug 23, 2023
28bc23d
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 28, 2023
c805bab
Merge pull request #346 from simonsobs/pre-commit-ci-update-config
BrianJKoopman Aug 30, 2023
e1cea68
A possible implementation for managing non-python agents
Feb 24, 2023
80bb45e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 24, 2023
87b6dce
Fix reference to removed variable
Feb 24, 2023
f1a29a3
Merge branch 'non-python-agents' of https://github.com/cnweaver/ocs i…
Sep 14, 2023
e11331b
Call the combined address root and instance ID the address
Sep 14, 2023
0f71bb5
Turn off logging instead of crashing if log_dir is not set
Sep 14, 2023
4c7549f
Flush log file later to avoid confusing log delays
Sep 15, 2023
9d31362
Log executable agent output by default
Sep 15, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ on:
- '**.md'
- '.flake8'
- '.pre-commit-config.yaml'
- '.readthedocs.yaml'

jobs:
test:
1 change: 1 addition & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ on:
- '**.md'
- '.flake8'
- '.pre-commit-config.yaml'
- '.readthedocs.yaml'
workflow_call:

jobs:
1 change: 1 addition & 0 deletions .github/workflows/skipped-pytest.yml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ on:
- '**.md'
- '.flake8'
- '.pre-commit-config.yaml'
- '.readthedocs.yaml'

jobs:
test:
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.1
rev: v2.0.4
hooks:
- id: autopep8
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
6 changes: 5 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.10"

sphinx:
configuration: docs/conf.py

python:
version: 3.7
install:
- requirements: docs/requirements.txt
- requirements: requirements.txt
9 changes: 6 additions & 3 deletions docker/crossbar/Dockerfile
Original file line number Diff line number Diff line change
@@ -8,8 +8,11 @@ FROM crossbario/crossbar:cpy3-20.8.1
# Run as root to put config in place and chown
USER root

# Copy in config and requirements files
COPY config.json /ocs/.crossbar/config.json
# Copy in config template and wrapper script
COPY run-crossbar.sh /ocs/run-crossbar.sh
RUN chmod a+x /ocs/run-crossbar.sh

COPY config.json.template /ocs/.crossbar/config-with-address.json.template
RUN chown -R crossbar:crossbar /ocs

# Run image as crossbar user during normal operation
@@ -20,4 +23,4 @@ EXPOSE 8001

# Run crossbar when the container launches
# User made config.json should be mounted to /ocs/.crossbar/config.json
ENTRYPOINT ["crossbar", "start", "--cbdir", "/ocs/.crossbar"]
ENTRYPOINT ["/ocs/run-crossbar.sh"]
Original file line number Diff line number Diff line change
@@ -10,13 +10,13 @@
},
"realms": [
{
"name": "test_realm",
"name": "{realm}",
"roles": [
{
"name": "iocs_agent",
"permissions": [
{
"uri": "observatory.",
"uri": "{address_root}.",
"match": "prefix",
"allow": {
"call": true,
@@ -36,7 +36,7 @@
"name": "iocs_controller",
"permissions": [
{
"uri": "observatory.",
"uri": "{address_root}.",
"match": "prefix",
"allow": {
"call": true,
@@ -60,7 +60,7 @@
"type": "web",
"endpoint": {
"type": "tcp",
"port": 8001
"port": {port}
},
"paths": {
"ws": {
@@ -81,7 +81,7 @@
},
"call": {
"type": "caller",
"realm": "test_realm",
"realm": "{realm}",
"role": "iocs_controller",
"options": {
}
28 changes: 28 additions & 0 deletions docker/crossbar/run-crossbar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

CONFIG_DIR=/ocs/.crossbar
OCS_ADDRESS_ROOT=${OCS_ADDRESS_ROOT:-observatory}
OCS_CROSSBAR_REALM=${OCS_REALM:-test_realm}
OCS_CROSSBAR_PORT=${OCS_PORT:-8001}

# Did user mount in a config.json?
if [ -e $CONFIG_DIR/config.json ]; then
echo Launching user-provided config.json
CONFIG_FILE=$CONFIG_DIR/config.json
else
pattern="
s/{address_root}/${OCS_ADDRESS_ROOT}/g
s/{realm}/${OCS_CROSSBAR_REALM}/g
s/{port}/${OCS_CROSSBAR_PORT}/g
"
echo "Processing template with replacements:"
echo "$pattern"
echo

CONFIG_FILE=$CONFIG_DIR/config-with-address.json
sed "$pattern" \
$CONFIG_DIR/config-with-address.json.template \
> $CONFIG_FILE
fi

crossbar start --cbdir $CONFIG_DIR --config $CONFIG_FILE
4 changes: 3 additions & 1 deletion docs/agents/aggregator.rst
Original file line number Diff line number Diff line change
@@ -90,7 +90,9 @@ to register a feed so that it will be recorded by the aggregator.
Unregistered providers will automatically be added when they send data,
and stale providers will be removed if no data is received in a specified
time period.
To do this, the aggregator monitors all feeds in the ``observatory`` namespace to find

To do this, the aggregator monitors all feeds in the namespace defined
by the `{address_root}` prefix to find
feeds that should be recorded. If the aggregator receives data from a feed
registered with ``record=True``, it will automatically add that feed as a
Provider, and will start putting incoming data into frames every ``frame_length``
1 change: 0 additions & 1 deletion docs/developer/writing_an_agent/docker.rst
Original file line number Diff line number Diff line change
@@ -84,7 +84,6 @@ the BarbonesAgent config to the ``ocs-docker`` host.:
wamp_http: http://localhost:8001/call
wamp_realm: test_realm
address_root: observatory
registry_address: observatory.registry

hosts:

1 change: 1 addition & 0 deletions docs/user/centralized_management.rst
Original file line number Diff line number Diff line change
@@ -476,6 +476,7 @@ should look something like this::
ExecStart=/home/ocs/git/ocs-site-configs/my-lab/launcher-hm-server5.sh
User=ocs
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target
167 changes: 95 additions & 72 deletions docs/user/crossbar_config.rst
Original file line number Diff line number Diff line change
@@ -12,48 +12,118 @@ the interface to the crossbar server.

.. note::

For most test deployments of OCS, you should not need to modify this file
and can use the one that comes with the ``simonsobs/ocs-crossbar`` Docker
Image.
For most simple lab deployments of OCS, you should not need to modify this
file and can use the one that comes with the ``simonsobs/ocs-crossbar``
Docker Image.

Example Config
--------------
An example of the default OCS crossbar config that is bundled into
``simonsobs/ocs-crossbar`` can be found in the repository at
`ocs/docker/crossbar/config.json`_. This is based on the template in
`ocs/ocs/support/crossbar_config.json`_.
Configuration File Template
---------------------------
The template that the default OCS crossbar config is built with is shown here:

.. literalinclude:: ../../docker/crossbar/config.json.template

The unique parts of this to OCS are the realm name, "test_realm", defined
roles of "iocs_agent" and "iocs_controller, and "address_root" of
"observatory.". Additionally, we run on port 8001.
The variables `realm`, `address_root`, and `port` are all configurable and must
match configuration options set in your SCF. Keep reading this page to see how
to configure these variables.

.. note::
Changing the `address_root` has implications for the how your data is
stored and accessed in tools such as Grafana. It is recommended you pick
something reasonable when you first configure your system and do not change it
later.

For further details on crossbar server configuration, see the crossbar `Router
Configuration`_ page.

.. _`ocs/docker/crossbar/config.json`: https://github.com/simonsobs/ocs/blob/main/docker/crossbar/config.json
.. _`ocs/ocs/support/crossbar_config.json`: https://github.com/simonsobs/ocs/blob/main/ocs/support/crossbar_config.json
.. _`Router Configuration`: https://crossbar.io/docs/Router-Configuration/

Running with Docker
===================

We recommend running crossbar within a Docker container. We build the
``simonsobs/ocs-crossbar`` container from the official `crossbar.io Docker
image`_, specifically the cpy3 version. Bundled within the container is a
simple crossbar configuration file template with defaults that are
compatible with examples in this documentation.

To adjust the crossbar configuration in the container, you can either:

- Use environment variables to alter the most basic settings
- Generate and mount a new configuration file over
``/ocs/.crossbar/config.json`` with the proper permissions

.. _`crossbar.io Docker image`: https://hub.docker.com/r/crossbario/crossbar

Environment variables in ocs-crossbar
-------------------------------------
The following environment variables can be set, to affect the
generation of the crossbar configuration file when the container
starts up:

- OCS_ADDRESS_ROOT (default "observatory"): the base URI for OCS
entities (this needs to match the `address_root` set in the SCF).
- OCS_CROSSBAR_REALM (default "test_realm"): the WAMP realm to
configure for OCS.
- OCS_CROSSBAR_PORT (default 8001): the port on which crossbar will
accept requests.

Here is an example of a docker-compose entry that overrides the
OCS_ADDRESS_ROOT::

crossbar:
image: simonsobs/ocs-crossbar:latest
ports:
- "127.0.0.1:8001:8001" # expose for OCS
environment:
- PYTHONUNBUFFERED=1
- OCS_ADDRESS_ROOT=laboratory

Bind Mounting the Configuration
-------------------------------
To instead mount a new configuration into the pre-built image, first chown
your file to be owned by user and group 242 (the default crossbar UID/GID),
then mount it appropriately in your docker-compose file. Here we assume you
put the configuration in the directory ``./dot_crossbar/``::

$ chown -R 242:242 dot_crossbar/

.. note::
If you do not already have a configuration file to modify and use, see the
next section on generating one.

Your docker-compose service should then be configured like::

crossbar:
image: simonsobs/ocs-crossbar
ports:
- "8001:8001" # expose for OCS
volumes:
- ./dot_crossbar:/ocs/.crossbar
environment:
- PYTHONUNBUFFERED=1

Generating a New Config File
----------------------------
``ocsbow`` can be used to generate a default configuration file, based on
options in your OSC file, which can then be modified if needed.
``ocs-local-support`` can be used to generate a default configuration
file, based on options in your SCF, which can then be modified if
needed.

First, we make sure our ``OCS_CONFIG_DIR`` environment variable is set::

$ cd ocs-site-configs/
$ export OCS_CONFIG_DIR=`pwd`

We should make a directory for the crossbar config, let's call it
``dot_crossbar/`` (typically a dot directory, but for visibility we'll avoid
that)::
We should make a directory for the crossbar config, following along above let's
call it ``dot_crossbar/`` (typically a dot directory, but for visibility we'll
avoid that)::

$ mkdir -p ocs-site-configs/dot_crossbar/

This directory needs to be configured as your crossbar 'config-dir' in your
ocs-site-config file. Now we can generate the config::
ocs-site-config file. (See example in :ref:`site_config_user`.) Now we can
generate the config::

$ ocsbow crossbar generate_config
$ ocs-local-support generate_crossbar_config
The crossbar config-dir is set to:
./dot_crossbar/
Using
@@ -68,54 +138,7 @@ modifications needed for your deployment.

.. note::

The crossbar 'config-dir' block and the 'agent-instance' block defining the
'HostManager' Agent are both required for the system you are running ocsbow
on. Be sure to add these to your SCF if they do not exist.

Running with Docker
===================

We recommend running crossbar within a Docker container. We build the
``simonsobs/ocs-crossbar`` container from the official `crossbar.io Docker
image`_, specifically the cpy3 version. Bundled within the container is a
simple OCS configuration that should work with the configuration
recommendations in this documentation.

If changes need to be made, then you will need to generate your own
configuration file as described above. To use a modified configuration in the
container you can either:

- Edit the default configuration file and rebuild the Docker image
- Mount the new configuration file over ``/ocs/.crossbar/config.json`` with the
proper permissions

.. _`crossbar.io Docker image`: https://hub.docker.com/r/crossbario/crossbar

Rebuilding the Docker Image
---------------------------
To rebuild the Docker image after modifying ``ocs/docker/config.json`` run::

$ docker build -t ocs-crossbar .

You should then update your configuration to use the new, local,
``ocs-crossbar`` image.

Bind Mounting the Configuration
-------------------------------
To instead mount the new configuration into the pre-built image, first chown
your file to be owned by user and group 242 (the default crossbar UID/GID),
then mount it appropriately in your docker-compose file. Here we assume you
put the configuration in the directory ``./dot_crossbar/``::

$ chown -R 242:242 dot_crossbar/

Your docker-compose service should then be configured like::

crossbar:
image: simonsobs/ocs-crossbar
ports:
- "8001:8001" # expose for OCS
volumes:
- ./dot_crossbar:/ocs/.crossbar
environment:
- PYTHONUNBUFFERED=1
The crossbar 'config-dir' block and the 'agent-instance' block
defining the 'HostManager' Agent are both required for the system
you are running `ocs-local-support` on. Be sure to add these to
your SCF if they do not exist.
4 changes: 2 additions & 2 deletions docs/user/docker_config.rst
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ components)::
ports:
- "127.0.0.1:8001:8001" # expose for OCS
environment:
- PYTHONUNBUFFERED=1
- PYTHONUNBUFFERED=1

# --------------------------------------------------------------------------
# OCS Agents
@@ -242,7 +242,7 @@ Where the separate compose files would look something like::
ports:
- "127.0.0.1:8001:8001" # expose for OCS
environment:
- PYTHONUNBUFFERED=1
- PYTHONUNBUFFERED=1

::

1 change: 0 additions & 1 deletion docs/user/quickstart.rst
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ structure.
wamp_http: http://localhost:8001/call
wamp_realm: test_realm
address_root: observatory
registry_address: observatory.registry

hosts:

Loading