namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
/// Lifecycle of this node's OPC UA endpoint as the Host's OtOpcUaServerHostedService drives it.
public enum OpcUaEndpointStatus
{
/// The hosted service has not run StartAsync yet.
NotStarted,
/// The SDK is listening and the address-space / ServiceLevel sinks are bound.
Started,
/// The SDK failed to start (port in use, PKI unwritable, bad OpcUa:* override, …).
Failed,
/// The hosted service stopped the SDK; the port is released.
Stopped,
}
///
/// The one place the "did the OPC UA SDK actually start?" fact lives (R03:2.1). Before it, a failed
/// start was one Error line: /health/ready stayed 200, the node joined its mesh, could be
/// elected driver Primary and acked deploys as Applied through the Null sink — while clients got
/// connection-refused from the node the fleet called healthy.
///
///
///
/// Lives in Commons (not the Host, where it started) so the Runtime can read it. Three consumers:
///
///
/// - OpcUaEndpointHealthCheck (Host) — Ready tier everywhere, Active tier on a driver-only node.
/// - OpcUaPublishActor (Runtime) — a endpoint feeds
/// EndpointListening=false into ServiceLevelCalculator, so the node computes ServiceLevel 0
/// instead of 250/240 (lmxopcua#762).
/// - OpcUaEndpointStepDownActor (Runtime) — a driver Primary whose endpoint failed gracefully
/// leaves its mesh once a peer reports a listening endpoint, so the peer becomes the oldest Up driver
/// member and therefore Primary (lmxopcua#762).
///
///
public interface IOpcUaEndpointState
{
/// The endpoint's current lifecycle status.
OpcUaEndpointStatus Status { get; }
/// Why the start failed, when is .
string? FailureReason { get; }
}
/// Mutable ; written by the hosted service, read by the health check, the
/// ServiceLevel computation and the Primary step-down.
public sealed class OpcUaEndpointState : IOpcUaEndpointState
{
private volatile OpcUaEndpointStatus _status = OpcUaEndpointStatus.NotStarted;
private volatile string? _failureReason;
///
public OpcUaEndpointStatus Status => _status;
///
public string? FailureReason => _failureReason;
/// Records a successful SDK start.
public void MarkStarted()
{
_failureReason = null;
_status = OpcUaEndpointStatus.Started;
}
/// Records a failed SDK start.
/// The failure, as the health probe should report it.
public void MarkFailed(string reason)
{
_failureReason = reason;
_status = OpcUaEndpointStatus.Failed;
}
/// Records that the hosted service stopped the SDK.
public void MarkStopped()
{
_failureReason = null;
_status = OpcUaEndpointStatus.Stopped;
}
}