feat(717): Warm non-transparent redundancy, default-off (T1-T10)
OpcUa:Redundancy:Mode (Unset default = today's server exactly; None; Warm; Hot and unknown values fail start). - T1 options + validator + effective-URI check + boot banner; Warm needs the driver role. - T2 metadata in OnNodeManagerStartedAsync: Warm -> NonTransparentRedundancyType, read-only ServerUriArray [self, peers], RedundancySupport=Warm, boot ServiceLevel 1; None -> RedundancySupport=None and the SDK's orphan i=11314 deleted; Unset untouched. - T3 RedundancyStateChanged.Revision (up-number, incarnation tick, sequence); subscribers drop older revisions under Warm (OpcUaPublishActor, DriverHostActor); unrevisioned never makes a node Active. - T4 WarmRoleAuthority + ComputeWarm bands (Standby 90/50, Active 250/200/100), PromoteWhilePrimaryUnreachable. - T5 IStandbyProjection + DeferredStandbyProjection; OpcUaPublishActor runs promotion/demotion in the spec 4.7 order (Active level last and retried; Standby level first, data degraded regardless). - T6 EquipmentVariableState read projection (BadOutOfService/null); Warm Standby refuses writes BadInvalidState. - T7 D4 mechanism adopted after T0: ordinary-tag marker on MonitoredItemNotification.Message validated by (ClientHandle, DataValue); first-delivery decision keyed by (SubscriptionId, SequenceNumber); the SDK's cached copy is never mutated. - T8 queue current/BadOutOfService to live ordinary-tag items ignoring filters. - T9 alarm stamp/deliver split (suppressed on Standby), Part 9 methods refused on Standby, promotion refresh via ISubscription.ConditionRefresh2Async on every live event item. - T10 deploy-time RedundancyMode cross-check + six instruments. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -4,6 +4,7 @@ using Opc.Ua;
|
||||
using Opc.Ua.Configuration;
|
||||
using Opc.Ua.Identity;
|
||||
using Opc.Ua.Server;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Authorization;
|
||||
using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security;
|
||||
|
||||
@@ -174,6 +175,83 @@ public sealed class OpcUaApplicationHostOptions
|
||||
/// Replaces the SDK's own lockout, which also refused Anonymous; see <see cref="FailedCredentialLockout"/>.
|
||||
/// </summary>
|
||||
public OpcUaCredentialLockoutOptions CredentialLockout { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Warm non-transparent redundancy (<c>OpcUa:Redundancy:*</c>, Gitea #717). The default <c>Mode=Unset</c> is
|
||||
/// byte-for-byte today's server. Startup-static.
|
||||
/// </summary>
|
||||
public OpcUaRedundancyOptions Redundancy { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>The <c>OpcUa:Redundancy</c> section (Gitea #717, spec §6).</summary>
|
||||
public sealed class OpcUaRedundancyOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// <c>Unset</c> (default) / <c>None</c> / <c>Warm</c>, case-insensitive. <c>Hot</c> is not advertisable
|
||||
/// (spec §3) and, like any other value, fails host start. Bound as a string so a bad value is a readable
|
||||
/// validation failure rather than a binder exception.
|
||||
/// </summary>
|
||||
public string Mode { get; set; } = nameof(OpcUaRedundancyMode.Unset);
|
||||
|
||||
/// <summary>
|
||||
/// Warm only: let the survivor go Active while the Primary is unreachable but not yet downed (spec §4.1, owner
|
||||
/// answer Q2). Default <c>true</c>.
|
||||
/// </summary>
|
||||
public bool PromoteWhilePrimaryUnreachable { get; set; } = true;
|
||||
|
||||
/// <summary>Parses <see cref="Mode"/>.</summary>
|
||||
/// <param name="mode">The parsed mode.</param>
|
||||
/// <returns><c>false</c> for <c>Hot</c>, numerics or any unknown value.</returns>
|
||||
public bool TryParseMode(out OpcUaRedundancyMode mode)
|
||||
{
|
||||
var text = (Mode ?? string.Empty).Trim();
|
||||
if (text.Length == 0) text = nameof(OpcUaRedundancyMode.Unset);
|
||||
if (!text.All(char.IsLetter)) { mode = default; return false; }
|
||||
return Enum.TryParse(text, ignoreCase: true, out mode) && Enum.IsDefined(mode);
|
||||
}
|
||||
|
||||
/// <summary>The parsed mode; throws on an invalid one (the validator rejects it first).</summary>
|
||||
public OpcUaRedundancyMode ParsedMode => TryParseMode(out var m)
|
||||
? m
|
||||
: throw new InvalidOperationException(
|
||||
$"OpcUa:Redundancy:Mode '{Mode}' is not supported; use Unset, None or Warm (Hot is not advertisable).");
|
||||
|
||||
/// <summary>The runtime settings the redundancy actors read.</summary>
|
||||
/// <returns>The settings.</returns>
|
||||
public WarmRedundancySettings ToSettings() => new(ParsedMode, PromoteWhilePrimaryUnreachable);
|
||||
|
||||
/// <summary>
|
||||
/// The rules of spec §3 that need only configuration: <c>Warm</c> needs at least one peer, all URIs distinct
|
||||
/// and the self URI not listed as a peer; <c>None</c> needs no peers. Returns the failure messages (empty when
|
||||
/// valid). The effective self URI is checked again after an <c>ApplicationConfigPath</c> load.
|
||||
/// </summary>
|
||||
/// <param name="selfUri">The self URI to check against.</param>
|
||||
/// <param name="peers">The configured peer URIs.</param>
|
||||
/// <returns>The failures.</returns>
|
||||
public IReadOnlyList<string> Check(string? selfUri, IEnumerable<string>? peers)
|
||||
{
|
||||
var failures = new List<string>();
|
||||
if (!TryParseMode(out var mode))
|
||||
{
|
||||
failures.Add($"OpcUa:Redundancy:Mode '{Mode}' is not supported; use Unset, None or Warm (Hot is not advertisable: continuous acquisition alone does not meet Part 4 Hot)");
|
||||
return failures;
|
||||
}
|
||||
|
||||
var list = (peers ?? Array.Empty<string>()).Where(p => !string.IsNullOrWhiteSpace(p)).Select(p => p.Trim()).ToList();
|
||||
if (mode == OpcUaRedundancyMode.None && list.Count > 0)
|
||||
failures.Add("OpcUa:PeerApplicationUris must be empty when OpcUa:Redundancy:Mode is None (a standalone server has no peers)");
|
||||
if (mode == OpcUaRedundancyMode.Warm)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
failures.Add("OpcUa:Redundancy:Mode Warm requires at least one OpcUa:PeerApplicationUris entry");
|
||||
if (list.Distinct(StringComparer.Ordinal).Count() != list.Count)
|
||||
failures.Add("OpcUa:PeerApplicationUris must not contain duplicates under OpcUa:Redundancy:Mode Warm");
|
||||
if (!string.IsNullOrWhiteSpace(selfUri) && list.Contains(selfUri.Trim(), StringComparer.Ordinal))
|
||||
failures.Add($"OpcUa:PeerApplicationUris must not list this server's own ApplicationUri '{selfUri}' under OpcUa:Redundancy:Mode Warm (each pair node needs a unique ApplicationUri)");
|
||||
}
|
||||
|
||||
return failures;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -289,7 +367,8 @@ public sealed class OpcUaApplicationHost : IAsyncDisposable
|
||||
|
||||
try
|
||||
{
|
||||
_ = await BuildConfigurationAsync(cancellationToken);
|
||||
var configuration = await BuildConfigurationAsync(cancellationToken);
|
||||
ConfigureRedundancy(sdkServer, configuration.ApplicationUri ?? _options.ApplicationUri);
|
||||
await EnsureApplicationCertificateAsync(cancellationToken).ConfigureAwait(false);
|
||||
AttachUserAuthenticator(sdkServer);
|
||||
await _application.StartAsync(server, cancellationToken).ConfigureAwait(false);
|
||||
@@ -305,6 +384,31 @@ public sealed class OpcUaApplicationHost : IAsyncDisposable
|
||||
_options.PublicHostname, _options.OpcUaPort);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #717 (spec §3): validate the redundancy mode against the EFFECTIVE self URI — the loaded
|
||||
/// <c>ApplicationConfigPath</c> XML wins over <c>OpcUa:ApplicationUri</c> (c7787) — log the boot banner and hand
|
||||
/// the startup-static metadata to the SDK server, which installs it in <c>OnNodeManagerStartedAsync</c>.
|
||||
/// <c>Unset</c> hands nothing over, so the SDK's graph is untouched.
|
||||
/// </summary>
|
||||
/// <param name="server">The SDK server about to start.</param>
|
||||
/// <param name="effectiveSelfUri">The effective <c>ApplicationConfiguration.ApplicationUri</c>.</param>
|
||||
/// <exception cref="InvalidOperationException">The redundancy configuration is invalid for the effective URI.</exception>
|
||||
private void ConfigureRedundancy(OtOpcUaSdkServer server, string effectiveSelfUri)
|
||||
{
|
||||
var redundancy = _options.Redundancy ?? new OpcUaRedundancyOptions();
|
||||
var failures = redundancy.Check(effectiveSelfUri, _options.PeerApplicationUris);
|
||||
if (failures.Count > 0)
|
||||
throw new InvalidOperationException("OPC UA redundancy configuration is invalid: " + string.Join("; ", failures));
|
||||
|
||||
var mode = redundancy.ParsedMode;
|
||||
var peers = (_options.PeerApplicationUris ?? new List<string>())
|
||||
.Where(p => !string.IsNullOrWhiteSpace(p)).Select(p => p.Trim()).ToArray();
|
||||
_logger.LogInformation(
|
||||
"OPC UA redundancy: Mode={Mode}, effective ApplicationUri={SelfUri}, peers=[{Peers}], PromoteWhilePrimaryUnreachable={Promote}",
|
||||
mode, effectiveSelfUri, string.Join(", ", peers), redundancy.PromoteWhilePrimaryUnreachable);
|
||||
server.ConfigureRedundancy(mode, effectiveSelfUri, peers);
|
||||
}
|
||||
|
||||
private void AttachUserAuthenticator(OtOpcUaSdkServer server)
|
||||
{
|
||||
foreach (var type in new[] { UserTokenType.Anonymous, UserTokenType.UserName })
|
||||
|
||||
Reference in New Issue
Block a user