@yarkivaev/scada 2.29.0 → 2.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/charts/scada-workloads/templates/_collector.tpl +3 -0
- package/charts/scada-workloads/templates/_control-agent.tpl +4 -1
- package/charts/scada-workloads/templates/_controller.tpl +3 -0
- package/charts/scada-workloads/templates/_history-maintenance.tpl +3 -0
- package/charts/scada-workloads/templates/_history-receiver.tpl +4 -1
- package/charts/scada-workloads/templates/_journal-supervisor.tpl +3 -0
- package/charts/scada-workloads/templates/_runtime.tpl +13 -0
- package/charts/scada-workloads/templates/_site-server.tpl +4 -1
- package/charts/scada-workloads/templates/_supervisor.tpl +3 -0
- package/charts/scada-workloads/templates/_telemetry.tpl +4 -1
- package/package.json +1 -1
- package/src/application/deploy/collectionEvents.js +7 -6
- package/src/application/deploy/compileLocalConsumers.js +14 -6
- package/src/application/deploy/historyPlacement.js +61 -0
- package/src/application/deploy/namedCollection.js +13 -4
- package/src/application/deploy/namedProcessing.js +80 -21
- package/src/application/deploy/normalizeControlPlane.js +2 -2
- package/src/application/deploy/paths.js +3 -1
- package/src/application/deploy/projectCollectionRoutes.js +3 -1
- package/src/application/deploy/readDeploymentDocument.js +5 -3
- package/src/application/deploy/releaseValues.js +5 -3
- package/src/application/deploy/streamNamespace.js +32 -0
- package/src/application/deploy/workloadDeclarations.js +26 -0
- package/src/application/runtime/applicationRuntime.js +2 -1
- package/src/infrastructure/deploy/configuredRuntimeArtifacts.js +98 -25
- package/src/infrastructure/deploy/index.js +2 -0
package/README.md
CHANGED
|
@@ -42,6 +42,16 @@ Module entries are local JS files relative to the declaring runtime document. Th
|
|
|
42
42
|
|
|
43
43
|
The release workflow publishes Node.js and JVM images and records their digests alongside the release revision. The Node image includes `scada-install-app URL SHA256 DESTINATION`, which verifies and extracts an application bundle for read-only mounting. The JVM image loads an optional profile JAR with the class named by `SCADA_RUNTIME_PROFILE`. The application selects compatible image and bundle digests in the deployment.
|
|
44
44
|
|
|
45
|
+
The optional `artifacts` section selects the bundle deployment targets and a JVM profile when needed. Kubernetes chart templates can declare the runtime in a resource annotation. The following binding runs `collector` through the application manifest and keeps the installed bundle read-only in the container.
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
metadata:
|
|
49
|
+
annotations:
|
|
50
|
+
scada.io/runtime: '{"reader":{"service":"collector"}}'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The map keys identify containers. Use `service` or `job` for a named declaration, or `jvm: true` for a JVM profile. An optional `args` array supplies application arguments. Unannotated manifests can still use conventional `node bin/<name>.js` commands or explicit compatibility aliases.
|
|
54
|
+
|
|
45
55
|
## Collection deployment DSL
|
|
46
56
|
|
|
47
57
|
A deployment document can declare equipment endpoints in `sources`, logical inputs in `streams`, and assignment policy in `controlPlane.readers`. Each reader refers to one stream through its key or to a list under `streams`. Its ordered `eligible` nodes and requested `copies` guide the controller. A source address can be a `$secret` reference that the executing adapter resolves. Push sources declare their API and event type through a stream.
|
|
@@ -13,6 +13,9 @@ apiVersion: apps/v1
|
|
|
13
13
|
kind: Deployment
|
|
14
14
|
metadata:
|
|
15
15
|
name: {{ .name }}
|
|
16
|
+
{{- with .runtime }}
|
|
17
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "collector" "binding" .) | nindent 2 }}
|
|
18
|
+
{{- end }}
|
|
16
19
|
labels:
|
|
17
20
|
{{- .labels | nindent 4 }}
|
|
18
21
|
spec:
|
|
@@ -3,6 +3,9 @@ apiVersion: apps/v1
|
|
|
3
3
|
kind: Deployment
|
|
4
4
|
metadata:
|
|
5
5
|
name: {{ .name }}
|
|
6
|
+
{{- with .runtime }}
|
|
7
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "collector" "binding" .) | nindent 2 }}
|
|
8
|
+
{{- end }}
|
|
6
9
|
spec:
|
|
7
10
|
replicas: 1
|
|
8
11
|
strategy: {type: Recreate}
|
|
@@ -19,7 +22,7 @@ spec:
|
|
|
19
22
|
containers:
|
|
20
23
|
- name: collector
|
|
21
24
|
image: {{ required "agent image required" .values.agent.image | quote }}
|
|
22
|
-
command: {{ .
|
|
25
|
+
command: {{ include "scada.workloads.runtimeCommand" . }}
|
|
23
26
|
env:
|
|
24
27
|
{{- range $key, $value := .values.agent.env }}
|
|
25
28
|
- name: {{ $key }}
|
|
@@ -4,6 +4,9 @@ apiVersion: apps/v1
|
|
|
4
4
|
kind: Deployment
|
|
5
5
|
metadata:
|
|
6
6
|
name: {{ .name }}
|
|
7
|
+
{{- with .runtime }}
|
|
8
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "controller" "binding" .) | nindent 2 }}
|
|
9
|
+
{{- end }}
|
|
7
10
|
spec:
|
|
8
11
|
replicas: 1
|
|
9
12
|
strategy: {type: Recreate}
|
|
@@ -3,6 +3,9 @@ apiVersion: batch/v1
|
|
|
3
3
|
kind: CronJob
|
|
4
4
|
metadata:
|
|
5
5
|
name: {{ .name }}
|
|
6
|
+
{{- with .runtime }}
|
|
7
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "history-retention" "binding" .) | nindent 2 }}
|
|
8
|
+
{{- end }}
|
|
6
9
|
spec:
|
|
7
10
|
schedule: {{ .schedule | quote }}
|
|
8
11
|
concurrencyPolicy: Forbid
|
|
@@ -14,6 +14,9 @@ apiVersion: apps/v1
|
|
|
14
14
|
kind: Deployment
|
|
15
15
|
metadata:
|
|
16
16
|
name: {{ .name }}
|
|
17
|
+
{{- with .runtime }}
|
|
18
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "history-api" "binding" .) | nindent 2 }}
|
|
19
|
+
{{- end }}
|
|
17
20
|
spec:
|
|
18
21
|
replicas: 1
|
|
19
22
|
strategy: {type: Recreate}
|
|
@@ -30,7 +33,7 @@ spec:
|
|
|
30
33
|
containers:
|
|
31
34
|
- name: history-api
|
|
32
35
|
image: {{ required "receiverImage required for local history API" .values.receiverImage | quote }}
|
|
33
|
-
command: {{ .
|
|
36
|
+
command: {{ include "scada.workloads.runtimeCommand" . }}
|
|
34
37
|
env:
|
|
35
38
|
- name: POSTGRES_URL
|
|
36
39
|
valueFrom:
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{- define "scada.workloads.runtimeBinding" -}}
|
|
2
|
+
annotations:
|
|
3
|
+
scada.io/runtime: {{ dict .container .binding | toJson | quote }}
|
|
4
|
+
{{- end -}}
|
|
5
|
+
|
|
6
|
+
{{- define "scada.workloads.runtimeCommand" -}}
|
|
7
|
+
{{- if .command -}}
|
|
8
|
+
{{- .command | toJson -}}
|
|
9
|
+
{{- else -}}
|
|
10
|
+
{{- $runtime := .runtime | default dict -}}
|
|
11
|
+
{{- list "node" (printf "bin/%s.js" (required "runtime service or command required" $runtime.service)) | toJson -}}
|
|
12
|
+
{{- end -}}
|
|
13
|
+
{{- end -}}
|
|
@@ -3,6 +3,9 @@ apiVersion: apps/v1
|
|
|
3
3
|
kind: Deployment
|
|
4
4
|
metadata:
|
|
5
5
|
name: {{ .name }}
|
|
6
|
+
{{- with .runtime }}
|
|
7
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "site-server" "binding" .) | nindent 2 }}
|
|
8
|
+
{{- end }}
|
|
6
9
|
labels:
|
|
7
10
|
{{- toYaml .labels | nindent 4 }}
|
|
8
11
|
spec:
|
|
@@ -21,7 +24,7 @@ spec:
|
|
|
21
24
|
containers:
|
|
22
25
|
- name: site-server
|
|
23
26
|
image: {{ .site.image | quote }}
|
|
24
|
-
command: {{ .
|
|
27
|
+
command: {{ include "scada.workloads.runtimeCommand" . }}
|
|
25
28
|
ports:
|
|
26
29
|
- {name: http, containerPort: 3000}
|
|
27
30
|
- {name: state-http, containerPort: 8081}
|
|
@@ -14,6 +14,9 @@ apiVersion: apps/v1
|
|
|
14
14
|
kind: Deployment
|
|
15
15
|
metadata:
|
|
16
16
|
name: {{ .release.Name }}
|
|
17
|
+
{{- with .runtime }}
|
|
18
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "supervisor" "binding" .) | nindent 2 }}
|
|
19
|
+
{{- end }}
|
|
17
20
|
namespace: {{ .release.Namespace }}
|
|
18
21
|
labels:
|
|
19
22
|
app: {{ .values.app | default .release.Name }}
|
|
@@ -93,6 +93,9 @@ apiVersion: apps/v1
|
|
|
93
93
|
kind: Deployment
|
|
94
94
|
metadata:
|
|
95
95
|
name: {{ .ingesterName }}
|
|
96
|
+
{{- with .runtime }}
|
|
97
|
+
{{- include "scada.workloads.runtimeBinding" (dict "container" "telemetry" "binding" .) | nindent 2 }}
|
|
98
|
+
{{- end }}
|
|
96
99
|
spec:
|
|
97
100
|
replicas: 1
|
|
98
101
|
strategy: {type: Recreate}
|
|
@@ -109,7 +112,7 @@ spec:
|
|
|
109
112
|
containers:
|
|
110
113
|
- name: telemetry
|
|
111
114
|
image: {{ $telemetry.image | quote }}
|
|
112
|
-
command: {{ .
|
|
115
|
+
command: {{ include "scada.workloads.runtimeCommand" . }}
|
|
113
116
|
env:
|
|
114
117
|
{{- with .extraEnv }}
|
|
115
118
|
{{- . | nindent 12 }}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { localOwner } from './collectionPlacement.js';
|
|
2
2
|
|
|
3
|
-
function eventRoute({ id, type, node, machine, api }, route, owners) {
|
|
3
|
+
function eventRoute({ id, type, node, machine, api, path }, route, owners) {
|
|
4
4
|
const home = route.localState && localOwner(owners, machine);
|
|
5
5
|
const to = home && !route.to.includes(home) ? [...route.to, home] : route.to;
|
|
6
6
|
const viaApi = route.viaApi ?? api;
|
|
7
|
-
return { id, type, node, machine, to, ...(viaApi && { viaApi }) };
|
|
7
|
+
return { id, type, node, machine, ...(path !== undefined && { path }), to, ...(viaApi && { viaApi }) };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
function pushRoutes(stream, route, machines, owners, servers) {
|
|
@@ -32,14 +32,15 @@ export function readerEvents(readers, deliverable, delivery, owners) {
|
|
|
32
32
|
export function eventRoutes({ document, streams, outputs, delivery, owners, workloads }) {
|
|
33
33
|
const machines = new Map(Object.entries(owners));
|
|
34
34
|
for (const { assignments } of Object.values(workloads)) {
|
|
35
|
-
for (const { machines: selected, nodes: [primary] } of assignments) {
|
|
36
|
-
selected.
|
|
35
|
+
for (const { machines: selected, nodes: [primary], scope } of assignments) {
|
|
36
|
+
const paths = scope ? [scope] : selected.map(({ path }) => { return path; });
|
|
37
|
+
paths.forEach((path) => { if (!machines.has(path)) { machines.set(path, primary); } });
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
const servers = new Map(document.servers?.map((server) => { return [server.id, server]; }));
|
|
40
|
-
const processing = Object.entries(outputs).filter(([id]) => { return Object.hasOwn(delivery, id); }).flatMap(([id, { type, producers }]) => {
|
|
41
|
+
const processing = Object.entries(outputs).filter(([id]) => { return Object.hasOwn(delivery, id); }).flatMap(([id, { type, path, producers }]) => {
|
|
41
42
|
return producers.flatMap(({ machine, nodes }) => {
|
|
42
|
-
return nodes.map((node) => { return eventRoute({ id, type, node, machine }, delivery[id], owners); });
|
|
43
|
+
return nodes.map((node) => { return eventRoute({ id, type, node, machine, path }, delivery[id], owners); });
|
|
43
44
|
});
|
|
44
45
|
});
|
|
45
46
|
const pushed = [...streams.values()].filter(({ source, output, id }) => {
|
|
@@ -5,16 +5,23 @@ import { resolveCollection } from './namedCollection.js';
|
|
|
5
5
|
const batchOptions = { size: 50, interval: 2, threshold: 5, timeout: 60 };
|
|
6
6
|
const postgres = { $secret: 'POSTGRES_URL' };
|
|
7
7
|
const amqp = { $secret: 'AMQP_URL' };
|
|
8
|
+
const stompEventTypes = ['segments', 'alerts', 'user_decisions'];
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
+
function incomingEventTypes(node, delivery, events) {
|
|
11
|
+
const legacy = ['operations', ...stompEventTypes].filter((id) => {
|
|
12
|
+
return delivery[id]?.localState || delivery[id]?.to.includes(node);
|
|
13
|
+
});
|
|
14
|
+
return new Set([...legacy, ...events.filter(({ to }) => { return to.includes(node); }).map(({ type }) => { return type; })]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function localReceivers({ eventTypes, topics, devices, clientId, localState, preferences }) {
|
|
10
18
|
const { operations, telemetry, stomp } = preferences;
|
|
11
|
-
function localEvents(event) { return routes[event]?.localState || routes[event]?.to.includes(node); }
|
|
12
19
|
return [
|
|
13
20
|
topics.length && { id: 'mqtt', spec: { adapter: 'mqtt-pg-metrics', mqtt: { $secret: 'MQTT_URL' },
|
|
14
21
|
postgres, devices, topic: topics.join(','), firstWins: true, options: { ...batchOptions, clientId } } },
|
|
15
|
-
|
|
22
|
+
eventTypes.has('operations') && operations?.enabled !== false && { id: 'operations', spec: { adapter: 'operation-sync', amqp,
|
|
16
23
|
postgres, queue: operations?.queue ?? 'scada.operations.from-sensors', options: batchOptions } },
|
|
17
|
-
|
|
24
|
+
stompEventTypes.some((type) => { return eventTypes.has(type); }) && { id: 'stomp', spec: { adapter: 'stomp-ingest',
|
|
18
25
|
stomp: { $secret: 'STOMP_URL' }, postgres, config: { ...batchOptions, ...localState,
|
|
19
26
|
prefetch: 128, repairHistoryOnStart: false, deadLetter: false, ...stomp } } },
|
|
20
27
|
topics.length && telemetry?.enabled !== false && { id: 'amqp-metrics', spec: { adapter: 'amqp-pg-metrics', amqp,
|
|
@@ -24,14 +31,15 @@ function localReceivers(node, { routes, topics, devices, clientId, localState, p
|
|
|
24
31
|
|
|
25
32
|
/** Build the ingress assignments for state owned by one node using collection and delivery. */
|
|
26
33
|
export function namedLocalConsumers(document, node, { generation = 1, wire, preferences = {} }) {
|
|
27
|
-
const { objectOwners, delivery, readers } = resolveCollection(document);
|
|
34
|
+
const { objectOwners, delivery, events, readers } = resolveCollection(document);
|
|
28
35
|
const paths = Object.keys(objectOwners).filter((path) => { return objectOwners[path] === node; });
|
|
29
36
|
if (!paths.length || wire === undefined) { return []; }
|
|
30
37
|
const targets = readers.flatMap(({ streams }) => { return streams; }).filter(({ id, path }) => {
|
|
31
38
|
return delivery[id]?.to.includes(node) && paths.some((home) => { return path === home || path.startsWith(`${home}/`); });
|
|
32
39
|
});
|
|
33
40
|
const configuration = wire(paths, targets);
|
|
34
|
-
|
|
41
|
+
const eventTypes = incomingEventTypes(node, delivery, events);
|
|
42
|
+
return collectorConsumerTasks(localReceivers({ ...configuration, eventTypes, preferences,
|
|
35
43
|
localState: document.controlPlane.history?.sink?.segmentPolicy }), node, {}, generation);
|
|
36
44
|
}
|
|
37
45
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function validateCache(cache, node) {
|
|
2
|
+
if (!cache || typeof cache !== 'object' || Array.isArray(cache)) {
|
|
3
|
+
throw new TypeError(`History cache must map groups to streams on ${node}`);
|
|
4
|
+
}
|
|
5
|
+
for (const [group, streams] of Object.entries(cache)) {
|
|
6
|
+
if (!Array.isArray(streams) || !streams.length || new Set(streams).size !== streams.length
|
|
7
|
+
|| streams.some((id) => { return typeof id !== 'string' || !id; })) {
|
|
8
|
+
throw new TypeError(`Invalid cache streams for ${group} on ${node}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function storageRules(document) {
|
|
14
|
+
const servers = new Set(document.servers.map(({ id }) => { return id; }));
|
|
15
|
+
return Object.entries(document.history).map(([node, { state, cache = {}, restore, retentionDays }]) => {
|
|
16
|
+
if (!servers.has(node)) { throw new TypeError(`Unknown history node ${node}`); }
|
|
17
|
+
if (retentionDays !== undefined && (!Number.isSafeInteger(retentionDays) || retentionDays < 1)) {
|
|
18
|
+
throw new TypeError(`History retentionDays must be a positive integer for ${node}`);
|
|
19
|
+
}
|
|
20
|
+
validateCache(cache, node);
|
|
21
|
+
return { node, state: state === undefined ? [] : [state].flat(), cache, restore };
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function historyReplicas(rules, placements) {
|
|
26
|
+
const entries = rules.flatMap(({ node, cache, restore }) => {
|
|
27
|
+
return Object.keys(cache)
|
|
28
|
+
.map((group) => { return [group, { ...restore?.[group], standby: node }]; });
|
|
29
|
+
});
|
|
30
|
+
const cached = new Map(entries);
|
|
31
|
+
if (cached.size !== entries.length) { throw new TypeError('A history group can have only one standby'); }
|
|
32
|
+
const groups = new Set([...Object.values(placements).flat(), ...cached.keys()]);
|
|
33
|
+
return Object.fromEntries([...groups].filter((group) => { return cached.has(group); })
|
|
34
|
+
.map((group) => { return [group, cached.get(group)]; }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Adapt the node storage rules to state owners and standby replicas. */
|
|
38
|
+
export function resolveHistoryPlacement(document) {
|
|
39
|
+
if (!document?.history) { return document; }
|
|
40
|
+
const rules = storageRules(document);
|
|
41
|
+
const placements = Object.fromEntries(rules.filter(({ state }) => { return state.length; })
|
|
42
|
+
.map(({ node, state }) => { return [node, state]; }));
|
|
43
|
+
const replicas = historyReplicas(rules, placements);
|
|
44
|
+
const { controlPlane } = document;
|
|
45
|
+
return { ...document, controlPlane: { ...controlPlane,
|
|
46
|
+
...(Object.keys(placements).length && { localState: { ...controlPlane?.localState, placements } }),
|
|
47
|
+
...(Object.keys(replicas).length && { history: { ...controlPlane?.history, replicas } }) } };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function archiveNode(document, fallback) {
|
|
51
|
+
if (!document.history && fallback) { return fallback; }
|
|
52
|
+
const archives = document.history
|
|
53
|
+
? Object.keys(document.history).filter((id) => { return document.history[id].archive === 'delivered'; })
|
|
54
|
+
: document.servers.filter(({ profile }) => { return profile?.id === 'archive'; }).map(({ id }) => { return id; });
|
|
55
|
+
if (archives.length !== 1) { throw new TypeError('Control plane requires exactly one archive server'); }
|
|
56
|
+
return archives[0];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function retentionFor(document, node) {
|
|
60
|
+
return document.history?.[node]?.retentionDays;
|
|
61
|
+
}
|
|
@@ -85,16 +85,25 @@ function routeEntries(delivery, known) {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
function deliveryObjectPath({ path, producers }) {
|
|
89
|
+
if (path === undefined || producers?.length > 1) { return undefined; }
|
|
90
|
+
return producers?.[0]?.machine ?? path;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function localDelivery(targets, stream, owners) {
|
|
94
|
+
if (!targets.some(localStateReference)) { return { dynamic: false }; }
|
|
95
|
+
const path = deliveryObjectPath(stream);
|
|
96
|
+
return { dynamic: path === undefined, home: localOwner(owners, path) };
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
function routeDestinations(id, route, stream, servers, owners) {
|
|
89
100
|
const { to, viaApi } = asMap(route, `Delivery ${id}`);
|
|
90
101
|
if (Object.hasOwn(route, 'from')) { throw new TypeError(`Delivery ${id} cannot declare from`); }
|
|
91
102
|
if (viaApi !== undefined && (typeof viaApi !== 'string' || !viaApi)) { throw new TypeError(`Invalid delivery API for ${id}`); }
|
|
92
103
|
const targets = Array.isArray(to) ? to : [to];
|
|
93
|
-
const
|
|
94
|
-
const dynamic = local && stream.path === undefined;
|
|
95
|
-
const home = localOwner(owners, stream.path);
|
|
104
|
+
const { dynamic, home } = localDelivery(targets, stream, owners);
|
|
96
105
|
const resolved = targets.filter((target) => { return !localStateReference(target); });
|
|
97
|
-
if (
|
|
106
|
+
if (home !== undefined && !resolved.includes(home)) { resolved.push(home); }
|
|
98
107
|
if (!dynamic || resolved.length > 0) { ids(resolved, `destinations for stream ${id}`, servers); }
|
|
99
108
|
return { to: resolved, viaApi, ...(dynamic && { localState: true }) };
|
|
100
109
|
}
|
|
@@ -1,27 +1,40 @@
|
|
|
1
|
+
import deploymentTemplate from '../../infrastructure/deploy/deploymentTemplate.js';
|
|
2
|
+
import { treePaths } from './expandNamespace.js';
|
|
3
|
+
|
|
1
4
|
function machineType(template, types) {
|
|
2
5
|
return Object.entries(types).find(([, type]) => { return type.signalTemplates?.includes(template); })?.[0];
|
|
3
6
|
}
|
|
4
7
|
|
|
5
8
|
function machinesAt(nodes, types, parent = '') {
|
|
6
|
-
return (nodes ?? []).flatMap(({ id, template, nodes: children }) => {
|
|
9
|
+
return (nodes ?? []).flatMap(({ id, template, type: declared, nodes: children }) => {
|
|
7
10
|
const path = parent ? `${parent}/${id}` : id;
|
|
8
|
-
const type = template && machineType(template, types);
|
|
11
|
+
const type = declared ?? (template && machineType(template, types));
|
|
9
12
|
return [...(type ? [{ id, path, type }] : []), ...machinesAt(children, types, path)];
|
|
10
13
|
});
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const files = new Map();
|
|
16
|
-
const profiles = Object.entries(document.machineTypes ?? {}).flatMap(([type, { processingProfile }]) => {
|
|
16
|
+
function profileEntries(declarations, read) {
|
|
17
|
+
return Object.entries(declarations ?? {}).flatMap(([id, { processingProfile }]) => {
|
|
17
18
|
if (processingProfile === undefined) { return []; }
|
|
18
19
|
if (typeof processingProfile !== 'string' || !processingProfile.trim()) {
|
|
19
|
-
throw new TypeError(`Invalid processing profile for ${
|
|
20
|
+
throw new TypeError(`Invalid processing profile for ${id}`);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
return [[type, files.get(processingProfile)]];
|
|
22
|
+
return [[id, read(processingProfile)]];
|
|
23
23
|
});
|
|
24
|
-
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Load workload and legacy machine-type profiles, sharing files between their users. */
|
|
27
|
+
export function readProcessingProfiles(document, load, parse) {
|
|
28
|
+
const files = new Map();
|
|
29
|
+
function read(path) {
|
|
30
|
+
if (!files.has(path)) { files.set(path, parse(load(path), load)); }
|
|
31
|
+
return files.get(path);
|
|
32
|
+
}
|
|
33
|
+
const profiles = profileEntries(document.machineTypes, read);
|
|
34
|
+
const workloads = profileEntries(document.controlPlane?.workloads, read);
|
|
35
|
+
if (!profiles.length && !workloads.length) { return document; }
|
|
36
|
+
return { ...document, ...(profiles.length && { processingProfiles: Object.fromEntries(profiles) }),
|
|
37
|
+
...(workloads.length && { workloadProcessingProfiles: Object.fromEntries(workloads) }) };
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
function chooseMachines(all, id, selector) {
|
|
@@ -34,11 +47,15 @@ function chooseMachines(all, id, selector) {
|
|
|
34
47
|
return matches;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
|
-
function
|
|
38
|
-
const nodes = workload.placement?.nodes;
|
|
50
|
+
function validNodes(nodes, serverIds, message) {
|
|
39
51
|
if (!Array.isArray(nodes) || !nodes.length || new Set(nodes).size !== nodes.length || nodes.some((node) => { return !serverIds.has(node); })) {
|
|
40
|
-
throw new TypeError(
|
|
52
|
+
throw new TypeError(message);
|
|
41
53
|
}
|
|
54
|
+
return nodes;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function assignmentEntries(all, workload, serverIds) {
|
|
58
|
+
const nodes = validNodes(workload.placement?.nodes, serverIds, 'Invalid workload placement');
|
|
42
59
|
return Object.entries(workload.assignments ?? {}).map(([id, assignment]) => {
|
|
43
60
|
const { preferred, standby } = assignment.placement ?? {};
|
|
44
61
|
const eligible = [preferred, standby].filter((node) => { return node !== undefined; });
|
|
@@ -49,11 +66,41 @@ function assignmentEntries(all, workload, serverIds) {
|
|
|
49
66
|
});
|
|
50
67
|
}
|
|
51
68
|
|
|
69
|
+
function processingScope(all, paths, id, bindings) {
|
|
70
|
+
const scope = bindings.objectPath;
|
|
71
|
+
if (scope === undefined) {
|
|
72
|
+
return { machines: all.filter(({ type }) => { return type === id; }) };
|
|
73
|
+
}
|
|
74
|
+
if (typeof scope !== 'string' || !paths.has(scope)) {
|
|
75
|
+
throw new TypeError(`Invalid processing object path for ${id}`);
|
|
76
|
+
}
|
|
77
|
+
const machines = all.filter(({ path }) => { return path === scope; });
|
|
78
|
+
return machines.length ? { machines } : { machines, scope };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function bindProcessing(id, workload, profile, { all, paths, serverIds }) {
|
|
82
|
+
const nodes = validNodes(workload.placement?.eligible, serverIds, `Invalid workload placement for ${id}`);
|
|
83
|
+
const { run = 'processing', with: bindings = {} } = workload;
|
|
84
|
+
if (!bindings || typeof bindings !== 'object' || Array.isArray(bindings)) {
|
|
85
|
+
throw new TypeError(`Invalid processing parameters for ${id}`);
|
|
86
|
+
}
|
|
87
|
+
if (!profile || typeof profile !== 'object' || Array.isArray(profile)) {
|
|
88
|
+
throw new TypeError(`Missing processing profile for ${id}`);
|
|
89
|
+
}
|
|
90
|
+
if (typeof run !== 'string' || !run) { throw new TypeError(`Workload ${id} requires a runtime`); }
|
|
91
|
+
const processing = deploymentTemplate(profile, bindings);
|
|
92
|
+
return { run, nodes, assignments: [{ id, nodes, ...processingScope(all, paths, id, bindings), processing }] };
|
|
93
|
+
}
|
|
94
|
+
|
|
52
95
|
/** Bind logical processing work to machine types without tying runtime ownership to its prerequisites. */
|
|
53
96
|
export function resolveWorkloads(document) {
|
|
54
97
|
const all = machinesAt(document.namespace, document.machineTypes ?? {});
|
|
55
98
|
const serverIds = new Set((document.servers ?? []).map(({ id }) => { return id; }));
|
|
99
|
+
const paths = new Set(treePaths(document.namespace));
|
|
56
100
|
return Object.fromEntries(Object.entries(document.controlPlane?.workloads ?? {}).map(([id, workload]) => {
|
|
101
|
+
if (workload.processingProfile !== undefined) {
|
|
102
|
+
return [id, bindProcessing(id, workload, document.workloadProcessingProfiles?.[id], { all, paths, serverIds })];
|
|
103
|
+
}
|
|
57
104
|
const { run } = workload;
|
|
58
105
|
if (typeof run !== 'string' || !run) { throw new TypeError(`Workload ${id} requires a runtime`); }
|
|
59
106
|
const assignments = assignmentEntries(all, workload, serverIds);
|
|
@@ -61,25 +108,37 @@ export function resolveWorkloads(document) {
|
|
|
61
108
|
}));
|
|
62
109
|
}
|
|
63
110
|
|
|
64
|
-
function addOutputs(outputs, declarations, producer) {
|
|
65
|
-
for (const [
|
|
111
|
+
function addOutputs(outputs, declarations, producer, prefix = '') {
|
|
112
|
+
for (const [name, declaration] of Object.entries(declarations ?? {})) {
|
|
113
|
+
const id = `${prefix}${name}`;
|
|
66
114
|
const prior = outputs.get(id);
|
|
67
|
-
|
|
115
|
+
const type = declaration?.type;
|
|
116
|
+
const path = prefix ? declaration?.path : undefined;
|
|
117
|
+
const validPath = path === undefined || (typeof path === 'string' && path.split('/').every(Boolean));
|
|
118
|
+
if (typeof type !== 'string' || !type || !validPath || (prior && (type !== prior.type || path !== prior.path))) {
|
|
68
119
|
throw new TypeError(`Invalid or conflicting processing output ${id}`);
|
|
69
120
|
}
|
|
70
|
-
if (!prior) { outputs.set(id, { type
|
|
121
|
+
if (!prior) { outputs.set(id, { type, ...(path !== undefined && { path }), producers: [] }); }
|
|
71
122
|
outputs.get(id).producers.push(producer);
|
|
72
123
|
}
|
|
73
124
|
}
|
|
74
125
|
|
|
126
|
+
function addAssignmentOutputs(outputs, document, workload, { machines, nodes, scope, processing }) {
|
|
127
|
+
if (processing && !machines.length) {
|
|
128
|
+
addOutputs(outputs, processing.outputs, { workload, ...(scope && { machine: scope }), nodes }, `${workload}.`);
|
|
129
|
+
}
|
|
130
|
+
for (const { path: machine, type } of machines) {
|
|
131
|
+
const declarations = processing ? processing.outputs : document.processingProfiles?.[type]?.outputs;
|
|
132
|
+
addOutputs(outputs, declarations, { workload, machine, nodes }, processing ? `${workload}.` : '');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
75
136
|
/** Map output streams to their processing workloads and eligible publishers. */
|
|
76
137
|
export function processingOutputs(document, workloads = resolveWorkloads(document)) {
|
|
77
138
|
const outputs = new Map();
|
|
78
139
|
for (const [workload, { assignments }] of Object.entries(workloads)) {
|
|
79
|
-
for (const
|
|
80
|
-
|
|
81
|
-
addOutputs(outputs, document.processingProfiles?.[type]?.outputs, { workload, machine, nodes });
|
|
82
|
-
}
|
|
140
|
+
for (const assignment of assignments) {
|
|
141
|
+
addAssignmentOutputs(outputs, document, workload, assignment);
|
|
83
142
|
}
|
|
84
143
|
}
|
|
85
144
|
return Object.fromEntries(outputs);
|
|
@@ -71,8 +71,8 @@ export function bindControlInstallation(document, installation, images = {}) {
|
|
|
71
71
|
return normalizeControlPlane({
|
|
72
72
|
...controlDefaults, ...release, ...etcd,
|
|
73
73
|
controllerAuthSecret: secrets.controllerAuth, controllerTlsSecret: secrets.controllerTls,
|
|
74
|
-
controllerEnabled: true, classifyApply: Object.values(plane.workloads ?? {}).some(({ assignments }) => {
|
|
75
|
-
return Object.keys(assignments ?? {}).length > 0;
|
|
74
|
+
controllerEnabled: true, classifyApply: Object.values(plane.workloads ?? {}).some(({ assignments, processingProfile }) => {
|
|
75
|
+
return processingProfile !== undefined || Object.keys(assignments ?? {}).length > 0;
|
|
76
76
|
}),
|
|
77
77
|
...plane, deployment,
|
|
78
78
|
nodes: (plane.nodes ?? []).map((node) => { return serverSettings(input, node); })
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import streamNamespace from './streamNamespace.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Joins a child id onto a parent path.
|
|
3
5
|
*
|
|
@@ -81,6 +83,6 @@ function walk(nodes, prefix, templates, found) {
|
|
|
81
83
|
*/
|
|
82
84
|
export default function paths(document) {
|
|
83
85
|
const found = [];
|
|
84
|
-
walk(document
|
|
86
|
+
walk(streamNamespace(document), '', document.templates || {}, found);
|
|
85
87
|
return found;
|
|
86
88
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveCollection } from './namedCollection.js';
|
|
2
2
|
import { fits, zipped } from './expandPattern.js';
|
|
3
3
|
import { profileDefinitionFor } from './releaseNodes.js';
|
|
4
|
+
import streamNamespace from './streamNamespace.js';
|
|
4
5
|
|
|
5
6
|
function addPublications(servers, declarations) {
|
|
6
7
|
for (const [node, publications] of Object.entries(declarations)) {
|
|
@@ -97,5 +98,6 @@ export default function projectCollectionRoutes(document) {
|
|
|
97
98
|
addExternalRoutes(servers, primary, stream, route, externalPublications);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
return { ...document,
|
|
101
|
+
return { ...document, ...(document.namespace && { namespace: streamNamespace(document) }),
|
|
102
|
+
servers: [...servers.values()], eventDelivery: events };
|
|
101
103
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import readDocumentFile, { selectDeploymentPhase } from './readDocumentFile.js';
|
|
2
2
|
import readDocument from './readDocument.js';
|
|
3
3
|
import resolveDeploymentRouting from './deploymentRouting.js';
|
|
4
|
+
import { resolveHistoryPlacement } from './historyPlacement.js';
|
|
5
|
+
import { normalizeWorkloadDeclarations } from './workloadDeclarations.js';
|
|
4
6
|
import { readProcessingProfiles } from './namedProcessing.js';
|
|
5
7
|
|
|
6
8
|
function fileSelection(file) {
|
|
@@ -38,17 +40,17 @@ export default function readDeploymentDocument(file, parse = readDocument) {
|
|
|
38
40
|
const { path, phase } = fileSelection(file);
|
|
39
41
|
const loaded = readDocumentFile(path, (text, load) => {
|
|
40
42
|
const document = controlFragments(parse(text, load), load, parse);
|
|
41
|
-
return readProcessingProfiles(document, load, parse);
|
|
43
|
+
return readProcessingProfiles(normalizeWorkloadDeclarations(document), load, parse);
|
|
42
44
|
});
|
|
43
45
|
const { deploymentPhase: policy, ...document } = resolveDeploymentRouting(loaded);
|
|
44
46
|
if (policy === undefined) {
|
|
45
47
|
if (phase !== undefined) { throw new TypeError('Deployment phase policy is missing'); }
|
|
46
|
-
return document;
|
|
48
|
+
return resolveHistoryPlacement(document);
|
|
47
49
|
}
|
|
48
50
|
if (typeof policy?.section !== 'string' || typeof policy.selection !== 'string'
|
|
49
51
|
|| !Array.isArray(policy.fields) || !policy.fields.length
|
|
50
52
|
|| policy.fields.some((field) => { return typeof field !== 'string'; })) {
|
|
51
53
|
throw new TypeError('Invalid deployment phase policy');
|
|
52
54
|
}
|
|
53
|
-
return selectDeploymentPhase(phase === undefined ? document : { ...document, [policy.selection]: phase }, policy);
|
|
55
|
+
return resolveHistoryPlacement(selectDeploymentPhase(phase === undefined ? document : { ...document, [policy.selection]: phase }, policy));
|
|
54
56
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isAddress } from './expandPattern.js';
|
|
2
2
|
import { clusterOf, objectPath, serverById, serviceOf } from './releaseNodes.js';
|
|
3
3
|
|
|
4
|
+
const postgresDataDirectory = '/var/lib/postgresql/data/pgdata';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Maps one module name onto a chart product.
|
|
6
8
|
*
|
|
@@ -13,7 +15,7 @@ import { clusterOf, objectPath, serverById, serviceOf } from './releaseNodes.js'
|
|
|
13
15
|
*/
|
|
14
16
|
function bindOne(name, spec, secret) {
|
|
15
17
|
if (name === 'state_store') {
|
|
16
|
-
return ['postgres', { ...spec.chart, ...(spec.pgdata !== undefined && { data: spec.pgdata }),
|
|
18
|
+
return ['postgres', { data: postgresDataDirectory, ...spec.chart, ...(spec.pgdata !== undefined && { data: spec.pgdata }),
|
|
17
19
|
enabled: spec.enabled !== false, secret: secret || 'scada-postgres' }];
|
|
18
20
|
}
|
|
19
21
|
if (name === 'message_bus') {
|
|
@@ -41,8 +43,8 @@ function bindOne(name, spec, secret) {
|
|
|
41
43
|
*/
|
|
42
44
|
export function bindModules(profile, secret) {
|
|
43
45
|
const values = {};
|
|
44
|
-
Object.
|
|
45
|
-
const [key, value] = bindOne(name,
|
|
46
|
+
Object.entries(profile.modules ?? {}).forEach(([name, spec]) => {
|
|
47
|
+
const [key, value] = bindOne(name, spec, secret);
|
|
46
48
|
values[key] = value;
|
|
47
49
|
});
|
|
48
50
|
return values;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import mergeDocuments from './mergeDocuments.js';
|
|
2
|
+
|
|
3
|
+
function typedPaths(nodes, prefix = '') {
|
|
4
|
+
return (nodes ?? []).flatMap(({ id, type, nodes: children }) => {
|
|
5
|
+
const path = prefix ? `${prefix}/${id}` : id;
|
|
6
|
+
return [...(type ? [path] : []), ...typedPaths(children, path)];
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function signalBranches({ path, mapping }, source, mappings) {
|
|
11
|
+
const resolved = typeof mapping === 'string' ? mappings[mapping] : mapping;
|
|
12
|
+
const emitted = source?.signals ?? [];
|
|
13
|
+
if (!Array.isArray(emitted) || emitted.some((id) => { return typeof id !== 'string' || !id || id.includes('/'); })) {
|
|
14
|
+
throw new TypeError(`Invalid emitted signals at ${path}`);
|
|
15
|
+
}
|
|
16
|
+
const channels = [...new Set([...Object.keys(resolved ?? {}), ...emitted])].map((id) => { return { id }; });
|
|
17
|
+
return path.split('/').reduceRight((children, id) => { return [{ id, ...(children.length && { nodes: children }) }]; }, channels);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Add the concrete branches and channels of named streams beneath explicitly typed equipment. */
|
|
21
|
+
export default function streamNamespace({ namespace, streams, mappings = {}, sources = {} }) {
|
|
22
|
+
if (!namespace || !streams) { return namespace; }
|
|
23
|
+
const objects = typedPaths(namespace);
|
|
24
|
+
if (!objects.length) { return namespace; }
|
|
25
|
+
const branches = Object.values(streams).flatMap((stream) => {
|
|
26
|
+
const source = sources[stream?.source];
|
|
27
|
+
const path = stream?.path;
|
|
28
|
+
const belowObject = typeof path === 'string' && objects.some((object) => { return path === object || path.startsWith(`${object}/`); });
|
|
29
|
+
return source?.mode !== 'push' && belowObject ? signalBranches(stream, source, mappings) : [];
|
|
30
|
+
});
|
|
31
|
+
return mergeDocuments({ namespace }, { namespace: branches }).namespace;
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function workloadsByType(type, declarations) {
|
|
2
|
+
if (!declarations || typeof declarations !== 'object' || Array.isArray(declarations)) {
|
|
3
|
+
throw new TypeError(`Workload type ${type} must contain a map of workloads`);
|
|
4
|
+
}
|
|
5
|
+
return Object.entries(declarations).map(([id, workload]) => {
|
|
6
|
+
if (!workload || typeof workload !== 'object' || Array.isArray(workload) || Object.hasOwn(workload, 'run')) {
|
|
7
|
+
throw new TypeError(`Invalid grouped workload ${type}.${id}`);
|
|
8
|
+
}
|
|
9
|
+
return [`${id}-${type}`, { run: type, ...workload }];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function normalizeWorkloadDeclarations(source) {
|
|
14
|
+
const { workloads } = source?.controlPlane ?? {};
|
|
15
|
+
if (workloads === undefined) { return source; }
|
|
16
|
+
if (!workloads || typeof workloads !== 'object' || Array.isArray(workloads)) {
|
|
17
|
+
throw new TypeError('Workloads must be a map');
|
|
18
|
+
}
|
|
19
|
+
if (Object.values(workloads).every((workload) => { return typeof workload?.run === 'string' || typeof workload?.processingProfile === 'string'; })) { return source; }
|
|
20
|
+
const entries = Object.entries(workloads).flatMap(([id, workload]) => {
|
|
21
|
+
return typeof workload?.run === 'string' || typeof workload?.processingProfile === 'string' ? [[id, workload]] : workloadsByType(id, workload);
|
|
22
|
+
});
|
|
23
|
+
const compiled = new Map(entries);
|
|
24
|
+
if (compiled.size !== entries.length) { throw new TypeError('Duplicate compiled workload ID'); }
|
|
25
|
+
return { ...source, controlPlane: { ...source.controlPlane, workloads: Object.fromEntries(compiled) } };
|
|
26
|
+
}
|
|
@@ -15,7 +15,8 @@ const runtimeDocument = z.strictObject({
|
|
|
15
15
|
modules: z.array(z.strictObject({ id: identifier, entry: z.string().min(1) })).default([]),
|
|
16
16
|
configProfiles: z.record(identifier, z.record(z.string(), z.unknown())).default({}),
|
|
17
17
|
services: z.record(identifier, workload).default({}),
|
|
18
|
-
jobs: z.record(identifier, workload).default({})
|
|
18
|
+
jobs: z.record(identifier, workload).default({}),
|
|
19
|
+
artifacts: z.record(z.string(), z.unknown()).optional()
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
function moduleEntries(modules) {
|
|
@@ -3,10 +3,27 @@ import yaml from 'js-yaml';
|
|
|
3
3
|
import { applicationBundle, projectApplicationBundle } from './applicationBundle.js';
|
|
4
4
|
|
|
5
5
|
const root = '/opt/scada/app';
|
|
6
|
+
const runtimeAnnotation = 'scada.io/runtime';
|
|
7
|
+
const jvmDefaults = {
|
|
8
|
+
javaClasspath: '/app/scada-stream-processing.jar:/app/profile/*',
|
|
9
|
+
javaMain: 'scada.processing.runtime.ProcessingApp',
|
|
10
|
+
mountPath: '/app/profile/profile.jar',
|
|
11
|
+
subPath: 'profile.jar',
|
|
12
|
+
container: 'supervisor',
|
|
13
|
+
argsPrefix: ['/app/config/application.conf']
|
|
14
|
+
};
|
|
6
15
|
|
|
7
|
-
function commandRules(services, jobs) {
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
function commandRules({ services, jobs }, application) {
|
|
17
|
+
const pairs = [['--service', services, application?.services, application?.jobs], ['--job', jobs, application?.jobs, application?.services]];
|
|
18
|
+
const explicit = new Set([...Object.keys(services ?? {}), ...Object.keys(jobs ?? {})]);
|
|
19
|
+
return pairs.flatMap(([kind, aliases, declarations, other]) => {
|
|
20
|
+
const unambiguous = Object.keys(declarations ?? {}).filter((name) => { return !Object.hasOwn(other ?? {}, name); });
|
|
21
|
+
const inferred = unambiguous.flatMap((name) => {
|
|
22
|
+
return [[`bin/${name}.js`, name], [`node_modules/@yarkivaev/scada/src/bin/${name}.js`, name]];
|
|
23
|
+
}).filter(([prefix]) => { return !explicit.has(prefix); });
|
|
24
|
+
return [...Object.entries(aliases ?? {}), ...inferred].map(([prefix, name]) => {
|
|
25
|
+
return { kind, name, match: ['node', ...prefix.split(' ')] };
|
|
26
|
+
});
|
|
10
27
|
}).sort((a, b) => { return b.match.length - a.match.length; });
|
|
11
28
|
}
|
|
12
29
|
|
|
@@ -21,31 +38,65 @@ function replaceNode(container, image, command) {
|
|
|
21
38
|
...(privileged && { securityContext: { ...securityContext, runAsUser: 0 } }) };
|
|
22
39
|
}
|
|
23
40
|
|
|
24
|
-
function
|
|
41
|
+
function replaceJvm(container, image, { jvmRuntime, jvmCommand }) {
|
|
42
|
+
if (!jvmRuntime) { throw new Error('A JVM runtime must be declared for the selected container'); }
|
|
43
|
+
if (!image) { throw new Error('SCADA_CORE_JVM_IMAGE is required for the selected JVM runtime'); }
|
|
44
|
+
const mounts = container.volumeMounts?.filter(({ name }) => { return name !== jvmRuntime.legacyMount; });
|
|
45
|
+
return { image, command: jvmCommand(), volumeMounts: mounts ?? [],
|
|
46
|
+
mountPath: jvmRuntime.mountPath, subPath: jvmRuntime.subPath,
|
|
47
|
+
env: [{ name: 'SCADA_RUNTIME_PROFILE', value: jvmRuntime.profile }] };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function directRuntime(binding, container, { bundle, jvm }, projection) {
|
|
51
|
+
const { service, job, jvm: useJvm, args = [] } = binding;
|
|
52
|
+
const { application, runtimeCommand } = projection;
|
|
53
|
+
const keys = Object.keys(binding).filter((key) => { return key !== 'args'; });
|
|
54
|
+
if (keys.length !== 1 || !['service', 'job', 'jvm'].includes(keys[0])
|
|
55
|
+
|| !Array.isArray(args) || args.some((arg) => { return typeof arg !== 'string'; })) {
|
|
56
|
+
throw new TypeError(`Invalid runtime binding for container ${container.name}`);
|
|
57
|
+
}
|
|
58
|
+
if (useJvm === true) {
|
|
59
|
+
const runtime = replaceJvm(container, jvm, projection);
|
|
60
|
+
return Object.hasOwn(binding, 'args') ? { ...runtime, args } : runtime;
|
|
61
|
+
}
|
|
62
|
+
const [name, kind, declarations] = keys[0] === 'service'
|
|
63
|
+
? [service, '--service', application?.services] : [job, '--job', application?.jobs];
|
|
64
|
+
if (typeof name !== 'string' || (application && !Object.hasOwn(declarations ?? {}, name))) {
|
|
65
|
+
throw new TypeError(`Undeclared application runtime ${name}`);
|
|
66
|
+
}
|
|
67
|
+
return replaceNode(container, bundle.image, runtimeCommand(kind, name, args));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function select(container, workload, artifact, projection) {
|
|
71
|
+
const { rules, jvmRuntime, namedJobs, runtimeCommand } = projection;
|
|
25
72
|
const args = [...(container.command ?? []), ...(container.args ?? [])];
|
|
26
73
|
const rule = rules.find(({ match }) => { return matches(args, match); });
|
|
27
|
-
if (rule) { return replaceNode(container, bundle.image, runtimeCommand(rule.kind, rule.name, args.slice(rule.match.length))); }
|
|
74
|
+
if (rule) { return replaceNode(container, artifact.bundle.image, runtimeCommand(rule.kind, rule.name, args.slice(rule.match.length))); }
|
|
28
75
|
if (jvmRuntime && jvmRuntime.container === container.name && matches(container.args ?? [], jvmRuntime.argsPrefix)) {
|
|
29
|
-
|
|
30
|
-
const mounts = container.volumeMounts?.filter(({ name }) => { return name !== jvmRuntime.legacyMount; });
|
|
31
|
-
return { image: jvm, command: jvmCommand(), volumeMounts: mounts ?? [],
|
|
32
|
-
mountPath: jvmRuntime.mountPath, subPath: jvmRuntime.subPath,
|
|
33
|
-
env: [{ name: 'SCADA_RUNTIME_PROFILE', value: jvmRuntime.profile }] };
|
|
76
|
+
return replaceJvm(container, artifact.jvm, projection);
|
|
34
77
|
}
|
|
35
78
|
const job = namedJobs.find(({ workloads, container: name }) => { return workloads.includes(workload) && name === container.name; });
|
|
36
|
-
|
|
37
|
-
return undefined;
|
|
79
|
+
return job ? replaceNode(container, artifact.bundle.image, runtimeCommand('--job', job.name)) : undefined;
|
|
38
80
|
}
|
|
39
81
|
|
|
40
|
-
function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
82
|
+
function explicitBindings(metadata, containers) {
|
|
83
|
+
const raw = metadata?.annotations?.[runtimeAnnotation];
|
|
84
|
+
if (raw === undefined) { return new Map(); }
|
|
85
|
+
const bindings = JSON.parse(raw);
|
|
86
|
+
if (!bindings || typeof bindings !== 'object' || Array.isArray(bindings)) {
|
|
87
|
+
throw new TypeError('Application runtime annotation must be a map of containers');
|
|
88
|
+
}
|
|
89
|
+
return new Map(Object.entries(bindings).map(([name, binding]) => {
|
|
90
|
+
if (!binding || typeof binding !== 'object' || Array.isArray(binding)
|
|
91
|
+
|| !containers.some((container) => { return container.name === name; })) {
|
|
92
|
+
throw new TypeError(`Invalid application runtime binding for container ${name}`);
|
|
93
|
+
}
|
|
94
|
+
return [name, binding];
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function cleanupLegacyMount(projected, template, runtime) {
|
|
99
|
+
const { legacyMount, legacyAnnotation } = runtime ?? {};
|
|
49
100
|
const legacyUsed = [...projected.containers, ...projected.initContainers].some((container) => {
|
|
50
101
|
return container.volumeMounts?.some(({ name }) => { return name === legacyMount; });
|
|
51
102
|
});
|
|
@@ -53,7 +104,27 @@ function projectObject(object, artifact, projection) {
|
|
|
53
104
|
projected.volumes = projected.volumes.filter(({ name }) => { return name !== legacyMount; });
|
|
54
105
|
if (legacyAnnotation && template.metadata?.annotations) { delete template.metadata.annotations[legacyAnnotation]; }
|
|
55
106
|
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function removeRuntimeAnnotation(metadata) {
|
|
110
|
+
delete metadata.annotations[runtimeAnnotation];
|
|
111
|
+
if (!Object.keys(metadata.annotations).length) { delete metadata.annotations; }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function projectObject(object, artifact, projection) {
|
|
115
|
+
const template = object?.kind === 'CronJob' ? object.spec?.jobTemplate?.spec?.template : object?.spec?.template;
|
|
116
|
+
const pod = template?.spec;
|
|
117
|
+
if (!pod?.containers) { return false; }
|
|
118
|
+
const bindings = explicitBindings(object.metadata, pod.containers);
|
|
119
|
+
const projected = projectApplicationBundle(pod, artifact.bundle, (container) => {
|
|
120
|
+
if (!bindings.size) { return select(container, object.metadata?.name, artifact, projection); }
|
|
121
|
+
const binding = bindings.get(container.name);
|
|
122
|
+
return binding ? directRuntime(binding, container, artifact, projection) : undefined;
|
|
123
|
+
});
|
|
124
|
+
if (projected === pod) { return false; }
|
|
125
|
+
cleanupLegacyMount(projected, template, projection.jvmRuntime);
|
|
56
126
|
template.spec = projected;
|
|
127
|
+
if (bindings.size) { removeRuntimeAnnotation(object.metadata); }
|
|
57
128
|
return true;
|
|
58
129
|
}
|
|
59
130
|
|
|
@@ -64,9 +135,11 @@ function transform(manifests, artifact, projection) {
|
|
|
64
135
|
}
|
|
65
136
|
|
|
66
137
|
/** Configure opt-in, immutable bundle projection for release plans and rendered Kubernetes manifests. */
|
|
67
|
-
export default function configuredRuntimeArtifacts({
|
|
68
|
-
|
|
69
|
-
const
|
|
138
|
+
export default function configuredRuntimeArtifacts({ application, ...options }) {
|
|
139
|
+
const settings = { ...application?.artifacts, ...options };
|
|
140
|
+
const { targets = [], namedJobs = [], document = 'plant/runtime.yaml', tokenKey = 'token', tokenHeader = 'Deploy-Token' } = settings;
|
|
141
|
+
const jvmRuntime = settings.jvmRuntime && { ...(application && jvmDefaults), ...settings.jvmRuntime };
|
|
142
|
+
const rules = commandRules(settings, application);
|
|
70
143
|
function runtimeArtifact(target, env = process.env) {
|
|
71
144
|
const selected = env.SCADA_APP_BUNDLE_TARGET;
|
|
72
145
|
if (!selected) { return null; }
|
|
@@ -87,7 +160,7 @@ export default function configuredRuntimeArtifacts({ targets, services, jobs, na
|
|
|
87
160
|
return ['java', '-cp', jvmRuntime.javaClasspath, jvmRuntime.javaMain];
|
|
88
161
|
}
|
|
89
162
|
|
|
90
|
-
const projection = { rules, jvmRuntime, namedJobs, runtimeCommand, jvmCommand };
|
|
163
|
+
const projection = { application, rules, jvmRuntime, namedJobs, runtimeCommand, jvmCommand };
|
|
91
164
|
|
|
92
165
|
function projectRuntimeManifests(manifests, target, env) {
|
|
93
166
|
const artifact = runtimeArtifact(target, env);
|
|
@@ -29,7 +29,9 @@ export { default as preflightKubeStorage } from './preflightKubeStorage.js';
|
|
|
29
29
|
export { default as applyWhenChanged } from './applyWhenChanged.js';
|
|
30
30
|
export { default as prepareKubePrerequisites } from './prepareKubePrerequisites.js';
|
|
31
31
|
export { default as readDeploymentDocument } from '../../application/deploy/readDeploymentDocument.js';
|
|
32
|
+
export { archiveNode, resolveHistoryPlacement, retentionFor } from '../../application/deploy/historyPlacement.js';
|
|
32
33
|
export { resolveCollection } from '../../application/deploy/namedCollection.js';
|
|
34
|
+
export { normalizeWorkloadDeclarations } from '../../application/deploy/workloadDeclarations.js';
|
|
33
35
|
export { resolveWorkloads } from '../../application/deploy/namedProcessing.js';
|
|
34
36
|
export { default as compileNamedControlCatalog } from '../../application/deploy/compileNamedControlCatalog.js';
|
|
35
37
|
export { default as compileLocalConsumers, namedLocalConsumers } from '../../application/deploy/compileLocalConsumers.js';
|