@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
@@ -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
- return [['--service', services], ['--job', jobs]].flatMap(([kind, entries]) => {
9
- return Object.entries(entries ?? {}).map(([prefix, name]) => { return { kind, name, match: ['node', ...prefix.split(' ')] }; });
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 select(container, workload, { bundle, jvm }, { rules, jvmRuntime, namedJobs, runtimeCommand, jvmCommand }) {
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
- if (!jvm) { throw new Error('SCADA_CORE_JVM_IMAGE is required for the selected JVM runtime'); }
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
- if (job) { return replaceNode(container, bundle.image, runtimeCommand('--job', job.name)); }
37
- return undefined;
79
+ return job ? replaceNode(container, artifact.bundle.image, runtimeCommand('--job', job.name)) : undefined;
38
80
  }
39
81
 
40
- function projectObject(object, artifact, projection) {
41
- const template = object?.kind === 'CronJob' ? object.spec?.jobTemplate?.spec?.template : object?.spec?.template;
42
- const pod = template?.spec;
43
- if (!pod?.containers) { return false; }
44
- const projected = projectApplicationBundle(pod, artifact.bundle, (container) => {
45
- return select(container, object.metadata?.name, artifact, projection);
46
- });
47
- if (projected === pod) { return false; }
48
- const { legacyMount, legacyAnnotation } = projection.jvmRuntime ?? {};
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({ targets, services, jobs, namedJobs = [], jvmRuntime,
68
- document = 'plant/runtime.yaml', tokenKey = 'token', tokenHeader = 'Deploy-Token' }) {
69
- const rules = commandRules(services, jobs);
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,10 +29,13 @@ 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';
35
+ export { resolveWorkloads } from '../../application/deploy/namedProcessing.js';
33
36
  export { default as compileNamedControlCatalog } from '../../application/deploy/compileNamedControlCatalog.js';
34
- export { default as compileLocalConsumers } from '../../application/deploy/compileLocalConsumers.js';
35
- export { default as normalizeControlPlane } from '../../application/deploy/normalizeControlPlane.js';
37
+ export { default as compileLocalConsumers, namedLocalConsumers } from '../../application/deploy/compileLocalConsumers.js';
38
+ export { default as normalizeControlPlane, bindControlInstallation } from '../../application/deploy/normalizeControlPlane.js';
36
39
  export { profileDefinitionFor } from '../../application/deploy/releaseNodes.js';
37
40
  export { sourceAddress } from '../../application/deploy/deploymentRouting.js';
38
41
  export { appendReplicaTopology, replicaShovels, brokerReplicaPlan, appendBrokerReplicas } from './brokerReplicaTopology.js';
@@ -1,8 +1,8 @@
1
1
  import { validateConnections } from './config.js';
2
2
 
3
3
  /** Selects sampling policy by stream path while the fan-in remains the source inventory. */
4
- function timing(name, config) {
5
- const match = (config.sampling || []).find((item) => {
4
+ function timing({ name, sampling }, config) {
5
+ const match = sampling ?? (config.sampling || []).find((item) => {
6
6
  const parts = item.name.split('/');
7
7
  const path = name.split('/');
8
8
  return parts.length === path.length && parts.every((part, index) => {
@@ -18,7 +18,7 @@ function timing(name, config) {
18
18
  export default function projectOpcuaSources(rows, config, deviceFor) {
19
19
  const connections = new Map();
20
20
  rows.forEach((row) => {
21
- const intervals = timing(row.name, config);
21
+ const intervals = timing(row, config);
22
22
  const connection = connections.get(row.from) || { url: row.from, ...intervals, channels: [] };
23
23
  if (connection.publishMs !== intervals.publishMs || connection.heartbeatMs !== intervals.heartbeatMs || connection.healthRequired !== intervals.healthRequired) {
24
24
  throw new Error(`incompatible OPC UA sampling policies at ${row.from}`);