feat(dcl): ServiceLevel-aware OPC UA failover for primary/backup pairs (#138)
Prerequisite for OtOpcUa Warm redundancy (lmxopcua#717): a Warm standby keeps a
healthy session but serves BadOutOfService at a standby ServiceLevel (90/50, boot 1),
so a connection that lands there sat on Bad quality forever.
- OPC UA connections with a backup poll Server_ServiceLevel (i=2267) on the connected
endpoint (IServiceLevelReadable, implemented by OpcUaDataConnection; never raises
Disconnected). A level < 200 sustained for the degraded window (default 10 s), or
the first sample after any (re)connect, triggers a probe of the other endpoint
(short-lived session: connect, read, dispose). Switch only when it reports a
Healthy (>= 200) higher level, and not within the minimum dwell (default 60 s) of
the previous ServiceLevel switch. Both degraded, other unreachable or level
unknown: stay put. 250/240 (today's OtOpcUa) never starts a streak.
- The switch reuses the failover path: SwitchToOtherEndpoint() now shared by all
three triggers, then BecomeReconnecting(ReconnectCause.ServiceLevelFailover) -
zero delay, no unstable accounting, ReSubscribeAll on the new endpoint.
- Config: OpcUaEndpointConfig.ServiceLevelFailover {enabled, degradedWindowSeconds,
minDwellSeconds}, read from the PRIMARY endpoint's JSON only; null = defaults
(enabled, 10, 60). Inside the encrypted protocol JSON, so no schema change or
migration. Central UI: fields in the Backup card next to Failover Retry Count.
Global: ScadaBridge:DataConnection:ServiceLevelPollInterval (2 s) and
ServiceLevelProbeTimeout (15 s).
- Tests: actor tests per trigger/non-trigger with positive controls, an unsolicited
promotion RefreshStart/RefreshEnd test at client and actor level, adapter tests,
and a real in-process OPC UA server pair end to end. All 15 mutants killed.
- Docs: Component-DataConnectionLayer, components/DataConnectionLayer, Component-CLI.
Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
+15
-3
@@ -18,11 +18,14 @@ namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests.Adapters;
|
||||
internal sealed class SecureOpcUaTestServer : IAsyncDisposable
|
||||
{
|
||||
private readonly ApplicationInstance _app;
|
||||
private readonly StandardServer _server;
|
||||
private readonly string _pkiRoot;
|
||||
|
||||
private SecureOpcUaTestServer(ApplicationInstance app, string pkiRoot, string url, X509Certificate2 certificate)
|
||||
private SecureOpcUaTestServer(
|
||||
ApplicationInstance app, StandardServer server, string pkiRoot, string url, X509Certificate2 certificate)
|
||||
{
|
||||
_app = app;
|
||||
_server = server;
|
||||
_pkiRoot = pkiRoot;
|
||||
Url = url;
|
||||
Certificate = certificate;
|
||||
@@ -110,16 +113,25 @@ internal sealed class SecureOpcUaTestServer : IAsyncDisposable
|
||||
ApplicationType = ApplicationType.Server,
|
||||
};
|
||||
await app.CheckApplicationInstanceCertificatesAsync(silent: true, lifeTimeInMonths: 12);
|
||||
await app.StartAsync(new TestServer(telemetry, apiKey));
|
||||
var server = new TestServer(telemetry, apiKey);
|
||||
await app.StartAsync(server);
|
||||
|
||||
// SDK 2: the loaded application certificate lives in the certificate manager, not on the identifier.
|
||||
using var entry = config.CertificateManager.AcquireApplicationCertificateByType(
|
||||
ObjectTypeIds.RsaSha256ApplicationCertificateType)
|
||||
?? throw new InvalidOperationException("The test server has no application certificate.");
|
||||
var cert = X509CertificateLoader.LoadCertificate(entry.Certificate.RawData);
|
||||
return new SecureOpcUaTestServer(app, pkiRoot, url, cert);
|
||||
return new SecureOpcUaTestServer(app, server, pkiRoot, url, cert);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server's <c>Server_ServiceLevel</c> (<c>i=2267</c>) — what a redundant server
|
||||
/// publishes for its role (ScadaBridge#138: 250/240 Active, 90/50 Warm standby, 1 booting).
|
||||
/// </summary>
|
||||
/// <param name="level">The ServiceLevel to publish.</param>
|
||||
public void SetServiceLevel(byte level) =>
|
||||
_server.CurrentInstance.ServerObject.ServiceLevel!.Value = level;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user