test(grpc-data): Gateway origin backend for the history rig — read-only AVEVA bindings, reverse/end-only H07, strict-ceiling H08 (#923)
This commit is contained in:
@@ -29,6 +29,23 @@ const DataOperations operations = DataOperations.Browse | DataOperations.Metadat
|
||||
// exports gain HistoryRead, and a second principal's export lacks it. Unset ⇒ the v1 fixture, unchanged.
|
||||
var history = Environment.GetEnvironmentVariable("GRPC_DATA_HISTORY") == "1";
|
||||
var grantedOperations = history ? operations | DataOperations.HistoryRead : operations;
|
||||
// #923 Gateway origin backend (`rig.py up --history --history-backend gateway`): `name=historianTag,...` binds the historized
|
||||
// fixture tags READ-ONLY (lmxopcua#899 `historianReadOnly`) to existing tags of the real historian behind a read-only
|
||||
// HistorianGateway, so OtOpcUa never provisions or records into them. Unset ⇒ the tags own their history, as before.
|
||||
var gatewayTags = (Environment.GetEnvironmentVariable("GRPC_DATA_HISTORY_GATEWAY_TAGS") ?? "")
|
||||
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(pair => pair.Split('=', 2, StringSplitOptions.TrimEntries))
|
||||
.ToDictionary(pair => pair.Length == 2 && pair[0].Length > 0 && pair[1].Length > 0 ? pair[0] : throw new InvalidOperationException("GRPC_DATA_HISTORY_GATEWAY_TAGS entries are name=historianTag"),
|
||||
pair => pair[1], StringComparer.Ordinal);
|
||||
if (gatewayTags.Count > 0 && !history) throw new InvalidOperationException("GRPC_DATA_HISTORY_GATEWAY_TAGS needs the history profile");
|
||||
string HistoryConfig(string name, string tagConfig)
|
||||
{
|
||||
if (!gatewayTags.TryGetValue(name, out var historianTag)) return tagConfig;
|
||||
var node = System.Text.Json.Nodes.JsonNode.Parse(tagConfig)!.AsObject();
|
||||
node["historianTagname"] = historianTag;
|
||||
node["historianReadOnly"] = true;
|
||||
return node.ToJsonString();
|
||||
}
|
||||
// A2a smoke profile (opt-in, `rig.py up --conditions`): SOURCE exports gain AlarmSubscribe and the SOURCE equipment gets
|
||||
// one scripted alarm, ScalarHigh (scalar > 100), so a condition stream sees a snapshot and a delta. Unset ⇒ v1 fixture.
|
||||
var conditions = Environment.GetEnvironmentVariable("GRPC_DATA_CONDITIONS") == "1";
|
||||
@@ -360,7 +377,7 @@ try
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-" + name, DeviceId = "source-device", Name = name, DataType = "UInt16",
|
||||
AccessLevel = writable ? TagAccessLevel.ReadWrite : TagAccessLevel.Read, WriteIdempotent = false, PollGroupId = "source-fast",
|
||||
TagConfig = history && name == "counter"
|
||||
? JsonSerializer.Serialize(new { region = "HoldingRegisters", address, dataType = "UInt16", writable, isHistorized = true })
|
||||
? HistoryConfig(name, JsonSerializer.Serialize(new { region = "HoldingRegisters", address, dataType = "UInt16", writable, isHistorized = true }))
|
||||
: JsonSerializer.Serialize(new { region = "HoldingRegisters", address, dataType = "UInt16", writable }) });
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-vector", DeviceId = "source-device", Name = "vector", DataType = "UInt16",
|
||||
AccessLevel = TagAccessLevel.ReadWrite, WriteIdempotent = false, PollGroupId = "source-fast",
|
||||
@@ -368,14 +385,14 @@ try
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-text", DeviceId = "source-device", Name = "text", DataType = "String",
|
||||
AccessLevel = TagAccessLevel.ReadWrite, WriteIdempotent = false, PollGroupId = "source-fast",
|
||||
TagConfig = history
|
||||
? """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true,"isHistorized":true}"""
|
||||
? HistoryConfig("text", """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true,"isHistorized":true}""")
|
||||
: """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true}""" });
|
||||
if (history)
|
||||
// H3 review: a historized Float32 (two registers 30..31, big-endian), so the gate proves a backend that stores Double
|
||||
// still reads Good Singles through the projection.
|
||||
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-flt", DeviceId = "source-device", Name = "flt", DataType = "Float",
|
||||
AccessLevel = TagAccessLevel.ReadWrite, WriteIdempotent = false, PollGroupId = "source-fast",
|
||||
TagConfig = """{"region":"HoldingRegisters","address":30,"dataType":"Float32","writable":true,"isHistorized":true}""" });
|
||||
TagConfig = HistoryConfig("flt", """{"region":"HoldingRegisters","address":30,"dataType":"Float32","writable":true,"isHistorized":true}""") });
|
||||
db.UnsAreas.Add(new() { UnsAreaRowId = Guid.NewGuid(), UnsAreaId = "source-area", ClusterId = "SOURCE", Name = "area" });
|
||||
db.UnsLines.Add(new() { UnsLineRowId = Guid.NewGuid(), UnsLineId = "source-line", UnsAreaId = "source-area", Name = "line" });
|
||||
var uuid = Guid.NewGuid();
|
||||
|
||||
Reference in New Issue
Block a user