@yarkivaev/scada 2.7.1 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +4 -4
  2. package/package.json +6 -3
  3. package/stream-processing/dependencies/stream-worker.jar +0 -0
  4. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Condition.scala +1 -1
  5. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/CyclePhases.scala +1 -1
  6. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Decision.scala +1 -1
  7. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Emission.scala +1 -1
  8. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineConfig.scala +1 -1
  9. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineId.scala +1 -1
  10. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineMode.scala +1 -1
  11. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Params.scala +1 -1
  12. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Reading.scala +1 -1
  13. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/ReadingWorker.scala +12 -7
  14. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Segment.scala +1 -1
  15. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/SegmentDef.scala +1 -1
  16. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Segmentation.scala +6 -22
  17. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Segments.scala +1 -1
  18. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/SplitFollow.scala +1 -1
  19. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/SplitPieces.scala +1 -1
  20. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/TagDef.scala +1 -1
  21. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/TaggedSegment.scala +1 -1
  22. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Tagging.scala +1 -1
  23. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Timestamp.scala +1 -1
  24. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/segmentation/Timeline.scala +2 -2
  25. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/Checkpoint.scala +2 -2
  26. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/ClickhouseReadingsCheckpoint.scala +3 -3
  27. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/SupervisorSinkCheckpoint.scala +3 -3
  28. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/AppConfig.scala +2 -2
  29. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/ConfigLoad.scala +2 -2
  30. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/ConfigProfile.scala +2 -2
  31. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/mqtt/Mqtt.scala +3 -3
  32. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/mqtt/Sessions.scala +1 -1
  33. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/AtomicStateFile.scala +1 -1
  34. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/CheckpointSegments.scala +5 -5
  35. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/SegmentStatePolicy.scala +2 -2
  36. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/Segments.scala +3 -3
  37. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/ClassifyQueue.scala +2 -2
  38. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/DecisionMessage.scala +2 -2
  39. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/DurableStomp.scala +1 -1
  40. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SegmentMessage.scala +2 -2
  41. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SegmentWirePolicy.scala +2 -2
  42. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SplitFamily.scala +2 -2
  43. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompConnection.scala +1 -1
  44. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompDecisions.scala +3 -3
  45. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompFrame.scala +1 -1
  46. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompMachineDecisions.scala +3 -3
  47. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompQueue.scala +1 -1
  48. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompReadings.scala +3 -3
  49. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompSegments.scala +4 -4
  50. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ClassifyHistory.scala +3 -3
  51. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ClassifyStreams.scala +42 -18
  52. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Close.scala +4 -4
  53. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HealthServer.scala +1 -1
  54. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryBus.scala +4 -4
  55. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryClient.scala +2 -2
  56. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryRun.scala +18 -14
  57. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/LocalHistory.scala +6 -6
  58. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ObservationLead.scala +1 -1
  59. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Orphans.scala +4 -4
  60. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/PendingIsland.scala +3 -3
  61. package/{supervisor-engine/src/main/scala/scada/supervisor/runtime/EngineApp.scala → stream-processing/src/main/scala/scada/processing/runtime/ProcessingApp.scala} +2 -2
  62. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ProcessingApplication.scala +10 -11
  63. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/RuntimeProfile.scala +7 -8
  64. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Seeding.scala +4 -4
  65. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/TimelineWriter.scala +3 -3
  66. package/{supervisor-engine/src/main/scala/scada/stream/worker/postgres → stream-processing/src/main/scala/scada/processing/runtime}/WorkerDatabase.scala +2 -2
  67. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterEpoch.scala +1 -1
  68. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterGate.scala +1 -1
  69. package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterLease.scala +4 -21
  70. package/{supervisor-engine → stream-processing}/src/main/scala/scada/stream/replay/Replay.scala +1 -1
  71. package/stream-processing/stream-worker.lock +2 -0
  72. package/supervisor-engine/src/main/scala/scada/stream/worker/OutputScope.scala +0 -13
  73. package/supervisor-engine/src/main/scala/scada/stream/worker/Processor.scala +0 -8
  74. package/supervisor-engine/src/main/scala/scada/stream/worker/StreamWorker.scala +0 -135
  75. package/supervisor-engine/src/main/scala/scada/stream/worker/postgres/PgCheckpointStore.scala +0 -83
  76. package/supervisor-engine/src/main/scala/scada/supervisor/runtime/ClassifierCursors.scala +0 -58
  77. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/LICENSE +0 -0
  78. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/UPSTREAM +0 -0
  79. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/Island.scala +0 -0
  80. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandEvent.scala +0 -0
  81. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsFlow.scala +0 -0
  82. /package/{supervisor-engine → stream-processing}/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsPolicy.scala +0 -0
  83. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/LICENSE +0 -0
  84. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/UPSTREAM +0 -0
  85. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/History.scala +0 -0
  86. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/LocalStreams.scala +0 -0
  87. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/Overlay.scala +0 -0
  88. /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/Worker.scala +0 -0
package/README.md CHANGED
@@ -1,20 +1,20 @@
1
1
  # SCADA
2
2
 
3
- `@yarkivaev/scada` provides the collector runtime, Scala Supervisor engine, state sink and plant API for industrial monitoring.
3
+ `@yarkivaev/scada` provides the collector runtime, Scala stream processing, state sink and plant API for industrial monitoring.
4
4
 
5
5
  - [Quick-start guide](docs/quick-start.md) — install the package and run a local API.
6
6
  - [Documentation](docs/README.md) — installation, architecture, collection, operations and reference.
7
7
 
8
8
  ## Architecture
9
9
 
10
- ![A collector publishes readings to RabbitMQ. Supervisor classifies the readings into segments, the state sink writes to PostgreSQL, and the site exposes the plant API.](docs/architecture/diagrams/single-edge-site.svg)
10
+ ![A collector publishes readings to RabbitMQ. Stream processing classifies the readings into segments, the state sink writes to PostgreSQL, and the site exposes the plant API.](docs/architecture/diagrams/single-edge-site.svg)
11
11
 
12
12
  - **Collect near the equipment.** `scada-collector` runs device and stream adapters and delivers readings to their configured destinations.
13
- - **Process readings with plant rules.** [Supervisor](supervisor-engine/README.md) turns telemetry into timeline segments. The [state sink](docs/architecture/README.md#state-sink) persists segments, decisions and alerts, and the site API serves them to clients.
13
+ - **Process readings with plant rules.** [Stream processing](stream-processing/README.md) turns telemetry into timeline segments. The [state sink](docs/architecture/README.md#state-sink) persists segments, decisions and alerts, and the site API serves them to clients.
14
14
  - **Keep plant state local.** An edge site can store its metrics and state in PostgreSQL. A central site can archive selected metrics from multiple edge sites in ClickHouse.
15
15
  - **Manage placement separately.** Agents can run from local manifests. An optional `scada-controller` assigns work through etcd, and agents can continue running saved assignments during a control-plane outage.
16
16
 
17
- For high availability, run collector copies on eligible nodes, prepare a standby Supervisor and persist historical work so another worker can resume it. See [High availability](docs/architecture/high-availability.md) for the guarantees and their prerequisites.
17
+ For high availability, run collector copies on eligible nodes, prepare a standby stream processor and persist historical work so another worker can resume it. See [High availability](docs/architecture/high-availability.md) for the guarantees and their prerequisites.
18
18
 
19
19
  ## Package boundary
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.7.1",
3
+ "version": "2.8.0",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,6 +33,7 @@
33
33
  "test": "mocha --exit 'test/**/test*.js'",
34
34
  "test:deep": "mocha --exit 'test/domain/**/test*.js' 'test/infrastructure/ingest/**/test*.js'",
35
35
  "coverage": "c8 --all --src src npm test",
36
+ "prepack": "sh stream-processing/resolve-worker.sh",
36
37
  "lint": "eslint . && node scripts/check-eo-names.mjs",
37
38
  "lint:fix": "eslint . --fix",
38
39
  "lint:eo": "node scripts/check-eo-names.mjs"
@@ -65,8 +66,10 @@
65
66
  "index.js",
66
67
  "charts/",
67
68
  "db/",
68
- "supervisor-engine/src/main/scala/",
69
- "supervisor-engine/vendor/",
69
+ "stream-processing/src/main/scala/",
70
+ "stream-processing/vendor/",
71
+ "stream-processing/dependencies/stream-worker.jar",
72
+ "stream-processing/stream-worker.lock",
70
73
  "src/"
71
74
  ]
72
75
  }
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Declarative predicate over a single [[Reading]]. Smart object:
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * One cycle phase loaded from HOCON: optional `enter` anchor and the
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  import cats.Monad
4
4
  import cats.MonadThrow
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Lifecycle marker for a value flowing through the pipeline.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Per-machine supervision configuration.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Type-safe identifier for a supervised machine. Opaque over
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /** Marker for machine configuration interpreted by a site profile. */
4
4
  trait MachineMode
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Immutable snapshot of the named metric values attached to one
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * One sensor observation for a machine at one instant. The atomic
@@ -1,19 +1,18 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  import cats.effect.IO
4
4
  import cats.syntax.all.*
5
5
  import fs2.Stream
6
- import scada.stream.worker.*
7
- import scada.supervisor.core.segmentation.Timeline.Interval
6
+ import io.yarkivaev.streamworker.*
7
+ import scada.processing.core.segmentation.Timeline.Interval
8
8
  import scala.concurrent.duration.*
9
9
 
10
10
  /** Assembles the MQTT session input and its segment output port. */
11
11
  final class ReadingWorker(
12
- segmentation: Segmentation[IO],
12
+ segmentation: Segmentation,
13
13
  tagging: Tagging,
14
14
  segments: Segments[IO],
15
15
  phases: CyclePhases = CyclePhases.empty,
16
- customRun: Option[(MachineConfig, Stream[IO, Reading], Segments[IO]) => IO[Unit]] = None,
17
16
  outputs: Option[OutputScope] = None
18
17
  ):
19
18
  import ReadingWorker.*
@@ -31,7 +30,7 @@ final class ReadingWorker(
31
30
 
32
31
  def run(machine: MachineConfig, readings: Stream[IO, Reading], initial: Option[SegmentCursor] = None): IO[Unit] =
33
32
  if machine.mode.isDefined then
34
- customRun.fold(IO.raiseError(IllegalStateException("Machine mode has no configured worker")))(_(machine, readings, segments))
33
+ IO.raiseError(IllegalStateException("A machine mode requires its own processor profile"))
35
34
  else
36
35
  for
37
36
  id <- IO.randomUUID
@@ -42,7 +41,7 @@ final class ReadingWorker(
42
41
  worker = StreamWorker(processor, store, (_, row) =>
43
42
  outputs.fold(write(machine, row.value))(_.within(row.id)(write(machine, row.value))))
44
43
  _ <- worker.run(task, mqttVersion, machine, 1): _ =>
45
- val samples = segmentation.gather(readings).map(reading => IO.pure(Input.Sample(reading)))
44
+ val samples = prepareInput(readings).map(reading => IO.pure(Input.Sample(reading)))
46
45
  val beats = Stream.awakeEvery[IO](1.second).as(for
47
46
  rows <- segments.list(machine.id)
48
47
  now <- IO.realTime.map(value => Timestamp(value.toMillis.toDouble / 1000.0))
@@ -60,6 +59,12 @@ object ReadingWorker:
60
59
  private type State = Option[Interval[Reading]]
61
60
  private val mqttVersion = ProcessorVersion("mqtt-segments/1", "session", "timeline/1")
62
61
 
62
+ private[processing] def prepareInput(input: Stream[IO, Reading]): Stream[IO, Reading] =
63
+ input.groupWithin(32, 50.millis).flatMap: chunk =>
64
+ Stream.emits:
65
+ chunk.toList.groupBy(_.timestamp.epoch).toList.sortBy(_._1).map: (_, rows) =>
66
+ rows.reduce((left, right) => Reading(right.timestamp, left.params.merge(right.params)))
67
+
63
68
  private enum Input:
64
69
  case Sample(reading: Reading)
65
70
  case Restore(cursor: SegmentCursor)
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * A named, closed time interval produced by segmentation from a
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * One named segment kind for a machine: a label and the predicate
@@ -1,11 +1,8 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
- import cats.effect.Async
4
- import fs2.{Pipe, Stream}
5
- import scala.concurrent.duration.*
6
- import scada.stream.worker.{ProcessingError, Processor, StepResult}
7
- import scada.supervisor.core.segmentation.Timeline
8
- import scada.supervisor.core.segmentation.Timeline.{Boundary, Event, Interval, Output}
3
+ import io.yarkivaev.streamworker.{ProcessingError, Processor, StepResult}
4
+ import scada.processing.core.segmentation.Timeline
5
+ import scada.processing.core.segmentation.Timeline.{Boundary, Event, Interval, Output}
9
6
 
10
7
  final case class ReadingOverride(name: String, properties: Map[String, String])
11
8
 
@@ -13,18 +10,11 @@ final case class ReadingOverride(name: String, properties: Map[String, String])
13
10
  * Class changes close at the next phase's first sample. A gap over twice
14
11
  * the machine's window splits equal phases without inventing downtime.
15
12
  */
16
- final class Segmentation[F[_]: Async](overrideReading: Reading => Option[ReadingOverride] = _ => None)
13
+ final class Segmentation(overrideReading: Reading => Option[ReadingOverride] = _ => None)
17
14
  extends Processor[MachineConfig, Option[Interval[Reading]], Reading, Emission[Segment]]:
18
15
  private val unclassified = "unclassified"
19
16
 
20
- def flow(machine: MachineConfig, initial: Option[SegmentCursor] = None): Pipe[F, Reading, Emission[Segment]] =
21
- input =>
22
- gather(input).mapAccumulate(seed(initial)): (open, reading) =>
23
- val result = advance(machine, open, reading)
24
- (result.state, result.outputs)
25
- .flatMap((_, emissions) => Stream.emits(emissions))
26
-
27
- private[core] def seed(initial: Option[SegmentCursor]): Option[Interval[Reading]] =
17
+ private[processing] def seed(initial: Option[SegmentCursor]): Option[Interval[Reading]] =
28
18
  initial.map: cursor =>
29
19
  Interval(cursor.name, Reading(cursor.start, Params(Map.empty)), Reading(cursor.end, Params(Map.empty)))
30
20
 
@@ -41,12 +31,6 @@ final class Segmentation[F[_]: Async](overrideReading: Reading => Option[Reading
41
31
  val result = Timeline.step(Boundary.Live, open, Event.Sample(reading, name, continuous))
42
32
  StepResult(result.open, result.outputs.flatMap(toEmission))
43
33
 
44
- private[core] def gather(in: Stream[F, Reading]): Stream[F, Reading] =
45
- in.groupWithin(32, 50.millis).flatMap: chunk =>
46
- Stream.emits:
47
- chunk.toList.groupBy(_.timestamp.epoch).toList.sortBy(_._1).map: (_, rows) =>
48
- rows.reduce((left, right) => Reading(right.timestamp, left.params.merge(right.params)))
49
-
50
34
  private def toEmission(output: Output[Reading]): Option[Emission[Segment]] =
51
35
  def segment(interval: Interval[Reading], closed: Boolean): Segment =
52
36
  val start = interval.start.timestamp
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  import cats.Monad
4
4
  import cats.syntax.all.*
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  import scala.collection.immutable.SortedMap
4
4
 
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Turns one operator split of an `off` island into flat `off` rows.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * One conditional label. When exactly one [[TagDef]] matches a
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * A [[Segment]] decorated with tagging output:
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Pure tagging of a [[Segment]] against a list of [[TagDef]]s.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.core
1
+ package scada.processing.core
2
2
 
3
3
  /**
4
4
  * Epoch seconds (double, millisecond precision) as an opaque type so
@@ -1,6 +1,6 @@
1
- package scada.supervisor.core.segmentation
1
+ package scada.processing.core.segmentation
2
2
 
3
- import scada.supervisor.core.{Params, SegmentDef}
3
+ import scada.processing.core.{Params, SegmentDef}
4
4
 
5
5
  /** Transitions over classified samples in input order. The coordinate type is
6
6
  * chosen by the caller and is never rounded or compared here.
@@ -1,8 +1,8 @@
1
- package scada.supervisor.infra.checkpoint
1
+ package scada.processing.infra.checkpoint
2
2
 
3
3
  import cats.effect.IO
4
4
  import fs2.Stream
5
- import scada.supervisor.core.*
5
+ import scada.processing.core.*
6
6
 
7
7
  /**
8
8
  * One raw metric row used to seed segmentation on startup.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.checkpoint
1
+ package scada.processing.infra.checkpoint
2
2
 
3
3
  import cats.effect.IO
4
4
  import cats.syntax.all.*
@@ -7,8 +7,8 @@ import io.circe.parser.parse
7
7
  import java.net.URI
8
8
  import java.net.http.{HttpClient, HttpRequest, HttpResponse}
9
9
  import java.time.Duration
10
- import scada.supervisor.core.*
11
- import scada.supervisor.infra.config.ClickhouseReadingsConfig
10
+ import scada.processing.core.*
11
+ import scada.processing.infra.config.ClickhouseReadingsConfig
12
12
 
13
13
  /**
14
14
  * Decorator that overrides readings fetch with ClickHouse paging.
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.checkpoint
1
+ package scada.processing.infra.checkpoint
2
2
 
3
3
  import cats.data.NonEmptyList
4
4
  import cats.effect.IO
@@ -13,8 +13,8 @@ import java.util.concurrent.TimeUnit
13
13
  import org.typelevel.log4cats.Logger
14
14
  import org.typelevel.log4cats.slf4j.Slf4jLogger
15
15
  import scala.concurrent.duration.*
16
- import scada.supervisor.core.*
17
- import scada.supervisor.infra.config.CheckpointApiConfig
16
+ import scada.processing.core.*
17
+ import scada.processing.infra.config.CheckpointApiConfig
18
18
 
19
19
  /**
20
20
  * HTTP checkpoint client against supervisor-sink /v1/checkpoint API.
@@ -1,6 +1,6 @@
1
- package scada.supervisor.infra.config
1
+ package scada.processing.infra.config
2
2
 
3
- import scada.supervisor.core.{CyclePhases, MachineConfig, MachineId}
3
+ import scada.processing.core.{CyclePhases, MachineConfig, MachineId}
4
4
 
5
5
  /**
6
6
  * Alias routing entry: which MQTT topic carries which metric.
@@ -1,8 +1,8 @@
1
- package scada.supervisor.infra.config
1
+ package scada.processing.infra.config
2
2
 
3
3
  import cats.effect.IO
4
4
  import com.typesafe.config.{Config, ConfigFactory, ConfigValueType}
5
- import scada.supervisor.core.*
5
+ import scada.processing.core.*
6
6
  import scala.jdk.CollectionConverters.*
7
7
 
8
8
  /**
@@ -1,7 +1,7 @@
1
- package scada.supervisor.infra.config
1
+ package scada.processing.infra.config
2
2
 
3
3
  import com.typesafe.config.Config
4
- import scada.supervisor.core.{MachineConfig, MachineMode}
4
+ import scada.processing.core.{MachineConfig, MachineMode}
5
5
 
6
6
  /** Extension points for site-specific HOCON rules and groups. */
7
7
  trait ConfigProfile:
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.mqtt
1
+ package scada.processing.infra.mqtt
2
2
 
3
3
  import cats.effect.{IO, Resource}
4
4
  import fs2.Stream
@@ -14,8 +14,8 @@ import org.eclipse.paho.client.mqttv3.{
14
14
  import org.slf4j.LoggerFactory
15
15
  import org.typelevel.log4cats.Logger
16
16
  import org.typelevel.log4cats.slf4j.Slf4jLogger
17
- import scada.supervisor.core.*
18
- import scada.supervisor.infra.config.{AliasMapping, MqttConfig}
17
+ import scada.processing.core.*
18
+ import scada.processing.infra.config.{AliasMapping, MqttConfig}
19
19
  import scala.concurrent.duration.*
20
20
 
21
21
  /**
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.mqtt
1
+ package scada.processing.infra.mqtt
2
2
 
3
3
  import cats.effect.IO
4
4
  import fs2.Stream
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.state
1
+ package scada.processing.infra.state
2
2
 
3
3
  import cats.effect.IO
4
4
  import java.nio.ByteBuffer
@@ -1,14 +1,14 @@
1
- package scada.supervisor.infra.state
1
+ package scada.processing.infra.state
2
2
 
3
3
  import cats.effect.IO
4
4
  import cats.syntax.all.*
5
- import scada.supervisor.core.*
6
- import scada.supervisor.core.Segments as CoreSegments
7
- import scada.supervisor.infra.checkpoint.Checkpoint
5
+ import scada.processing.core.*
6
+ import scada.processing.core.Segments as CoreSegments
7
+ import scada.processing.infra.checkpoint.Checkpoint
8
8
 
9
9
  /**
10
10
  * [[CoreSegments]] decorator that falls back to checkpoint API when
11
- * the in-memory store misses one segment row. Legacy `list` stays in memory.
11
+ * the in-memory store misses one segment row. `list` uses the local cache unless checkpoint-first reads are configured.
12
12
  * History-mode decision reads may prefer checkpoint snapshots, refreshing exact
13
13
  * cached keys through an injected port. Lists refresh already-known sibling keys;
14
14
  * this decorator does not download or discover the complete historical family.
@@ -1,6 +1,6 @@
1
- package scada.supervisor.infra.state
1
+ package scada.processing.infra.state
2
2
 
3
- import scada.supervisor.core.TaggedSegment
3
+ import scada.processing.core.TaggedSegment
4
4
 
5
5
  /** Preserves or replaces operator annotations when a segment is updated. */
6
6
  trait SegmentStatePolicy:
@@ -1,10 +1,10 @@
1
- package scada.supervisor.infra.state
1
+ package scada.processing.infra.state
2
2
 
3
3
  import cats.Functor
4
4
  import cats.effect.Ref
5
5
  import cats.syntax.all.*
6
- import scada.supervisor.core.*
7
- import scada.supervisor.core.Segments as CoreSegments
6
+ import scada.processing.core.*
7
+ import scada.processing.core.Segments as CoreSegments
8
8
  import scala.collection.immutable.SortedMap
9
9
 
10
10
  /**
@@ -1,10 +1,10 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO, Resource}
4
4
  import fs2.Stream
5
5
  import io.circe.parser.parse
6
6
  import io.yarkivaev.temporal.Observation
7
- import scada.supervisor.infra.config.{AliasMapping, RabbitMqConfig}
7
+ import scada.processing.infra.config.{AliasMapping, RabbitMqConfig}
8
8
 
9
9
  /**
10
10
  * Durable AMQP classify queue for one machine. MQTT slash aliases match
@@ -1,8 +1,8 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import io.circe.Json
4
4
  import io.circe.parser.parse as parseJson
5
- import scada.supervisor.core.{Decision, MachineId, SplitEntry, Timestamp}
5
+ import scada.processing.core.{Decision, MachineId, SplitEntry, Timestamp}
6
6
 
7
7
  /**
8
8
  * Inbound-wire parser for operator [[Decision]]s arriving on the
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO, Ref}
4
4
  import scala.concurrent.duration.*
@@ -1,8 +1,8 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import io.circe.Json
4
4
  import io.circe.syntax.*
5
- import scada.supervisor.core.{MachineId, TaggedSegment}
5
+ import scada.processing.core.{MachineId, TaggedSegment}
6
6
 
7
7
  /**
8
8
  * Wire-format envelope for one event on the supervisor-sink channel.
@@ -1,6 +1,6 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
- import scada.supervisor.core.{TaggedSegment, Timestamp}
3
+ import scada.processing.core.{TaggedSegment, Timestamp}
4
4
 
5
5
  /** Controls the wire representation and publishing semantics for segment types. */
6
6
  trait SegmentWirePolicy:
@@ -1,8 +1,8 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import io.circe.Json
4
4
  import io.circe.syntax.*
5
- import scada.supervisor.core.{MachineId, TaggedSegment, Timestamp}
5
+ import scada.processing.core.{MachineId, TaggedSegment, Timestamp}
6
6
 
7
7
  /**
8
8
  * One STOMP body that replaces a whole split family. The sink applies
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO, Resource}
4
4
  import cats.syntax.all.*
@@ -1,9 +1,9 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO, Resource}
4
4
  import fs2.Stream
5
- import scada.supervisor.core.Decision
6
- import scada.supervisor.infra.config.RabbitMqConfig
5
+ import scada.processing.core.Decision
6
+ import scada.processing.infra.config.RabbitMqConfig
7
7
 
8
8
  /**
9
9
  * STOMP subscription emitting operator [[Decision]]s parsed from the
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  /**
4
4
  * Minimal STOMP 1.2 frame: command, headers, body. Round-trips via
@@ -1,9 +1,9 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.IO
4
4
  import fs2.Stream
5
- import scada.supervisor.core.{Decision,MachineId}
6
- import scada.supervisor.infra.config.RabbitMqConfig
5
+ import scada.processing.core.{Decision,MachineId}
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. */
9
9
  final class StompMachineDecisions(config: RabbitMqConfig, queue: String, machine: MachineId):
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO,Resource}
4
4
  import fs2.Stream
@@ -1,10 +1,10 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.effect.{IO, Resource}
4
4
  import fs2.Stream
5
5
  import io.circe.parser.parse
6
- import scada.supervisor.core.*
7
- import scada.supervisor.infra.config.{AliasMapping,RabbitMqConfig}
6
+ import scada.processing.core.*
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. */
10
10
  final class StompReadings(open: Resource[IO,StompLink], queue: String, aliases: List[AliasMapping]):
@@ -1,4 +1,4 @@
1
- package scada.supervisor.infra.stomp
1
+ package scada.processing.infra.stomp
2
2
 
3
3
  import cats.Monad
4
4
  import cats.effect.IO
@@ -7,9 +7,9 @@ import io.circe.Json
7
7
  import io.circe.syntax.*
8
8
  import org.typelevel.log4cats.Logger
9
9
  import org.typelevel.log4cats.slf4j.Slf4jLogger
10
- import scada.supervisor.core.*
11
- import scada.supervisor.core.Segments as CoreSegments
12
- import scada.supervisor.runtime.{HistoryHttpError, TimelineWriter}
10
+ import scada.processing.core.*
11
+ import scada.processing.core.Segments as CoreSegments
12
+ import scada.processing.runtime.{HistoryHttpError, TimelineWriter}
13
13
  import scala.collection.concurrent.TrieMap
14
14
  import scala.concurrent.duration.*
15
15