feat(grpc-data): H1 SDK-free IDataHistoryService contract in Core.Abstractions
This commit is contained in:
@@ -186,3 +186,86 @@ public interface IDataSubscriptionService
|
||||
/// <summary>Stream lifetime is independent of unary deadlines; cancellation ends the stream.</summary>
|
||||
Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// Remote history (gRPC data history plan §2.1, §3.1–§3.3). Declared by H1; the origin implementation over the node
|
||||
// manager's override-level history port and the wire arrive with H2. SDK-free by construction: aggregates are their
|
||||
// standard ns=0 numeric ids, statuses the full OPC UA uint32, an unset Part 11 bound is ABSENT (null), never MinValue —
|
||||
// the origin's end-only / open-end rules depend on the difference.
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>The variable-history request shape. HistoryUpdate and event history are not served remotely.</summary>
|
||||
public abstract record DataHistoryDetails;
|
||||
|
||||
/// <summary>Part 11 ReadRawModifiedDetails without the modified flag (a remote raw read is never a modified read).</summary>
|
||||
/// <param name="StartUtc">StartTime; null = unset.</param>
|
||||
/// <param name="EndUtc">EndTime; null = unset.</param>
|
||||
/// <param name="NumValuesPerNode">Per-page cap; 0 = all (the origin still pages at its ceiling).</param>
|
||||
/// <param name="ReturnBounds">Part 11 bounding values.</param>
|
||||
public sealed record DataHistoryRawDetails(DateTimeOffset? StartUtc, DateTimeOffset? EndUtc, uint NumValuesPerNode, bool ReturnBounds)
|
||||
: DataHistoryDetails;
|
||||
|
||||
/// <summary>The Part 13 aggregate configuration a processed read asks for.</summary>
|
||||
public sealed record DataAggregateConfiguration(
|
||||
bool UseServerCapabilitiesDefaults, bool TreatUncertainAsBad, byte PercentDataBad, byte PercentDataGood, bool UseSlopedExtrapolation);
|
||||
|
||||
/// <summary>Part 11 ReadProcessedDetails. The aggregate is per item (<see cref="DataHistoryReadItem.AggregateId"/>).</summary>
|
||||
/// <param name="StartUtc">StartTime; null = unset.</param>
|
||||
/// <param name="EndUtc">EndTime; null = unset.</param>
|
||||
/// <param name="ProcessingInterval">The interval.</param>
|
||||
/// <param name="Configuration">The configuration; null = server defaults.</param>
|
||||
public sealed record DataHistoryProcessedDetails(
|
||||
DateTimeOffset? StartUtc, DateTimeOffset? EndUtc, TimeSpan ProcessingInterval, DataAggregateConfiguration? Configuration)
|
||||
: DataHistoryDetails;
|
||||
|
||||
/// <summary>Part 11 ReadAtTimeDetails.</summary>
|
||||
/// <param name="RequestedTimesUtc">The requested times, in order.</param>
|
||||
public sealed record DataHistoryAtTimeDetails(IReadOnlyList<DateTimeOffset> RequestedTimesUtc) : DataHistoryDetails;
|
||||
|
||||
/// <summary>One node of a remote history read.</summary>
|
||||
/// <param name="CorrelationId">Echoed on the result.</param>
|
||||
/// <param name="View">The exported view being read.</param>
|
||||
/// <param name="AggregateId">Processed only: the standard aggregate function's ns=0 numeric NodeId.</param>
|
||||
/// <param name="Continuation">The origin's opaque continuation token from a previous page; null = a fresh read.</param>
|
||||
public sealed record DataHistoryReadItem(string CorrelationId, DataView View, uint? AggregateId = null, byte[]? Continuation = null);
|
||||
|
||||
/// <summary>A batch of nodes read with one set of details.</summary>
|
||||
public sealed record DataHistoryReadRequest(DataHistoryDetails Details, IReadOnlyList<DataHistoryReadItem> Items, DataBudget Budget);
|
||||
|
||||
/// <summary>
|
||||
/// One returned history value, verbatim from the origin's Part 11 answer: the full status (Calculated / Interpolated /
|
||||
/// Partial bits included) and timestamps that stay absent when absent. Owns <see cref="Value"/>.
|
||||
/// </summary>
|
||||
public sealed record DataHistorySample(DataValue Value, uint StatusCode, DateTimeOffset? SourceTimestampUtc, DateTimeOffset? ServerTimestampUtc)
|
||||
: IDisposable
|
||||
{
|
||||
public void Dispose() => Value.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One node's answer: the Part 11 operation status (full uint32 — <c>BadContinuationPointInvalid</c>,
|
||||
/// <c>BadAggregateNotSupported</c>, <c>GoodNoData</c> …), its samples and the origin's next continuation token (null
|
||||
/// when the read is complete). Owns its samples.
|
||||
/// </summary>
|
||||
public sealed record DataHistoryReadResult(string CorrelationId, uint StatusCode, IReadOnlyList<DataHistorySample> Samples, byte[]? Continuation)
|
||||
: IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var sample in Samples) sample.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remote HistoryRead (Raw / Processed / AtTime) served by the origin's own historian pipeline. Operations use the
|
||||
/// authenticated caller bound to the containing connection facade; continuations are bound to that caller, the serving
|
||||
/// incarnation, the history epoch, the view and the request details, and are single-use.
|
||||
/// </summary>
|
||||
public interface IDataHistoryService
|
||||
{
|
||||
/// <summary>Reads every item, returning results in request order.</summary>
|
||||
Task<IReadOnlyList<DataHistoryReadResult>> ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Releases continuation tokens without reading (Part 11 <c>releaseContinuationPoints</c>); best effort, idempotent.</summary>
|
||||
Task ReleaseAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests.DataConnections;
|
||||
|
||||
/// <summary>H1: the SDK-free remote-history contract H2 implements on the origin side.</summary>
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H1")]
|
||||
public sealed class GrpcDataHistoryContractTests
|
||||
{
|
||||
[Fact]
|
||||
public void The_contract_lives_in_the_data_connection_namespace_and_names_no_sdk_type()
|
||||
{
|
||||
var types = new[]
|
||||
{
|
||||
typeof(IDataHistoryService), typeof(DataHistoryDetails), typeof(DataHistoryRawDetails), typeof(DataHistoryProcessedDetails),
|
||||
typeof(DataHistoryAtTimeDetails), typeof(DataAggregateConfiguration), typeof(DataHistoryReadItem),
|
||||
typeof(DataHistoryReadRequest), typeof(DataHistorySample), typeof(DataHistoryReadResult),
|
||||
};
|
||||
foreach (var type in types)
|
||||
{
|
||||
type.Namespace.ShouldBe("ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections");
|
||||
type.IsPublic.ShouldBeTrue(type.Name);
|
||||
var referenced = type.GetProperties().Select(p => p.PropertyType)
|
||||
.Concat(type.GetMethods().SelectMany(m => m.GetParameters().Select(p => p.ParameterType).Append(m.ReturnType)));
|
||||
referenced.ShouldAllBe(t => t.Namespace == null || !t.Namespace.StartsWith("Opc.", StringComparison.Ordinal), type.Name);
|
||||
}
|
||||
|
||||
typeof(DataHistoryDetails).IsAbstract.ShouldBeTrue();
|
||||
typeof(DataHistoryRawDetails).BaseType.ShouldBe(typeof(DataHistoryDetails));
|
||||
typeof(DataHistoryProcessedDetails).BaseType.ShouldBe(typeof(DataHistoryDetails));
|
||||
typeof(DataHistoryAtTimeDetails).BaseType.ShouldBe(typeof(DataHistoryDetails));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unset_bounds_are_absent_not_MinValue_and_statuses_are_full_uint32()
|
||||
{
|
||||
// §3.3: the origin's end-only / open-end rules depend on "absent", so the contract cannot spell it MinValue.
|
||||
typeof(DataHistoryRawDetails).GetProperty(nameof(DataHistoryRawDetails.StartUtc))!.PropertyType.ShouldBe(typeof(DateTimeOffset?));
|
||||
typeof(DataHistoryRawDetails).GetProperty(nameof(DataHistoryRawDetails.EndUtc))!.PropertyType.ShouldBe(typeof(DateTimeOffset?));
|
||||
typeof(DataHistoryProcessedDetails).GetProperty(nameof(DataHistoryProcessedDetails.StartUtc))!.PropertyType.ShouldBe(typeof(DateTimeOffset?));
|
||||
typeof(DataHistorySample).GetProperty(nameof(DataHistorySample.SourceTimestampUtc))!.PropertyType.ShouldBe(typeof(DateTimeOffset?));
|
||||
typeof(DataHistoryReadResult).GetProperty(nameof(DataHistoryReadResult.StatusCode))!.PropertyType.ShouldBe(typeof(uint));
|
||||
typeof(DataHistorySample).GetProperty(nameof(DataHistorySample.StatusCode))!.PropertyType.ShouldBe(typeof(uint));
|
||||
|
||||
var endOnly = new DataHistoryRawDetails(null, DateTimeOffset.UnixEpoch, 5, ReturnBounds: false);
|
||||
endOnly.StartUtc.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_result_owns_and_disposes_its_samples()
|
||||
{
|
||||
var value = DataValue.FromScalar(DataValueKind.Double, 1.5);
|
||||
var result = new DataHistoryReadResult("c1", 0x00A50000u,
|
||||
[new DataHistorySample(value, 0x00000000u, DateTimeOffset.UnixEpoch, null)], Continuation: null);
|
||||
result.Dispose();
|
||||
Should.Throw<ObjectDisposedException>(() => value.GetScalar());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user