fix(alarms): Severity runs one direction, higher = more urgent; raw priority kept (#129)
AlarmConditionState.Severity mixed two conventions: OPC UA rows carried Part 9 Severity (higher = more severe) while MxGateway native alarms and computed alarms carried a raw AVEVA-style priority (1 = most urgent). Every consumer ranks higher as worse, so Worst Severity, the severity filter/sort and the site event-log Error threshold picked the LEAST urgent MxGateway/computed alarms. - AlarmPriorityBands: the OtOpcUa GalaxyAlarmPriority table (lmxopcua#887, b61f3e05), value for value: 1-250 -> 1000, 251-500 -> 750, 501-750 -> 500, 751-999 -> 250; <= 0 clamps to Critical, > 999 to Low. - MxGatewayAlarmMapper bands the gateway severity (= AVEVA priority); AlarmConditionStateFactory.ForComputed bands PriorityLevel. OPC UA unchanged. - AlarmConditionState gains trailing Priority (int?): the raw source number, exactly the pre-#129 Severity. AlarmStateChanged.Priority and the wire AlarmStateUpdate.priority keep that meaning (no proto change); central derives Severity by kind (SeverityFromPriority), so an older site decodes correctly. - ScriptAlarm gains trailing Priority. The native MES 900-999 band and the MES API Severity/MinSeverity/MaxSeverity key off Priority; rig seed scripts moved from a.Severity to a.Priority, so MES output is unchanged. - AlarmActor raise logs Error when the banded severity >= 700 (same threshold as NativeAlarmActor): priority 1-500 Error, 501+ Warning (was raw >= 700). - NativeAlarmActor upgrades pre-#129 native_alarm_state rows on rehydrate. - Debug snapshot decode restores Condition.Priority from the row's priority. - Docs: Commons, DCL, SiteRuntime, Communication, CentralUI, InboundAPI, HighLevelReqs, MES alarm-status plan, CLAUDE.md. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -668,6 +668,80 @@ public class NativeAlarmActorTests : TestKit, IDisposable
|
||||
Assert.Null(emitted.AckTime); // …with no ack time invented
|
||||
}
|
||||
|
||||
// ── Gitea #129: one Severity direction, raw priority kept ──
|
||||
|
||||
private IActorRef SpawnKind(IActorRef instanceActor, IActorRef dclManager, AlarmKind kind,
|
||||
IServiceProvider? serviceProvider = null) =>
|
||||
ActorOf(Props.Create(() => new NativeAlarmActor(
|
||||
Source(), "inst", instanceActor, dclManager, _storage, _options,
|
||||
NullLogger<NativeAlarmActor>.Instance, kind, serviceProvider)));
|
||||
|
||||
/// <summary>
|
||||
/// An MxAccess condition as the DCL now builds it (AVEVA priority banded onto Severity, raw kept on
|
||||
/// Priority): the record's Priority is the raw priority — the value the MES band and the stream's
|
||||
/// <c>AlarmStateUpdate.priority</c> carry — and the event log ranks priority 1 as an Error, 950 as a Warning.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(1, 1000, "Error")]
|
||||
[InlineData(400, 750, "Error")]
|
||||
[InlineData(600, 500, "Warning")]
|
||||
[InlineData(950, 250, "Warning")]
|
||||
public void MxAccessRaise_CarriesRawPriority_AndLogsByBandedSeverity(int priority, int severity, string logSeverity)
|
||||
{
|
||||
var siteLog = new FakeSiteEventLogger();
|
||||
var instance = CreateTestProbe();
|
||||
var dcl = CreateTestProbe();
|
||||
var actor = SpawnKind(instance.Ref, dcl.Ref, AlarmKind.NativeMxAccess, new SingleServiceProvider(siteLog));
|
||||
dcl.ExpectMsg<SubscribeAlarmsRequest>();
|
||||
|
||||
actor.Tell(new NativeAlarmTransitionUpdate("Opc", Transition(
|
||||
"T01.Hi", AlarmTransitionKind.Raise,
|
||||
new AlarmConditionState(true, false, null, AlarmShelveState.Unshelved, false, severity, Priority: priority))));
|
||||
var emitted = instance.ExpectMsg<AlarmStateChanged>(m => m.State == AlarmState.Active);
|
||||
|
||||
Assert.Equal(priority, emitted.Priority);
|
||||
Assert.Equal(priority, emitted.Condition.Priority);
|
||||
Assert.Equal(severity, emitted.Condition.Severity);
|
||||
AwaitAssert(() => Assert.Equal(logSeverity, Assert.Single(siteLog.OfType("alarm")).Severity),
|
||||
TimeSpan.FromSeconds(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A row persisted by a pre-#129 build holds the raw number in Severity and no Priority. Rehydration
|
||||
/// moves it to Priority and re-derives Severity: banded for an MxAccess source, kept for OPC UA.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(AlarmKind.NativeMxAccess, 950, 250)]
|
||||
[InlineData(AlarmKind.NativeMxAccess, 1, 1000)]
|
||||
[InlineData(AlarmKind.NativeOpcUa, 800, 800)]
|
||||
public async Task Rehydration_OfAPre129Row_MovesTheRawValueToPriority(AlarmKind kind, int legacySeverity, int expectedSeverity)
|
||||
{
|
||||
var legacyJson = JsonSerializer.Serialize(new
|
||||
{
|
||||
Active = true, Acknowledged = false, Confirmed = (bool?)null,
|
||||
Shelve = AlarmShelveState.Unshelved, Suppressed = false, Severity = legacySeverity
|
||||
});
|
||||
await _storage.UpsertNativeAlarmAsync(
|
||||
"inst", Source().CanonicalName, "ref-129", legacyJson, DateTimeOffset.UtcNow, null);
|
||||
|
||||
var instance = CreateTestProbe();
|
||||
SpawnKind(instance.Ref, CreateTestProbe().Ref, kind);
|
||||
|
||||
var emitted = instance.FishForMessage<AlarmStateChanged>(
|
||||
m => m.SourceReference == "ref-129", TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(expectedSeverity, emitted.Condition.Severity);
|
||||
Assert.Equal(legacySeverity, emitted.Condition.Priority);
|
||||
Assert.Equal(legacySeverity, emitted.Priority);
|
||||
}
|
||||
|
||||
/// <summary>A post-#129 row (Priority present) is left exactly as persisted.</summary>
|
||||
[Fact]
|
||||
public void UpgradeLegacyCondition_LeavesACurrentRowAlone()
|
||||
{
|
||||
var current = new AlarmConditionState(true, false, null, AlarmShelveState.Unshelved, false, 250, Priority: 950);
|
||||
Assert.Same(current, NativeAlarmActor.UpgradeLegacyCondition(current, AlarmKind.NativeMxAccess));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a lost subscribe response causes the subscribe to be resent.</summary>
|
||||
[Fact]
|
||||
public void LostSubscribeResponse_ResendsSubscribe()
|
||||
|
||||
Reference in New Issue
Block a user