Modules
Plugin hosts: operations in other languages, run in OS processes the proxy
supervises (PluginHosts.Host, PluginHosts.Pool), called by the steps of
the plugin of their kind (PluginHosts.Kind): Plugins.Camel for Apache
Camel routes, Plugins.Command for a program in any language that speaks
the protocol. The steps' own logic is PluginHosts.Step. Design and
measurements: Alternera's docs/EXTERNAL_PLUGINS_RESEARCH.md.
A plugin host on some nodes of a cluster. A node runs the hosts its own
configuration lists (PluginHosts); no node is named anywhere. A host
is known by its key, {tenant_id, name} (PluginHosts.key/2): host
names are per tenant, so two tenants' hosts of one name are two hosts.
Three :pg groups of its kind's scope (scope/1) say where a host is
A document of operations written in a step, not read from a host's files (a Camel step's routes "written here"), and how it reaches the host's members: by content, so the proxy keeps no member, restart or release in step with what it holds.
The address of a plugin host's HTTP call channel, as a plugin host
step writes it into a call's URL:
<scheme>://<host>.<tenant id><suffix>:<port>/ops/<op>, where <host>
is the configured host's name and <tenant id> the id of the tenant it
belongs to (PluginHosts.key/2: two tenants' hosts of one name are two
names here, never one upstream), <suffix> its kind's
(.camel.internal, .command.internal: upstream_suffix/0 of the
kind's plugin, PluginHosts.Kind) and <port> the loopback
port a ready member announced in its hello (PluginHosts.Host).
The frames between the proxy and a plugin host: a 4-byte big-endian length
of what follows, a 1-byte type, an 8-byte call id and the payload. The
hello is JSON; a call and its reply are in the host's codec, JSON or, for
a :msgpack host, MessagePack (pack/2, unpack/2). A reload (proxy
to host) and the catalogue that answers it, or that a host sends of id
0 after reloading on its own, are JSON. A define (proxy to host) carries
a written document (PluginHosts.Definition) in the host's codec, and the
host answers it with a reply of the same id; so does a check, which
asks the host to check a document without defining it, and a
vocabulary, which asks what the editor completes in one, and a
describe, which asks for the tables, columns or procedures of a
database a written route may use. A variables (proxy to host, JSON,
{"values": {...}}, id 0) comes before the hello of a host whose entry
lists tenant variables, and is not answered: the values its routes on
disk read. A source (proxy to host, the host's codec) is a call to one
of the host's message sources, answered with a reply of its id; a
messages (host to proxy, JSON, id 0, not answered) is what a pushing
source sends to the sink its open named (PluginHosts.Host.subscribe/3).
One plugin host: an OS process (a JVM running Camel, say) the proxy starts
through a port and talks to in PluginHosts.Frames on file
descriptors 3 and 4 (:nouse_stdio). This process is the only owner of
the port, and nothing the host does can reach further than it: a crash,
a hang or bytes that are not a frame end the OS process, never the BEAM.
A plugin host step's call over a plugin host's HTTP channel: POST /ops/<operation> with the inputs as a JSON object, made as the plugin's
own outbound call (Plugin.Provisional.Outbound, with upstream:) to the
address PluginHosts.Endpoint names, under the suffix
its kind claims (PluginHosts.Kind, Plugin.Provisional.Upstream).
A kind of plugin host: the plugin whose steps call hosts of that kind,
which also configures them, builds their commands and claims their names.
Plugins.Camel and Plugins.Command are the two. Every function of
Alternera.PluginHosts takes the kind first, and each kind has its
own hosts, registries (PluginHosts.registry/1), supervisor
(PluginHosts.Supervisor) and host suffix, so two kinds may each have a
host of the same name.
One plugin host served by several processes: PluginHosts.Host members,
each with its own OS process started from the same spec. Calls spread
over them, a crash takes down only the calls in flight on one member, and
rolling_restart/2 replaces them one at a time while the others serve.
Starts and tracks the members of one PluginHosts.Pool.
Brings one kind's hosts up to date with the tenant variables they read
(a host entry's variables, PluginHosts.variables/1). A member reads
them once, as it starts (PluginHosts.Host), so a saved variable
reaches it only through a restart.
Starts one kind's configured hosts (PluginHosts.configured/1), each
once its tenant slug names a tenant (Plugin.Host.tenant_id_for_slug/1):
the pool (PluginHosts.pool_child/3) runs under the kind's
DynamicSupervisor of pools (pools/1) and carries the tenant's id.
The step a plugin host's plugin runs (PluginHosts.Kind): Plugins.Camel
and Plugins.Command each use Alternera.Plugin and hand every
callback here with their t/0, which names the kind, the step's name
and the setting that names what the host is asked to run ("route" for
Camel, "operation" for a command). Settings, as a Camel step stores
them
The editor of a plugin host step (PluginHosts.Step): Plugins.Camel.Editor
and Plugins.Command.Editor are LiveComponents that hand update/3,
handle_event/4 and render/2 here with their t/0, which names the
step (PluginHosts.Step) and its wording. It is mounted by the pipeline
editor once per step.
The MCP tools of a plugin-host step that takes written documents
(Alternera.Plugin.Provisional.Tools), for an agent writing one: the
same check the editor and a save run (Step.check/3), and what a host
offers such a document, which the editor completes from.
Supervises one kind's plugin hosts (PluginHosts.Kind, the :kind
option): a registry of pools by name, the registry their ready members
join, the :pg scope they join across the cluster with the cache of
what other nodes run (PluginHosts.Cluster), a DynamicSupervisor with
one PluginHosts.Pool per host the kind's application environment
configures (Alternera.PluginHosts), and the PluginHosts.Starter
that starts each pool once its tenant's slug is looked up, and the
PluginHosts.Refresher that restarts the members of a host whose tenant
variables changed. Each kind's plugin
package starts one in its own application. A Host restarts its own OS
process; a supervisor here restarts a Host or a Pool only if it crashed
itself, which is a bug in it, not in the plugin. Nothing a host does
reaches the processes around this supervisor.