@yarkivaev/scada 2.8.0 → 2.9.1

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 (70) hide show
  1. package/package.json +4 -2
  2. package/src/application/management/loadText.js +37 -0
  3. package/src/application/management/management.js +17 -3
  4. package/src/application/management/networkLoad.js +80 -0
  5. package/src/application/management/terminalLabel.js +6 -0
  6. package/src/application/management/topology.js +36 -0
  7. package/src/application/management/topologyStatus.js +44 -0
  8. package/src/application/management/topologyText.js +28 -0
  9. package/src/bin/scada.js +25 -7
  10. package/src/infrastructure/management/controlLoad.js +33 -0
  11. package/src/infrastructure/management/inventory.js +34 -5
  12. package/src/infrastructure/management/kubernetes.js +35 -11
  13. package/src/infrastructure/management/observations.js +80 -0
  14. package/src/infrastructure/management/prometheusLoad.js +69 -0
  15. package/src/infrastructure/management/protocol.js +51 -5
  16. package/src/infrastructure/management/rabbitmqLoad.js +79 -0
  17. package/src/infrastructure/management/responseJson.js +13 -0
  18. package/stream-processing/dependencies/timeline-segmentation.jar +0 -0
  19. package/stream-processing/src/main/scala/scada/processing/core/Decision.scala +1 -11
  20. package/stream-processing/src/main/scala/scada/processing/core/MachineConfig.scala +1 -0
  21. package/stream-processing/src/main/scala/scada/processing/core/ReadingWorker.scala +6 -16
  22. package/stream-processing/src/main/scala/scada/processing/core/Segments.scala +1 -0
  23. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/Checkpoint.scala +1 -0
  24. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/ClickhouseReadingsCheckpoint.scala +1 -0
  25. package/stream-processing/src/main/scala/scada/processing/infra/checkpoint/SupervisorSinkCheckpoint.scala +1 -0
  26. package/stream-processing/src/main/scala/scada/processing/infra/config/AppConfig.scala +2 -2
  27. package/stream-processing/src/main/scala/scada/processing/infra/config/ConfigLoad.scala +1 -0
  28. package/stream-processing/src/main/scala/scada/processing/infra/config/ConfigProfile.scala +0 -1
  29. package/stream-processing/src/main/scala/scada/processing/infra/mqtt/Mqtt.scala +1 -1
  30. package/stream-processing/src/main/scala/scada/processing/infra/state/CheckpointSegments.scala +1 -0
  31. package/stream-processing/src/main/scala/scada/processing/infra/state/SegmentStatePolicy.scala +1 -2
  32. package/stream-processing/src/main/scala/scada/processing/infra/state/Segments.scala +1 -0
  33. package/stream-processing/src/main/scala/scada/processing/infra/stomp/DecisionMessage.scala +2 -2
  34. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SegmentMessage.scala +2 -2
  35. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SegmentWirePolicy.scala +1 -2
  36. package/stream-processing/src/main/scala/scada/processing/infra/stomp/SplitFamily.scala +2 -2
  37. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompMachineDecisions.scala +1 -1
  38. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompReadings.scala +1 -1
  39. package/stream-processing/src/main/scala/scada/processing/infra/stomp/StompSegments.scala +1 -0
  40. package/stream-processing/src/main/scala/scada/processing/runtime/ClassifyHistory.scala +2 -1
  41. package/stream-processing/src/main/scala/scada/processing/runtime/ClassifyStreams.scala +1 -0
  42. package/stream-processing/src/main/scala/scada/processing/runtime/Close.scala +1 -1
  43. package/stream-processing/src/main/scala/scada/processing/runtime/HistoryBus.scala +1 -0
  44. package/stream-processing/src/main/scala/scada/processing/runtime/LocalHistory.scala +13 -61
  45. package/stream-processing/src/main/scala/scada/processing/runtime/PendingIsland.scala +2 -1
  46. package/stream-processing/src/main/scala/scada/processing/runtime/ProcessingApplication.scala +2 -12
  47. package/stream-processing/src/main/scala/scada/processing/runtime/RuntimeProfile.scala +2 -1
  48. package/stream-processing/src/main/scala/scada/processing/runtime/Seeding.scala +2 -1
  49. package/stream-processing/timeline-segmentation.lock +2 -0
  50. package/stream-processing/src/main/scala/scada/processing/core/Condition.scala +0 -33
  51. package/stream-processing/src/main/scala/scada/processing/core/CyclePhases.scala +0 -65
  52. package/stream-processing/src/main/scala/scada/processing/core/Emission.scala +0 -19
  53. package/stream-processing/src/main/scala/scada/processing/core/Params.scala +0 -15
  54. package/stream-processing/src/main/scala/scada/processing/core/Reading.scala +0 -11
  55. package/stream-processing/src/main/scala/scada/processing/core/Segment.scala +0 -28
  56. package/stream-processing/src/main/scala/scada/processing/core/SegmentDef.scala +0 -14
  57. package/stream-processing/src/main/scala/scada/processing/core/Segmentation.scala +0 -47
  58. package/stream-processing/src/main/scala/scada/processing/core/SplitFollow.scala +0 -50
  59. package/stream-processing/src/main/scala/scada/processing/core/SplitPieces.scala +0 -102
  60. package/stream-processing/src/main/scala/scada/processing/core/TagDef.scala +0 -12
  61. package/stream-processing/src/main/scala/scada/processing/core/TaggedSegment.scala +0 -19
  62. package/stream-processing/src/main/scala/scada/processing/core/Tagging.scala +0 -42
  63. package/stream-processing/src/main/scala/scada/processing/core/Timestamp.scala +0 -26
  64. package/stream-processing/src/main/scala/scada/processing/core/segmentation/Timeline.scala +0 -43
  65. package/stream-processing/vendor/gaps-and-islands/LICENSE +0 -21
  66. package/stream-processing/vendor/gaps-and-islands/UPSTREAM +0 -4
  67. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/Island.scala +0 -40
  68. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandEvent.scala +0 -55
  69. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsFlow.scala +0 -127
  70. package/stream-processing/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsPolicy.scala +0 -105
@@ -0,0 +1,69 @@
1
+ /** Read configured Prometheus instant queries as site load observations. */
2
+ import responseJson from './responseJson.js';
3
+ import { urlOf } from './protocol.js';
4
+
5
+ const maxSeries = 200;
6
+
7
+ function rowsOf({ resultType, result }) {
8
+ if (resultType === 'scalar') {
9
+ return [{ value: result }];
10
+ }
11
+ if (resultType === 'vector' && Array.isArray(result)) {
12
+ return result;
13
+ }
14
+ return [];
15
+ }
16
+
17
+ function observations(data, base, resourceLabel) {
18
+ return rowsOf(data).flatMap((series) => {
19
+ const raw = series?.value?.[1];
20
+ if (typeof raw !== 'string' || !raw.trim() || !Number.isFinite(Number(raw))) {
21
+ return [];
22
+ }
23
+ const label = resourceLabel && series.metric?.[resourceLabel];
24
+ return [{
25
+ ...base, value: Number(raw),
26
+ ...(typeof label === 'string' && label && { resource: label.replace(/\p{Cc}/gu, '') })
27
+ }];
28
+ });
29
+ }
30
+
31
+ function queryRows({ status, data }, base, resourceLabel) {
32
+ if (status !== 'success' || !data) {
33
+ return [{ ...base, error: 'Prometheus query failed' }];
34
+ }
35
+ const rows = observations(data, base, resourceLabel);
36
+ if (rows.length > maxSeries) {
37
+ return [{ ...base, error: 'too many Prometheus series for this query' }];
38
+ }
39
+ return rows.length ? rows : [{ ...base, error: 'no finite Prometheus samples' }];
40
+ }
41
+
42
+ async function measure(endpoint, headers, { name, query, unit, resourceLabel }) {
43
+ const base = { name, unit };
44
+ const url = new URL(endpoint);
45
+ url.searchParams.set('query', query);
46
+ url.searchParams.set('limit', String(maxSeries + 1));
47
+ try {
48
+ const response = await fetch(url, { method: 'GET', headers, redirect: 'error', signal: AbortSignal.timeout(10000) });
49
+ if (!response.ok) {
50
+ return [{ ...base, error: 'Prometheus query failed' }];
51
+ }
52
+ return queryRows(await responseJson(response, 1024 * 1024), base, resourceLabel);
53
+ } catch {
54
+ return [{ ...base, error: 'Prometheus query failed' }];
55
+ }
56
+ }
57
+
58
+ export default function prometheusLoad({ site, url, tokenEnv, metrics }, env = process.env) {
59
+ const endpoint = new URL('/api/v1/query', urlOf(url));
60
+ const token = tokenEnv && env[tokenEnv];
61
+ if (tokenEnv && !token) {
62
+ throw new Error(`missing credential ${tokenEnv}`);
63
+ }
64
+ const headers = token ? { authorization: `Bearer ${token}` } : {};
65
+ return { site, async sample() {
66
+ const groups = await Promise.all(metrics.map((metric) => { return measure(endpoint, headers, metric); }));
67
+ return groups.flat();
68
+ } };
69
+ }
@@ -6,6 +6,8 @@ export const contextName = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,79}$/u
6
6
  const scope = { forwarded: z.boolean().optional() };
7
7
  export const request = z.discriminatedUnion('action', [
8
8
  z.strictObject({ action: z.literal('contexts') }),
9
+ z.strictObject({ action: z.literal('status'), context: contextName.optional() }),
10
+ z.strictObject({ action: z.literal('load'), context: contextName.optional() }),
9
11
  z.strictObject({ action: z.literal('components'), context: contextName.optional(), ...scope }),
10
12
  z.strictObject({
11
13
  action: z.literal('logs'), context: contextName, ...scope,
@@ -35,17 +37,58 @@ const component = z.object({
35
37
  id: z.string(), state: z.enum(['ready', 'stopped', 'pending', 'failed'])
36
38
  });
37
39
  const changes = z.object({ changes: z.array(z.object({ id: z.string(), action: z.string() })) });
40
+ const components = z.object({ contexts: z.array(z.union([
41
+ z.object({ name: contextName, components: z.array(component) }),
42
+ z.object({ name: contextName, error: z.string() })
43
+ ])) });
44
+ const traffic = z.enum(['flowing', 'idle', 'unknown']);
45
+ const observation = z.object({
46
+ broker: contextName, queue: z.string(), stream: z.string().optional(), traffic, ackRate: z.number().optional()
47
+ });
48
+ const queue = z.object({
49
+ name: z.string(), ready: z.number().optional(), unacked: z.number().optional(), consumers: z.number().optional(),
50
+ bytes: z.number().optional(), publishRate: z.number().optional(), ackRate: z.number().optional()
51
+ });
52
+ const metric = z.union([
53
+ z.object({ name: z.string(), unit: z.string(), resource: z.string().optional(), value: z.number() }),
54
+ z.object({ name: z.string(), unit: z.string(), resource: z.string().optional(), error: z.string() })
55
+ ]);
56
+ const source = { name: contextName, site: contextName };
57
+ const sourceError = z.object({ ...source, error: z.string() });
58
+ const load = z.object({ load: z.object({
59
+ brokers: z.array(z.union([z.object({ ...source, queues: z.array(queue) }), sourceError])),
60
+ metrics: z.array(z.union([z.object({ ...source, metrics: z.array(metric) }), sourceError]))
61
+ }) });
62
+ const state = z.enum(['ready', 'degraded', 'unknown']);
63
+ const topology = z.object({ topology: z.object({
64
+ state,
65
+ namespace: z.array(z.string()),
66
+ sites: z.array(z.object({
67
+ name: z.string(), state, contexts: z.array(contextName),
68
+ objects: z.array(z.string()), localStreams: z.array(z.string())
69
+ })),
70
+ flows: z.array(z.object({
71
+ from: z.string(), to: z.string(), streams: z.array(z.string()), declared: z.boolean().optional(),
72
+ traffic, evidence: z.array(observation)
73
+ }))
74
+ }) });
38
75
  const results = {
39
76
  contexts: z.object({ contexts: z.array(z.object({ name: contextName, runtime: z.string() })) }),
40
- components: z.object({ contexts: z.array(z.union([
41
- z.object({ name: contextName, components: z.array(component) }),
42
- z.object({ name: contextName, error: z.string() })
43
- ])) }),
77
+ components,
78
+ status: z.union([topology, components]),
79
+ load,
44
80
  logs: z.object({ logs: z.string() }),
45
81
  plan: changes,
46
82
  apply: changes
47
83
  };
48
84
 
85
+ function deadline({ action, forwarded }) {
86
+ if (action === 'apply') {
87
+ return 720000;
88
+ }
89
+ return forwarded ? 45000 : 90000;
90
+ }
91
+
49
92
  export async function send(server, token, command) {
50
93
  const url = urlOf(server);
51
94
  const response = await fetch(url, {
@@ -53,9 +96,12 @@ export async function send(server, token, command) {
53
96
  headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
54
97
  body: JSON.stringify(command),
55
98
  redirect: 'error',
56
- signal: AbortSignal.timeout(command.action === 'apply' ? 720000 : 90000)
99
+ signal: AbortSignal.timeout(deadline(command))
57
100
  });
58
101
  const data = await response.json().catch(() => { return null; });
102
+ if (command.action === 'status' && response.status === 400 && data?.error === 'invalid management command') {
103
+ return send(server, token, { ...command, action: 'components' });
104
+ }
59
105
  if (!response.ok) {
60
106
  throw new Error(typeof data?.error === 'string' ? data.error : `management HTTP ${response.status}`);
61
107
  }
@@ -0,0 +1,79 @@
1
+ /** Read bounded RabbitMQ queue snapshots through the management HTTP API. */
2
+ import responseJson from './responseJson.js';
3
+ import { urlOf } from './protocol.js';
4
+
5
+ const pageSize = 100;
6
+ const maxPages = 10;
7
+
8
+ function number(value) {
9
+ return Number.isFinite(value) && value >= 0 ? value : undefined;
10
+ }
11
+
12
+ function queueOf(row) {
13
+ const stats = row.message_stats;
14
+ return {
15
+ name: row.name,
16
+ ready: number(row.messages_ready),
17
+ unacked: number(row.messages_unacknowledged),
18
+ consumers: number(row.consumers),
19
+ bytes: number(row.message_bytes),
20
+ publishRate: number(stats?.publish_details?.rate),
21
+ ackRate: number(stats?.ack_details?.rate)
22
+ };
23
+ }
24
+
25
+ function credentials({ username, passwordEnv }, env) {
26
+ if (!username) {
27
+ return {};
28
+ }
29
+ if (!env[passwordEnv]) {
30
+ throw new Error(`missing credential ${passwordEnv}`);
31
+ }
32
+ const encoded = Buffer.from(`${username}:${env[passwordEnv]}`).toString('base64');
33
+ return { authorization: `Basic ${encoded}` };
34
+ }
35
+
36
+ export default function rabbitmqLoad({ site, url, vhost, prefix, username, passwordEnv }, env) {
37
+ const { origin } = urlOf(url);
38
+ const headers = credentials({ username, passwordEnv }, env);
39
+ const endpoint = new URL(`/api/queues/${encodeURIComponent(vhost)}`, origin);
40
+ const search = endpoint.searchParams;
41
+ search.set('pagination', 'true');
42
+ search.set('page_size', String(pageSize));
43
+ if (prefix) {
44
+ search.set('name', `^${prefix.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')}`);
45
+ search.set('use_regex', 'true');
46
+ }
47
+
48
+ async function page(index) {
49
+ const target = new URL(endpoint);
50
+ target.searchParams.set('page', String(index));
51
+ const response = await fetch(target, { headers, redirect: 'error', signal: AbortSignal.timeout(8000) })
52
+ .catch(() => { throw new Error('RabbitMQ management endpoint unavailable'); });
53
+ if (!response.ok) {
54
+ throw new Error(`RabbitMQ management HTTP ${response.status}`);
55
+ }
56
+ const data = await responseJson(response, 4 * 1024 * 1024).catch(() => { return null; });
57
+ if (!Array.isArray(data?.items) || !Number.isInteger(data.page_count) || data.page_count < 0) {
58
+ throw new Error('invalid RabbitMQ queue response');
59
+ }
60
+ return data;
61
+ }
62
+
63
+ async function sample() {
64
+ const first = await page(1);
65
+ if (first.page_count > maxPages) {
66
+ throw new Error('RabbitMQ queue scope is too large; configure a narrower prefix');
67
+ }
68
+ const rest = await Promise.all(Array.from({ length: Math.max(0, first.page_count - 1) }, (unused, index) => {
69
+ return page(index + 2);
70
+ }));
71
+ const rows = [first, ...rest].flatMap(({ items }) => { return items; });
72
+ const queues = new Map(rows.filter((row) => {
73
+ return typeof row?.name === 'string' && (!prefix || row.name.startsWith(prefix));
74
+ }).map((row) => { return [row.name, queueOf(row)]; }));
75
+ return Array.from(queues.values());
76
+ }
77
+
78
+ return { site, sample };
79
+ }
@@ -0,0 +1,13 @@
1
+ /** Bound monitoring response memory, including chunked or compressed bodies. */
2
+ export default async function responseJson(response, maxBytes) {
3
+ const chunks = [];
4
+ let bytes = 0;
5
+ for await (const chunk of response.body) {
6
+ bytes += chunk.length;
7
+ if (bytes > maxBytes) {
8
+ throw new Error('monitoring response is too large');
9
+ }
10
+ chunks.push(chunk);
11
+ }
12
+ return JSON.parse(Buffer.concat(chunks).toString('utf8'));
13
+ }
@@ -1,5 +1,6 @@
1
1
  package scada.processing.core
2
2
 
3
+ import io.yarkivaev.segmentation.{SplitEntry, SplitPieces, TagDef, TaggedSegment, Tagging, Timestamp}
3
4
  import cats.Monad
4
5
  import cats.MonadThrow
5
6
  import cats.syntax.all.*
@@ -54,14 +55,3 @@ enum Decision:
54
55
  ): F[Unit] =
55
56
  val cascaded = tagging.resolve(tagDefs, seg.segment, tags)
56
57
  segments.resolve(machine, seg.segment, cascaded.tags, cascaded.options, properties)
57
-
58
- /**
59
- * One piece of a [[Decision.Split]]. `tag` may be empty when the
60
- * operator does not know the reason. `open` marks the live tail.
61
- *
62
- * {{{
63
- * SplitEntry(Timestamp(100.0), Timestamp(160.0), "maintenance")
64
- * }}}
65
- */
66
- final case class SplitEntry(start: Timestamp, end: Timestamp, tag: String, open: Boolean = false):
67
- def tagged: TaggedSegment = SplitPieces.row(start, this)
@@ -1,5 +1,6 @@
1
1
  package scada.processing.core
2
2
 
3
+ import io.yarkivaev.segmentation.{SegmentDef, TagDef}
3
4
  /**
4
5
  * Per-machine supervision configuration.
5
6
  *
@@ -1,10 +1,11 @@
1
1
  package scada.processing.core
2
2
 
3
+ import io.yarkivaev.segmentation.{CyclePhases, Reading, SegmentCursor, Segmentation, TaggedSegment, Tagging, Timestamp}
3
4
  import cats.effect.IO
4
5
  import cats.syntax.all.*
5
6
  import fs2.Stream
6
7
  import io.yarkivaev.streamworker.*
7
- import scada.processing.core.segmentation.Timeline.Interval
8
+ import io.yarkivaev.segmentation.Timeline.Interval
8
9
  import scala.concurrent.duration.*
9
10
 
10
11
  /** Assembles the MQTT session input and its segment output port. */
@@ -21,12 +22,12 @@ final class ReadingWorker(
21
22
  def step(machine: MachineConfig, state: State, input: Input): Either[ProcessingError, StepResult[State, TaggedSegment]] =
22
23
  input match
23
24
  case Input.Sample(reading) =>
24
- segmentation.step(machine, state, reading).map(result =>
25
- StepResult(result.state, result.outputs.map(emission => tagging.resolve(machine.tags, emission.value))))
25
+ val result = segmentation.step(machine.segments, machine.window, state, reading)
26
+ Right(StepResult(result.state, result.outputs.map(emission => tagging.resolve(machine.tags, emission.value))))
26
27
  case Input.Restore(cursor) =>
27
- Right(StepResult(state, Vector(pending(cursor.name, cursor.start, cursor.end))))
28
+ Right(StepResult(state, Vector(Segmentation.pending(cursor.name, cursor.start, cursor.end))))
28
29
  case Input.Pulse(now, rows) =>
29
- Right(StepResult(state, pulse(now, rows).toVector))
30
+ Right(StepResult(state, Segmentation.extendPending(now, rows).toVector))
30
31
 
31
32
  def run(machine: MachineConfig, readings: Stream[IO, Reading], initial: Option[SegmentCursor] = None): IO[Unit] =
32
33
  if machine.mode.isDefined then
@@ -69,14 +70,3 @@ object ReadingWorker:
69
70
  case Sample(reading: Reading)
70
71
  case Restore(cursor: SegmentCursor)
71
72
  case Pulse(now: Timestamp, rows: List[TaggedSegment])
72
-
73
- private def pending(name: String, start: Timestamp, end: Timestamp): TaggedSegment =
74
- TaggedSegment(Segment(name, start, end, 0.0), Nil, Nil, Map.empty)
75
-
76
- private def pulse(now: Timestamp, rows: List[TaggedSegment]): Option[TaggedSegment] =
77
- rows.filter(_.segment.duration == 0).maxByOption(_.segment.start) match
78
- case Some(open) =>
79
- Option.when(now.isAfter(open.segment.end))(open.copy(segment = open.segment.copy(end = now)))
80
- case None =>
81
- rows.maxByOption(_.segment.end).filter(last => now.isAfter(last.segment.end))
82
- .map(last => pending(last.segment.name, last.segment.end, now))
@@ -1,5 +1,6 @@
1
1
  package scada.processing.core
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, TaggedSegment, Timestamp}
3
4
  import cats.Monad
4
5
  import cats.syntax.all.*
5
6
 
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.checkpoint
2
2
 
3
+ import io.yarkivaev.segmentation.{TaggedSegment, Timestamp}
3
4
  import cats.effect.IO
4
5
  import fs2.Stream
5
6
  import scada.processing.core.*
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.checkpoint
2
2
 
3
+ import io.yarkivaev.segmentation.{TaggedSegment, Timestamp}
3
4
  import cats.effect.IO
4
5
  import cats.syntax.all.*
5
6
  import fs2.Stream
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.checkpoint
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, TaggedSegment, Timestamp}
3
4
  import cats.data.NonEmptyList
4
5
  import cats.effect.IO
5
6
  import fs2.Stream
@@ -1,7 +1,7 @@
1
1
  package scada.processing.infra.config
2
2
 
3
- import scada.processing.core.{CyclePhases, MachineConfig, MachineId}
4
-
3
+ import io.yarkivaev.segmentation.CyclePhases
4
+ import scada.processing.core.{MachineConfig, MachineId}
5
5
  /**
6
6
  * Alias routing entry: which MQTT topic carries which metric.
7
7
  *
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.config
2
2
 
3
+ import io.yarkivaev.segmentation.{Condition, CycleAnchors, CyclePhase, CyclePhases, SegmentDef, TagDef}
3
4
  import cats.effect.IO
4
5
  import com.typesafe.config.{Config, ConfigFactory, ConfigValueType}
5
6
  import scada.processing.core.*
@@ -2,7 +2,6 @@ package scada.processing.infra.config
2
2
 
3
3
  import com.typesafe.config.Config
4
4
  import scada.processing.core.{MachineConfig, MachineMode}
5
-
6
5
  /** Extension points for site-specific HOCON rules and groups. */
7
6
  trait ConfigProfile:
8
7
  def mode(machine: Config): Option[MachineMode] = None
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.mqtt
2
2
 
3
+ import io.yarkivaev.segmentation.{Params, Reading, Timestamp}
3
4
  import cats.effect.{IO, Resource}
4
5
  import fs2.Stream
5
6
  import io.circe.parser.parse as parseJson
@@ -14,7 +15,6 @@ import org.eclipse.paho.client.mqttv3.{
14
15
  import org.slf4j.LoggerFactory
15
16
  import org.typelevel.log4cats.Logger
16
17
  import org.typelevel.log4cats.slf4j.Slf4jLogger
17
- import scada.processing.core.*
18
18
  import scada.processing.infra.config.{AliasMapping, MqttConfig}
19
19
  import scala.concurrent.duration.*
20
20
 
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.state
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, TaggedSegment, Timestamp}
3
4
  import cats.effect.IO
4
5
  import cats.syntax.all.*
5
6
  import scada.processing.core.*
@@ -1,7 +1,6 @@
1
1
  package scada.processing.infra.state
2
2
 
3
- import scada.processing.core.TaggedSegment
4
-
3
+ import io.yarkivaev.segmentation.TaggedSegment
5
4
  /** Preserves or replaces operator annotations when a segment is updated. */
6
5
  trait SegmentStatePolicy:
7
6
  def merge(existing: TaggedSegment, incoming: TaggedSegment): TaggedSegment =
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.state
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, SplitFollow, TaggedSegment, Timestamp}
3
4
  import cats.Functor
4
5
  import cats.effect.Ref
5
6
  import cats.syntax.all.*
@@ -1,9 +1,9 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
+ import io.yarkivaev.segmentation.{SplitEntry, Timestamp}
3
4
  import io.circe.Json
4
5
  import io.circe.parser.parse as parseJson
5
- import scada.processing.core.{Decision, MachineId, SplitEntry, Timestamp}
6
-
6
+ import scada.processing.core.{Decision, MachineId}
7
7
  /**
8
8
  * Inbound-wire parser for operator [[Decision]]s arriving on the
9
9
  * STOMP `user_decisions` destination. Reads a JSON body and picks the
@@ -1,9 +1,9 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
+ import io.yarkivaev.segmentation.TaggedSegment
3
4
  import io.circe.Json
4
5
  import io.circe.syntax.*
5
- import scada.processing.core.{MachineId, TaggedSegment}
6
-
6
+ import scada.processing.core.MachineId
7
7
  /**
8
8
  * Wire-format envelope for one event on the supervisor-sink channel.
9
9
  * Knows how to render itself as JSON; STOMP publishing just treats the
@@ -1,7 +1,6 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
- import scada.processing.core.{TaggedSegment, Timestamp}
4
-
3
+ import io.yarkivaev.segmentation.{TaggedSegment, Timestamp}
5
4
  /** Controls the wire representation and publishing semantics for segment types. */
6
5
  trait SegmentWirePolicy:
7
6
  def boundary(row: TaggedSegment, time: Timestamp): Long = time.millis
@@ -1,9 +1,9 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
+ import io.yarkivaev.segmentation.{TaggedSegment, Timestamp}
3
4
  import io.circe.Json
4
5
  import io.circe.syntax.*
5
- import scada.processing.core.{MachineId, TaggedSegment, Timestamp}
6
-
6
+ import scada.processing.core.MachineId
7
7
  /**
8
8
  * One STOMP body that replaces a whole split family. The sink applies
9
9
  * it in a single transaction so a boundary edit cannot leave the
@@ -2,7 +2,7 @@ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.IO
4
4
  import fs2.Stream
5
- import scada.processing.core.{Decision,MachineId}
5
+ import scada.processing.core.{Decision, MachineId}
6
6
  import scada.processing.infra.config.RabbitMqConfig
7
7
 
8
8
  /** A durable per-machine copy; unrelated machine decisions are discarded only from this copy. */
@@ -1,9 +1,9 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
+ import io.yarkivaev.segmentation.{Params, Reading, Timestamp}
3
4
  import cats.effect.{IO, Resource}
4
5
  import fs2.Stream
5
6
  import io.circe.parser.parse
6
- import scada.processing.core.*
7
7
  import scada.processing.infra.config.{AliasMapping,RabbitMqConfig}
8
8
 
9
9
  /** One pre-bound durable AMQP queue preserves parameter/rise order. Slash aliases match dotted routing keys. */
@@ -1,5 +1,6 @@
1
1
  package scada.processing.infra.stomp
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, SplitFollow, TaggedSegment, Timestamp}
3
4
  import cats.Monad
4
5
  import cats.effect.IO
5
6
  import cats.syntax.all.*
@@ -1,12 +1,13 @@
1
1
  package scada.processing.runtime
2
2
 
3
+ import io.yarkivaev.segmentation.{HistorySegment, Segment, TaggedSegment, Timestamp}
3
4
  import cats.effect.{IO, Ref}
4
5
  import cats.syntax.all.*
5
6
  import fs2.Stream
6
7
  import io.circe.Json
7
8
  import io.yarkivaev.temporal.{Conflict, History, Observation}
8
9
  import java.time.Instant
9
- import scada.processing.core.{MachineConfig, MachineId, Segment, TaggedSegment, Timestamp}
10
+ import scada.processing.core.{MachineConfig, MachineId}
10
11
  import scada.processing.infra.stomp.SplitFamily
11
12
 
12
13
  /**
@@ -1,5 +1,6 @@
1
1
  package scada.processing.runtime
2
2
 
3
+ import io.yarkivaev.segmentation.{HistorySegment, HistoryState}
3
4
  import cats.effect.IO
4
5
  import cats.effect.std.Semaphore
5
6
  import fs2.Stream
@@ -1,7 +1,7 @@
1
1
  package scada.processing.runtime
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, TaggedSegment, Timestamp}
3
4
  import cats.effect.IO
4
- import scada.processing.core.*
5
5
  import scada.processing.core.Segments as CoreSegments
6
6
  import scada.processing.infra.checkpoint.PendingSegmentData
7
7
 
@@ -1,5 +1,6 @@
1
1
  package scada.processing.runtime
2
2
 
3
+ import io.yarkivaev.segmentation.{Segment, TaggedSegment, Timestamp}
3
4
  import cats.effect.IO
4
5
  import cats.syntax.all.*
5
6
  import io.circe.Json