A Plugin
A Plugin is a program the Core launches, admits and holds a Session with. It does the work of a domain: it reads an instrument, drives a motor, transforms data, answers a question. Yoke gives it a process supervised and restarted on a policy, a socket of its own, a way to be asked and to report, and a log. The Core never reads what a Plugin's messages mean: a payload is bytes to it.
Before it is a process, a Plugin is a file and a declaration. The file is its executable, or an image when it runs in a container. The declaration is its Manifest. Together they are what a Plugin author ships, and what an application or a device carries.
What it is made of
| Part | What it is |
|---|---|
| an identity | a namespaced name, such as com.example.greeter: who the program is. The Manifest, the operator's policy and every application name it by it |
| the Manifest | manifest.yaml: what the Plugin declares about itself before it runs — the commands it accepts, the questions it answers, the streams it publishes, the occurrences it reports, a capability governing each, and the classes of thing it needs to reach, such as a device or a directory (the Manifest) |
| the executable | the program itself, written with the library of its language; or an image, for a Plugin that runs in a container (containerised units) |
A declaration grants nothing. The Manifest says what the Plugin may ask for. What it is allowed to do is what it declared and what the operator authorised, computed when it is admitted. A Plugin that declares a question nobody granted is admitted, and the question is withheld (admission, capabilities).
A plugin is authorised once, and every copy of it is covered. One application may run the same Plugin
several times, as several units — camera-1 and camera-2 from one camera Plugin. The plugin is what
the operator authorises; a unit is what the Core launches, addresses and supervises
(vocabulary).
The declaration, in five languages
Every library generates the Manifest from the declaration the program itself starts with, so the two cannot disagree: the program prints it when asked, and that output is the file shipped beside it. Here is the same Plugin, one question governed by one capability, in each family's library.
- Go
- Rust
- Python
- C
- C++
import "github.com/yoke-project/yoke-sdk-go/plugin"
func declaration() plugin.Declaration {
return plugin.Declaration{
ID: "com.example.greeter",
Queries: []string{"greeter.hello"},
Capabilities: []plugin.Capability{
{Name: "query.hello.answer", Governs: plugin.Object{Query: "greeter.hello"}},
},
}
}
use yoke_sdk::plugin::{Capability, Declaration, Object};
fn declaration() -> Declaration {
Declaration {
id: "com.example.greeter".into(),
queries: vec!["greeter.hello".into()],
capabilities: vec![Capability {
name: "query.hello.answer".into(),
governs: Object::Query("greeter.hello".into()),
}],
..Default::default()
}
}
from yoke_sdk import plugin
def declaration():
return plugin.Declaration(
id="com.example.greeter",
queries=["greeter.hello"],
capabilities=[
plugin.Capability("query.hello.answer", plugin.Object(query="greeter.hello")),
],
)
#include <yoke/plugin.h>
static const char *const queries[] = {"greeter.hello", NULL};
static const yoke_capability capabilities[] = {
{.name = "query.hello.answer", .governs = {YOKE_GOVERNS_QUERY, "greeter.hello"}},
{0},
};
static const yoke_declaration declaration = {
.id = "com.example.greeter",
.queries = queries,
.capabilities = capabilities,
};
#include <yoke/plugin.hpp>
using namespace yoke::plugin;
Declaration declaration() {
return {
.id = "com.example.greeter",
.queries = {"greeter.hello"},
.capabilities = {{"query.hello.answer", {Governs::query, "greeter.hello"}}},
};
}
Each of the five generates this Manifest, spelled with more or less indentation and quoting:
manifest: 1
id: com.example.greeter
protocol: 1
queries:
- id: greeter.hello
capabilities:
- name: query.hello.answer
governs:
query: greeter.hello
| Family | The library | A Plugin imports |
|---|---|---|
| Go | the module github.com/yoke-project/yoke-sdk-go | plugin |
| Rust | the crate yoke-sdk | yoke_sdk::plugin |
| Python | the package yoke-sdk | yoke_sdk.plugin |
| C | yoke-sdk-c, released as its source | yoke/plugin.h |
| C++ | yoke-sdk-cpp, released as its source | yoke/plugin.hpp |
The model is the same in each, and the spelling follows the language: a declaration, a start that registers, events to answer, an orderly close. Every library is held to the same conformance suite (what each family offers).
Its life
- The Core launches it. A Plugin started by hand has no token and is not admitted, unless a run asks for it explicitly, as a debugger needs (running it).
- It is admitted, not merely launched. Admission checks the token, that the program describes itself as its Manifest does, that the plugin is enabled, and what it was granted (admission).
- The Session is its one conversation with the Core, and everything it does travels on it or on a stream the Core activated (the Session, the families).
- A Plugin that falls is restarted according to its policy, and each life of its process is a new incarnation, numbered and kept in the log. The policy is the application's, not the Plugin's.
The library does the order for you. Reading the environment, binding before registering, the heartbeat, the end of the Session: every family discharges them in the order the contract requires, so a Plugin author writes the declaration and what to do with each event.
Where a Plugin goes
A Plugin is delivered in whichever form the application that uses it is delivered, and the files are the same two in both: the executable and the Manifest.
| The executable | The Manifest | |
|---|---|---|
| in an application's package | components/ of the bundle, pinned by its digest in yoke.yaml | manifests/ of the bundle |
| in the service form | /usr/lib/yoke/plugins/<plugin>, found from the identity | /etc/yoke/plugins.d/<plugin>/manifest.yaml |
The Manifest is the same file in both. Only who puts it there differs: the package's payload in the one, the distribution's package or the image in the other (an application as a service).
A Plugin is not an application
| A Plugin | An application | |
|---|---|---|
| what it is | a program | a description of what runs together |
| written in | one of five languages, with its library | YAML, with yoke-compose |
| identified by | its plugin identity, com.example.greeter | its application identity and version, com.example.hello 0.1.0 |
| declares | what it may do: commands, questions, streams, occurrences, needs | what runs: units, channels, parameters, an order of start |
| built into | an executable and a Manifest | a package, <id>-<version>.yoke, or a composition in the service form |
| runs | as one or more units, inside an instance | as an instance, which the Core runs |
| authorised | once, by the operator, for every copy | never: an application is checked, and its Plugins are authorised |
| used by | any number of applications, by any author | the hosts that install it |
A Plugin is tried inside the smallest application there is: a project with one unit, run from the
working directory with yoke app run --from, and nothing installed (trying it).
That application exists to run the Plugin, and is a second thing beside it.