diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs index 285874026..113299d84 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs @@ -13,9 +13,10 @@ public static class DataConnectionValidator /// The operations AUTHORING may grant. It grows only in the phase that implements a bit, so authoring cannot get ahead /// of the code (plan section 4.3, "grow site"): H2 added together with /// and the origin's Implemented(target); A2a adds - /// ; A2b adds the method bits (acknowledge/confirm/shelve). + /// ; A2b adds the method bits and + /// ( stays reserved). /// - private const DataOperations KnownOperations = DataOperationSets.V1 | DataOperations.HistoryRead | DataOperations.AlarmSubscribe; + private const DataOperations KnownOperations = DataOperationSets.V1 | DataOperations.HistoryRead | DataOperationSets.ConditionGrants; private static readonly StringComparer Ids = StringComparer.OrdinalIgnoreCase; // H2 upper bounds: keep derived capacities (sessions x reads x batch, remainder budgets) far from int overflow. @@ -359,4 +360,12 @@ public static class DataConnectionValidator x.Node)) .ToArray(); } + + /// + /// The deploy gate's non-blocking data-connection warnings (A2b, plan §6): today the condition-capacity rule + /// (). AdminOperationsActor.StartDeployment logs each one and deploys anyway, + /// like the other non-blocking deploy checks; the AdminUI mappings panel shows the same rule while authoring. + /// + public static IReadOnlyList DeployWarnings(DraftSnapshot draft) => + ConditionCapacityWarnings(draft).Select(w => $"[{w.Code}] {w.Message}").ToArray(); } diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor index b48b929c5..80c2c27b1 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor @@ -118,6 +118,7 @@ else
Larger answers are sent in bounded chunks.
A remote AlarmSubscribe scope with more conditions than this is refused (ConditionCapacity) before anything is imported.
+
Galaxy-sourced alarms are acknowledged under this peer's API-key Galaxy ack identity (provision otopcua/apikeys/<keyId>/galaxy-ack-user and …/galaxy-ack-password on this cluster). Requires AlarmAcknowledge.
@Actions(e, e.DataExportRowId != Guid.Empty) } diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs index 44bba8434..e72b7e7b5 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs @@ -13,7 +13,7 @@ public static class DataOperationAuthoring /// The operation bits an operator can tick, in display order. public static IReadOnlyList AuthorableOperations { get; } = [DataOperations.Browse, DataOperations.Metadata, DataOperations.Read, DataOperations.Subscribe, DataOperations.Write, DataOperations.HistoryRead, - DataOperations.AlarmSubscribe]; + DataOperations.AlarmSubscribe, DataOperations.AlarmAcknowledge, DataOperations.AlarmConfirm]; /// The checkbox label of a bit. public static string Label(DataOperations operation) => operation.ToString(); diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.ControlPlane/AdminOperations/AdminOperationsActor.cs b/src/Server/ZB.MOM.WW.OtOpcUa.ControlPlane/AdminOperations/AdminOperationsActor.cs index 984c10ad2..5b40d7cf1 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.ControlPlane/AdminOperations/AdminOperationsActor.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.ControlPlane/AdminOperations/AdminOperationsActor.cs @@ -489,6 +489,10 @@ public sealed class AdminOperationsActor : ReceiveActor foreach (var w in writableWarnings) _log.Warning("StartDeployment: Sql writable mismatch (non-blocking): {Warning}", w); + // A2b (plan §6): Σ MaxConditions × 49 of a consumer node's alarm mappings over the host cap — non-blocking. + foreach (var w in DataConnectionValidator.DeployWarnings(draft)) + _log.Warning("StartDeployment: data-connection warning (non-blocking): {Warning}", w); + if (errors.Count > 0) { var summary = string.Join("; ", errors.Select(e => $"[{e.Code}] {e.Message}")); diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.ConditionMethods.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.ConditionMethods.cs new file mode 100644 index 000000000..caad6dce5 --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/GrpcDataConnection.ConditionMethods.cs @@ -0,0 +1,99 @@ +using Grpc.Core; +using ZB.MOM.WW.OtOpcUa.Commons.DataConnections; +using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; + +namespace ZB.MOM.WW.OtOpcUa.Runtime.DataConnections; + +/// +/// A2b consumer side of CallConditionMethod (plan §5.6 consumer steps 4–5). One bounded call: deadline = +/// min(the request's remaining budget, — the mapping's +/// ConditionMethodTimeoutMilliseconds, 5 s by default). Only an endpoint that advertised conditions with +/// the method, is Primary and serves the incarnation the caller expects is eligible; nothing is dispatched otherwise. +/// No retry anywhere: once the request has been handed to the transport, a failure answers +/// (BadCommunicationError) and no other endpoint is tried — the +/// origin may have applied it, and a duplicate operation id would only join there anyway. +/// +public sealed partial class GrpcDataConnection : IDataConditionMethodService +{ + internal const uint BadCommunicationError = 0x80050000u; + private TimeSpan _conditionMethodTimeout = TimeSpan.FromSeconds(5); + + /// The per-call method ceiling (the mapping's ConditionMethodTimeoutMilliseconds; A3 binds it per mapping). + public TimeSpan ConditionMethodTimeout + { + get => _conditionMethodTimeout; + init => _conditionMethodTimeout = value > TimeSpan.Zero ? value : throw new ArgumentOutOfRangeException(nameof(value)); + } + + /// Remote condition method (). + public async Task CallConditionMethodAsync(DataConditionMethodRequest request, CancellationToken cancellationToken) + { + ArgumentNullException.ThrowIfNull(request); + request.Validate(); + var start = Clock.GetTimestamp(); + var deadline = request.RemainingBudget < ConditionMethodTimeout ? request.RemainingBudget : ConditionMethodTimeout; + if (deadline <= TimeSpan.Zero) return new(DataWriteState.RejectedBeforeDispatch, BadTimeout, "Budget expired before dispatch."); + var budget = new DataBudget(deadline, 1, Math.Min(_maxMessageBytes, 1 << 20)); + EnterWork(); + var admitted = false; + try + { + using var admission = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _scope.CancellationToken, _shutdown.Token); + admitted = await _unaryCapacity.WaitAsync(0, admission.Token).ConfigureAwait(false); + if (!admitted) return new(DataWriteState.RejectedBeforeDispatch, BadTooManyOperations, "Unary capacity exhausted."); + var unsupported = false; + foreach (var endpoint in _endpoints) + { + Check(); + cancellationToken.ThrowIfCancellationRequested(); + Selected selected; + try { selected = await SelectAsync(endpoint, start, budget, false, cancellationToken).ConfigureAwait(false); ProbeSucceeded(); } + catch (Exception ex) when (!cancellationToken.IsCancellationRequested + && ex is RpcException or InvalidOperationException or UnauthorizedAccessException or HttpRequestException or TimeoutException or ArgumentException) + { RecordFailure(ex); continue; } + var caps = selected.Capabilities; + if (caps.Conditions is null || (caps.Conditions.Methods & (uint)request.Method) == 0 + || !caps.Operations.HasFlag(DataConditionMethodSets.OperationFor(request.Method)) + || !string.Equals(caps.Serving.Role, "Primary", StringComparison.OrdinalIgnoreCase) + || !string.Equals(caps.Serving.Incarnation, request.ExpectedServingIncarnation, StringComparison.Ordinal)) + { unsupported = true; continue; } + + TimeSpan remaining; + try { remaining = Remaining(start, budget); } + catch (TimeoutException) { return new(DataWriteState.RejectedBeforeDispatch, BadTimeout, "Budget expired before dispatch."); } + var wire = DataConditionProtoMapper.EncodeMethodRequest(request with { RemainingBudget = remaining }); + using var linked = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _scope.CancellationToken, + selected.Channel.Retired.Token, _shutdown.Token); + var options = new CallOptions(Headers(selected.Channel, RequestedFeatures(caps)), DateTime.UtcNow + remaining, linked.Token); + // From here on the request may reach the origin: never retried, never moved to another endpoint. + try + { + var response = await selected.Channel.Client.CallConditionMethodAsync(wire, options).ResponseAsync.ConfigureAwait(false); + var result = DataConditionProtoMapper.DecodeMethodResponse(response); + if (result.Serving is { } serving && (serving.NodeId != caps.Serving.NodeId || serving.Incarnation != caps.Serving.Incarnation)) + return new(DataWriteState.OutcomeUnknown, BadCommunicationError, "OutcomeUnknown: the answer came from another serving incarnation."); + return result; + } + catch (RpcException ex) when (ex.StatusCode is StatusCode.FailedPrecondition or StatusCode.Unimplemented + or StatusCode.InvalidArgument or StatusCode.PermissionDenied or StatusCode.Unauthenticated) + { + // Refused by the transport before the origin facade ran: nothing was applied. + return new(DataWriteState.RejectedBeforeDispatch, + ex.StatusCode is StatusCode.PermissionDenied or StatusCode.Unauthenticated ? 0x801F0000u : BadNotSupportedMethod, + "Refused by the origin transport: " + ex.StatusCode); + } + catch (Exception ex) when (ex is RpcException or HttpRequestException or OperationCanceledException or InvalidOperationException + or ArgumentException or IOException) + { + if (cancellationToken.IsCancellationRequested && ex is OperationCanceledException) throw; + return new(DataWriteState.OutcomeUnknown, BadCommunicationError, "OutcomeUnknown: the transport failed after the request was sent."); + } + } + return new(DataWriteState.RejectedBeforeDispatch, unsupported ? BadNotSupportedMethod : BadNoCommunication, + unsupported ? "No Primary endpoint serves this condition method." : "No ready endpoint."); + } + finally { if (admitted) _unaryCapacity.Release(); ExitWork(); } + } + + private const uint BadNotSupportedMethod = 0x803D0000u; +} diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs index 7690d206b..e6d31a977 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataV1RealOriginCompatibilityTests.cs @@ -362,6 +362,16 @@ internal sealed class RealOrigin : IAsyncDisposable : []; return [new(watermark, records, watermark, 1, true)]; } + + /// A2b: every method call that reached the node-manager port (a native ack, accepted). + public List Calls { get; } = []; + + public ZB.MOM.WW.OtOpcUa.OpcUaServer.OriginConditionMethodOutcome TryExecuteConditionMethod( + ZB.MOM.WW.OtOpcUa.OpcUaServer.OriginConditionMethodCall call) + { + lock (Calls) Calls.Add(call); + return new(true, true, 0, null); + } } private static DraftSnapshot Snapshot(DataOperations operations, int concurrentReads, int responseBytes, int valuesPerPage) diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionStreamTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionStreamTests.cs index 38095af3d..887bfe3c4 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionStreamTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConditionStreamTests.cs @@ -257,6 +257,16 @@ internal sealed class FakeConditionSource(ConditionStateHub hub) : IOriginCondit new ConditionActivationMarker("inc", 1), ConditionType: "nsu=http://opcfoundation.org/UA/;i=2915", ConditionName: id[(id.LastIndexOf('/') + 1)..]); + /// A2b: the method port's verdict (default: applied, native); every call is recorded. + internal Func Execute { get; set; } = _ => new(true, true, 0, null); + internal List MethodCalls { get; } = []; + + public OriginConditionMethodOutcome TryExecuteConditionMethod(OriginConditionMethodCall call) + { + lock (MethodCalls) MethodCalls.Add(call); + return Execute(call); + } + public IReadOnlyList SnapshotConditions(Func scope, int maxConditionsPerHold) { Interlocked.Increment(ref SnapshotCalls);