@yarkivaev/scada 2.7.1 → 2.9.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/README.md +4 -4
- package/package.json +8 -3
- package/stream-processing/dependencies/stream-worker.jar +0 -0
- package/stream-processing/dependencies/timeline-segmentation.jar +0 -0
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Decision.scala +2 -12
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineConfig.scala +2 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineId.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/MachineMode.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/ReadingWorker.scala +17 -22
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/core/Segments.scala +2 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/Checkpoint.scala +3 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/ClickhouseReadingsCheckpoint.scala +4 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/checkpoint/SupervisorSinkCheckpoint.scala +4 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/AppConfig.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/ConfigLoad.scala +3 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/config/ConfigProfile.scala +2 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/mqtt/Mqtt.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/mqtt/Sessions.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/AtomicStateFile.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/CheckpointSegments.scala +6 -5
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/SegmentStatePolicy.scala +2 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/state/Segments.scala +4 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/ClassifyQueue.scala +2 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/DecisionMessage.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/DurableStomp.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SegmentMessage.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SegmentWirePolicy.scala +2 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/SplitFamily.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompConnection.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompDecisions.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompFrame.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompMachineDecisions.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompQueue.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompReadings.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/infra/stomp/StompSegments.scala +5 -4
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ClassifyHistory.scala +4 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ClassifyStreams.scala +43 -18
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Close.scala +4 -4
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HealthServer.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryBus.scala +5 -4
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryClient.scala +2 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/HistoryRun.scala +18 -14
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/LocalHistory.scala +17 -65
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ObservationLead.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Orphans.scala +4 -4
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/PendingIsland.scala +4 -3
- package/{supervisor-engine/src/main/scala/scada/supervisor/runtime/EngineApp.scala → stream-processing/src/main/scala/scada/processing/runtime/ProcessingApp.scala} +2 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/ProcessingApplication.scala +11 -22
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/RuntimeProfile.scala +8 -8
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/Seeding.scala +5 -4
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/TimelineWriter.scala +3 -3
- package/{supervisor-engine/src/main/scala/scada/stream/worker/postgres → stream-processing/src/main/scala/scada/processing/runtime}/WorkerDatabase.scala +2 -2
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterEpoch.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterGate.scala +1 -1
- package/{supervisor-engine/src/main/scala/scada/supervisor → stream-processing/src/main/scala/scada/processing}/runtime/WriterLease.scala +4 -21
- package/{supervisor-engine → stream-processing}/src/main/scala/scada/stream/replay/Replay.scala +1 -1
- package/stream-processing/stream-worker.lock +2 -0
- package/stream-processing/timeline-segmentation.lock +2 -0
- package/supervisor-engine/src/main/scala/scada/stream/worker/OutputScope.scala +0 -13
- package/supervisor-engine/src/main/scala/scada/stream/worker/Processor.scala +0 -8
- package/supervisor-engine/src/main/scala/scada/stream/worker/StreamWorker.scala +0 -135
- package/supervisor-engine/src/main/scala/scada/stream/worker/postgres/PgCheckpointStore.scala +0 -83
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Condition.scala +0 -33
- package/supervisor-engine/src/main/scala/scada/supervisor/core/CyclePhases.scala +0 -65
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Emission.scala +0 -19
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Params.scala +0 -15
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Reading.scala +0 -11
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Segment.scala +0 -28
- package/supervisor-engine/src/main/scala/scada/supervisor/core/SegmentDef.scala +0 -14
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Segmentation.scala +0 -63
- package/supervisor-engine/src/main/scala/scada/supervisor/core/SplitFollow.scala +0 -50
- package/supervisor-engine/src/main/scala/scada/supervisor/core/SplitPieces.scala +0 -102
- package/supervisor-engine/src/main/scala/scada/supervisor/core/TagDef.scala +0 -12
- package/supervisor-engine/src/main/scala/scada/supervisor/core/TaggedSegment.scala +0 -19
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Tagging.scala +0 -42
- package/supervisor-engine/src/main/scala/scada/supervisor/core/Timestamp.scala +0 -26
- package/supervisor-engine/src/main/scala/scada/supervisor/core/segmentation/Timeline.scala +0 -43
- package/supervisor-engine/src/main/scala/scada/supervisor/runtime/ClassifierCursors.scala +0 -58
- package/supervisor-engine/vendor/gaps-and-islands/UPSTREAM +0 -4
- package/supervisor-engine/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/Island.scala +0 -40
- package/supervisor-engine/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandEvent.scala +0 -55
- package/supervisor-engine/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsFlow.scala +0 -127
- package/supervisor-engine/vendor/gaps-and-islands/src/main/scala/yarkivaev/gapsandislands/api/IslandsPolicy.scala +0 -105
- package/supervisor-engine/vendor/temporal-streams/LICENSE +0 -21
- /package/{supervisor-engine/vendor/gaps-and-islands → stream-processing/vendor/temporal-streams}/LICENSE +0 -0
- /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/UPSTREAM +0 -0
- /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/History.scala +0 -0
- /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/LocalStreams.scala +0 -0
- /package/{supervisor-engine → stream-processing}/vendor/temporal-streams/src/main/scala/io/yarkivaev/temporal/Overlay.scala +0 -0
- /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
|
|
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
|
-

|
|
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.** [
|
|
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
|
|
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.
|
|
3
|
+
"version": "2.9.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-dependencies.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,12 @@
|
|
|
65
66
|
"index.js",
|
|
66
67
|
"charts/",
|
|
67
68
|
"db/",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
69
|
+
"stream-processing/src/main/scala/",
|
|
70
|
+
"stream-processing/vendor/",
|
|
71
|
+
"stream-processing/dependencies/stream-worker.jar",
|
|
72
|
+
"stream-processing/stream-worker.lock",
|
|
73
|
+
"stream-processing/dependencies/timeline-segmentation.jar",
|
|
74
|
+
"stream-processing/timeline-segmentation.lock",
|
|
70
75
|
"src/"
|
|
71
76
|
]
|
|
72
77
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
package scada.
|
|
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,19 +1,19 @@
|
|
|
1
|
-
package scada.
|
|
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
|
-
import
|
|
7
|
-
import
|
|
7
|
+
import io.yarkivaev.streamworker.*
|
|
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. */
|
|
11
12
|
final class ReadingWorker(
|
|
12
|
-
segmentation: Segmentation
|
|
13
|
+
segmentation: Segmentation,
|
|
13
14
|
tagging: Tagging,
|
|
14
15
|
segments: Segments[IO],
|
|
15
16
|
phases: CyclePhases = CyclePhases.empty,
|
|
16
|
-
customRun: Option[(MachineConfig, Stream[IO, Reading], Segments[IO]) => IO[Unit]] = None,
|
|
17
17
|
outputs: Option[OutputScope] = None
|
|
18
18
|
):
|
|
19
19
|
import ReadingWorker.*
|
|
@@ -22,16 +22,16 @@ final class ReadingWorker(
|
|
|
22
22
|
def step(machine: MachineConfig, state: State, input: Input): Either[ProcessingError, StepResult[State, TaggedSegment]] =
|
|
23
23
|
input match
|
|
24
24
|
case Input.Sample(reading) =>
|
|
25
|
-
segmentation.step(machine, state, reading)
|
|
26
|
-
|
|
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))))
|
|
27
27
|
case Input.Restore(cursor) =>
|
|
28
|
-
Right(StepResult(state, Vector(pending(cursor.name, cursor.start, cursor.end))))
|
|
28
|
+
Right(StepResult(state, Vector(Segmentation.pending(cursor.name, cursor.start, cursor.end))))
|
|
29
29
|
case Input.Pulse(now, rows) =>
|
|
30
|
-
Right(StepResult(state,
|
|
30
|
+
Right(StepResult(state, Segmentation.extendPending(now, rows).toVector))
|
|
31
31
|
|
|
32
32
|
def run(machine: MachineConfig, readings: Stream[IO, Reading], initial: Option[SegmentCursor] = None): IO[Unit] =
|
|
33
33
|
if machine.mode.isDefined then
|
|
34
|
-
|
|
34
|
+
IO.raiseError(IllegalStateException("A machine mode requires its own processor profile"))
|
|
35
35
|
else
|
|
36
36
|
for
|
|
37
37
|
id <- IO.randomUUID
|
|
@@ -42,7 +42,7 @@ final class ReadingWorker(
|
|
|
42
42
|
worker = StreamWorker(processor, store, (_, row) =>
|
|
43
43
|
outputs.fold(write(machine, row.value))(_.within(row.id)(write(machine, row.value))))
|
|
44
44
|
_ <- worker.run(task, mqttVersion, machine, 1): _ =>
|
|
45
|
-
val samples =
|
|
45
|
+
val samples = prepareInput(readings).map(reading => IO.pure(Input.Sample(reading)))
|
|
46
46
|
val beats = Stream.awakeEvery[IO](1.second).as(for
|
|
47
47
|
rows <- segments.list(machine.id)
|
|
48
48
|
now <- IO.realTime.map(value => Timestamp(value.toMillis.toDouble / 1000.0))
|
|
@@ -60,18 +60,13 @@ object ReadingWorker:
|
|
|
60
60
|
private type State = Option[Interval[Reading]]
|
|
61
61
|
private val mqttVersion = ProcessorVersion("mqtt-segments/1", "session", "timeline/1")
|
|
62
62
|
|
|
63
|
+
private[processing] def prepareInput(input: Stream[IO, Reading]): Stream[IO, Reading] =
|
|
64
|
+
input.groupWithin(32, 50.millis).flatMap: chunk =>
|
|
65
|
+
Stream.emits:
|
|
66
|
+
chunk.toList.groupBy(_.timestamp.epoch).toList.sortBy(_._1).map: (_, rows) =>
|
|
67
|
+
rows.reduce((left, right) => Reading(right.timestamp, left.params.merge(right.params)))
|
|
68
|
+
|
|
63
69
|
private enum Input:
|
|
64
70
|
case Sample(reading: Reading)
|
|
65
71
|
case Restore(cursor: SegmentCursor)
|
|
66
72
|
case Pulse(now: Timestamp, rows: List[TaggedSegment])
|
|
67
|
-
|
|
68
|
-
private def pending(name: String, start: Timestamp, end: Timestamp): TaggedSegment =
|
|
69
|
-
TaggedSegment(Segment(name, start, end, 0.0), Nil, Nil, Map.empty)
|
|
70
|
-
|
|
71
|
-
private def pulse(now: Timestamp, rows: List[TaggedSegment]): Option[TaggedSegment] =
|
|
72
|
-
rows.filter(_.segment.duration == 0).maxByOption(_.segment.start) match
|
|
73
|
-
case Some(open) =>
|
|
74
|
-
Option.when(now.isAfter(open.segment.end))(open.copy(segment = open.segment.copy(end = now)))
|
|
75
|
-
case None =>
|
|
76
|
-
rows.maxByOption(_.segment.end).filter(last => now.isAfter(last.segment.end))
|
|
77
|
-
.map(last => pending(last.segment.name, last.segment.end, now))
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
package scada.
|
|
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
|
-
import scada.
|
|
6
|
+
import scada.processing.core.*
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* One raw metric row used to seed segmentation on startup.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
package scada.
|
|
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
|
|
@@ -7,8 +8,8 @@ import io.circe.parser.parse
|
|
|
7
8
|
import java.net.URI
|
|
8
9
|
import java.net.http.{HttpClient, HttpRequest, HttpResponse}
|
|
9
10
|
import java.time.Duration
|
|
10
|
-
import scada.
|
|
11
|
-
import scada.
|
|
11
|
+
import scada.processing.core.*
|
|
12
|
+
import scada.processing.infra.config.ClickhouseReadingsConfig
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Decorator that overrides readings fetch with ClickHouse paging.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
package scada.
|
|
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
|
|
@@ -13,8 +14,8 @@ import java.util.concurrent.TimeUnit
|
|
|
13
14
|
import org.typelevel.log4cats.Logger
|
|
14
15
|
import org.typelevel.log4cats.slf4j.Slf4jLogger
|
|
15
16
|
import scala.concurrent.duration.*
|
|
16
|
-
import scada.
|
|
17
|
-
import scada.
|
|
17
|
+
import scada.processing.core.*
|
|
18
|
+
import scada.processing.infra.config.CheckpointApiConfig
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* HTTP checkpoint client against supervisor-sink /v1/checkpoint API.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
package scada.
|
|
2
|
-
|
|
3
|
-
import scada.supervisor.core.{CyclePhases, MachineConfig, MachineId}
|
|
1
|
+
package scada.processing.infra.config
|
|
4
2
|
|
|
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,8 +1,9 @@
|
|
|
1
|
-
package scada.
|
|
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
|
-
import scada.
|
|
6
|
+
import scada.processing.core.*
|
|
6
7
|
import scala.jdk.CollectionConverters.*
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
package scada.
|
|
1
|
+
package scada.processing.infra.config
|
|
2
2
|
|
|
3
3
|
import com.typesafe.config.Config
|
|
4
|
-
import scada.
|
|
5
|
-
|
|
4
|
+
import scada.processing.core.{MachineConfig, MachineMode}
|
|
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
|
-
package scada.
|
|
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,8 +15,7 @@ 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.
|
|
18
|
-
import scada.supervisor.infra.config.{AliasMapping, MqttConfig}
|
|
18
|
+
import scada.processing.infra.config.{AliasMapping, MqttConfig}
|
|
19
19
|
import scala.concurrent.duration.*
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
package scada.
|
|
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
|
-
import scada.
|
|
6
|
-
import scada.
|
|
7
|
-
import scada.
|
|
6
|
+
import scada.processing.core.*
|
|
7
|
+
import scada.processing.core.Segments as CoreSegments
|
|
8
|
+
import scada.processing.infra.checkpoint.Checkpoint
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* [[CoreSegments]] decorator that falls back to checkpoint API when
|
|
11
|
-
* the in-memory store misses one segment row.
|
|
12
|
+
* the in-memory store misses one segment row. `list` uses the local cache unless checkpoint-first reads are configured.
|
|
12
13
|
* History-mode decision reads may prefer checkpoint snapshots, refreshing exact
|
|
13
14
|
* cached keys through an injected port. Lists refresh already-known sibling keys;
|
|
14
15
|
* this decorator does not download or discover the complete historical family.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
package scada.
|
|
2
|
-
|
|
3
|
-
import scada.supervisor.core.TaggedSegment
|
|
1
|
+
package scada.processing.infra.state
|
|
4
2
|
|
|
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,10 +1,11 @@
|
|
|
1
|
-
package scada.
|
|
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.*
|
|
6
|
-
import scada.
|
|
7
|
-
import scada.
|
|
7
|
+
import scada.processing.core.*
|
|
8
|
+
import scada.processing.core.Segments as CoreSegments
|
|
8
9
|
import scala.collection.immutable.SortedMap
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
package scada.
|
|
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.
|
|
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,9 +1,9 @@
|
|
|
1
|
-
package scada.
|
|
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.
|
|
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
|
-
package scada.
|
|
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.
|
|
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
|
-
package scada.
|
|
2
|
-
|
|
3
|
-
import scada.supervisor.core.{TaggedSegment, Timestamp}
|
|
1
|
+
package scada.processing.infra.stomp
|
|
4
2
|
|
|
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
|
-
package scada.
|
|
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.
|
|
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
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
package scada.
|
|
1
|
+
package scada.processing.infra.stomp
|
|
2
2
|
|
|
3
3
|
import cats.effect.{IO, Resource}
|
|
4
4
|
import fs2.Stream
|
|
5
|
-
import scada.
|
|
6
|
-
import scada.
|
|
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,9 +1,9 @@
|
|
|
1
|
-
package scada.
|
|
1
|
+
package scada.processing.infra.stomp
|
|
2
2
|
|
|
3
3
|
import cats.effect.IO
|
|
4
4
|
import fs2.Stream
|
|
5
|
-
import scada.
|
|
6
|
-
import scada.
|
|
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,10 +1,10 @@
|
|
|
1
|
-
package scada.
|
|
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.
|
|
7
|
-
import scada.supervisor.infra.config.{AliasMapping,RabbitMqConfig}
|
|
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,5 +1,6 @@
|
|
|
1
|
-
package scada.
|
|
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.*
|
|
@@ -7,9 +8,9 @@ import io.circe.Json
|
|
|
7
8
|
import io.circe.syntax.*
|
|
8
9
|
import org.typelevel.log4cats.Logger
|
|
9
10
|
import org.typelevel.log4cats.slf4j.Slf4jLogger
|
|
10
|
-
import scada.
|
|
11
|
-
import scada.
|
|
12
|
-
import scada.
|
|
11
|
+
import scada.processing.core.*
|
|
12
|
+
import scada.processing.core.Segments as CoreSegments
|
|
13
|
+
import scada.processing.runtime.{HistoryHttpError, TimelineWriter}
|
|
13
14
|
import scala.collection.concurrent.TrieMap
|
|
14
15
|
import scala.concurrent.duration.*
|
|
15
16
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
package scada.
|
|
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.
|
|
10
|
-
import scada.
|
|
10
|
+
import scada.processing.core.{MachineConfig, MachineId}
|
|
11
|
+
import scada.processing.infra.stomp.SplitFamily
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Event-time machine classification from an AMQP classify stream.
|