feat(grpc-data): A1 — realm-local condition placement enumeration and per-export condition listing
This commit is contained in:
+62
-3
@@ -62,9 +62,13 @@ public sealed partial class LocalExportCatalog
|
||||
areas.ToDictionary(x => x.UnsAreaId, x => x.Name, ids),
|
||||
lines.ToDictionary(x => x.UnsLineId, x => (x.UnsAreaId, x.Name), ids),
|
||||
equipment.ToDictionary(x => x.EquipmentId, x => (x.UnsLineId, x.Name), ids), referenceNames);
|
||||
var composition = AddressSpaceComposer.Compose(areas, lines, equipment, drivers, [], virtuals,
|
||||
// A1: the cluster's scripted alarms ride the same composition so their placements come from the producer the node
|
||||
// manager materialises (EquipmentScriptedAlarms); nothing the v1 catalog reads depends on them.
|
||||
var scriptedAlarms = snapshot.ScriptedAlarms.Where(x => equipmentIds.Contains(x.EquipmentId)).ToArray();
|
||||
var composition = AddressSpaceComposer.Compose(areas, lines, equipment, drivers, scriptedAlarms, virtuals,
|
||||
snapshot.Scripts, references, tags, folders, devices, groups);
|
||||
var nodes = new List<LocalDataNode>((int)count);
|
||||
var conditionPlacements = new List<LocalConditionPlacement>();
|
||||
var views = new Dictionary<(DataRealm Realm, string Kind, string Id), DataView>();
|
||||
var rawViewsByPath = new Dictionary<string, DataView>(StringComparer.Ordinal);
|
||||
const DataOperations navigation = DataOperations.Browse | DataOperations.Metadata;
|
||||
@@ -127,9 +131,14 @@ public sealed partial class LocalExportCatalog
|
||||
rawSources.Add(plan.NodeId, (source, enabled));
|
||||
var kind = ValueKind(plan.DataType);
|
||||
var supported = kind != DataValueKind.Unspecified && (!plan.IsArray || DataValue.IsSupportedArrayElementKind(kind));
|
||||
Add("RawTag", plan.TagId, plan.Name, View(DataRealm.Raw, plan.NodeId, scope), scope, RawParent(scope), source,
|
||||
var rawView = View(DataRealm.Raw, plan.NodeId, scope);
|
||||
Add("RawTag", plan.TagId, plan.Name, rawView, scope, RawParent(scope), source,
|
||||
supported ? kind : DataValueKind.Null, plan.Writable && (!plan.IsArray || plan.ArrayWritable),
|
||||
plan.IsArray, plan.ArrayLength, supported, enabled);
|
||||
// A1: a native condition's Raw placement is its RawPath (ConditionId = RawPath), under its device/group folder.
|
||||
if (plan.Alarm is not null)
|
||||
conditionPlacements.Add(new(rawView, RawParent(scope), scope, plan.Name, ConditionSourceKind.Native,
|
||||
new(AddressSpaceRealm.Raw, plan.NodeId), "RawTag", plan.TagId));
|
||||
}
|
||||
foreach (var area in areas)
|
||||
{
|
||||
@@ -141,9 +150,11 @@ public sealed partial class LocalExportCatalog
|
||||
var scope = Scope(NodeAclScopeKind.UnsLine, line.UnsLineId, DataRealm.Uns);
|
||||
Add("UnsLine", line.UnsLineId, line.Name, View(DataRealm.Uns, line.UnsLineId, scope), scope, views[(DataRealm.Uns, "UnsArea", line.UnsAreaId.ToUpperInvariant())]);
|
||||
}
|
||||
var equipmentScopes = new Dictionary<string, NodeScope>(ids);
|
||||
foreach (var item in equipment)
|
||||
{
|
||||
var scope = Scope(NodeAclScopeKind.Equipment, item.EquipmentId, DataRealm.Uns);
|
||||
equipmentScopes[item.EquipmentId] = scope;
|
||||
Add("Equipment", item.EquipmentId, item.Name, View(DataRealm.Uns, item.EquipmentId, scope), scope,
|
||||
views[(DataRealm.Uns, "UnsLine", item.UnsLineId.ToUpperInvariant())]);
|
||||
}
|
||||
@@ -172,9 +183,57 @@ public sealed partial class LocalExportCatalog
|
||||
SourceKey.ForVirtual(cluster, value.VirtualTagId, serving.NodeId, serving.Incarnation),
|
||||
kind == DataValueKind.Unspecified ? DataValueKind.Null : kind, supported: kind != DataValueKind.Unspecified, enabled: value.Enabled);
|
||||
}
|
||||
return new(cluster, serving, activation, nodes, snapshot.DataExports, maximumNodes);
|
||||
AddConditionPlacements();
|
||||
return new(cluster, serving, activation, nodes, snapshot.DataExports, maximumNodes, DistinctPlacements(conditionPlacements));
|
||||
|
||||
// A1 (§5.2): the UNS placements. Native: the RESERVED reference id Area/Line/Equipment/EffectiveName of every
|
||||
// reference to an alarm-bearing tag — the same derivation as AddressSpaceComposer.BuildUnsReferenceVariables, which
|
||||
// skips exactly these references (#896), so no UNS node exists there and the guard keeps the id unique. Scripted:
|
||||
// the ScriptedAlarmId the node manager registers the condition under. Both are authorized against the
|
||||
// equipment-owned subject and parented at the equipment. Nothing here carries a RawPath except the internal
|
||||
// OriginConditionRef of a native condition.
|
||||
void AddConditionPlacements()
|
||||
{
|
||||
var alarmPlans = composition.RawTags.Where(x => x.Alarm is not null).ToDictionary(x => x.TagId, ids);
|
||||
var areaById = areas.ToDictionary(x => x.UnsAreaId, ids);
|
||||
var lineById = lines.ToDictionary(x => x.UnsLineId, ids);
|
||||
var equipmentById = equipment.ToDictionary(x => x.EquipmentId, ids);
|
||||
foreach (var reference in references.OrderBy(x => x.UnsTagReferenceId, StringComparer.Ordinal))
|
||||
{
|
||||
if (!alarmPlans.TryGetValue(reference.TagId, out var plan)
|
||||
|| !equipmentById.TryGetValue(reference.EquipmentId, out var owner)
|
||||
|| !lineById.TryGetValue(owner.UnsLineId, out var line) || !areaById.TryGetValue(line.UnsAreaId, out var area))
|
||||
continue;
|
||||
var effectiveName = string.IsNullOrEmpty(reference.DisplayNameOverride) ? tagById[reference.TagId].Name
|
||||
: reference.DisplayNameOverride!;
|
||||
string reserved;
|
||||
try { reserved = V3NodeIds.UnsChild(V3NodeIds.Uns(area.Name, line.Name, owner.Name), effectiveName); }
|
||||
catch (ArgumentException) { continue; } // an invalid name segment: the deploy gate rejects it; never listed
|
||||
var view = new DataView(new(cluster, V3NodeIds.UnsNamespaceUri, "string", reserved), DataRealm.Uns, null, 0, reserved);
|
||||
conditionPlacements.Add(new(view, views[(DataRealm.Uns, "Equipment", owner.EquipmentId.ToUpperInvariant())],
|
||||
DataScopeSubjects.Owned(equipmentScopes[owner.EquipmentId]), effectiveName, ConditionSourceKind.Native,
|
||||
new(AddressSpaceRealm.Raw, plan.NodeId), "UnsTagReference", reference.UnsTagReferenceId));
|
||||
}
|
||||
foreach (var alarm in composition.EquipmentScriptedAlarms)
|
||||
{
|
||||
// The node manager materialises only enabled scripted alarms (AddressSpaceApplier).
|
||||
if (!alarm.Enabled || !equipmentScopes.TryGetValue(alarm.EquipmentId, out var owner)) continue;
|
||||
var view = new DataView(new(cluster, V3NodeIds.UnsNamespaceUri, "string", alarm.ScriptedAlarmId), DataRealm.Uns,
|
||||
null, 0, string.Join('/', owner.Segments.Append(alarm.Name)));
|
||||
conditionPlacements.Add(new(view, views[(DataRealm.Uns, "Equipment", alarm.EquipmentId.ToUpperInvariant())],
|
||||
DataScopeSubjects.Owned(owner), alarm.Name, ConditionSourceKind.Scripted,
|
||||
new(AddressSpaceRealm.Uns, alarm.ScriptedAlarmId), "ScriptedAlarm", alarm.ScriptedAlarmId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An address claimed by two placements is ambiguous: neither is listed (fail closed for conditions), and the v1
|
||||
/// catalog compiles exactly as before.
|
||||
/// </summary>
|
||||
private static IReadOnlyList<LocalConditionPlacement> DistinctPlacements(IEnumerable<LocalConditionPlacement> placements) =>
|
||||
placements.GroupBy(x => (x.View.Realm, x.View.Address.Identifier)).Where(x => x.Count() == 1).Select(x => x.Single()).ToArray();
|
||||
|
||||
private static DataValueKind ValueKind(string type) => type switch
|
||||
{
|
||||
"Boolean" => DataValueKind.Boolean, "SByte" => DataValueKind.Int8, "Byte" => DataValueKind.UInt8,
|
||||
|
||||
Reference in New Issue
Block a user