dc6cc7779d
Projected variables advertise Historizing + the HistoryRead access bit (never HistoryWrite) only when the definition says so. The Raw/Processed/AtTime overrides split authorized handles: local ones go to the H1 port unchanged, projected ones to IProjectedHistoryAccess, each written back to its own slot; nothing waits under Lock. HistoryCursorKind.Remote stores the projection's cursor in the SDK session store; disposing the point (session close, eviction, releaseContinuationPoints, faulted request) releases it at the origin. Mapped HistoryRead is opened deliberately in DataPlaneAuthorizer; other mapped operations outside the allowlist stay closed.
87 lines
4.9 KiB
C#
87 lines
4.9 KiB
C#
using Opc.Ua;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
|
|
|
/// <summary>
|
|
/// H3 — the remote cursor behind a <see cref="HistoryCursorKind.Remote"/> continuation point in the consumer's SDK session
|
|
/// store (gRPC data history plan §3.2). Opaque to the node manager: the projection side (Runtime) owns what it binds —
|
|
/// the origin token, mapping id/revision, serving incarnation, projection generation, caller key and the ORIGINAL request
|
|
/// details — and re-checks all of it on resume. The node manager only binds it to the projected node it was issued for.
|
|
/// </summary>
|
|
public abstract class ProjectedHistoryContinuation
|
|
{
|
|
private int _released;
|
|
|
|
/// <summary>Creates a cursor bound to one projected node.</summary>
|
|
/// <param name="realm">The projected node's realm.</param>
|
|
/// <param name="localIdentifier">The projected node's opaque local identifier.</param>
|
|
protected ProjectedHistoryContinuation(DataRealm realm, string localIdentifier)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(localIdentifier);
|
|
Realm = realm;
|
|
LocalIdentifier = localIdentifier;
|
|
}
|
|
|
|
/// <summary>The projected node's realm.</summary>
|
|
public DataRealm Realm { get; }
|
|
|
|
/// <summary>The projected node's local identifier.</summary>
|
|
public string LocalIdentifier { get; }
|
|
|
|
/// <summary>True once the cursor was released or handed back for a resume (it is single-use either way).</summary>
|
|
public bool IsSpent => Volatile.Read(ref _released) != 0;
|
|
|
|
/// <summary>
|
|
/// Best-effort, idempotent, non-blocking release of the origin continuation (<c>releaseContinuationPoints</c>, session
|
|
/// close, eviction, a store refusal). The origin's idle expiry is the backstop.
|
|
/// </summary>
|
|
public void Release()
|
|
{
|
|
if (Interlocked.Exchange(ref _released, 1) == 0) OnRelease();
|
|
}
|
|
|
|
/// <summary>Marks the cursor as handed back for a resume: the resume read owns the origin token from here on.</summary>
|
|
/// <returns><c>false</c> when it was already released or resumed.</returns>
|
|
public bool TryClaimForResume() => Interlocked.Exchange(ref _released, 1) == 0;
|
|
|
|
/// <summary>Forwards the release to the origin (called at most once).</summary>
|
|
protected abstract void OnRelease();
|
|
}
|
|
|
|
/// <summary>One projected node of a consumer HistoryRead (H3).</summary>
|
|
/// <param name="NodeId">The projected node.</param>
|
|
/// <param name="AggregateId">Processed only: the requested aggregate's ns=0 numeric id.</param>
|
|
/// <param name="Resume">The claimed remote cursor of a resumed read; null = a fresh read.</param>
|
|
public sealed record ProjectedHistoryNode(NodeId NodeId, uint? AggregateId = null, ProjectedHistoryContinuation? Resume = null);
|
|
|
|
/// <summary>One projected node's outcome: the origin's Part 11 status verbatim, its values, and the next cursor.</summary>
|
|
/// <param name="StatusCode">The full OPC UA status.</param>
|
|
/// <param name="Samples">The values (CLR values, verbatim status and timestamps).</param>
|
|
/// <param name="Continuation">The next remote cursor; null when the read is complete.</param>
|
|
public sealed record ProjectedHistoryOutcome(uint StatusCode, IReadOnlyList<OriginHistorySample> Samples, ProjectedHistoryContinuation? Continuation = null);
|
|
|
|
/// <summary>
|
|
/// H3 — HistoryRead on projected variables (plan §2.1, §3.2): resolves each projected node to its mapping, deployed
|
|
/// connection lease and origin view, authorizes it (the mapping's HistoryRead bit and a local
|
|
/// <c>NodePermissions.HistoryRead</c> grant on the mapping scope, ACLs on or off), and forwards through
|
|
/// <see cref="IDataHistoryService"/>. A fresh read may move endpoint within its deadline; a resumed read never moves.
|
|
/// </summary>
|
|
public interface IProjectedHistoryAccess
|
|
{
|
|
/// <summary>
|
|
/// Reads one batch of projected nodes for <paramref name="caller"/>. Never called under the node-manager <c>Lock</c>.
|
|
/// Results are in <paramref name="nodes"/> order. Every <see cref="ProjectedHistoryNode.Resume"/> cursor is owned by
|
|
/// the call (resumed or released), whatever the outcome.
|
|
/// </summary>
|
|
/// <param name="caller">The session identity.</param>
|
|
/// <param name="details">The request details (fresh nodes; a resumed node resends its ORIGINAL details).</param>
|
|
/// <param name="nodes">The projected nodes.</param>
|
|
/// <param name="deadline">The consumer request's remaining <c>HistoryReadDeadline</c>; non-positive = unbounded.</param>
|
|
/// <param name="cancellationToken">The SDK request lifetime.</param>
|
|
/// <returns>One outcome per node.</returns>
|
|
Task<IReadOnlyList<ProjectedHistoryOutcome>> ReadAsync(RoleCarryingUserIdentity caller, DataHistoryDetails details,
|
|
IReadOnlyList<ProjectedHistoryNode> nodes, TimeSpan deadline, CancellationToken cancellationToken);
|
|
}
|