@yarkivaev/scada 2.18.0 → 2.20.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 +17 -0
- package/package.json +4 -2
- package/src/application/cycleTimelineFetch.js +56 -0
- package/src/application/deploy/collectorProcesses.js +1 -0
- package/src/application/deploy/collectorSourcePlan.js +41 -0
- package/src/application/deploy/compileCollectorTasks.js +2 -2
- package/src/application/deploy/edgeDescriptors.js +31 -0
- package/src/application/deploy/fieldbusSourcePlan.js +93 -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/domain/timeline/taggedCycleWindows.js +17 -0
- package/src/domain/timeline/taggedSegment.js +47 -0
- package/src/domain/timeline/taggedTimeline.js +98 -0
- package/src/domain/timeline/timelineSegment.js +25 -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/configuredCollectorChartDeployment.js +22 -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/controlPlaneCli.js +17 -0
- package/src/infrastructure/deploy/highAvailability/configuredBrokerReconciliation.js +21 -0
- package/src/infrastructure/deploy/highAvailability/historyWatermark.js +2 -2
- package/src/infrastructure/deploy/highAvailability/index.js +3 -1
- package/src/infrastructure/deploy/highAvailability/replicaHistoryStore.js +7 -0
- package/src/infrastructure/deploy/index.js +22 -1
- 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 +6 -0
- package/src/infrastructure/streams/namedSerialDevices.js +26 -0
- package/src/infrastructure/streams/pollSnapshot.js +11 -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,98 @@
|
|
|
1
|
+
import taggedSegment from './taggedSegment.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sorts tagged segments by start time ascending.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} left - left tagged segment
|
|
7
|
+
* @param {object} right - right tagged segment
|
|
8
|
+
* @returns {number} sort order
|
|
9
|
+
*/
|
|
10
|
+
function sortByStart(left, right) {
|
|
11
|
+
return left.segment().startMs() - right.segment().startMs();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sorts anchor start times ascending.
|
|
16
|
+
*
|
|
17
|
+
* @param {number} left - left start time
|
|
18
|
+
* @param {number} right - right start time
|
|
19
|
+
* @returns {number} sort order
|
|
20
|
+
*/
|
|
21
|
+
function sortStarts(left, right) {
|
|
22
|
+
return left - right;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Ordered collection of tagged segments for anchor-based derivation.
|
|
27
|
+
*
|
|
28
|
+
* @param {Array<object>} rows - raw timeline segments
|
|
29
|
+
* @returns {object} timeline with anchorStarts, firstAtOrAfter, operationStarts
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const timeline = taggedTimeline([{ start: '2026-01-01T00:00:00.000Z', end: '2026-01-01T01:00:00.000Z', tags: '["inspection"]' }]);
|
|
33
|
+
* timeline.anchorStarts('inspection', -1, Number.MAX_SAFE_INTEGER);
|
|
34
|
+
*/
|
|
35
|
+
export default function taggedTimeline(rows) {
|
|
36
|
+
const items = [];
|
|
37
|
+
const source = rows || [];
|
|
38
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
39
|
+
items.push(taggedSegment(source[index]));
|
|
40
|
+
}
|
|
41
|
+
items.sort(sortByStart);
|
|
42
|
+
return {
|
|
43
|
+
/**
|
|
44
|
+
* Returns sorted anchor start times inside half-open bounds.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} tag - anchor tag name
|
|
47
|
+
* @param {number} after - exclusive lower bound in epoch ms
|
|
48
|
+
* @param {number} before - exclusive upper bound in epoch ms
|
|
49
|
+
* @returns {Array<number>} anchor start times in epoch ms
|
|
50
|
+
*/
|
|
51
|
+
anchorStarts(tag, after, before) {
|
|
52
|
+
const times = [];
|
|
53
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
54
|
+
const item = items[index];
|
|
55
|
+
if (item.has(tag)) {
|
|
56
|
+
const start = item.segment().startMs();
|
|
57
|
+
if (start > after && start < before) {
|
|
58
|
+
times.push(start);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
times.sort(sortStarts);
|
|
63
|
+
return times;
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Returns first start time at or after bound.
|
|
67
|
+
*
|
|
68
|
+
* @param {Array<number>} starts - sorted start times in epoch ms
|
|
69
|
+
* @param {number} bound - inclusive lower bound in epoch ms
|
|
70
|
+
* @returns {number|undefined} first matching start time
|
|
71
|
+
*/
|
|
72
|
+
firstAtOrAfter(starts, bound) {
|
|
73
|
+
for (let index = 0; index < starts.length; index += 1) {
|
|
74
|
+
if (starts[index] >= bound) {
|
|
75
|
+
return starts[index];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Returns ISO start timestamps for segments intersecting a cycle window.
|
|
82
|
+
*
|
|
83
|
+
* @param {number} cycleStart - inclusive cycle start in epoch ms
|
|
84
|
+
* @param {number} cycleEnd - exclusive cycle end in epoch ms
|
|
85
|
+
* @returns {Array<string>} segment start ISO timestamps
|
|
86
|
+
*/
|
|
87
|
+
operationStarts(cycleStart, cycleEnd) {
|
|
88
|
+
const starts = [];
|
|
89
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
90
|
+
const item = items[index];
|
|
91
|
+
if (item.segment().intersects(cycleStart, cycleEnd)) {
|
|
92
|
+
starts.push(new Date(item.segment().startMs()).toISOString());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return starts;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable timeline segment with half-open time bounds.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} row - segment with ISO start and end timestamps
|
|
5
|
+
* @returns {object} segment with startMs, endMs, intersects
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const item = timelineSegment({ start: '2026-01-01T00:00:00.000Z', end: '2026-01-01T01:00:00.000Z' });
|
|
9
|
+
* item.intersects(0, Date.parse('2026-01-01T00:30:00.000Z'));
|
|
10
|
+
*/
|
|
11
|
+
export default function timelineSegment(row) {
|
|
12
|
+
const start = new Date(row.start).getTime();
|
|
13
|
+
const end = new Date(row.end).getTime();
|
|
14
|
+
return {
|
|
15
|
+
startMs() {
|
|
16
|
+
return start;
|
|
17
|
+
},
|
|
18
|
+
endMs() {
|
|
19
|
+
return end;
|
|
20
|
+
},
|
|
21
|
+
intersects(windowStart, windowEnd) {
|
|
22
|
+
return end > windowStart && start < windowEnd;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { appendBrokerReplicas, brokerReplicaPlan } from './brokerReplicaTopology.js';
|
|
2
|
+
import { attachBrokerMesh, brokerEndpoint } from './brokerTopology.js';
|
|
3
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
4
|
+
|
|
5
|
+
function pairsFor(machines, rules) {
|
|
6
|
+
return rules.flatMap((rule) => {
|
|
7
|
+
const rows = machines.filter(({ kind }) => { return kind === rule.kind; });
|
|
8
|
+
const homes = rows.map((row) => { return deploymentTemplate(rule.leader, row); });
|
|
9
|
+
return rows.map(({ id: machine }, index) => {
|
|
10
|
+
return { machine, leader: homes[index], standby: rule.standby ?? homes[(index + 1) % homes.length] };
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function streamPolicy(policy, machine, forwardOutbox) {
|
|
16
|
+
const rule = policy.streams.find(({ prefix }) => { return machine.startsWith(prefix); }) ?? policy.defaultStreams;
|
|
17
|
+
return deploymentTemplate(rule.templates, { machine, suffix: machine.slice(rule.prefix?.length ?? 0), forwardOutbox });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function landingBindings(result, machine, exchange, policy) {
|
|
21
|
+
const rule = policy.restoreBindings;
|
|
22
|
+
if (!rule || !machine.startsWith(rule.prefix)) { return []; }
|
|
23
|
+
const queue = deploymentTemplate(rule.queue, { machine });
|
|
24
|
+
const live = result.bindings.find(({ source, destination, routing_key: key }) => {
|
|
25
|
+
return source === rule.source && destination === queue && key.endsWith(rule.keySuffix);
|
|
26
|
+
});
|
|
27
|
+
return live ? rule.metrics.map((metric) => {
|
|
28
|
+
return { source: exchange, destination: queue, key: live.routing_key.replace('*', metric) };
|
|
29
|
+
}) : [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function attachReplicas(policy, pairs, document, node, result) {
|
|
33
|
+
if (document.edgeControlPlane?.historyEnabled !== true) { return result; }
|
|
34
|
+
const { brokerService, writerEpoch: epoch } = document.edgeControlPlane;
|
|
35
|
+
const options = { ...policy.access, fallbackPort: brokerService.nodePort };
|
|
36
|
+
const ids = new Set(pairs.flatMap(({ leader, standby }) => { return [leader, standby]; }));
|
|
37
|
+
const brokers = Object.fromEntries([...ids].map((id) => { return [id, brokerEndpoint(document, id, options)]; }));
|
|
38
|
+
const replicas = pairs.map((pair) => {
|
|
39
|
+
const streams = streamPolicy(policy, pair.machine, true);
|
|
40
|
+
const telemetry = streams.find(({ landing }) => { return landing; });
|
|
41
|
+
const { exchange } = telemetry.restore;
|
|
42
|
+
return { ...pair, epoch, streams, landings: [{ exchange, queue: telemetry.landing, keys: ['#'],
|
|
43
|
+
bindings: landingBindings(result, pair.machine, exchange, policy) }] };
|
|
44
|
+
});
|
|
45
|
+
const blocked = brokers[node] && brokerEndpoint(document, policy.archive, options);
|
|
46
|
+
return appendBrokerReplicas(result, { node, brokers, blocked, replicas });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function meshRestriction(rules, policy, node) {
|
|
50
|
+
const home = rules.groups.find(({ history, preference }) => { return history && preference[0] === node; });
|
|
51
|
+
const keys = home?.keys.filter((key) => { return policy.restrictPrefixes.some((prefix) => { return key.startsWith(prefix); }); });
|
|
52
|
+
return keys && { queue: policy.restrictQueue, keys: Object.fromEntries(keys.map((key) => {
|
|
53
|
+
return [`${key.split('.')[0]}.#`, key];
|
|
54
|
+
})) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Compile replica streams and peer mesh from the installation's topology and broker declarations. */
|
|
58
|
+
export default function brokerFleetPolicy(policy, { machines, classifierRules: rules, federation }) {
|
|
59
|
+
const pairs = pairsFor(machines, policy.pairs);
|
|
60
|
+
const meshIds = Object.freeze([...new Set([
|
|
61
|
+
...rules.groups.filter(({ history }) => { return history; }).flatMap(({ preference }) => { return preference; }),
|
|
62
|
+
...rules.mesh.originCopies,
|
|
63
|
+
...rules.groups.flatMap(({ preference }) => { return preference; })
|
|
64
|
+
])]);
|
|
65
|
+
function replicaPlan({ machine, leader, standby, epoch, brokers, central, forwardOutbox = false }) {
|
|
66
|
+
if (leader === standby) { throw new TypeError(deploymentTemplate(policy.sameTargetError, { machine })); }
|
|
67
|
+
if (!brokers[leader] || !brokers[standby]) { throw new TypeError(deploymentTemplate(policy.missingBrokerError, { machine })); }
|
|
68
|
+
return brokerReplicaPlan({ leader, standby, epoch, brokers, blocked: central,
|
|
69
|
+
exchange: policy.exchange, streams: streamPolicy(policy, machine, forwardOutbox) });
|
|
70
|
+
}
|
|
71
|
+
function edgeReplicas(brokers, central, epoch, forwardOutbox = false) {
|
|
72
|
+
return pairs.map((pair) => { return replicaPlan({ ...pair, epoch, brokers, central, forwardOutbox }); });
|
|
73
|
+
}
|
|
74
|
+
function meshEndpoint(document, node) {
|
|
75
|
+
return brokerEndpoint(document, node, { ...policy.access, ...policy.meshAccess,
|
|
76
|
+
fallbackPort: document.edgeControlPlane?.brokerService?.nodePort ?? policy.meshAccess.fallbackPort });
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
replicaPlan, edgeReplicas, meshEndpoint, meshIds,
|
|
80
|
+
edgePairs() { return pairs.map((pair) => { return { ...pair }; }); },
|
|
81
|
+
fleetFor(nodes, central, epoch) {
|
|
82
|
+
const brokers = Object.fromEntries(nodes.map(({ id, brokerEndpoint: endpoint }) => { return [id, endpoint]; }));
|
|
83
|
+
return edgeReplicas(brokers, central, epoch);
|
|
84
|
+
},
|
|
85
|
+
attachReplicas(document, node, result) { return attachReplicas(policy, pairs, document, node, result); },
|
|
86
|
+
attachTelemetryMesh(document, node, result) {
|
|
87
|
+
return attachBrokerMesh(document, node, result, { peers: meshIds, endpoint: meshEndpoint,
|
|
88
|
+
restrict: meshRestriction(rules, policy, node), federation });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import appReleases from '../../application/deploy/appReleases.js';
|
|
2
|
+
import { liveChartApps, liveChartValues } from '../../application/deploy/liveReleaseOverlay.js';
|
|
3
|
+
import readDeploymentDocument from '../../application/deploy/readDeploymentDocument.js';
|
|
4
|
+
import releases from '../../application/deploy/releases.js';
|
|
5
|
+
import { centralTelemetryChartEnv } from './centralTelemetry.js';
|
|
6
|
+
|
|
7
|
+
/** Render a declared archive contour with its immutable live chart overlays. */
|
|
8
|
+
export default function configuredArchivePlan(file, policy) {
|
|
9
|
+
const declarations = readDeploymentDocument(file).liveReleases;
|
|
10
|
+
function withLive(values, target) {
|
|
11
|
+
return Object.hasOwn(declarations, target) ? liveChartValues(values, declarations[target].chart) : values;
|
|
12
|
+
}
|
|
13
|
+
function withLiveApps(apps, target) {
|
|
14
|
+
return Object.hasOwn(declarations, target) ? liveChartApps(apps, declarations[target].apps) : apps;
|
|
15
|
+
}
|
|
16
|
+
return { withLive, withLiveApps,
|
|
17
|
+
plan(target = policy.target) {
|
|
18
|
+
if (target !== policy.target) { throw new Error(policy.targetError); }
|
|
19
|
+
const document = readDeploymentDocument(file);
|
|
20
|
+
const projected = releases(document, target);
|
|
21
|
+
return { context: policy.context, namespace: policy.namespace, release: target,
|
|
22
|
+
scada: withLive({ ...projected.scada, env: centralTelemetryChartEnv(document, policy.file, projected.scada.env) }, target),
|
|
23
|
+
apps: withLiveApps(appReleases(projected.apps, target), target) };
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { brokerStreamRoutes } from './brokerTopology.js';
|
|
2
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
3
|
+
|
|
4
|
+
function routeBindings(row, policy) {
|
|
5
|
+
const machine = row.name.split('/')[policy.pathIndex];
|
|
6
|
+
const device = machine?.replace(policy.machinePrefix, policy.devicePrefix);
|
|
7
|
+
return { name: row.name, machine, device };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function compileRule(rule, bindings, row) {
|
|
11
|
+
const route = deploymentTemplate(rule.route, bindings);
|
|
12
|
+
const metrics = rule.metrics ?? (rule.mappingKeys && Object.keys(row.mapping));
|
|
13
|
+
if (!metrics) { return route; }
|
|
14
|
+
return { ...route, keys: metrics.map((metric) => { return deploymentTemplate(rule.key, { ...bindings, metric }); }) };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Project broker route keys from declared publisher, protocol and adapter policies. */
|
|
18
|
+
export default function configuredBrokerRoutes(policy, identifyAdapter) {
|
|
19
|
+
return function routes(source) {
|
|
20
|
+
return brokerStreamRoutes(source, { service: policy.service,
|
|
21
|
+
passive(row) {
|
|
22
|
+
const { contract } = row;
|
|
23
|
+
if (!Object.hasOwn(policy.publishers, contract)) {
|
|
24
|
+
throw new Error(deploymentTemplate(policy.contractError, { contract: String(contract) }));
|
|
25
|
+
}
|
|
26
|
+
return compileRule(policy.publishers[contract], routeBindings(row, policy), row);
|
|
27
|
+
},
|
|
28
|
+
local(row) {
|
|
29
|
+
const selected = policy.protocols.find(({ prefix }) => { return row.from.startsWith(prefix); });
|
|
30
|
+
const rule = selected ?? policy.adapters[identifyAdapter(row)];
|
|
31
|
+
return compileRule(rule, routeBindings(row, policy), row);
|
|
32
|
+
} });
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import deploymentTemplate from './deploymentTemplate.js';
|
|
2
|
+
import { holdersFrom } from './highAvailability/classifyShovels.js';
|
|
3
|
+
import projectClassification from './projectClassification.js';
|
|
4
|
+
|
|
5
|
+
function localMachines(ids, rule) {
|
|
6
|
+
const pattern = new RegExp(rule.homePattern, 'u');
|
|
7
|
+
const nodes = ids.filter((id) => { return id.startsWith(rule.homePrefix); });
|
|
8
|
+
if (nodes.length < 2) { throw new TypeError(rule.minimumError); }
|
|
9
|
+
return nodes.map((home) => {
|
|
10
|
+
if (!pattern.test(home)) { throw new TypeError(deploymentTemplate(rule.targetError, { home })); }
|
|
11
|
+
return { machine: rule.machinePrefix + home.at(-1), home, eligibleNodes: [...ids], area: rule.homeArea };
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function remoteMachines(ids, rule) {
|
|
16
|
+
const eligibleNodes = ids.filter((id) => { return rule.remoteEligible.includes(id); });
|
|
17
|
+
return rule.remoteMachines.map((machine) => {
|
|
18
|
+
return { machine, home: rule.remoteHome, eligibleNodes, area: rule.remoteArea };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Project classification tasks with the installation's declared home and spare groups. */
|
|
23
|
+
export function configuredClassification(policy, calculatePlacement) {
|
|
24
|
+
const { classification: rule } = policy;
|
|
25
|
+
return {
|
|
26
|
+
plan(ids, brokers, central, holders = {}) {
|
|
27
|
+
return projectClassification(localMachines(ids, rule), { ...rule, brokers, central, holders });
|
|
28
|
+
},
|
|
29
|
+
forControl(plant, config) {
|
|
30
|
+
const central = plant.servers.find(({ id }) => { return id === policy.central; })
|
|
31
|
+
?.api.find(({ id }) => { return id === policy.brokerApi; })?.url;
|
|
32
|
+
if (!central) { throw new TypeError(rule.centralError); }
|
|
33
|
+
const ids = config.nodes.map(({ id }) => { return id; });
|
|
34
|
+
const declarations = [...localMachines(ids, rule), ...remoteMachines(ids, rule)].map(({ area, ...item }) => {
|
|
35
|
+
return { ...item, placement: calculatePlacement(config, area, item.home, ids) };
|
|
36
|
+
});
|
|
37
|
+
const brokers = Object.fromEntries(config.nodes.map(({ id, brokerEndpoint }) => { return [id, brokerEndpoint]; }));
|
|
38
|
+
return projectClassification(declarations, { ...rule, brokers, central,
|
|
39
|
+
holders: { ...holdersFrom(config.classifyRecord ?? {}), ...config.classificationHolders } });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function location(server, service) {
|
|
45
|
+
const endpoint = server.api?.find(({ id }) => { return id === service; });
|
|
46
|
+
if (!endpoint?.url) { return []; }
|
|
47
|
+
const url = new URL(endpoint.url);
|
|
48
|
+
return [[server.id, `${url.protocol}//${url.host}`]];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Resolve the peer directory behind an enabled classification service. */
|
|
52
|
+
export function classificationEnvironment(policy) {
|
|
53
|
+
return function environment(target, document) {
|
|
54
|
+
if (!document?.[policy.section]?.enabled) { return {}; }
|
|
55
|
+
const peers = Object.fromEntries((document.servers || []).flatMap((server) => { return location(server, policy.service); }));
|
|
56
|
+
return deploymentTemplate(policy.values, { target, peers });
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Project classifier chart values using the declared profile and config renderer. */
|
|
61
|
+
export function configuredSupervisor(policy, render) {
|
|
62
|
+
return function supervisor(config, node, machines = null) {
|
|
63
|
+
const home = node.id.startsWith(policy.homePrefix);
|
|
64
|
+
const targetMachine = policy.machinePrefix + node.id.at(-1);
|
|
65
|
+
const defaults = home ? [targetMachine] : [];
|
|
66
|
+
const selected = machines?.length ? [...new Set(machines)] : defaults;
|
|
67
|
+
const credentials = home ? policy.homeSecret : policy.deliverySecret;
|
|
68
|
+
const env = Object.fromEntries(policy.secretKeys.map((key) => { return [key, { valueFrom: { secretKeyRef: { name: credentials, key } } }]; }));
|
|
69
|
+
return { chart: policy.chart, release: policy.releases[node.id] ?? policy.defaultRelease, values: {
|
|
70
|
+
image: config.supervisorImage ?? null, config: render(node.id, false, selected, policy.checkpoint),
|
|
71
|
+
writerEpoch: config.writerEpoch, machines: selected, env, history: { retentionDays: config.historyRetentionDays }
|
|
72
|
+
} };
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import publicBrokerPlan from './publicBrokerPlan.js';
|
|
3
|
+
import executeConfiguredChartDeployment from './executeConfiguredChartDeployment.js';
|
|
4
|
+
import { brokerPolicy } from './securityPolicy.js';
|
|
5
|
+
|
|
6
|
+
/** Apply the common broker preparation, preflight and reconciliation around a collector chart. */
|
|
7
|
+
export default function configuredCollectorChartDeployment(policy, { chartRoot, resolveSecurity, plan, preflight, reconcile }) {
|
|
8
|
+
return function deploy(action, execute = execFileSync, cluster = policy.defaultTarget, inputSecurity = null, document = null) {
|
|
9
|
+
let broker;
|
|
10
|
+
return executeConfiguredChartDeployment(policy, action, {
|
|
11
|
+
chartRoot, execute,
|
|
12
|
+
create() {
|
|
13
|
+
const security = resolveSecurity(action, cluster, execute, inputSecurity);
|
|
14
|
+
broker = brokerPolicy(security);
|
|
15
|
+
const compiled = plan(cluster, document, security);
|
|
16
|
+
return { plan: action === 'render' ? publicBrokerPlan(compiled) : compiled, bindings: { security, broker } };
|
|
17
|
+
},
|
|
18
|
+
preflight(current) { preflight(current, execute); },
|
|
19
|
+
afterReady(current, kube) { reconcile(current, kube, broker, execute); }
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -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
|
+
}
|