fix(galaxy): #895 review - re-areaed, subtag-provider and pre-subscription alarm references resolve
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
Review of e113faf5 found three gaps in the alarm-feed reverse map:
- A tag hand-authored as Galaxy!<Area>.tag.Attr stopped resolving once Galaxy moved the object to
another area: the feed's full reference named the new area and none of the fallbacks looked at the
authored provider form. Provider-form attributeRefs are now also indexed by their area-free
tag.Attr, and the ack dials the reference the feed now uses.
- A reference composed with an empty area (Galaxy!tag.Attr, the gateway's ComposeFullReference when
the area is blank) with the subtag provider's object-only source reference stripped "tag." and
missed. The part after the '!' is now also tried.
- Resolution ran after the subscription gate, so a transition seen with no handle registered taught
nothing for the ack. It now resolves first; fan-out is still gated.
A picker tag and a provider-form tag for the same alarm resolve deterministically and log a warning.
New tests cover re-area for both forms, subtag shapes, H6-style dotted refs, unmatched/malformed
refs, the collision, pre-subscription learning, and the #869 confirmation of a picker-form ack;
reverted-code runs fail them.
Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -110,6 +110,12 @@ public sealed class GalaxyDriver
|
||||
private readonly System.Collections.Concurrent.ConcurrentDictionary<string, string> _alarmFullRefByRawPath =
|
||||
new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// lmxopcua#895 review: a tag hand-authored with the provider-qualified form ("Galaxy!<Area>.<tag>.<Attr>")
|
||||
// indexed by its area-free "<tag>.<Attr>", so its alarms still resolve after Galaxy moves the object to
|
||||
// another area (the feed's full reference then names the new area and no longer matches the authored one).
|
||||
// Built once with the raw-tag tables; read-only afterwards.
|
||||
private readonly Dictionary<string, RawTagEntry> _rawTagByAreaFreeRef;
|
||||
|
||||
// PR 4.4 — subscription lifecycle. The pump consumes the gw event stream and fans
|
||||
// out OnDataChange events to every registered driver subscription via the registry's
|
||||
// reverse map. The subscriber is the test seam — production uses
|
||||
@@ -401,6 +407,7 @@ public sealed class GalaxyDriver
|
||||
// Build the v3 RawPath ⇄ attributeRef tables from the authored raw tags. Empty when no tags
|
||||
// are authored (live-browse path), leaving every translation an identity no-op.
|
||||
(_attributeRefByRawPath, _rawTagByAttributeRef) = BuildRawTagTables(_options.RawTags, _logger, _skippedTags);
|
||||
_rawTagByAreaFreeRef = BuildAreaFreeAlarmIndex(_rawTagByAttributeRef, _logger);
|
||||
|
||||
// Forward the aggregator's transitions through IHostConnectivityProbe.
|
||||
_hostStatuses.OnHostStatusChanged += (_, args) => OnHostStatusChanged?.Invoke(this, args);
|
||||
@@ -477,34 +484,75 @@ public sealed class GalaxyDriver
|
||||
/// Resolves the RawPath an alarm-feed transition belongs to (lmxopcua#895). The authored attributeRef
|
||||
/// is matched against, in order: the transition's full reference (a tag authored with the
|
||||
/// provider-qualified <c>Galaxy!Area.tag.Attr</c> form), its <c>SourceObjectReference</c>
|
||||
/// (<c>tag.Attr</c> — the form the AdminUI Galaxy picker authors), and the full reference with its
|
||||
/// <c>Provider!Area.</c> prefix stripped. Identity on a miss, as before. A match through either
|
||||
/// fallback records the full reference for <see cref="ToAlarmAckReference"/>.
|
||||
/// (<c>tag.Attr</c> — the form the AdminUI Galaxy picker authors), the full reference with its
|
||||
/// <c>Provider!Area.</c> prefix stripped (the subtag provider sends only the object as its source), and the
|
||||
/// full reference after its <c>Provider!</c> (an empty area). Those area-free names are then tried against
|
||||
/// the hand-authored <c>Galaxy!Area.tag.Attr</c> refs by their own area-free part, so a re-areaed object
|
||||
/// still resolves. Identity on a miss, as before. A match through any fallback records the full reference
|
||||
/// for <see cref="ToAlarmAckReference"/> (latest wins, so a re-area is picked up on the next transition).
|
||||
/// </summary>
|
||||
/// <param name="alarmFullReference">The feed's provider-qualified alarm reference.</param>
|
||||
/// <param name="sourceObjectReference">The feed's source reference (<c>tag.Attr</c>), may be empty.</param>
|
||||
/// <returns>The authored RawPath, or <paramref name="alarmFullReference"/> when no authored tag matches.</returns>
|
||||
internal string ResolveAlarmRawPath(string alarmFullReference, string? sourceObjectReference)
|
||||
{
|
||||
if (string.IsNullOrEmpty(alarmFullReference)) return alarmFullReference;
|
||||
if (_rawTagByAttributeRef.TryGetValue(alarmFullReference, out var direct)) return direct.RawPath;
|
||||
|
||||
if (!string.IsNullOrEmpty(sourceObjectReference)
|
||||
&& _rawTagByAttributeRef.TryGetValue(sourceObjectReference, out var bySource))
|
||||
{
|
||||
_alarmFullRefByRawPath[bySource.RawPath] = alarmFullReference;
|
||||
return bySource.RawPath;
|
||||
}
|
||||
|
||||
// The feed's area-free name for the alarm. The alarmmgr provider sends it as SourceObjectReference; the
|
||||
// subtag fallback sends only the object there, so it is also derived from the full reference — with the
|
||||
// area segment stripped, or (a reference composed with an empty area, "Galaxy!tag.Attr") everything
|
||||
// after the '!'.
|
||||
var stripped = StripProviderAndArea(alarmFullReference);
|
||||
if (stripped is not null && _rawTagByAttributeRef.TryGetValue(stripped, out var byStripped))
|
||||
var afterBang = AfterProvider(alarmFullReference);
|
||||
string?[] candidates = [sourceObjectReference, stripped, afterBang];
|
||||
|
||||
// Picker form first (attributeRef = tag.Attr), then a hand-authored Galaxy!<OldArea>.tag.Attr whose object
|
||||
// Galaxy has since moved to another area.
|
||||
foreach (var table in (Dictionary<string, RawTagEntry>[])[_rawTagByAttributeRef, _rawTagByAreaFreeRef])
|
||||
{
|
||||
_alarmFullRefByRawPath[byStripped.RawPath] = alarmFullReference;
|
||||
return byStripped.RawPath;
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
if (string.IsNullOrEmpty(candidate) || !table.TryGetValue(candidate, out var entry)) continue;
|
||||
_alarmFullRefByRawPath[entry.RawPath] = alarmFullReference;
|
||||
return entry.RawPath;
|
||||
}
|
||||
}
|
||||
|
||||
return alarmFullReference;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index the provider-qualified authored attributeRefs (<c>Galaxy!Area.tag.Attr</c>) by their area-free
|
||||
/// <c>tag.Attr</c> (lmxopcua#895 review). First wins on a shared key; an area-free key that is also authored
|
||||
/// as a plain attributeRef is left to the plain entry. Both overlaps are logged, since the losing tag's
|
||||
/// alarms then surface under another RawPath.
|
||||
/// </summary>
|
||||
private static Dictionary<string, RawTagEntry> BuildAreaFreeAlarmIndex(
|
||||
Dictionary<string, RawTagEntry> rawTagByAttributeRef, ILogger logger)
|
||||
{
|
||||
var index = new Dictionary<string, RawTagEntry>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var (attributeRef, entry) in rawTagByAttributeRef)
|
||||
{
|
||||
var areaFree = StripProviderAndArea(attributeRef);
|
||||
if (areaFree is null) continue;
|
||||
if (rawTagByAttributeRef.TryGetValue(areaFree, out var plain))
|
||||
{
|
||||
logger.LogWarning(
|
||||
"GalaxyDriver raw tags {RawPath} ({AttributeRef}) and {PlainRawPath} ({AreaFreeRef}) name the same Galaxy alarm — its transitions surface under {RawPath} while the area matches, otherwise under {PlainRawPath}.",
|
||||
entry.RawPath, attributeRef, plain.RawPath, areaFree, entry.RawPath, plain.RawPath);
|
||||
continue;
|
||||
}
|
||||
if (!index.TryAdd(areaFree, entry))
|
||||
{
|
||||
logger.LogWarning(
|
||||
"GalaxyDriver raw tags {RawPath} ({AttributeRef}) and {Winner} name the same Galaxy alarm {AreaFreeRef} in different areas — a transition from any other area surfaces under {Winner} only.",
|
||||
entry.RawPath, attributeRef, index[areaFree].RawPath, areaFree, index[areaFree].RawPath);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The reference an acknowledge of the condition <paramref name="rawPath"/> dials: the provider-qualified
|
||||
/// reference the alarm feed reported for it when one was learned (lmxopcua#895), otherwise the authored
|
||||
@@ -525,6 +573,13 @@ public sealed class GalaxyDriver
|
||||
return dot < 0 || dot == alarmFullReference.Length - 1 ? null : alarmFullReference[(dot + 1)..];
|
||||
}
|
||||
|
||||
/// <summary><c>Galaxy!tag.Attr</c> → <c>tag.Attr</c>; null without a <c>!</c> or with nothing after it.</summary>
|
||||
private static string? AfterProvider(string alarmFullReference)
|
||||
{
|
||||
var bang = alarmFullReference.IndexOf('!');
|
||||
return bang < 0 || bang == alarmFullReference.Length - 1 ? null : alarmFullReference[(bang + 1)..];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DriverInstanceId => _driverInstanceId;
|
||||
|
||||
@@ -2817,6 +2872,15 @@ public sealed class GalaxyDriver
|
||||
// subscription gate below, which only governs fan-out to OnAlarmEvent.
|
||||
_ackConfirmations.Observe(transition);
|
||||
|
||||
// v3: the ConditionId the driver reports must be the tag's RawPath — the same key the value
|
||||
// fan-out uses (OnPumpDataChange) and the identity the discoverer stamped as SourceName — so the
|
||||
// server-side condition state correlates the alarm to its node and a subsequent ack round-trips
|
||||
// back through AcknowledgeAsync. The feed reports the provider-qualified reference
|
||||
// (Galaxy!Area.tag.Attr); reverse-map it to the authored tag, also through the plain tag.Attr form the
|
||||
// AdminUI picker authors (lmxopcua#895), identity on a miss. Resolved ahead of the subscription gate so
|
||||
// every transition the driver sees teaches the ack reference, fanned out or not.
|
||||
var conditionRawPath = ResolveAlarmRawPath(transition.AlarmFullReference, transition.SourceObjectReference);
|
||||
|
||||
GalaxyAlarmSubscriptionHandle? handle;
|
||||
int subCount;
|
||||
lock (_alarmHandlersLock)
|
||||
@@ -2841,13 +2905,6 @@ public sealed class GalaxyDriver
|
||||
transition.TransitionKind, transition.AlarmFullReference, subCount, handle is not null);
|
||||
if (handle is null) return;
|
||||
|
||||
// v3: the ConditionId the driver reports must be the tag's RawPath — the same key the value
|
||||
// fan-out uses (OnPumpDataChange) and the identity the discoverer stamped as SourceName — so the
|
||||
// server-side condition state correlates the alarm to its node and a subsequent ack round-trips
|
||||
// back through AcknowledgeAsync. The feed reports the provider-qualified reference
|
||||
// (Galaxy!Area.tag.Attr); reverse-map it to the authored tag, also through the plain tag.Attr form the
|
||||
// AdminUI picker authors (lmxopcua#895), identity on a miss.
|
||||
var conditionRawPath = ResolveAlarmRawPath(transition.AlarmFullReference, transition.SourceObjectReference);
|
||||
var args = new AlarmEventArgs(
|
||||
SubscriptionHandle: handle,
|
||||
SourceNodeId: transition.SourceObjectReference,
|
||||
|
||||
Reference in New Issue
Block a user