@yarkivaev/scada 2.18.0 → 2.19.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/index.js +13 -0
- package/package.json +4 -2
- package/src/application/cycleTimelineFetch.js +56 -0
- package/src/application/deploy/edgeDescriptors.js +31 -0
- package/src/application/deploy/fieldbusSourcePlan.js +79 -0
- package/src/application/deploy/plantBindingProfile.js +24 -0
- package/src/application/deploy/topologyGraph.js +81 -0
- package/src/application/edgeOperatorCatalog.js +9 -7
- package/src/application/mcp/analyticsMcpPort.js +20 -0
- package/src/application/mcp/analyticsNamespaceNodes.js +29 -0
- package/src/application/mcp/analyticsTextContent.js +13 -0
- package/src/application/mcp/plantReadPorts.js +168 -0
- package/src/application/mcp/textContentCatalog.js +7 -0
- package/src/application/operationPrefixes.js +67 -0
- package/src/application/operatorCatalogView.js +8 -0
- package/src/application/projectPlantShops.js +17 -0
- package/src/application/runtime/collectorDslManifest.js +44 -0
- package/src/application/runtime/collectorLaunch.js +34 -0
- package/src/application/runtime/collectorOptions.js +21 -0
- package/src/application/runtime/controlDeliveryEnvironment.js +19 -0
- package/src/application/runtime/embeddedCollectors.js +6 -0
- package/src/application/runtime/index.js +7 -1
- package/src/application/runtime/pagedDelivery.js +87 -0
- package/src/application/runtime/resolveSecrets.js +9 -0
- package/src/application/siteOperatorCatalog.js +8 -7
- package/src/application/siteRuntime/checkpointedOperationPoll.js +77 -0
- package/src/application/siteRuntime/cutoverOperations.js +25 -0
- package/src/application/siteRuntime/databaseMigrations.js +27 -0
- package/src/application/siteRuntime/edgeMetricsStore.js +35 -0
- package/src/application/siteRuntime/history.js +29 -0
- package/src/application/siteRuntime/index.js +16 -0
- package/src/application/siteRuntime/measurementTopic.js +9 -0
- package/src/application/siteRuntime/operationFederation.js +15 -0
- package/src/application/siteRuntime/operationSnapshot.js +18 -0
- package/src/application/siteRuntime/operatorField.js +49 -0
- package/src/application/siteRuntime/operatorUpdates.js +37 -0
- package/src/application/siteRuntime/telemetry.js +31 -0
- package/src/application/siteRuntime/telemetryBackfillCommand.js +64 -0
- package/src/application/timelineMetrics.js +36 -0
- package/src/domain/timeline/cyclePhases.js +191 -0
- package/src/infrastructure/deploy/brokerFleetPolicy.js +91 -0
- package/src/infrastructure/deploy/configuredArchivePlan.js +25 -0
- package/src/infrastructure/deploy/configuredBrokerRoutes.js +34 -0
- package/src/infrastructure/deploy/configuredClassification.js +74 -0
- package/src/infrastructure/deploy/configuredControlPlane.js +116 -0
- package/src/infrastructure/deploy/configuredDeploymentCredentials.js +45 -0
- package/src/infrastructure/deploy/configuredEtcdInventory.js +30 -0
- package/src/infrastructure/deploy/configuredRuntimeCapabilities.js +14 -0
- package/src/infrastructure/deploy/configuredSiteAssets.js +50 -0
- package/src/infrastructure/deploy/configuredStagedDeployment.js +48 -0
- package/src/infrastructure/deploy/highAvailability/configuredBrokerReconciliation.js +21 -0
- package/src/infrastructure/deploy/highAvailability/index.js +1 -0
- package/src/infrastructure/deploy/index.js +19 -0
- package/src/infrastructure/deploy/mixedStoreHistory.js +27 -0
- package/src/infrastructure/deploy/publicBrokerPlan.js +15 -0
- package/src/infrastructure/deploy/siteBrokerDefinitions.js +97 -0
- package/src/infrastructure/deploy/stagedSitePlan.js +132 -0
- package/src/infrastructure/deploy/supervisedServicePlan.js +82 -0
- package/src/infrastructure/http/edge/attachClassify.js +30 -0
- package/src/infrastructure/http/edge/classifyProxy.js +72 -0
- package/src/infrastructure/http/edge/classifyRecord.js +32 -0
- package/src/infrastructure/http/edge/classifyRouting.js +14 -0
- package/src/infrastructure/http/edge/siteAccess.js +7 -0
- package/src/infrastructure/http/edge/writeGuard.js +84 -0
- package/src/infrastructure/http/plant/routes/machineOperationList.js +18 -0
- package/src/infrastructure/http/plant/routes/operationRoute.js +2 -11
- package/src/infrastructure/http/plant/routes/operatorRoute.js +25 -0
- package/src/infrastructure/http/plant/streams/operationStream.js +25 -37
- package/src/infrastructure/ingest/mqtt/modbusDeviceSpec.js +5 -28
- package/src/infrastructure/ingest/mqtt/registerPoint.js +2 -2
- package/src/infrastructure/mdmesh/adminReconciliation.js +19 -0
- package/src/infrastructure/mdmesh/bootstrapMdmeshCredentials.js +4 -4
- package/src/infrastructure/mdmesh/controllerOperation.js +17 -0
- package/src/infrastructure/mdmesh/index.js +3 -0
- package/src/infrastructure/mdmesh/publishApk.js +30 -0
- package/src/infrastructure/persistence/clickhouse/metricBursts.js +73 -0
- package/src/infrastructure/persistence/pg/cyclePhaseQuery.js +168 -0
- package/src/infrastructure/persistence/pg/cyclePrior.js +96 -0
- package/src/infrastructure/persistence/pg/operatorFieldStore.js +50 -0
- package/src/infrastructure/streams/boundedTextFrames.js +27 -0
- package/src/infrastructure/streams/framedSerialSource.js +25 -0
- package/src/infrastructure/streams/index.js +5 -0
- package/src/infrastructure/streams/namedSerialDevices.js +26 -0
- package/src/infrastructure/streams/serialLine.js +26 -0
- package/src/infrastructure/streams/watchCurrentReading.js +31 -0
- package/src/infrastructure/streams/windowPublication.js +73 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import compileControlCatalog, { matchesDeviceInput, scopeControlSecrets } from '../../application/deploy/compileControlCatalog.js';
|
|
2
|
+
import controlReaderSpec from '../../application/deploy/controlReaderSpecs.js';
|
|
3
|
+
import expand from '../../application/deploy/expand.js';
|
|
4
|
+
import projectControlPlane from '../../application/deploy/projectControlPlane.js';
|
|
5
|
+
import { brokerSinkOptions } from './brokerTopology.js';
|
|
6
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
7
|
+
import { reconciliationBundle } from './highAvailability/reconciliationBundle.js';
|
|
8
|
+
|
|
9
|
+
function serverFor(document, name) {
|
|
10
|
+
return document.servers.find(({ id }) => { return id === name; });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function historyBindings(expanded, server, policy) {
|
|
14
|
+
const app = expanded.profiles[server.profile.id].apps.scada;
|
|
15
|
+
const contracts = app.applicationContracts.filter(({ family }) => { return family === policy.historyFamily; });
|
|
16
|
+
const device = server.id.slice(policy.historyDeviceOffset);
|
|
17
|
+
return contracts.flatMap(({ publisherContracts, key }) => {
|
|
18
|
+
return publisherContracts ? publisherContracts.map((id) => {
|
|
19
|
+
if (!Object.hasOwn(policy.historyPublishers, id)) { throw new TypeError(`Unknown history publisher contract ${id}`); }
|
|
20
|
+
return deploymentTemplate(policy.historyPublishers[id], { device, machine: device.replace('-', '') });
|
|
21
|
+
}) : [key];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function combinedHistoryBindings(owner, document, policy, routes) {
|
|
26
|
+
const { historyOwnerPrefix, historySource, historyPeer } = policy;
|
|
27
|
+
if (!owner.startsWith(historyOwnerPrefix)) { return []; }
|
|
28
|
+
const expanded = expand(document);
|
|
29
|
+
const server = serverFor(expanded, owner);
|
|
30
|
+
const sensor = serverFor(expanded, historySource);
|
|
31
|
+
const names = new Set(server.fan_in.filter(({ from }) => { return from === sensor.id; }).map(({ name }) => { return name; }));
|
|
32
|
+
const remote = routes(sensor).filter(({ name, peer }) => { return names.has(name) && peer === historyPeer; });
|
|
33
|
+
return [...new Set([...historyBindings(expanded, server, policy), ...remote.flatMap(({ keys }) => { return keys; })])];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readerOptions(spec, owner, config, document, { policy, ports }) {
|
|
37
|
+
return controlReaderSpec(spec, owner, config, {
|
|
38
|
+
delivery(task) { return task.adapter === policy.singleReader ? 'durable' : 'spooled'; },
|
|
39
|
+
pinCredentials(task) { return task.adapter === policy.serialAdapter || Boolean(task.config?.devices); },
|
|
40
|
+
readerExchanges: policy.readerExchanges,
|
|
41
|
+
sinkOptions(exchange) {
|
|
42
|
+
const expanded = expand(document);
|
|
43
|
+
const server = serverFor(expanded, owner);
|
|
44
|
+
const profile = expanded.profiles[server.profile.id];
|
|
45
|
+
return brokerSinkOptions(ports.readerBroker({ ...expanded, edgeControlPlane: config }, server, profile), exchange);
|
|
46
|
+
},
|
|
47
|
+
historyAdapter: policy.historyAdapter,
|
|
48
|
+
historyNodes(node) { return node.startsWith(policy.historyOwnerPrefix); },
|
|
49
|
+
historyExchange: policy.historyExchange,
|
|
50
|
+
historyBindings(node) { return combinedHistoryBindings(node, document, policy, ports.routes); },
|
|
51
|
+
keyPrefix(node) { return deploymentTemplate(policy.historyKeyPrefix, { device: node.slice(policy.historyDeviceOffset) }); }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function catalogPorts(policy, ports) {
|
|
56
|
+
return {
|
|
57
|
+
readers: ports.readers,
|
|
58
|
+
assignments(document, server, profile, readers) {
|
|
59
|
+
return server.id.startsWith(policy.historyOwnerPrefix) ? ports.localAssignments(document, server, profile.apps.scada) : readers;
|
|
60
|
+
},
|
|
61
|
+
pinned(spec) { return spec.adapter === policy.serialAdapter || spec.config?.devices?.includes('rtu:'); },
|
|
62
|
+
oneCopy(spec) { return spec.adapter === policy.singleReader; },
|
|
63
|
+
matchesInput(document, task, { from, name }, node) {
|
|
64
|
+
if (matchesDeviceInput(task.spec, from)) { return true; }
|
|
65
|
+
if (task.spec.adapter === policy.singleReader && from.startsWith(policy.hostMatchingScheme) && new URL(from).hostname === task.spec.source.host) { return true; }
|
|
66
|
+
return ports.readers(document, node.id, name).some(({ taskId }) => { return taskId === task.taskId; });
|
|
67
|
+
},
|
|
68
|
+
localSpec(spec, node) {
|
|
69
|
+
return scopeControlSecrets({ ...spec, ...(policy.localFirstWins.includes(spec.adapter) && { firstWins: true }) }, node);
|
|
70
|
+
},
|
|
71
|
+
readerSpec(spec, owner, config, document) { return readerOptions(spec, owner, config, document, { policy, ports }); },
|
|
72
|
+
placement: ports.placement
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function checkpoint(config, node, policy) {
|
|
77
|
+
if (node.id !== policy.historyCheckpointNode || config.classifyApply !== true) { return {}; }
|
|
78
|
+
const { historyTokenSecret: name, historyTokenKey: key } = config;
|
|
79
|
+
if (![name, key].every((value) => { return typeof value === 'string' && value.length > 0; })) {
|
|
80
|
+
throw new TypeError('Collector checkpoint credential requires a Secret name and key');
|
|
81
|
+
}
|
|
82
|
+
return { [policy.historyCheckpointKey]: { valueFrom: { secretKeyRef: { name, key } } } };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function associatedTasks(classification, catalog) {
|
|
86
|
+
const tasks = classification.tasks.map((task) => {
|
|
87
|
+
const machine = task.spec.machine.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
88
|
+
const marker = new RegExp(`(?:/|"|')${machine}(?:/|"|')`, 'u');
|
|
89
|
+
const near = catalog.tasks.filter(({ spec }) => { return marker.test(JSON.stringify(spec)); }).map(({ taskId }) => { return taskId; });
|
|
90
|
+
return near.length ? { ...task, near } : task;
|
|
91
|
+
});
|
|
92
|
+
return { ...classification, tasks };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Bind reader, broker and supervisor ports to a declaratively configured control-plane release. */
|
|
96
|
+
export default function configuredControlPlane(policy, ports) {
|
|
97
|
+
function historyOwner(node) { return node.startsWith(policy.historyOwnerPrefix); }
|
|
98
|
+
const readers = catalogPorts(policy, ports);
|
|
99
|
+
return function plan(cluster, document = null) {
|
|
100
|
+
const source = document || ports.read();
|
|
101
|
+
return projectControlPlane(cluster, source, policy, {
|
|
102
|
+
catalog(input, config) { return compileControlCatalog(input, config, readers); },
|
|
103
|
+
classification(input, config, catalog) { return associatedTasks(ports.classification(input, config), catalog); },
|
|
104
|
+
replicas(config, input) {
|
|
105
|
+
const central = serverFor(input, policy.central);
|
|
106
|
+
const bus = central.api.find(({ id }) => { return id === policy.brokerApi; });
|
|
107
|
+
return ports.replicas(config.nodes, bus.url, config.writerEpoch);
|
|
108
|
+
},
|
|
109
|
+
supervisor: ports.supervisor,
|
|
110
|
+
historyBindings(node) { return historyOwner(node) ? ports.historyKeys() : []; },
|
|
111
|
+
historyMaintenance: historyOwner,
|
|
112
|
+
checkpoint(config, node) { return checkpoint(config, node, policy); },
|
|
113
|
+
reconcile(apply) { return reconciliationBundle(ports.classifierRules, { apply, catalogSecret: policy.catalogSecret }); }
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
3
|
+
|
|
4
|
+
function sourceReader(execute, policy) {
|
|
5
|
+
const options = { encoding: 'utf8', timeout: 30000 };
|
|
6
|
+
const source = ['--context', policy.context, '--namespace', policy.namespace];
|
|
7
|
+
const deployment = JSON.parse(execute('kubectl', [...source, '--request-timeout=20s', 'get', policy.workload, '-o', 'json'], options));
|
|
8
|
+
const { env } = deployment.spec.template.spec.containers[policy.container];
|
|
9
|
+
return function credentials() {
|
|
10
|
+
return Object.fromEntries(policy.keys.map((name) => {
|
|
11
|
+
const field = env.find((item) => { return item.name === name; });
|
|
12
|
+
if (field?.value !== undefined) { return [name, field.value]; }
|
|
13
|
+
if (!field?.valueFrom?.secretKeyRef) { throw new Error(deploymentTemplate(policy.missingKey, { name })); }
|
|
14
|
+
const ref = field.valueFrom.secretKeyRef;
|
|
15
|
+
const secret = JSON.parse(execute('kubectl', [...source, 'get', `secret/${ref.name}`, '-o', 'json'], options));
|
|
16
|
+
return [name, Buffer.from(secret.data[ref.key], 'base64').toString('utf8')];
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Copy declared workload credentials and initialize absent database credentials. */
|
|
22
|
+
export default function configuredDeploymentCredentials(policy) {
|
|
23
|
+
return function prepare(execute, settings, cluster = policy.defaultTarget) {
|
|
24
|
+
const { namespace, fieldManager } = policy;
|
|
25
|
+
const postgres = settings[policy.databaseSetting];
|
|
26
|
+
const runtime = settings[policy.runtimeSetting];
|
|
27
|
+
const read = sourceReader(execute, policy.source);
|
|
28
|
+
function kube(args, input) {
|
|
29
|
+
return execute('kubectl', ['--context', cluster, '--namespace', namespace, '--request-timeout=20s', ...args],
|
|
30
|
+
{ input, encoding: 'utf8', stdio: ['pipe', 'pipe', 'inherit'], timeout: 30000 });
|
|
31
|
+
}
|
|
32
|
+
function create(name, stringData) {
|
|
33
|
+
const object = { apiVersion: 'v1', kind: 'Secret', metadata: { name, namespace }, type: 'Opaque', stringData };
|
|
34
|
+
kube(['apply', '--server-side', `--field-manager=${fieldManager}`, '-f', '-'], JSON.stringify(object));
|
|
35
|
+
}
|
|
36
|
+
const raw = kube(['get', `secret/${postgres}`, '--ignore-not-found', '-o', 'json']).trim();
|
|
37
|
+
const credentials = read();
|
|
38
|
+
if (!raw) {
|
|
39
|
+
const password = randomBytes(24).toString('hex');
|
|
40
|
+
create(postgres, deploymentTemplate(policy.database, { password }));
|
|
41
|
+
}
|
|
42
|
+
create(runtime, credentials);
|
|
43
|
+
return { postgres, runtime };
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
2
|
+
|
|
3
|
+
function membersOf(members, learner) {
|
|
4
|
+
return members.filter((item) => { return (item.learner === true) === learner; }).map(({ name }) => { return name; });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function grants(prefix, nodeIds, policy) {
|
|
8
|
+
return [...deploymentTemplate(policy.shared ?? [], { prefix }),
|
|
9
|
+
...nodeIds.map((id) => { return deploymentTemplate(policy.node, { id, prefix }); })];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Inspect a quorum and compile declared namespaced grants. */
|
|
13
|
+
export default function configuredEtcdInventory(policy) {
|
|
14
|
+
const { members, client } = policy;
|
|
15
|
+
return {
|
|
16
|
+
inventory(snapshot) {
|
|
17
|
+
const services = snapshot.services ?? [];
|
|
18
|
+
const live = snapshot.members ?? [];
|
|
19
|
+
return { voters: membersOf(live, false), learners: membersOf(live, true),
|
|
20
|
+
localTraffic: services.length > 0 && services.every(({ externalTrafficPolicy }) => { return externalTrafficPolicy === 'Local'; }),
|
|
21
|
+
clientPort: snapshot.clientPort ?? members.clientPort, peerPort: snapshot.peerPort ?? members.peerPort };
|
|
22
|
+
},
|
|
23
|
+
nextLearner(liveVoters) { return members.voters.find((id) => { return !liveVoters.includes(id); }) ?? null; },
|
|
24
|
+
targetMembers() { return { ...members, voters: [...members.voters], agents: [...members.agents] }; },
|
|
25
|
+
roles(prefix, nodeIds) { return grants(prefix, nodeIds, policy.control); },
|
|
26
|
+
claimRoles(prefix, nodeIds) { return grants(prefix, nodeIds, policy.claims); },
|
|
27
|
+
clientSubject() { return client.subject; },
|
|
28
|
+
clientExtensions() { return client.extensions; }
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import deploymentTemplate, { deploymentCondition } from './deploymentTemplate.js';
|
|
2
|
+
import verifyRuntimeCapabilities from './verifyRuntimeCapabilities.js';
|
|
3
|
+
|
|
4
|
+
/** Check declared runtime roles only when the corresponding release feature is enabled. */
|
|
5
|
+
export default function configuredRuntimeCapabilities(policy) {
|
|
6
|
+
return function preflight(plan, execute) {
|
|
7
|
+
if (!deploymentCondition(policy.feature, plan)) { return; }
|
|
8
|
+
const { images, protocol } = deploymentTemplate(policy.selection, plan);
|
|
9
|
+
verifyRuntimeCapabilities({
|
|
10
|
+
candidates: Object.entries(policy.roles).map(([role, command]) => { return { role, image: images[role], ...command }; }),
|
|
11
|
+
required: [protocol], match: policy.match, subject: policy.subject, mismatch: policy.mismatch
|
|
12
|
+
}, execute);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { databaseEnvironment } from './databaseSecurity.js';
|
|
3
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
4
|
+
|
|
5
|
+
function aliases(machine, policy) {
|
|
6
|
+
const pattern = new RegExp(policy.machinePattern, 'u');
|
|
7
|
+
const match = pattern.exec(machine);
|
|
8
|
+
if (!match) { return ''; }
|
|
9
|
+
const { number } = match.groups;
|
|
10
|
+
const rows = policy.topicRows.map((row) => { return deploymentTemplate(policy.machineAlias, { number, ...row }); }).join('\n');
|
|
11
|
+
return deploymentTemplate(policy.routeAlias, { machine, aliases: rows });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Resolve an app checkpoint to its declared local endpoint. */
|
|
15
|
+
export function configuredObservationUrl(policy) {
|
|
16
|
+
return function observation(node, home) {
|
|
17
|
+
if (node.startsWith(policy.homePrefix)) { return home; }
|
|
18
|
+
return policy.endpoints[node] ?? policy.fallback;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function supervisorConfig(policy, text, observationUrl) {
|
|
23
|
+
const clientPattern = new RegExp(policy.clientPattern, 'u');
|
|
24
|
+
return function render(cluster, authenticatedMqtt = false, machines = null, checkpointUrl = observationUrl(cluster, policy.checkpointUrl)) {
|
|
25
|
+
const selected = machines === null && cluster.startsWith(policy.homePrefix) ? policy.defaultMachines : (machines ?? []);
|
|
26
|
+
return deploymentTemplate(text(policy.config), {
|
|
27
|
+
client: cluster.replace(clientPattern, policy.clientPrefix), checkpointUrl,
|
|
28
|
+
authentication: authenticatedMqtt ? policy.authenticatedMqtt : '',
|
|
29
|
+
routing: selected.length ? selected.map((machine) => { return aliases(machine, policy); }).join('\n') : policy.emptyRouting,
|
|
30
|
+
tags: text(policy.tags), phases: text(policy.phases).trim(),
|
|
31
|
+
machines: selected.map((machine) => { return deploymentTemplate(policy.machine, { machine }); }).join(', ')
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render concrete site environment, Kubernetes objects and supervisor file assets. */
|
|
37
|
+
export function configuredSiteAssets(settings, base, startupHistoryPolicy) {
|
|
38
|
+
function text(file) { return readFileSync(new URL(file, base), 'utf8'); }
|
|
39
|
+
const observationUrl = configuredObservationUrl(settings.observation);
|
|
40
|
+
return {
|
|
41
|
+
observationUrl,
|
|
42
|
+
supervisorConfig: supervisorConfig(settings.supervisor, text, observationUrl),
|
|
43
|
+
siteEnvironment(cluster, app, security) {
|
|
44
|
+
const repairHistoryOnStart = startupHistoryPolicy(app.ingest.stomp.repairHistoryOnStart);
|
|
45
|
+
const bindings = { app, number: cluster.at(-1), repairHistoryOnStart };
|
|
46
|
+
return databaseEnvironment(deploymentTemplate(settings.apiEnvironment, bindings), security, app.api.secret);
|
|
47
|
+
},
|
|
48
|
+
siteObjects(namespace, app) { return deploymentTemplate(settings.apiObjects, { namespace, app }, { text }); }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import compileDeploymentHooks, { deploymentStage } from './compileDeploymentHooks.js';
|
|
3
|
+
import executeStagedDeployment from './executeStagedDeployment.js';
|
|
4
|
+
import stagedStoragePreflight from './stagedStoragePreflight.js';
|
|
5
|
+
import validateStagedDeploymentEvidence from './validateStagedDeploymentEvidence.js';
|
|
6
|
+
|
|
7
|
+
function registeredHooks(plan, policy, evidence, execute, ports) {
|
|
8
|
+
return compileDeploymentHooks(policy.hooks, { plan, evidence, execute, ports: {
|
|
9
|
+
reconcileBroker(ready, kube, { process, pruneShovels }) {
|
|
10
|
+
const { rabbitmq } = deploymentStage(plan, policy.storage.stage).values;
|
|
11
|
+
const input = { ...ready, brokerReconcileProcess: process, brokerPruneShovels: pruneShovels,
|
|
12
|
+
values: { ...ready.values, rabbitmq } };
|
|
13
|
+
ports.reconcile(input, kube, plan.brokerSecurity, execute);
|
|
14
|
+
}
|
|
15
|
+
} });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function operations(plan, policy, execute, operate) {
|
|
19
|
+
return Object.fromEntries(Object.entries(policy.operations ?? {}).map(([command, action]) => {
|
|
20
|
+
return [command, () => { return operate(plan.kiosk, action, execute); }];
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Execute isolation and evidence guards around a declared staged deployment. */
|
|
25
|
+
export default function configuredStagedDeployment(policy, ports) {
|
|
26
|
+
return function deploy(cluster, action = 'render', options = {}) {
|
|
27
|
+
const { execute = execFileSync, evidence, document, security: input, now = Date.now(), backendOnly = false } = options;
|
|
28
|
+
if (backendOnly && action.startsWith(policy.backendOnlyActionPrefix)) { throw new Error(policy.backendOnlyError); }
|
|
29
|
+
const plan = ports.plan(cluster, document, input);
|
|
30
|
+
return executeStagedDeployment({
|
|
31
|
+
plan, action,
|
|
32
|
+
disabledActions: plan.deploymentEnabled ? [] : policy.disabledActions,
|
|
33
|
+
omitStages: backendOnly ? policy.backendOnlyOmit : [],
|
|
34
|
+
actions: operations(plan, policy, execute, ports.operate),
|
|
35
|
+
prepare(mode) {
|
|
36
|
+
const security = ports.security(mode, cluster, execute, input);
|
|
37
|
+
const prepared = ports.plan(cluster, document, security);
|
|
38
|
+
return mode === 'render' ? ports.publicOutput(prepared) : prepared;
|
|
39
|
+
},
|
|
40
|
+
validateMutation(current) { validateStagedDeploymentEvidence(current, policy.evidence, evidence, now); },
|
|
41
|
+
preflight(current, mode, mutate) {
|
|
42
|
+
stagedStoragePreflight(current, policy.storage, { evidence: mutate ? evidence : null, execute, action: mode });
|
|
43
|
+
},
|
|
44
|
+
stageHooks(current) { return registeredHooks(current, policy, evidence, execute, ports); },
|
|
45
|
+
afterApply: backendOnly ? undefined : (current) => { return ports.operate(current.kiosk, policy.afterApply, execute); }
|
|
46
|
+
}, execute);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { brokerManagement } from '../brokerSecurity.js';
|
|
2
|
+
import { brokerPolicy } from '../securityPolicy.js';
|
|
3
|
+
import { reconcileRabbitmqTopology } from '../../messaging/rabbitmq/reconcile.js';
|
|
4
|
+
import { brokerOwnership } from './brokerOwnership.js';
|
|
5
|
+
import { reconcileBrokerThroughController } from './reconcileBrokerThroughController.js';
|
|
6
|
+
|
|
7
|
+
/** Bind broker reconciliation to its declared management identity and classifier ownership. */
|
|
8
|
+
export default function configuredBrokerReconciliation(identity, classifierRules) {
|
|
9
|
+
function management(base, security) {
|
|
10
|
+
const broker = brokerPolicy(security);
|
|
11
|
+
return broker ? brokerManagement(base, broker) : { base, ...identity };
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
reconcile(desired, base, security) {
|
|
15
|
+
return reconcileRabbitmqTopology(desired, { ...management(base, security), ...brokerOwnership(desired, classifierRules) });
|
|
16
|
+
},
|
|
17
|
+
reconcileDeployment(plan, _kube, security, execute) {
|
|
18
|
+
return reconcileBrokerThroughController(plan, management('', security), classifierRules, execute);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -12,3 +12,4 @@ export { acceptEpoch, admitWriter, applyReplica, readyToLead, restored } from '.
|
|
|
12
12
|
export { default as runHistoryReceiver, segmentCollector } from './historyReceiver.js';
|
|
13
13
|
export { fromPool as replicaWatermarkFromPool, watermark as replicaWatermark } from './historyWatermark.js';
|
|
14
14
|
export { default as segmentAdmit, grantedEpoch } from './segmentAdmit.js';
|
|
15
|
+
export { default as configuredBrokerReconciliation } from './configuredBrokerReconciliation.js';
|
|
@@ -59,3 +59,22 @@ export { centralTelemetryValues, centralTelemetryChartEnv, centralTelemetryEnvir
|
|
|
59
59
|
export { collectorCommand, collectorPublisherCommand, collectorConsumerTasks, collectorDeviceAssignments, collectorSourceProcesses, mapCollectorRelease, parseSerialSource } from '../../application/deploy/collectorSourcePlan.js';
|
|
60
60
|
export { default as collectorChartPlan } from './collectorChartPlan.js';
|
|
61
61
|
export { default as configuredPostgresMaintenance } from './configuredPostgresMaintenance.js';
|
|
62
|
+
export { default as brokerFleetPolicy } from './brokerFleetPolicy.js';
|
|
63
|
+
export { publisherBrokerDefinitions, subscriberBrokerDefinitions } from './siteBrokerDefinitions.js';
|
|
64
|
+
export { projectRegisterMaps, sharedRegisterBus, rawSerialDeviceList, databaseSourceGroups } from '../../application/deploy/fieldbusSourcePlan.js';
|
|
65
|
+
export { default as stagedSitePlan } from './stagedSitePlan.js';
|
|
66
|
+
export { default as topologyGraph } from '../../application/deploy/topologyGraph.js';
|
|
67
|
+
export { default as edgeDescriptors } from '../../application/deploy/edgeDescriptors.js';
|
|
68
|
+
export { default as configuredControlPlane } from './configuredControlPlane.js';
|
|
69
|
+
export { standbySupervisor, supervisedServicePlan } from './supervisedServicePlan.js';
|
|
70
|
+
export { default as configuredStagedDeployment } from './configuredStagedDeployment.js';
|
|
71
|
+
export { default as publicBrokerPlan } from './publicBrokerPlan.js';
|
|
72
|
+
export { default as plantBindingProfile } from '../../application/deploy/plantBindingProfile.js';
|
|
73
|
+
export { default as configuredDeploymentCredentials } from './configuredDeploymentCredentials.js';
|
|
74
|
+
export { default as mixedStoreHistory } from './mixedStoreHistory.js';
|
|
75
|
+
export { default as configuredRuntimeCapabilities } from './configuredRuntimeCapabilities.js';
|
|
76
|
+
export { classificationEnvironment, configuredClassification, configuredSupervisor } from './configuredClassification.js';
|
|
77
|
+
export { default as configuredArchivePlan } from './configuredArchivePlan.js';
|
|
78
|
+
export { default as configuredEtcdInventory } from './configuredEtcdInventory.js';
|
|
79
|
+
export { configuredSiteAssets } from './configuredSiteAssets.js';
|
|
80
|
+
export { default as configuredBrokerRoutes } from './configuredBrokerRoutes.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function validateSettings(settings, policy) {
|
|
2
|
+
const { rawBackend, stateBackend, errors } = policy;
|
|
3
|
+
if (settings.rawBackend !== rawBackend || settings.stateBackend !== stateBackend) { throw new Error(errors.backends); }
|
|
4
|
+
if (!Number.isSafeInteger(settings.retentionDays) || settings.retentionDays < 1 || settings.retentionDays > 365) {
|
|
5
|
+
throw new Error(errors.retention);
|
|
6
|
+
}
|
|
7
|
+
if (!/^[a-z0-9][a-z0-9.-]*$/u.test(settings.tokenSecret ?? '') || !/^[A-Za-z0-9._-]+$/u.test(settings.tokenKey ?? '')) {
|
|
8
|
+
throw new Error(errors.secret);
|
|
9
|
+
}
|
|
10
|
+
if (!/^(?:\*|\d+(?:[-/,]\d+)*)(?:\s+(?:\*|\d+(?:[-/,]\d+)*)){4}$/u.test(settings.purgeSchedule ?? '')) {
|
|
11
|
+
throw new Error(errors.schedule);
|
|
12
|
+
}
|
|
13
|
+
const missing = policy.roles.find((role) => { return !/^\S+@sha256:[a-f0-9]{64}$/u.test(settings.images?.[role] ?? ''); });
|
|
14
|
+
if (missing) { throw new Error(errors.image.replace('{role}', missing)); }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Verify the declared immutable candidates and retention policy for an optional mixed-store history. */
|
|
18
|
+
export default function mixedStoreHistory(policy) {
|
|
19
|
+
return function normalize(settings = { enabled: false }) {
|
|
20
|
+
if (typeof settings.enabled !== 'boolean') { throw new Error(policy.errors.enabled); }
|
|
21
|
+
if (!settings.enabled) { return { ...settings, enabled: false }; }
|
|
22
|
+
validateSettings(settings, policy);
|
|
23
|
+
const writerEpoch = settings.writerEpoch ?? 1;
|
|
24
|
+
if (!Number.isSafeInteger(writerEpoch) || writerEpoch < 1) { throw new Error(policy.errors.epoch); }
|
|
25
|
+
return { ...settings, protocol: policy.protocol, writerEpoch };
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Public deployment output excludes controller credentials and Secret-backed definitions. */
|
|
2
|
+
export default function publicBrokerPlan(value) {
|
|
3
|
+
if (Array.isArray(value)) { return value.map(publicBrokerPlan); }
|
|
4
|
+
if (!value || typeof value !== 'object') {
|
|
5
|
+
return typeof value === 'string' ? value.replace(/(?<protocol>amqps?|mqtts?|stomps?):\/\/[^@\s"]+@/gu, '$<protocol>://[redacted]@') : value;
|
|
6
|
+
}
|
|
7
|
+
return Object.fromEntries(Object.entries(value).flatMap(([key, entry]) => {
|
|
8
|
+
if (key === 'definitions' && value.definitionsSecret) { return []; }
|
|
9
|
+
if (key === 'brokerSecurity') {
|
|
10
|
+
const { phase, definitionsSecret, runtimeSecret } = entry;
|
|
11
|
+
return [[key, { phase, definitionsSecret, runtimeSecret }]];
|
|
12
|
+
}
|
|
13
|
+
return [[key, publicBrokerPlan(entry)]];
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import rabbitmqDefinitions from '../messaging/rabbitmq/definitions.js';
|
|
2
|
+
import { appendBrokerResources, brokerEndpoint, brokerOutboxes, brokerPeerOutboxes, brokerShovel, brokerStreamBindings, brokerStreams } from './brokerTopology.js';
|
|
3
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
4
|
+
|
|
5
|
+
function archiveOutboxes(document, families, policy, reconnectDelay) {
|
|
6
|
+
const { archive, local, access, exchange } = policy;
|
|
7
|
+
return brokerOutboxes(families, { sourceUri: local, destinationUri: brokerEndpoint(document, archive, access),
|
|
8
|
+
reconnectDelay, destination: archive, exchange(family) { return deploymentTemplate(exchange, { family }); } });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function publisherKeys(contract, patterns) {
|
|
12
|
+
return contract.publisherContracts ? contract.publisherContracts.map((id) => {
|
|
13
|
+
if (!Object.hasOwn(patterns, id)) { throw new TypeError(`Unknown publisher contract ${id}`); }
|
|
14
|
+
return patterns[id];
|
|
15
|
+
}) : [contract.key];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function inboundShovels(document, server, context, policy) {
|
|
19
|
+
const peers = server.fan_in.filter(({ from }) => { return from === policy.peerSource; });
|
|
20
|
+
const sourceUri = brokerEndpoint(document, policy.peerSource, policy.access);
|
|
21
|
+
return policy.inbound.filter(({ suffix }) => {
|
|
22
|
+
return peers.some(({ name }) => { return name.endsWith(`/${suffix}`); });
|
|
23
|
+
}).map((item) => {
|
|
24
|
+
return brokerShovel({ ...deploymentTemplate(item, context), sourceUri, destinationUri: policy.local, reconnectDelay: policy.reconnectDelay });
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function retargetArchive(document, result, policy) {
|
|
29
|
+
const { archiveRetarget } = policy;
|
|
30
|
+
if (document.edgeControlPlane?.historyEnabled !== true) { return; }
|
|
31
|
+
const shovel = result.parameters.find(({ name }) => { return name === archiveRetarget.shovel; });
|
|
32
|
+
if (shovel) {
|
|
33
|
+
shovel.value['src-queue'] = archiveRetarget.queue;
|
|
34
|
+
appendBrokerResources(result, { queues: [archiveRetarget.queue] });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Project a subscriber broker with local publishers, incoming shovels and replicated resources. */
|
|
39
|
+
export function subscriberBrokerDefinitions(document, server, app, policy, ports) {
|
|
40
|
+
const contracts = app.applicationContracts;
|
|
41
|
+
const families = contracts.map((contract) => { return { family: contract.family, keys: publisherKeys(contract, policy.publishers) }; });
|
|
42
|
+
const exchanges = [...new Set([...families.map(({ family }) => { return deploymentTemplate(policy.exchange, { family }); }), ...policy.base.exchanges])];
|
|
43
|
+
const context = { app, device: server.id.slice(policy.nodePrefix.length), suffix: server.id.replace(policy.shortPrefix, '') };
|
|
44
|
+
const outboxes = archiveOutboxes(document, families, policy, policy.reconnectDelay);
|
|
45
|
+
const result = rabbitmqDefinitions({ ...deploymentTemplate(policy.base, context), exchanges, outboxes });
|
|
46
|
+
result.parameters.push(...inboundShovels(document, server, context, policy));
|
|
47
|
+
result.policies = deploymentTemplate(policy.policies, context);
|
|
48
|
+
retargetArchive(document, result, policy);
|
|
49
|
+
const replicated = ports.replicate(document, server.id, result);
|
|
50
|
+
return appendBrokerResources(replicated, deploymentTemplate(policy.resources, context));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function routeQueues(target, host, policy) {
|
|
54
|
+
const pattern = new RegExp(policy.pattern, 'u');
|
|
55
|
+
const rows = host.fan_in.filter(({ name }) => { return pattern.test(name); });
|
|
56
|
+
const fragments = rows.map(({ from, name }) => {
|
|
57
|
+
const machine = name.split('/')[policy.pathIndex];
|
|
58
|
+
const device = deploymentTemplate(from.startsWith(policy.specialSource.prefix) ? policy.specialSource.device : policy.device, { machine });
|
|
59
|
+
return deploymentTemplate(policy.instance, { machine, device });
|
|
60
|
+
});
|
|
61
|
+
return appendBrokerResources(target, {
|
|
62
|
+
queues: [...fragments.flatMap(({ queues }) => { return queues; }), ...policy.extraQueues],
|
|
63
|
+
bindings: [...fragments.flatMap(({ bindings }) => { return bindings; }), ...fragments.map(({ extraBinding }) => { return extraBinding; })]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function outboundPeers(document, routes, streams, policy) {
|
|
68
|
+
return document.servers.filter(({ id }) => { return id.startsWith(policy.peerPrefix); }).flatMap(({ id }) => {
|
|
69
|
+
return brokerPeerOutboxes(id, routes, streams.subscriptionsTo(id), (group, peer) => {
|
|
70
|
+
const { queue, exchanges, defaultExchange } = policy.peerOutboxes;
|
|
71
|
+
return { queue: deploymentTemplate(queue, { group, device: peer.slice(policy.peerDeviceOffset) }),
|
|
72
|
+
exchange: exchanges[group] ?? defaultExchange };
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function publishedExchanges(config, policy) {
|
|
78
|
+
return [...config.centralExchanges, ...policy.extraExchanges].map((family) => {
|
|
79
|
+
return deploymentTemplate(policy.exchange, { family });
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Build a publisher broker and its downstream outboxes from subscriptions. */
|
|
84
|
+
export function publisherBrokerDefinitions(document, source, config, policy, ports) {
|
|
85
|
+
const additionalSource = document.edgeControlPlane?.enabled === true && source.id === policy.additionalHost ? policy.additionalSource : undefined;
|
|
86
|
+
const streams = brokerStreams(document, source, { service: policy.access.service, additionalSource });
|
|
87
|
+
const routes = ports.routes(streams.host);
|
|
88
|
+
const archive = streams.subscriptionsTo(policy.archive);
|
|
89
|
+
const keys = brokerStreamBindings(routes, archive);
|
|
90
|
+
const families = config.centralExchanges.map((family) => { return { family, keys: family === policy.archiveFilteredFamily ? keys : ['#'] }; });
|
|
91
|
+
const outboxes = [...archive.size ? archiveOutboxes(document, families, policy, config.reconnectDelay) : [],
|
|
92
|
+
...outboundPeers(document, routes, streams, policy)];
|
|
93
|
+
const result = rabbitmqDefinitions({ ...policy.base, exchanges: publishedExchanges(config, policy), outboxes });
|
|
94
|
+
const expanded = routeQueues(result, streams.host, policy.routeQueues);
|
|
95
|
+
const module = document.profiles?.[source.profile?.id];
|
|
96
|
+
return ports.replicate(document, source.id, ports.transform(expanded, module));
|
|
97
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { deploymentContext, peerNodePort } from '../../application/deploy/deploymentPlan.js';
|
|
2
|
+
import { brokerClientEnvironment } from './brokerSecurity.js';
|
|
3
|
+
import buildDeploymentStages from './buildDeploymentStages.js';
|
|
4
|
+
import { databaseSecurity } from './databaseSecurity.js';
|
|
5
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
6
|
+
import { brokerPolicy } from './securityPolicy.js';
|
|
7
|
+
|
|
8
|
+
function nodeAddress(server, service) {
|
|
9
|
+
return new URL(server.api.find(({ id }) => { return id === service; }).url).hostname;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function peerResources({ document, target }, policy) {
|
|
13
|
+
if (!document.edgeControlPlane?.enabled) { return []; }
|
|
14
|
+
const { brokerService: service, nodes } = document.edgeControlPlane;
|
|
15
|
+
const peerAddresses = nodes.map(({ id }) => {
|
|
16
|
+
const server = document.servers.find((row) => { return row.id === id; });
|
|
17
|
+
return nodeAddress(server, policy.target.address);
|
|
18
|
+
});
|
|
19
|
+
return peerNodePort({ ...policy.peerBroker, name: service.name, namespace: target.namespace, peerAddresses,
|
|
20
|
+
port: service.port, nodePort: service.nodePort });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function secretBindings(assignments, secret) {
|
|
24
|
+
const names = new Set();
|
|
25
|
+
JSON.stringify(assignments, (key, value) => {
|
|
26
|
+
if (key === '$secret') { names.add(value); }
|
|
27
|
+
return value;
|
|
28
|
+
});
|
|
29
|
+
return Object.fromEntries([...names].map((name) => { return [name, { valueFrom: { secretKeyRef: { name: secret, key: name } } }]; }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function buildSiteState(context, policy, ports) {
|
|
33
|
+
const { app, broker, cluster, document, server, target, profile } = context;
|
|
34
|
+
const assignments = ports.assignments(document, server, app);
|
|
35
|
+
const secretEnvironment = secretBindings(assignments, app.api.secret);
|
|
36
|
+
const controlCatalog = document.edgeControlPlane?.enabled ? ports.catalog(cluster, document) : null;
|
|
37
|
+
const brokerEnvironment = broker && broker.phase !== 'prepare' && brokerClientEnvironment(broker);
|
|
38
|
+
const peers = peerResources(context, policy);
|
|
39
|
+
const authorizationJob = ports.authorizationJob(target.namespace, app);
|
|
40
|
+
const address = nodeAddress(server, policy.target.address);
|
|
41
|
+
return { ...context, assignments, controlCatalog, brokerEnvironment, nodeAddress: address,
|
|
42
|
+
kiosk: ports.kioskPlan(cluster, address, profile.kiosk),
|
|
43
|
+
collectorEnv: { ...deploymentTemplate(policy.collectorEnvironment, { assignments }), ...secretEnvironment, ...brokerEnvironment },
|
|
44
|
+
peers, secretNames: Object.keys(secretEnvironment), authorizationJob };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function storage(state, ports) {
|
|
48
|
+
const { app, authorizationJob, broker, cluster, document, expanded, peers, scada, server } = state;
|
|
49
|
+
const definitions = ports.broker({ ...expanded, edgeControlPlane: document.edgeControlPlane }, server, app);
|
|
50
|
+
const rabbitmq = ports.brokerValues({ ...scada.rabbitmq, extraConfig: { ...scada.rabbitmq.extraConfig, cluster_name: cluster }, definitions }, broker);
|
|
51
|
+
return { values: { extraObjects: [authorizationJob, ...peers], postgres: { ...scada.postgres }, rabbitmq } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function api(state, policy, ports) {
|
|
55
|
+
const { app, brokerEnvironment, cluster, document, profile, security, server, target } = state;
|
|
56
|
+
const image = server.profile.variables?.siteImage ?? profile.variables?.siteImage ?? app.collector.image;
|
|
57
|
+
const environment = { ...ports.siteEnvironment(cluster, app, security), ...ports.classifyEnvironment(cluster, document), ...brokerEnvironment };
|
|
58
|
+
const process = deploymentTemplate(policy.apiProcess, { app, image, environment });
|
|
59
|
+
return { values: { processes: [process], extraObjects: ports.siteObjects(target.namespace, app) } };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function collector(state, policy, ports) {
|
|
63
|
+
const { app, assignments, cluster, collectorEnv, controlCatalog, document } = state;
|
|
64
|
+
const plane = document.edgeControlPlane;
|
|
65
|
+
const resources = (plane?.historyEnabled === true && plane.agentResources) || app.collector.resources;
|
|
66
|
+
const process = deploymentTemplate(policy.collectorProcess, { app, collectorEnv, collectorResources: resources });
|
|
67
|
+
return { values: { processes: [ports.controlCollector(document, cluster, process)] },
|
|
68
|
+
...(controlCatalog && { controlCatalog, cutoverTasks: controlCatalog.tasks.filter((task) => {
|
|
69
|
+
return !task.pinnedNode && assignments.some(({ taskId }) => { return taskId === task.taskId; });
|
|
70
|
+
}) }) };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function supervisorImage(document, fallback, cluster, policy) {
|
|
74
|
+
const pin = document.servers?.find(({ id }) => { return id === cluster; })?.profile?.variables?.supervisorImage;
|
|
75
|
+
if (pin) { return pin; }
|
|
76
|
+
if (!document.edgeControlPlane?.enabled) { return fallback; }
|
|
77
|
+
if (!document.edgeControlPlane.supervisorImage) { throw new TypeError(policy.supervisorImageError); }
|
|
78
|
+
return document.edgeControlPlane.supervisorImage;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function supervisor(state, policy, ports) {
|
|
82
|
+
const { app, brokerEnvironment, cluster, document, profile } = state;
|
|
83
|
+
const image = supervisorImage(document, profile.apps.supervisor.image, cluster, policy);
|
|
84
|
+
const machine = deploymentTemplate(policy.supervisor.machineId, { number: cluster.at(-1) });
|
|
85
|
+
const config = ports.supervisorConfig(cluster, Boolean(brokerEnvironment), [machine], policy.supervisor.checkpointUrl);
|
|
86
|
+
const environment = { ...(document.edgeControlPlane && { [policy.supervisor.groupVariable]: machine }),
|
|
87
|
+
...deploymentTemplate(policy.supervisorEnvironment, { app }), ...brokerEnvironment };
|
|
88
|
+
return { values: { ...profile.apps.supervisor, ...deploymentTemplate(policy.supervisorValues, { app, image, config, environment }) } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function stagesFor(state, policy, rollout, ports) {
|
|
92
|
+
const { app, cluster, profile, target, kiosk } = state;
|
|
93
|
+
const common = { context: cluster, namespace: target.namespace, release: cluster, ...rollout.release };
|
|
94
|
+
const defaults = deploymentTemplate(policy.defaults, { app, edgeId: cluster.slice(policy.target.labelOffset) });
|
|
95
|
+
return buildDeploymentStages(rollout.stages, { common, defaults, ports: {
|
|
96
|
+
storage() { return storage(state, ports); },
|
|
97
|
+
api() { return api(state, policy, ports); },
|
|
98
|
+
collector() { return collector(state, policy, ports); },
|
|
99
|
+
supervisor() { return supervisor(state, policy, ports); },
|
|
100
|
+
frontend() { return { values: { ...profile.apps.frontend, ...deploymentTemplate(policy.frontendValues, { app }) } }; },
|
|
101
|
+
kiosk() { return profile.kiosk.browserTargets.includes(cluster) ? { values: { extraObjects: ports.kioskObjects(kiosk) } } : null; }
|
|
102
|
+
} });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function sitePlan(state, policy, stages) {
|
|
106
|
+
const { app, broker, cluster, document, kiosk, nodeAddress: address, server, target, peers, security } = state;
|
|
107
|
+
return { ...(broker && { brokerSecurity: broker }), deploymentEnabled: server.profile.variables?.deployEnabled !== false,
|
|
108
|
+
kiosk, context: cluster, namespace: target.namespace, nodeAddress: address, preserveStoragePodTemplates: app.adoption.freezeStoragePodTemplates,
|
|
109
|
+
prerequisites: {
|
|
110
|
+
...(document.edgeControlPlane?.enabled && { peerBrokerPerimeter: peers[1] }),
|
|
111
|
+
...(security?.database && { databaseRuntime: databaseSecurity(security) }),
|
|
112
|
+
...(broker && { brokerSecrets: [broker.definitionsSecret, broker.runtimeSecret] }),
|
|
113
|
+
runtimeAuthJob: state.authorizationJob.metadata.name, runtimeSecret: app.api.secret, postgresSecret: state.scada.postgres.secret,
|
|
114
|
+
...policy.prerequisites, requiredSecretKeys: [...new Set([...state.secretNames, ...policy.prerequisites.requiredSecretKeys])].sort()
|
|
115
|
+
}, stages };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Compile an isolated storage/API/reader release from chart templates, runtime policy and plant ports. */
|
|
119
|
+
export default function stagedSitePlan(policy, rollout, ports) {
|
|
120
|
+
const targetPattern = new RegExp(policy.target.pattern, 'u');
|
|
121
|
+
return function plan(cluster, input, security) {
|
|
122
|
+
if (!targetPattern.test(cluster ?? '')) { throw new TypeError(policy.target.invalidTarget); }
|
|
123
|
+
const broker = brokerPolicy(security);
|
|
124
|
+
const document = input ?? ports.read();
|
|
125
|
+
const context = deploymentContext(document, cluster);
|
|
126
|
+
if (context.target.namespace !== policy.target.namespace || context.target.prefix !== policy.target.prefix) {
|
|
127
|
+
throw new TypeError(policy.target.invalidScope);
|
|
128
|
+
}
|
|
129
|
+
const state = buildSiteState({ ...context, app: context.profile.apps.scada, cluster, document, security, broker }, policy, ports);
|
|
130
|
+
return sitePlan(state, policy, stagesFor(state, policy, rollout, ports));
|
|
131
|
+
};
|
|
132
|
+
}
|