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:
%{"host" => "erp",
"route" => "customer.lookup",
"inputs" => [%{"name" => "id", "value" => "${path.id}"}],
"targets" => [%{"output" => "body", "to" => %{"in" => "vars", "name" => "customer"}}]}inputs are built as a Call step's are (Plugin.Provisional.Inputs): each
named, a value template or a from location resolved in this exchange.
They go to the operation as one object, name to value, in the host's
protocol (PluginHosts, moduledoc). A step with destinations
(input_destinations?, Camel) lets each row say where it goes, as:
field, a field of that object; header, a header of the exchange;
property, an exchange property. A row without as is a field, or a
header when the step has a source; the header and property rows go
beside the object (the frame's headers and properties, over HTTP
Alternera-Headers and Alternera-Properties). A source
(a location, as a Request step's) is a body sent as it is, with
content_type or, for a whole body, its side's own Content-Type; the
inputs then travel beside it (PluginHosts.HttpCall). Only a host
over HTTP or HTTPS takes a body: on any other the step fails
invalid_input. A source that is its side's body runs the step in that
body phase. Input templates take plain variables only (they are
:plain templates, so a save refuses {{secret.…}}): a secret an input
carried would be the route's data. Routes written in the step
(definition) read the tenant's variables and secrets as {{NAME}}
and {{secret.NAME}}: the step sends their values beside the text
(PluginHosts.Definition), the host builds the routes with them as
Camel properties, and both the host and the step take the secrets out of
the trace, the headers and the errors that come back
(Plugin.Secret.scrub/2). A reference that does not resolve fails the
step unresolved_variable before anything is sent. A call of a route
of the host's own files has the secrets the host's entry lists
(PluginHosts.variables/1) taken out the same way.
A step with answer_headers? (Camel) also has a keyed headers output,
the answer's headers (outputs/1): over the port the reply's
values.headers, over HTTP Alternera-Answer-Headers
(HttpCall.answer_headers/3), names lower-cased, as a Request step's
response headers are.
The operation's answer is the step's body output (outputs/0), JSON as
the host sent it, kept for later steps and written where the To rows
(targets) say; with none it is only kept. Among an Implementation's own
steps a row to the whole response body makes the answer the response, and
a JSON answer (a map or a list) makes it application/json unless its
Content-Type already names JSON, as a Call step's result does.
Failures
The host and the operation are checked when the step runs, not at save: hosts are the installation's, start after the pipelines load, and a host's catalogue may change with its routes. A failed call keeps its kind:
unavailable: no such host, the tenant may not call it, or none of its members is ready; nothing was sent;timeout: no answer within the step's time left (the host is told to cancel);connection: the member died with the call in flight; the operation may have run (it is never repeated);invalid_input: an input is not JSON (a body that is not UTF-8 text), the whole is too large for a frame, or the host refuses an input's name (a Camel host, a control header's);operation_failed: the operation answered with an error; the message is the host's type and message (an unknown operation is one,unknown_op).
The error carries outbound_us, the time spent waiting on the host.
Running
The step waits on another process, so it runs in a task of its own
(run_in_task: true) that the runner kills at the step's time left; the
host then cancels the call. It reaches outside the proxy
(the plugin's side_effect?/0 is true): in the editor's preview it sends nothing and says
what it would call, with a fingerprint of the host, the operation and
the resolved input, until it is played. In a provisional request pass it
sends nothing and asks for the deciding pass, as Request does.
Camel is shipped; Command is installed only with :experimental_plugins
(Pipelines.PluginRegistry).
Summary
Types
A plugin's step: plugin, its module, which is also the hosts' kind;
id, its plugin id (the first part of a call's fingerprint); name, the
step's name in its errors and log lines; op_key, the setting that names
what the host runs, op_noun the word for it in messages, and
op_description that setting's description in the schema;
reserved_inputs, the prefixes (lower case) of input names the host
refuses because they would steer it rather than feed the operation
(reserved_input?/2), none by default; input_destinations?, whether
each input row says where it goes (as: a field of the input object, a
header or a property), which only Camel's exchange has; answer_headers?,
whether the step offers the answer's headers as its keyed headers
output (outputs/1), which a Camel host sends with every answer;
definitions?, whether a step may hold the document its operation is in
(definition, PluginHosts.Definition): Camel's routes "written here".
Functions
Runs the step (Alternera.Plugin.call/3).
Has the host check the document the step holds, without defining it:
{:ok, %{diagnostics: [diagnostic], inputs: [%{name, as}]}}, :none
when there is nothing to check (no document, or a host that takes none
or is not the tenant's), or {:error, message} when the host could not
check it. A diagnostic is %{severity: :error | :warning, kind, message, line, column} (line and column nil when unknown). Kind :routes is
the host's: what it refuses, an entry route the document lacks, a route
the entry never reaches. Kind :inputs compares the entry route's
inputs with the rows (input_warnings/3). inputs is what the entry
route reads.
The step's one-line description (Alternera.Plugin.describe/1).
What a person reads for a host request's failure (a check, a vocabulary,
a describe): {:error, reason} as PluginHosts gives it.
Parses a step's settings (Alternera.Plugin.init/1).
What a route reads against what the step's rows send: a warning for
each input in listed (%{name, as}) that no row sends there, and for
each row whose name the route never reads. With a body, a field the
route reads is the body's. Without input destinations only names count.
The outputs every plugin host step has: body, the operation's answer,
its default. A step's own are outputs/1.
The step's outputs (Alternera.Plugin.outputs/0): body, and for
a step with answer_headers? the keyed headers.
Whether its To rows may write the response (Provisional.Analysis).
The recorded call's output (Alternera.Plugin.replay_recorded/2).
Whether name starts with one of the step's reserved_inputs, in any
case: Camel refuses Camel…, the names of Camel's control headers, which
a component reads before the route's own settings (CamelSqlQuery
replaces a camel-sql route's query).
The step's save warnings (Alternera.Plugin.save_warnings/2):
each diagnostic of check/3 as text, with , line N when it has a line,
and a host that could not check as one warning.
Where a row sends its input: its as, or without one a header when the
step sends a body (source?) and a field when it does not.
The step's settings (Alternera.Plugin.settings_schema/0).
The step's signature (Alternera.Plugin.signature/2).
Calls the step's operation once with sample values, for the editor's
Try: samples maps an input row's name to the text it sends, body
the sample body when the step sends one. The step's settings must parse
(init/2); its templates are not resolved, its To rows not written, and
the call goes over the host's port whatever its protocol, so nothing is
recorded and a body travels as the input (JSON when it parses as JSON).
Types
@type t() :: %Alternera.PluginHosts.Step{ answer_headers?: boolean(), definitions?: boolean(), id: String.t(), input_destinations?: boolean(), name: String.t(), op_description: String.t(), op_key: String.t(), op_noun: String.t(), plugin: module(), reserved_inputs: [String.t()] }
A plugin's step: plugin, its module, which is also the hosts' kind;
id, its plugin id (the first part of a call's fingerprint); name, the
step's name in its errors and log lines; op_key, the setting that names
what the host runs, op_noun the word for it in messages, and
op_description that setting's description in the schema;
reserved_inputs, the prefixes (lower case) of input names the host
refuses because they would steer it rather than feed the operation
(reserved_input?/2), none by default; input_destinations?, whether
each input row says where it goes (as: a field of the input object, a
header or a property), which only Camel's exchange has; answer_headers?,
whether the step offers the answer's headers as its keyed headers
output (outputs/1), which a Camel host sends with every answer;
definitions?, whether a step may hold the document its operation is in
(definition, PluginHosts.Definition): Camel's routes "written here".
Functions
Runs the step (Alternera.Plugin.call/3).
@spec check(t(), map(), term()) :: {:ok, %{diagnostics: [map()], inputs: [map()], routes: [String.t()]}} | :none | {:error, String.t()}
Has the host check the document the step holds, without defining it:
{:ok, %{diagnostics: [diagnostic], inputs: [%{name, as}]}}, :none
when there is nothing to check (no document, or a host that takes none
or is not the tenant's), or {:error, message} when the host could not
check it. A diagnostic is %{severity: :error | :warning, kind, message, line, column} (line and column nil when unknown). Kind :routes is
the host's: what it refuses, an entry route the document lacks, a route
the entry never reaches. Kind :inputs compares the entry route's
inputs with the rows (input_warnings/3). inputs is what the entry
route reads.
The step's one-line description (Alternera.Plugin.describe/1).
What a person reads for a host request's failure (a check, a vocabulary,
a describe): {:error, reason} as PluginHosts gives it.
Parses a step's settings (Alternera.Plugin.init/1).
What a route reads against what the step's rows send: a warning for
each input in listed (%{name, as}) that no row sends there, and for
each row whose name the route never reads. With a body, a field the
route reads is the body's. Without input destinations only names count.
The outputs every plugin host step has: body, the operation's answer,
its default. A step's own are outputs/1.
The step's outputs (Alternera.Plugin.outputs/0): body, and for
a step with answer_headers? the keyed headers.
Whether its To rows may write the response (Provisional.Analysis).
The recorded call's output (Alternera.Plugin.replay_recorded/2).
Whether name starts with one of the step's reserved_inputs, in any
case: Camel refuses Camel…, the names of Camel's control headers, which
a component reads before the route's own settings (CamelSqlQuery
replaces a camel-sql route's query).
The step's save warnings (Alternera.Plugin.save_warnings/2):
each diagnostic of check/3 as text, with , line N when it has a line,
and a host that could not check as one warning.
Where a row sends its input: its as, or without one a header when the
step sends a body (source?) and a field when it does not.
The step's settings (Alternera.Plugin.settings_schema/0).
The step's signature (Alternera.Plugin.signature/2).
@spec try_call( t(), map(), %{required(String.t()) => String.t()}, String.t() | nil, String.t() | nil ) :: {:ok, map()} | {:error, map()}
Calls the step's operation once with sample values, for the editor's
Try: samples maps an input row's name to the text it sends, body
the sample body when the step sends one. The step's settings must parse
(init/2); its templates are not resolved, its To rows not written, and
the call goes over the host's port whatever its protocol, so nothing is
recorded and a body travels as the input (JSON when it parses as JSON).
Returns {:ok, %{body, headers, trace, trace_omitted, ms}} or
{:error, %{type, message, …}}, the host's error object (with at,
exception, status, on_purpose and trace when it sent them) or the
proxy's reason as type.