Skip to content

Commit 63fd5ef

Browse files
Remove old agent plugin system (#407)
* Remove old plugin system and any usage of it * Remove old plugin system docs and use of 'agent-paths' config * Remove use of 'agent_script' when launching plugin * Update 'agent_script' docstring * Add autodoc for drivers to HostManager agent docs * Remove use of 'launcher script' in logs
1 parent ceeaff8 commit 63fd5ef

File tree

15 files changed

+19
-182
lines changed

15 files changed

+19
-182
lines changed

docs/agents/host_manager.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ Supporting APIs
5959
---------------
6060

6161
.. automethod:: ocs.agents.host_manager.agent.HostManager._reload_config
62+
63+
.. automodule:: ocs.agents.host_manager.drivers
64+
:members:
65+
:show-inheritance:

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ agents.host_manager
5454
:members:
5555
:undoc-members:
5656
:show-inheritance:
57+
:noindex:
5758

5859
agents.influxdb_publisher
5960
`````````````````````````

docs/developer/site_config.rst

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ the CrossbarConfig class:
9090
:members: from_dict
9191
:noindex:
9292

93-
The significance of ``agent-paths`` is described more in
94-
:ref:`agent_plugins`.
95-
9693
InstanceConfig
9794
--------------
9895

@@ -205,43 +202,3 @@ river_ctrl.py in the examples):
205202
print('Starting a data acquisition process...')
206203
d1 = yield cw.start()
207204
#...
208-
209-
210-
.. _agent_plugins:
211-
212-
Agent Script Discovery
213-
======================
214-
215-
Agent scripts are currently written as stand-alone python scripts (and
216-
thus not not importable through the main ``ocs`` python module). To
217-
support automatic launching of Agents, ``site_config`` includes a
218-
plugin-style system to register Agent scripts. This is flexible
219-
enough to support both the natively packaged Agents and any
220-
"third-party" agents needed in a particular installation. The system
221-
works like this:
222-
223-
- A bundle of Agent scripts is assembled at some location. There are
224-
no restrictions on where these scripts can live in the file system.
225-
For example, a script called ``riverbank_agent.py`` might live in
226-
``/simonsobs/agents/``.
227-
- A special "registration script" is written, with a filename of the
228-
form ``ocs_plugin_*.py``. This script should live in Python's
229-
import path, or else (and this is better), the path to the script
230-
should be included in the ``agent-paths`` variable in the SCF for
231-
this host. For example, we might put the file in ``/simonsobs/agents``
232-
and call it ``ocs_plugin_simonsobs.py``.
233-
- When the site_config system (specifically the HostManager agent)
234-
needs to find a particular agent script, it:
235-
236-
- Adds any directories in ``agent-paths`` to the Python import path.
237-
- Scans through all importable modules, and imports them if they
238-
match the ``ocs_plugin_*`` name pattern.
239-
240-
- The ``ocs_plugin`` script makes calls into ocs to associate a
241-
particular script filenames to agent class names. In our example,
242-
``ocs_plugin_simonsobs.py`` would call
243-
``ocs.site_config.register_agent_class('RiverBank',
244-
'/simonsobs/agents/riverbank_agent.py')``.
245-
246-
A good example of a plugin script can be found in the OCS agents
247-
directory, ``ocs_plugins_standard.py``.

docs/user/centralized_management.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ block would become:
7878
# Directory for logs.
7979
'log-dir': '/simonsobs/log/ocs/',
8080
81-
# List of additional paths to Agent plugin modules.
82-
'agent-paths': [
83-
'/simonsobs/ocs/agents/',
84-
],
85-
8681
# Description of host-1's Agents.
8782
# We have two readout devices; they are both Lakeshore 240. But they can
8883
# be distinguished, on startup, by a device serial number.

docs/user/quickstart.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ structure.
5555
# Directory for logs.
5656
'log-dir': '/home/<user>/log/ocs/',
5757

58-
# List of additional paths to Agent plugin modules.
59-
'agent-paths': [
60-
'/home/<user>/git/ocs/agents/',
61-
'/home/<user>/git/socs/agents/',
62-
],
63-
6458
# Agents running directly on the host machine
6559
# Note: We aren't going to run this Agent in the quickstart example,
6660
# but this gives a good example of configuring an agent directly

docs/user/site_config.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ instances (running two different classes of agent):
4343
# Directory for logs.
4444
'log-dir': '/simonsobs/log/ocs/',
4545
46-
# List of additional paths to Agent plugin modules.
47-
'agent-paths': [
48-
'/simonsobs/ocs/agents/',
49-
],
50-
5146
# Description of host-1's Agents.
5247
# We have two readout devices; they are both Lakeshore 240. But they can
5348
# be distinguished, on startup, by a device serial number.
@@ -89,11 +84,6 @@ instances (running two different classes of agent):
8984
# Directory for logs.
9085
'log-dir': '/simonsobs/log/ocs/',
9186
92-
# List of additional paths to Agent plugin modules.
93-
'agent-paths': [
94-
'/simonsobs/ocs/agents/',
95-
],
96-
9787
# Description of host-2's Agents.
9888
# We have two devices; another Lakeshore 240, and the OCS g3 file
9989
# Aggregator.

example/miniobs/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In particular:
1212

1313
- The list of Agents is defined under hostname ``localhost``. This is
1414
a wildcard that can only work in a single-host system.
15-
- ``log-dir``, ``agent-paths``, and the ``crossbar:config-dir`` are
15+
- ``log-dir`` and the ``crossbar:config-dir`` are
1616
all specified as relative paths. Behavior will be unpredictable if
1717
Agents are not all invoked in the same working directory.
1818

example/miniobs/default.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ hosts:
1111
localhost: {
1212
'crossbar': {'config-dir': './dot_crossbar/'},
1313
'log-dir': './logs',
14-
'agent-paths': [
15-
'../../agents/',
16-
'./',
17-
],
1814
'agent-instances': [
1915
{'agent-class': 'HostManager',
2016
'instance-id': 'hm1',

ocs/agents/host_manager/agent.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ def _get_local_instances(self):
6868
f'likely syntax error: {e}')
6969
return returnValue((False, instances, warnings))
7070

71-
# Scan for agent scripts in (deprecated) script registry
72-
try:
73-
for p in hc.agent_paths:
74-
if p not in sys.path:
75-
sys.path.append(p)
76-
site_config.scan_for_agents()
77-
except Exception as e:
78-
warnings.append('Failed to scan for old plugin agents -- '
79-
f'likely plugin config problem: {e}')
80-
return returnValue((False, instances, warnings))
81-
8271
# Gather managed items from site config.
8372
for inst in hc.instances:
8473
if inst['instance-id'] in instances:
@@ -317,18 +306,13 @@ def same_base_class(a, b):
317306
continue
318307
if instance['management'] == 'host':
319308
cls = instance['agent_class']
320-
# Check for the agent class in the plugin system;
321-
# then check the (deprecated) agent script registry.
309+
# Check for the agent class in the plugin system
322310
if cls in agent_plugins:
323311
session.add_message(f'Found plugin for "{cls}"')
324312
instance['agent_script'] = '__plugin__'
325313
instance['operable'] = True
326-
elif cls in site_config.agent_script_reg:
327-
session.add_message(f'Found launcher script for "{cls}"')
328-
instance['agent_script'] = site_config.agent_script_reg[cls]
329-
instance['operable'] = True
330314
else:
331-
session.add_message(f'No plugin (nor launcher script) '
315+
session.add_message('No plugin '
332316
f'found for agent_class "{cls}"!')
333317
elif instance['management'] == 'docker':
334318
instance['agent_script'] = self.docker_service_prefix + iid
@@ -361,16 +345,11 @@ def _launch_instance(self, instance):
361345
else:
362346
iid = instance['instance_id']
363347
pyth = sys.executable
364-
script = instance['agent_script']
365-
if script == '__plugin__':
366-
cmd = [pyth, '-m', 'ocs.agent_cli']
367-
else:
368-
cmd = [pyth, script]
369-
cmd.extend([
370-
'--instance-id', iid,
371-
'--site-file', self.site_config_file,
372-
'--site-host', self.host_name,
373-
'--working-dir', self.working_dir])
348+
cmd = [pyth, '-m', 'ocs.agent_cli',
349+
'--instance-id', iid,
350+
'--site-file', self.site_config_file,
351+
'--site-host', self.host_name,
352+
'--working-dir', self.working_dir]
374353
prot = hm_utils.AgentProcessHelper(iid, cmd)
375354
prot.up()
376355
instance['prot'] = prot

ocs/agents/host_manager/drivers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class ManagedInstance(dict):
2626
- 'operable' (bool): indicates whether the instance can be
2727
manipulated (whether calls to up/down should be expected to
2828
work).
29-
- 'agent_script' (str): Path to the launcher script (if host
30-
system managed). If docker-managed, this is the service name.
29+
- 'agent_script' (str): The docker service_name, if docker-managed.
30+
Otherwise, the string ``__plugin__`` to indicate it is host managed.
3131
- 'prot': The twisted ProcessProtocol object (if host system
3232
managed), or the DockerContainerHelper (if a docker container).
3333
- 'target_state' (state): The state we're trying to achieve (up or

0 commit comments

Comments
 (0)