47b1fd422c
Adds the missing trigger that activates the worker's wnwrap consumer.
Without this, every session opened in OK state but the consumer never
started, so AcknowledgeAlarm/QueryActiveAlarms returned "alarm consumer
not configured" forever.
New AlarmsOptions config block (under MxGateway:Alarms):
- Enabled (default false): gates the auto-subscribe path so existing
deployments without alarm configuration are unaffected.
- SubscriptionExpression: explicit AVEVA expression like
\<machine>\Galaxy!<area>.
- DefaultArea: fallback used when SubscriptionExpression is empty;
composes \$(MachineName)\Galaxy!$(DefaultArea).
- RequireSubscribeOnOpen (default false): when true, an auto-subscribe
failure faults the session; when false, the failure is logged and
the session stays Ready (data subscriptions keep working, alarms
return "not subscribed" until the operator retries).
SessionManager.OpenSessionAsync gains a TryAutoSubscribeAlarmsAsync hook
that runs after MarkReady. Skips when alarms are disabled; otherwise
builds a SubscribeAlarmsCommand, invokes it on the session's worker
client, and either logs the resulting status or escalates per
RequireSubscribeOnOpen. SessionManagerException is the failure mode for
the strict path so callers in MxAccessGatewayService surface it as
session-open-failed.
Tests: 7 new unit tests cover the disabled lane, expression-driven
subscribe, DefaultArea fallback, success path, soft-failure (require
off), strict-failure (require on), and missing-config-strict-throw.
Server suite total: 295 pass / 0 fail. Solution builds clean.
End-to-end alarms-over-gateway path is now live (with config). Open a
session against a gateway with Alarms.Enabled=true + a valid
SubscriptionExpression; the worker's wnwrap consumer auto-subscribes;
QueryActiveAlarms streams snapshots; AcknowledgeAlarm acks by GUID.
Reference→GUID resolution (AlarmAckByName worker command) and the live
dev-rig smoke test remain follow-ups.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
namespace MxGateway.Server.Configuration;
|
|
|
|
/// <summary>
|
|
/// Per-gateway alarm-subsystem configuration. Drives the auto-subscribe
|
|
/// hook in <see cref="Sessions.SessionManager"/>: when
|
|
/// <see cref="Enabled"/> is true and a session reaches Ready, the
|
|
/// manager issues a <c>SubscribeAlarmsCommand</c> to the worker with
|
|
/// the configured <see cref="SubscriptionExpression"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Defaults preserve current behaviour (alarms disabled). Operators
|
|
/// opt in by setting <c>MxGateway:Alarms:Enabled = true</c> and
|
|
/// supplying a canonical
|
|
/// <c>\\<machine>\Galaxy!<area></c> subscription
|
|
/// expression. The literal "Galaxy" provider is correct regardless of
|
|
/// the configured Galaxy database name (the wnwrap consumer doesn't
|
|
/// accept the database name as the provider).
|
|
/// </remarks>
|
|
public sealed class AlarmsOptions
|
|
{
|
|
/// <summary>Gate the auto-subscribe hook on session open. Default false.</summary>
|
|
public bool Enabled { get; init; }
|
|
|
|
/// <summary>
|
|
/// AVEVA alarm-subscription expression. When empty and
|
|
/// <see cref="Enabled"/> is true, the gateway falls back to
|
|
/// <c>\\$(MachineName)\Galaxy!$(DefaultArea)</c> if
|
|
/// <see cref="DefaultArea"/> is set; otherwise the session open
|
|
/// fails with a configuration diagnostic.
|
|
/// </summary>
|
|
public string SubscriptionExpression { get; init; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Optional area name used to compose a default subscription when
|
|
/// <see cref="SubscriptionExpression"/> is empty. Combined with
|
|
/// <c>Environment.MachineName</c> as
|
|
/// <c>\\<MachineName>\Galaxy!<DefaultArea></c>.
|
|
/// </summary>
|
|
public string DefaultArea { get; init; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// If true, an auto-subscribe failure faults the session. If false
|
|
/// (default), the failure is logged and the session remains Ready —
|
|
/// alarm-side commands return "not subscribed" but data subscriptions
|
|
/// work normally.
|
|
/// </summary>
|
|
public bool RequireSubscribeOnOpen { get; init; }
|
|
}
|