@yarkivaev/scada 2.28.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.
Files changed (38) hide show
  1. package/README.md +14 -2
  2. package/charts/scada-workloads/templates/_collector.tpl +3 -0
  3. package/charts/scada-workloads/templates/_control-agent.tpl +4 -1
  4. package/charts/scada-workloads/templates/_controller.tpl +3 -0
  5. package/charts/scada-workloads/templates/_history-maintenance.tpl +3 -0
  6. package/charts/scada-workloads/templates/_history-receiver.tpl +4 -1
  7. package/charts/scada-workloads/templates/_journal-supervisor.tpl +3 -0
  8. package/charts/scada-workloads/templates/_runtime.tpl +13 -0
  9. package/charts/scada-workloads/templates/_site-server.tpl +4 -1
  10. package/charts/scada-workloads/templates/_supervisor.tpl +3 -0
  11. package/charts/scada-workloads/templates/_telemetry.tpl +4 -1
  12. package/package.json +1 -1
  13. package/src/application/deploy/collectionEvents.js +50 -0
  14. package/src/application/deploy/collectionPlacement.js +42 -0
  15. package/src/application/deploy/compileLocalConsumers.js +42 -0
  16. package/src/application/deploy/expand.js +1 -0
  17. package/src/application/deploy/historyPlacement.js +61 -0
  18. package/src/application/deploy/mergeDocuments.js +9 -1
  19. package/src/application/deploy/namedCollection.js +119 -21
  20. package/src/application/deploy/namedProcessing.js +145 -0
  21. package/src/application/deploy/normalizeControlPlane.js +43 -0
  22. package/src/application/deploy/paths.js +3 -1
  23. package/src/application/deploy/projectCollectionRoutes.js +22 -18
  24. package/src/application/deploy/projectControlPlane.js +2 -2
  25. package/src/application/deploy/readDeploymentDocument.js +9 -3
  26. package/src/application/deploy/releaseValues.js +5 -3
  27. package/src/application/deploy/streamNamespace.js +32 -0
  28. package/src/application/deploy/workloadDeclarations.js +26 -0
  29. package/src/application/plantServer.js +1 -0
  30. package/src/application/runtime/applicationRuntime.js +2 -1
  31. package/src/application/siteServer.js +1 -0
  32. package/src/infrastructure/catalog/tagCatalog.js +4 -3
  33. package/src/infrastructure/deploy/centralTelemetry.js +10 -1
  34. package/src/infrastructure/deploy/collectorChartPlan.js +1 -1
  35. package/src/infrastructure/deploy/configuredBundleCapabilities.js +1 -1
  36. package/src/infrastructure/deploy/configuredRuntimeArtifacts.js +98 -25
  37. package/src/infrastructure/deploy/index.js +5 -2
  38. package/src/infrastructure/opcua/projectSources.js +3 -3
@@ -0,0 +1,145 @@
1
+ import deploymentTemplate from '../../infrastructure/deploy/deploymentTemplate.js';
2
+ import { treePaths } from './expandNamespace.js';
3
+
4
+ function machineType(template, types) {
5
+ return Object.entries(types).find(([, type]) => { return type.signalTemplates?.includes(template); })?.[0];
6
+ }
7
+
8
+ function machinesAt(nodes, types, parent = '') {
9
+ return (nodes ?? []).flatMap(({ id, template, type: declared, nodes: children }) => {
10
+ const path = parent ? `${parent}/${id}` : id;
11
+ const type = declared ?? (template && machineType(template, types));
12
+ return [...(type ? [{ id, path, type }] : []), ...machinesAt(children, types, path)];
13
+ });
14
+ }
15
+
16
+ function profileEntries(declarations, read) {
17
+ return Object.entries(declarations ?? {}).flatMap(([id, { processingProfile }]) => {
18
+ if (processingProfile === undefined) { return []; }
19
+ if (typeof processingProfile !== 'string' || !processingProfile.trim()) {
20
+ throw new TypeError(`Invalid processing profile for ${id}`);
21
+ }
22
+ return [[id, read(processingProfile)]];
23
+ });
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) }) };
38
+ }
39
+
40
+ function chooseMachines(all, id, selector) {
41
+ const matches = selector?.type
42
+ ? all.filter(({ type }) => { return type === selector.type; })
43
+ : all.filter(({ id: short, path }) => { return id === short || id === path; });
44
+ if (!matches.length || (!selector?.type && matches.length !== 1)) {
45
+ throw new TypeError(`Invalid workload machine assignment ${id}`);
46
+ }
47
+ return matches;
48
+ }
49
+
50
+ function validNodes(nodes, serverIds, message) {
51
+ if (!Array.isArray(nodes) || !nodes.length || new Set(nodes).size !== nodes.length || nodes.some((node) => { return !serverIds.has(node); })) {
52
+ throw new TypeError(message);
53
+ }
54
+ return nodes;
55
+ }
56
+
57
+ function assignmentEntries(all, workload, serverIds) {
58
+ const nodes = validNodes(workload.placement?.nodes, serverIds, 'Invalid workload placement');
59
+ return Object.entries(workload.assignments ?? {}).map(([id, assignment]) => {
60
+ const { preferred, standby } = assignment.placement ?? {};
61
+ const eligible = [preferred, standby].filter((node) => { return node !== undefined; });
62
+ if (!eligible.length || new Set(eligible).size !== eligible.length || eligible.some((node) => { return !nodes.includes(node); })) {
63
+ throw new TypeError(`Invalid workload placement for ${id}`);
64
+ }
65
+ return { id, nodes: eligible, machines: chooseMachines(all, id, assignment.machines) };
66
+ });
67
+ }
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
+
95
+ /** Bind logical processing work to machine types without tying runtime ownership to its prerequisites. */
96
+ export function resolveWorkloads(document) {
97
+ const all = machinesAt(document.namespace, document.machineTypes ?? {});
98
+ const serverIds = new Set((document.servers ?? []).map(({ id }) => { return id; }));
99
+ const paths = new Set(treePaths(document.namespace));
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
+ }
104
+ const { run } = workload;
105
+ if (typeof run !== 'string' || !run) { throw new TypeError(`Workload ${id} requires a runtime`); }
106
+ const assignments = assignmentEntries(all, workload, serverIds);
107
+ return [id, { run, nodes: workload.placement.nodes, assignments }];
108
+ }));
109
+ }
110
+
111
+ function addOutputs(outputs, declarations, producer, prefix = '') {
112
+ for (const [name, declaration] of Object.entries(declarations ?? {})) {
113
+ const id = `${prefix}${name}`;
114
+ const prior = outputs.get(id);
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))) {
119
+ throw new TypeError(`Invalid or conflicting processing output ${id}`);
120
+ }
121
+ if (!prior) { outputs.set(id, { type, ...(path !== undefined && { path }), producers: [] }); }
122
+ outputs.get(id).producers.push(producer);
123
+ }
124
+ }
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
+
136
+ /** Map output streams to their processing workloads and eligible publishers. */
137
+ export function processingOutputs(document, workloads = resolveWorkloads(document)) {
138
+ const outputs = new Map();
139
+ for (const [workload, { assignments }] of Object.entries(workloads)) {
140
+ for (const assignment of assignments) {
141
+ addAssignmentOutputs(outputs, document, workload, assignment);
142
+ }
143
+ }
144
+ return Object.fromEntries(outputs);
145
+ }
@@ -1,4 +1,20 @@
1
1
  import deploymentTemplate from '../../infrastructure/deploy/deploymentTemplate.js';
2
+ import { profileDefinitionFor } from './releaseNodes.js';
3
+ import { expandProfiles } from './expandProfiles.js';
4
+
5
+ function resources(cpu, memory, maxCpu, maxMemory) {
6
+ return { requests: { cpu, memory }, limits: { cpu: maxCpu, memory: maxMemory } };
7
+ }
8
+
9
+ const controlDefaults = {
10
+ authUsernameKey: 'username', authPasswordKey: 'password', replacementDelayMs: 30000, clockSkewMs: 5000,
11
+ initialClusterState: 'new', autoCompactionRetention: '1h', storage: '4Gi', storageClass: 'local-path',
12
+ queueMaxBytes: 16777216, queueMaxRecords: 8192,
13
+ agentResources: resources('100m', '128Mi', '1', '640Mi'),
14
+ memberResources: resources('100m', '96Mi', '500m', '256Mi'),
15
+ controllerResources: resources('25m', '32Mi', '250m', '128Mi'),
16
+ historyResources: resources('50m', '96Mi', '500m', '384Mi')
17
+ };
2
18
 
3
19
  function nodeSettings(node, deployment) {
4
20
  const profile = node.agentProfile;
@@ -35,3 +51,30 @@ export default function normalizeControlPlane(raw) {
35
51
  nodes: nodes.map((node) => { return nodeSettings(node, deployment); })
36
52
  };
37
53
  }
54
+
55
+ function serverSettings(document, node) {
56
+ const server = document.servers?.find(({ id }) => { return id === node.id; });
57
+ const profile = server?.profile && profileDefinitionFor(document, server);
58
+ const agent = profile?.apps?.scada?.collector?.controlAgent;
59
+ return { ...node, ...(agent && { agent: { ...agent, ...node.agent } }) };
60
+ }
61
+
62
+ /** Bind a named topology to its installation's Kubernetes, credentials and release settings. */
63
+ export function bindControlInstallation(document, installation, images = {}) {
64
+ const plane = document.controlPlane;
65
+ const { etcd = {}, secrets = {}, ...release } = installation;
66
+ const deployment = {
67
+ nodeTlsSecretTemplate: secrets.nodeTls, catalogSecret: secrets.catalog, deliverySecret: secrets.delivery,
68
+ ...plane.deployment, images: { ...plane.deployment?.images, ...images }
69
+ };
70
+ const input = { ...document, profiles: expandProfiles(document.profiles ?? {}) };
71
+ return normalizeControlPlane({
72
+ ...controlDefaults, ...release, ...etcd,
73
+ controllerAuthSecret: secrets.controllerAuth, controllerTlsSecret: secrets.controllerTls,
74
+ controllerEnabled: true, classifyApply: Object.values(plane.workloads ?? {}).some(({ assignments, processingProfile }) => {
75
+ return processingProfile !== undefined || Object.keys(assignments ?? {}).length > 0;
76
+ }),
77
+ ...plane, deployment,
78
+ nodes: (plane.nodes ?? []).map((node) => { return serverSettings(input, node); })
79
+ });
80
+ }
@@ -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.namespace, '', document.templates || {}, found);
86
+ walk(streamNamespace(document), '', document.templates || {}, found);
85
87
  return found;
86
88
  }
@@ -1,5 +1,7 @@
1
1
  import { resolveCollection } from './namedCollection.js';
2
2
  import { fits, zipped } from './expandPattern.js';
3
+ import { profileDefinitionFor } from './releaseNodes.js';
4
+ import streamNamespace from './streamNamespace.js';
3
5
 
4
6
  function addPublications(servers, declarations) {
5
7
  for (const [node, publications] of Object.entries(declarations)) {
@@ -42,22 +44,22 @@ function addExternalRoutes(servers, primary, stream, route, declarations) {
42
44
  }
43
45
 
44
46
  function deliveryApi(plane, objectOwners, origin, path) {
45
- const { addressApi, brokerApi } = plane.deployment ?? {};
47
+ const { addressApi = 'plant', brokerApi = 'bus' } = plane.deployment ?? {};
46
48
  const owns = Object.entries(objectOwners).some(([object, owner]) => {
47
- return owner === origin && (path === object || path.startsWith(`${object}/`));
49
+ return owner === origin.id && (path === object || path.startsWith(`${object}/`));
48
50
  });
49
- return owns ? addressApi : brokerApi;
51
+ return owns && origin.api?.some(({ id }) => { return id === addressApi; }) ? addressApi : brokerApi;
50
52
  }
51
53
 
52
- function brokerServices(servers, plane) {
53
- const { addressApi, brokerApi } = plane.deployment ?? {};
54
- const port = plane.brokerService?.nodePort;
55
- if (!addressApi || !brokerApi || !port) { return; }
56
- const nodes = plane.nodes.map(({ id }) => { return servers.get(id); });
57
- const missing = nodes.filter((server) => { return !server.api?.some(({ id }) => { return id === brokerApi; }); });
58
- for (const server of missing) {
59
- const address = server.api?.find(({ id }) => { return id === addressApi; });
60
- if (address) {
54
+ function brokerServices(servers, document) {
55
+ const plane = document.controlPlane;
56
+ const { addressApi = 'plant', brokerApi = 'bus' } = plane.deployment ?? {};
57
+ for (const { id } of plane.nodes) {
58
+ const server = servers.get(id);
59
+ const peer = server.profile && profileDefinitionFor(document, server).modules?.message_bus?.peerService;
60
+ const port = peer?.nodePort ?? plane.brokerService?.nodePort;
61
+ const address = server.api?.find(({ id: api }) => { return api === addressApi; });
62
+ if (port && address && !server.api.some(({ id: api }) => { return api === brokerApi; })) {
61
63
  const { hostname } = new URL(address.url);
62
64
  server.api = [...server.api, { id: brokerApi, url: `amqp://${hostname}:${port}` }];
63
65
  }
@@ -82,18 +84,20 @@ function routeServers(declarations, objectOwners) {
82
84
  /** Derive the static transport view used by runtime and broker plan consumers. */
83
85
  export default function projectCollectionRoutes(document) {
84
86
  if (document.controlPlane?.readers === undefined) { return document; }
85
- const { readers, delivery, objectOwners, externalPublications } = resolveCollection(document);
87
+ const { readers, delivery, objectOwners, externalPublications, events } = resolveCollection(document);
86
88
  const servers = routeServers(document.servers, objectOwners);
87
- brokerServices(servers, document.controlPlane);
89
+ brokerServices(servers, document);
88
90
  addPublications(servers, externalPublications);
89
91
  for (const { eligible: [primary], streams } of readers) {
90
92
  const origin = servers.get(primary);
91
- for (const stream of streams) {
92
- origin.fan_in.push({ from: stream.from, name: stream.path, ...(stream.mapping !== undefined && { mapping: stream.mapping }) });
93
+ for (const stream of streams.filter(({ from }) => { return typeof from === 'string'; })) {
94
+ const { from, path: name, mapping, sampling } = stream;
95
+ origin.fan_in.push({ from, name, ...(mapping !== undefined && { mapping }), ...(sampling !== undefined && { sampling }) });
93
96
  const route = delivery[stream.id];
94
- addRoute(servers, origin, stream, route, deliveryApi(document.controlPlane, objectOwners, origin.id, stream.path));
97
+ addRoute(servers, origin, stream, route, deliveryApi(document.controlPlane, objectOwners, origin, stream.path));
95
98
  addExternalRoutes(servers, primary, stream, route, externalPublications);
96
99
  }
97
100
  }
98
- return { ...document, servers: [...servers.values()] };
101
+ return { ...document, ...(document.namespace && { namespace: streamNamespace(document) }),
102
+ servers: [...servers.values()], eventDelivery: events };
99
103
  }
@@ -35,10 +35,10 @@ function chartValues(config, server, servers, policy, ports) {
35
35
 
36
36
  /** Project one control release from a plant document and supplied policy and runtime bindings. */
37
37
  export default function projectControlPlane(cluster, document, policy, ports) {
38
- const config = controlPlaneConfiguration(normalizeControlPlane(document[policy.section]), document.servers, policy);
38
+ const { servers } = projectCollectionRoutes(document);
39
+ const config = controlPlaneConfiguration(normalizeControlPlane(document[policy.section]), servers, policy);
39
40
  const server = config.nodes.find(({ id }) => { return id === cluster; });
40
41
  if (!server) { throw new TypeError(`Unknown edge ${cluster}`); }
41
- const { servers } = projectCollectionRoutes(document);
42
42
  const catalog = ports.catalog(document, config);
43
43
  const classification = ports.classification(document, config, catalog);
44
44
  return {
@@ -1,6 +1,9 @@
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';
6
+ import { readProcessingProfiles } from './namedProcessing.js';
4
7
 
5
8
  function fileSelection(file) {
6
9
  if (file instanceof URL) {
@@ -35,16 +38,19 @@ function controlFragments(document, load, parse) {
35
38
  /** A deployment document can declare its phase policy and be opened as path#phase. */
36
39
  export default function readDeploymentDocument(file, parse = readDocument) {
37
40
  const { path, phase } = fileSelection(file);
38
- const loaded = readDocumentFile(path, (text, load) => { return controlFragments(parse(text, load), load, parse); });
41
+ const loaded = readDocumentFile(path, (text, load) => {
42
+ const document = controlFragments(parse(text, load), load, parse);
43
+ return readProcessingProfiles(normalizeWorkloadDeclarations(document), load, parse);
44
+ });
39
45
  const { deploymentPhase: policy, ...document } = resolveDeploymentRouting(loaded);
40
46
  if (policy === undefined) {
41
47
  if (phase !== undefined) { throw new TypeError('Deployment phase policy is missing'); }
42
- return document;
48
+ return resolveHistoryPlacement(document);
43
49
  }
44
50
  if (typeof policy?.section !== 'string' || typeof policy.selection !== 'string'
45
51
  || !Array.isArray(policy.fields) || !policy.fields.length
46
52
  || policy.fields.some((field) => { return typeof field !== 'string'; })) {
47
53
  throw new TypeError('Invalid deployment phase policy');
48
54
  }
49
- return selectDeploymentPhase(phase === undefined ? document : { ...document, [policy.selection]: phase }, policy);
55
+ return resolveHistoryPlacement(selectDeploymentPhase(phase === undefined ? document : { ...document, [policy.selection]: phase }, policy));
50
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.keys(profile.modules || {}).forEach((name) => {
45
- const [key, value] = bindOne(name, profile.modules[name], secret);
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
+ }
@@ -110,6 +110,7 @@ export default async function plantServer(config) {
110
110
  heartbeat: config.heartbeat || 1000,
111
111
  requestTimeoutMs,
112
112
  extraRoutes: extra,
113
+ tagCatalog: config.tagCatalog,
113
114
  timelineOperator: config.timelineOperator,
114
115
  operationDecisions: config.operationDecisions,
115
116
  owners: config.owners,
@@ -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) {
@@ -167,6 +167,7 @@ export default async function siteServer(config) {
167
167
  port: config.port || parseInt(env.PORT || '3000', 10),
168
168
  basePath,
169
169
  translations: config.translations,
170
+ tagCatalog: config.tagCatalog,
170
171
  requirePool: config.requirePool,
171
172
  stomp: stompFromEnv(env),
172
173
  plantFactory: plantFactoryWithOperations(config.plantFactory, ops, sink),
@@ -3,19 +3,20 @@ import { readFileSync } from 'node:fs';
3
3
  /**
4
4
  * Loads hierarchical tag catalog entries from a configured JSON file.
5
5
  *
6
- * Uses an empty catalog when TAG_CATALOG_PATH is unset.
6
+ * Uses the declared catalog when TAG_CATALOG_PATH is unset.
7
7
  *
8
8
  * @example
9
9
  * const catalog = tagCatalog({ TAG_CATALOG_PATH: '/etc/scada/tag-catalog.json' });
10
10
  * catalog.labels();
11
11
  *
12
12
  * @param {object} [env] - environment map, defaults to process.env
13
+ * @param {Array<object>} [fallback] - declared catalog rows
13
14
  * @returns {object} catalog with entries(), labels(), children(parent)
14
15
  */
15
- export default function tagCatalog(env) {
16
+ export default function tagCatalog(env, fallback = []) {
16
17
  const source = env || process.env;
17
18
  const path = source.TAG_CATALOG_PATH;
18
- const raw = path ? JSON.parse(readFileSync(path, 'utf8')) : [];
19
+ const raw = path ? JSON.parse(readFileSync(path, 'utf8')) : fallback.slice();
19
20
  if (!Array.isArray(raw)) {
20
21
  throw new Error('tag catalog must be a JSON array');
21
22
  }
@@ -1,3 +1,5 @@
1
+ import { expandProfiles } from '../../application/deploy/expandProfiles.js';
2
+ import { profileFor } from '../../application/deploy/releaseNodes.js';
1
3
  import readDeploymentDocument from '../../application/deploy/readDeploymentDocument.js';
2
4
  import centralTelemetryPolicy, { centralTelemetryVersion, normalizeCentralPolicy } from '../ingest/telemetry/centralPolicy.js';
3
5
 
@@ -5,7 +7,14 @@ const policyRuntime = { centralTelemetryPolicy, centralTelemetryVersion };
5
7
  const metricsAdapters = new Set(['amqp-metrics', 'mqtt-metrics', 'amqp-pg-metrics', 'mqtt-pg-metrics', 'silent-streams']);
6
8
 
7
9
  export function centralTelemetryValues(document) {
8
- return normalizeCentralPolicy(document.centralTelemetry);
10
+ if (Object.hasOwn(document, 'centralTelemetry')) { return normalizeCentralPolicy(document.centralTelemetry); }
11
+ const profiles = expandProfiles(document.profiles ?? {});
12
+ const stores = (document.servers ?? []).filter(({ profile }) => { return profile?.id && profiles[profile.id]; }).map((server) => {
13
+ return profileFor({ ...document, profiles }, server).modules?.telemetry_store;
14
+ }).filter((store) => { return store?.policy && store.enabled !== false; });
15
+ const store = stores[0] ?? profiles.archive?.modules?.telemetry_store;
16
+ if (stores.length > 1) { throw new TypeError('Central telemetry policy requires a single archive store'); }
17
+ return normalizeCentralPolicy(store?.policy ? { enabled: store.enabled, ...store.policy } : undefined);
9
18
  }
10
19
 
11
20
  export function centralTelemetryChartEnv(document, file, previous = []) {
@@ -16,7 +16,7 @@ function compileCollectors(context, policy, ports) {
16
16
  const machines = scada.machines.filter(({ from }) => {
17
17
  return !policy.excludedSources.some((prefix) => { return from.startsWith(prefix); });
18
18
  });
19
- const sources = ports.processes(machines, app);
19
+ const sources = ports.processes(machines, app, context);
20
20
  const initial = sources[0];
21
21
  const defaults = initial ? deploymentTemplate(policy.environment, target) : {};
22
22
  const environment = Object.fromEntries(Object.entries(defaults).map(([key, value]) => {
@@ -46,7 +46,7 @@ export default function configuredBundleCapabilities(policy, runtime) {
46
46
  try {
47
47
  installBundle(artifact, volume, execute, kube);
48
48
  const candidates = bundleCandidates(policy.applicationBundle, runtime, artifact, volume);
49
- const { protocol } = deploymentTemplate(policy.selection, plan);
49
+ const protocol = deploymentTemplate(policy.applicationBundle.protocol ?? policy.selection.protocol, plan);
50
50
  verifyRuntimeCapabilities({ candidates, required: [protocol], match: policy.match,
51
51
  subject: policy.subject, mismatch: policy.mismatch }, execute);
52
52
  } finally {