fix(historian-gateway): map alarm severity numerically; dispose provisioner's gRPC channel
Driver.Historian.Gateway-001 (High): AlarmEventMapper wrote the alarm's
Severity wire property as the .NET enum name (e.g. "High"), but
EventMapper's read side int.TryParse()s that same property and silently
falls back to the minimum severity on any unparseable value - so every
alarm event's severity round-tripped through this module's own mappers
collapsed to 1 (Low), contradicting AlarmHistorianEvent.Severity's own
documented contract ("mapped to Historian's numeric priority"). Now
mapped through a numeric priority mirroring the existing
NativeAlarmProjector.MapSeverity convention (200/500/700/900).
Driver.Historian.Gateway-002 (Low): GatewayTagProvisioner never disposed
its IHistorianGatewayClient, unlike its GatewayHistorianDataSource /
GatewayAlarmHistorianWriter siblings. Now implements IAsyncDisposable so
the DI-owned singleton's gRPC channel closes gracefully at shutdown.
Both TDD: new/corrected tests confirmed RED against the pre-fix code.
This commit is contained in:
@@ -17,7 +17,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway;
|
||||
/// as <see cref="HistorianProvisionResult.Failed"/> and returns. The method never throws and never
|
||||
/// logs tag values, hostnames, or credentials.
|
||||
/// </remarks>
|
||||
public sealed class GatewayTagProvisioner : IHistorianProvisioning
|
||||
public sealed class GatewayTagProvisioner : IHistorianProvisioning, IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage rate (ms) stamped on every provisioned analog tag. The gateway's <c>EnsureTags</c> path
|
||||
@@ -104,4 +104,13 @@ public sealed class GatewayTagProvisioner : IHistorianProvisioning
|
||||
return new HistorianProvisionResult(requests.Count, Ensured: 0, Skipped: skipped, Failed: definitions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the underlying gateway client (and its gRPC channel). The DI container owns this
|
||||
/// provisioner as a singleton (<c>AddHistorianProvisioning</c>), so this fires once at host
|
||||
/// shutdown — closing the channel gracefully, matching the read (<see cref="GatewayHistorianDataSource"/>)
|
||||
/// and alarm-write (<see cref="GatewayAlarmHistorianWriter"/>) paths' dispose ownership.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public ValueTask DisposeAsync() => _client.DisposeAsync();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ZB.MOM.WW.HistorianGateway.Contracts.Grpc;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Mapping;
|
||||
@@ -10,6 +11,25 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Mapping;
|
||||
/// </summary>
|
||||
internal static class AlarmEventMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps <see cref="AlarmSeverity"/> to the numeric OPC UA Part 9 priority (1-1000) carried in the
|
||||
/// wire event's <c>Severity</c> property, per the <see cref="AlarmHistorianEvent.Severity"/>
|
||||
/// contract ("Mapped to Historian's numeric priority on the sink side"). The read side
|
||||
/// (<see cref="EventMapper.ToHistoricalEvent"/>) <c>int.TryParse</c>s this same property, so it
|
||||
/// must stay a numeric string — the enum's <c>.ToString()</c> name (e.g. "High") is NOT
|
||||
/// parseable and used to silently collapse every read-back severity to the minimum (1). The
|
||||
/// values mirror the existing native-alarm convention
|
||||
/// (<c>ZB.MOM.WW.OtOpcUa.Runtime.Drivers.NativeAlarmProjector.MapSeverity</c>).
|
||||
/// </summary>
|
||||
private static string ToNumericSeverity(AlarmSeverity severity) => severity switch
|
||||
{
|
||||
AlarmSeverity.Low => "200",
|
||||
AlarmSeverity.Medium => "500",
|
||||
AlarmSeverity.High => "700",
|
||||
AlarmSeverity.Critical => "900",
|
||||
_ => "500",
|
||||
};
|
||||
|
||||
/// <summary>Maps an alarm historian event to a gateway event.</summary>
|
||||
/// <param name="alarm">The driver-agnostic alarm event.</param>
|
||||
/// <returns>The gateway wire event ready for <c>SendEvent</c>.</returns>
|
||||
@@ -36,7 +56,7 @@ internal static class AlarmEventMapper
|
||||
historianEvent.Properties["AlarmId"] = alarm.AlarmId;
|
||||
historianEvent.Properties["AlarmName"] = alarm.AlarmName;
|
||||
historianEvent.Properties["EventKind"] = alarm.EventKind;
|
||||
historianEvent.Properties["Severity"] = alarm.Severity.ToString();
|
||||
historianEvent.Properties["Severity"] = ToNumericSeverity(alarm.Severity);
|
||||
historianEvent.Properties["User"] = alarm.User;
|
||||
historianEvent.Properties["Message"] = alarm.Message;
|
||||
if (alarm.Comment is not null)
|
||||
|
||||
Reference in New Issue
Block a user