feat(grpc-data): H2 AddDataConnectionHistory schema; authoring accepts HistoryRead
Migration per plan 6 (HistoryTimeoutMilliseconds 30000; MaxConcurrentHistoryReads 4, MaxHistoryValuesPerPage 10000, MaxHistoryResponseBytes 4 MiB; MaxHistoryAssemblyBytesPerRequest 16 MiB) with non-null defaults and widened check constraints. Validator known set grows by HistoryRead (mapping bits still subset of connection bits; history limits positive); scope revision includes the history timeout.
This commit is contained in:
@@ -28,5 +28,7 @@ public sealed class DataConnection
|
||||
public int MaxStreams { get; set; } = 100;
|
||||
public int MaxMonitoredItems { get; set; } = 10000;
|
||||
public long MaxPendingBytes { get; set; } = 4 * 1024 * 1024;
|
||||
/// <summary>H2: per-call ceiling for a remote HistoryRead (min of the caller's remaining deadline and this).</summary>
|
||||
public int HistoryTimeoutMilliseconds { get; set; } = 30000;
|
||||
public byte[] RowVersion { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -19,5 +19,11 @@ public sealed class DataExport
|
||||
public int MaxPageItems { get; set; } = 500;
|
||||
public int MaxMonitoredItems { get; set; } = 10000;
|
||||
public int MaxStreams { get; set; } = 100;
|
||||
/// <summary>H2: concurrent remote HistoryRead requests admitted per principal (past it ⇒ BadTooManyOperations).</summary>
|
||||
public int MaxConcurrentHistoryReads { get; set; } = 4;
|
||||
/// <summary>H2: per-node page ceiling of a remote raw read (an uncapped read pages at this and returns a continuation).</summary>
|
||||
public int MaxHistoryValuesPerPage { get; set; } = 10000;
|
||||
/// <summary>H2: response-byte cap; a larger answer is split into bounded chunks (chunk_continues).</summary>
|
||||
public int MaxHistoryResponseBytes { get; set; } = 4 * 1024 * 1024;
|
||||
public byte[] RowVersion { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -32,5 +32,7 @@ public sealed class RemoteNamespaceMapping
|
||||
public int StaleTimeoutMilliseconds { get; set; } = 30000;
|
||||
public int SamplingIntervalMilliseconds { get; set; } = 1000;
|
||||
public int PublishingIntervalMilliseconds { get; set; } = 1000;
|
||||
/// <summary>H2 (used by H3): per-request budget for assembling chunked remote Processed/AtTime answers.</summary>
|
||||
public int MaxHistoryAssemblyBytesPerRequest { get; set; } = 16 * 1024 * 1024;
|
||||
public byte[] RowVersion { get; set; } = [];
|
||||
}
|
||||
|
||||
+1994
File diff suppressed because it is too large
Load Diff
+129
@@ -0,0 +1,129 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDataConnectionHistory : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// H2 (plan §6): non-null columns with the plan's defaults, so existing rows need no backfill and satisfy the
|
||||
// widened check constraints (an EF-default 0 would violate them).
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_RemoteNamespaceMapping_Limits",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_DataExport_Limits",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_DataConnection_Limits",
|
||||
table: "DataConnection");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxHistoryAssemblyBytesPerRequest",
|
||||
table: "RemoteNamespaceMapping",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 16777216);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxConcurrentHistoryReads",
|
||||
table: "DataExport",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 4);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxHistoryResponseBytes",
|
||||
table: "DataExport",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 4194304);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxHistoryValuesPerPage",
|
||||
table: "DataExport",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 10000);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "HistoryTimeoutMilliseconds",
|
||||
table: "DataConnection",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 30000);
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_RemoteNamespaceMapping_Limits",
|
||||
table: "RemoteNamespaceMapping",
|
||||
sql: "[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0 AND [MaxHistoryAssemblyBytesPerRequest] > 0");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_DataExport_Limits",
|
||||
table: "DataExport",
|
||||
sql: "[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_DataConnection_Limits",
|
||||
table: "DataConnection",
|
||||
sql: "[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0 AND [HistoryTimeoutMilliseconds] > 0");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_RemoteNamespaceMapping_Limits",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_DataExport_Limits",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_DataConnection_Limits",
|
||||
table: "DataConnection");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxHistoryAssemblyBytesPerRequest",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxConcurrentHistoryReads",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxHistoryResponseBytes",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxHistoryValuesPerPage",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HistoryTimeoutMilliseconds",
|
||||
table: "DataConnection");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_RemoteNamespaceMapping_Limits",
|
||||
table: "RemoteNamespaceMapping",
|
||||
sql: "[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_DataExport_Limits",
|
||||
table: "DataExport",
|
||||
sql: "[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_DataConnection_Limits",
|
||||
table: "DataConnection",
|
||||
sql: "[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-3
@@ -391,6 +391,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("nvarchar(64)");
|
||||
|
||||
b.Property<int>("HistoryTimeoutMilliseconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxBatchItems")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -444,7 +447,7 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
|
||||
b.ToTable("DataConnection", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_DataConnection_Limits", "[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0");
|
||||
t.HasCheckConstraint("CK_DataConnection_Limits", "[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0 AND [HistoryTimeoutMilliseconds] > 0");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -506,6 +509,15 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
b.Property<int>("MaxBatchItems")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxConcurrentHistoryReads")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxHistoryResponseBytes")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxHistoryValuesPerPage")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxMonitoredItems")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -552,7 +564,7 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
|
||||
b.ToTable("DataExport", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_DataExport_Limits", "[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0");
|
||||
t.HasCheckConstraint("CK_DataExport_Limits", "[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1226,6 +1238,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("nvarchar(32)");
|
||||
|
||||
b.Property<int>("MaxHistoryAssemblyBytesPerRequest")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxProjectionDepth")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -1297,7 +1312,7 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
|
||||
b.ToTable("RemoteNamespaceMapping", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_RemoteNamespaceMapping_Limits", "[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0");
|
||||
t.HasCheckConstraint("CK_RemoteNamespaceMapping_Limits", "[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0 AND [MaxHistoryAssemblyBytesPerRequest] > 0");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public sealed class OtOpcUaConfigDbContext(DbContextOptions<OtOpcUaConfigDbConte
|
||||
modelBuilder.Entity<DataConnection>(e =>
|
||||
{
|
||||
e.ToTable("DataConnection", t => t.HasCheckConstraint("CK_DataConnection_Limits",
|
||||
"[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0"));
|
||||
"[Revision] > 0 AND [TimeoutMilliseconds] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMessageBytes] > 0 AND [MaxStreams] > 0 AND [MaxMonitoredItems] > 0 AND [MaxPendingBytes] > 0 AND [HistoryTimeoutMilliseconds] > 0"));
|
||||
e.HasKey(x => x.DataConnectionRowId);
|
||||
e.Property(x => x.DataConnectionRowId).HasDefaultValueSql("NEWSEQUENTIALID()");
|
||||
e.Property(x => x.DataConnectionId).HasMaxLength(64);
|
||||
@@ -136,7 +136,7 @@ public sealed class OtOpcUaConfigDbContext(DbContextOptions<OtOpcUaConfigDbConte
|
||||
modelBuilder.Entity<DataExport>(e =>
|
||||
{
|
||||
e.ToTable("DataExport", t => t.HasCheckConstraint("CK_DataExport_Limits",
|
||||
"[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0"));
|
||||
"[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0"));
|
||||
e.HasKey(x => x.DataExportRowId);
|
||||
e.Property(x => x.DataExportRowId).HasDefaultValueSql("NEWSEQUENTIALID()");
|
||||
e.Property(x => x.DataExportId).HasMaxLength(64);
|
||||
@@ -151,7 +151,7 @@ public sealed class OtOpcUaConfigDbContext(DbContextOptions<OtOpcUaConfigDbConte
|
||||
modelBuilder.Entity<RemoteNamespaceMapping>(e =>
|
||||
{
|
||||
e.ToTable("RemoteNamespaceMapping", t => t.HasCheckConstraint("CK_RemoteNamespaceMapping_Limits",
|
||||
"[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0"));
|
||||
"[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0 AND [MaxHistoryAssemblyBytesPerRequest] > 0"));
|
||||
e.HasKey(x => x.RemoteNamespaceMappingRowId);
|
||||
e.Property(x => x.RemoteNamespaceMappingRowId).HasDefaultValueSql("NEWSEQUENTIALID()");
|
||||
e.Property(x => x.RemoteNamespaceMappingId).HasMaxLength(64);
|
||||
|
||||
@@ -15,7 +15,9 @@ public static class DataConnectionScopeRevision
|
||||
var entries = connections.Where(c => c.Enabled).SelectMany(c => c.ConsumerNodeIds.Select(node => new
|
||||
{
|
||||
Owner = c.ClusterId.ToUpperInvariant(), Consumer = node.ToUpperInvariant(),
|
||||
Connection = c.DataConnectionId.ToUpperInvariant(), SecretOwner = c.SecretScopeClusterId.ToUpperInvariant(), Secret = c.SecretReference
|
||||
Connection = c.DataConnectionId.ToUpperInvariant(), SecretOwner = c.SecretScopeClusterId.ToUpperInvariant(), Secret = c.SecretReference,
|
||||
// H2 (plan §6): new connection fields are part of the scope so DB-less nodes and the LocalDb cache re-scope on a change.
|
||||
c.HistoryTimeoutMilliseconds
|
||||
})).OrderBy(x => x.Owner, StringComparer.Ordinal).ThenBy(x => x.Consumer, StringComparer.Ordinal)
|
||||
.ThenBy(x => x.Connection, StringComparer.Ordinal).ThenBy(x => x.SecretOwner, StringComparer.Ordinal).ThenBy(x => x.Secret, StringComparer.Ordinal).ToArray();
|
||||
var fingerprint = Convert.ToHexString(SHA256.HashData(JsonSerializer.SerializeToUtf8Bytes(entries)));
|
||||
|
||||
@@ -10,10 +10,11 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
||||
public static class DataConnectionValidator
|
||||
{
|
||||
/// <summary>
|
||||
/// The operations AUTHORING may grant. Deliberately the v1 set: it grows only in the phase that implements a bit
|
||||
/// (H2, A2), so authoring cannot get ahead of the code (plan section 4.3, "grow site").
|
||||
/// 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 <see cref="DataOperations.HistoryRead"/> together with
|
||||
/// <see cref="DataOperationSets.Understood"/> and the origin's <c>Implemented(target)</c>; A2 adds the alarm bits.
|
||||
/// </summary>
|
||||
private const DataOperations KnownOperations = DataOperationSets.V1;
|
||||
private const DataOperations KnownOperations = DataOperationSets.V1 | DataOperations.HistoryRead;
|
||||
private static readonly StringComparer Ids = StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
/// <summary>Authoring/deploy-gate validation: an operation bit outside the known set is an error.</summary>
|
||||
@@ -122,7 +123,8 @@ public static class DataConnectionValidator
|
||||
if (!ValidOps(connection.AllowedOperations))
|
||||
Add("DataConnectionOperationsInvalid", id, "Connection operations must be a supported nonempty subset.");
|
||||
if (connection.TimeoutMilliseconds <= 0 || connection.MaxBatchItems <= 0 || connection.MaxPageItems <= 0 ||
|
||||
connection.MaxMessageBytes <= 0 || connection.MaxStreams <= 0 || connection.MaxMonitoredItems <= 0 || connection.MaxPendingBytes <= 0)
|
||||
connection.MaxMessageBytes <= 0 || connection.MaxStreams <= 0 || connection.MaxMonitoredItems <= 0 || connection.MaxPendingBytes <= 0 ||
|
||||
connection.HistoryTimeoutMilliseconds <= 0)
|
||||
Add("DataConnectionLimitInvalid", id, "Connection limits must be positive.");
|
||||
}
|
||||
|
||||
@@ -274,7 +276,8 @@ public static class DataConnectionValidator
|
||||
(mapping.AllowedOperations.HasFlag(DataOperations.Write) && !mapping.WriteThrough))
|
||||
Add("DataMappingOperationsInvalid", id, "Mapping operations must be permitted by the connection and write-through policy.");
|
||||
if (mapping.MaxProjectionNodes <= 0 || mapping.MaxProjectionDepth <= 0 || mapping.MetadataLeaseMilliseconds <= 0 ||
|
||||
mapping.StaleTimeoutMilliseconds <= 0 || mapping.SamplingIntervalMilliseconds <= 0 || mapping.PublishingIntervalMilliseconds <= 0)
|
||||
mapping.StaleTimeoutMilliseconds <= 0 || mapping.SamplingIntervalMilliseconds <= 0 || mapping.PublishingIntervalMilliseconds <= 0 ||
|
||||
mapping.MaxHistoryAssemblyBytesPerRequest <= 0)
|
||||
Add("DataMappingLimitInvalid", id, "Mapping limits and intervals must be positive and the metadata lease bounded.");
|
||||
}
|
||||
foreach (var export in draft.DataExports.Where(x => x.Enabled))
|
||||
@@ -285,7 +288,8 @@ public static class DataConnectionValidator
|
||||
!Same(Owner(export.RootKind, export.RootEntityId), export.ClusterId))
|
||||
Add("DataExportRootInvalid", id, "Export requires a named principal and an origin-local root in its realm.");
|
||||
if (!ValidOps(export.AllowedOperations)) Add("DataExportOperationsInvalid", id, "Export operations must be a supported nonempty subset.");
|
||||
if (export.MaxBatchItems <= 0 || export.MaxPageItems <= 0 || export.MaxMonitoredItems <= 0 || export.MaxStreams <= 0)
|
||||
if (export.MaxBatchItems <= 0 || export.MaxPageItems <= 0 || export.MaxMonitoredItems <= 0 || export.MaxStreams <= 0 ||
|
||||
export.MaxConcurrentHistoryReads <= 0 || export.MaxHistoryValuesPerPage <= 0 || export.MaxHistoryResponseBytes <= 0)
|
||||
Add("DataExportLimitInvalid", id, "Export limits must be positive.");
|
||||
}
|
||||
return errors;
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
|
||||
|
||||
/// <summary>H2 schema (plan §6 <c>AddDataConnectionHistory</c>) and authoring rules for remote history.</summary>
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H2")]
|
||||
public sealed class GrpcDataHistoryConfigurationTests
|
||||
{
|
||||
[Fact]
|
||||
public void Authoring_accepts_HistoryRead_on_connections_exports_and_mappings()
|
||||
{
|
||||
var errors = DataConnectionValidator.Validate(GrpcDataReservedOperationAuthoringTests.Snapshot(DataOperations.Read | DataOperations.HistoryRead));
|
||||
errors.ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_mapping_HistoryRead_bit_must_be_granted_by_its_connection()
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(DataOperations.Read);
|
||||
draft.RemoteNamespaceMappings[0].AllowedOperations = DataOperations.Read | DataOperations.HistoryRead;
|
||||
DataConnectionValidator.Validate(draft).ShouldContain(x => x.Code == "DataMappingOperationsInvalid" && x.Context == "mapping");
|
||||
draft.DataConnections[0].AllowedOperations = DataOperations.Read | DataOperations.HistoryRead;
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code == "DataMappingOperationsInvalid");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void New_entities_carry_the_plans_defaults()
|
||||
{
|
||||
new DataConnection().HistoryTimeoutMilliseconds.ShouldBe(30000);
|
||||
var export = new DataExport();
|
||||
export.MaxConcurrentHistoryReads.ShouldBe(4);
|
||||
export.MaxHistoryValuesPerPage.ShouldBe(10000);
|
||||
export.MaxHistoryResponseBytes.ShouldBe(4 * 1024 * 1024);
|
||||
new RemoteNamespaceMapping().MaxHistoryAssemblyBytesPerRequest.ShouldBe(16 * 1024 * 1024);
|
||||
}
|
||||
|
||||
public static TheoryData<string> Limits => new(
|
||||
"connection.HistoryTimeoutMilliseconds", "export.MaxConcurrentHistoryReads", "export.MaxHistoryValuesPerPage",
|
||||
"export.MaxHistoryResponseBytes", "mapping.MaxHistoryAssemblyBytesPerRequest");
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Limits))]
|
||||
public void History_limits_must_be_positive_at_authoring_and_on_a_deployed_artifact(string limit)
|
||||
{
|
||||
foreach (var value in new[] { 0, -1 })
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(DataOperations.Read | DataOperations.HistoryRead);
|
||||
var (code, context) = limit switch
|
||||
{
|
||||
"connection.HistoryTimeoutMilliseconds" => Set(() => draft.DataConnections[0].HistoryTimeoutMilliseconds = value, "DataConnectionLimitInvalid", "connection"),
|
||||
"export.MaxConcurrentHistoryReads" => Set(() => draft.DataExports[0].MaxConcurrentHistoryReads = value, "DataExportLimitInvalid", "export"),
|
||||
"export.MaxHistoryValuesPerPage" => Set(() => draft.DataExports[0].MaxHistoryValuesPerPage = value, "DataExportLimitInvalid", "export"),
|
||||
"export.MaxHistoryResponseBytes" => Set(() => draft.DataExports[0].MaxHistoryResponseBytes = value, "DataExportLimitInvalid", "export"),
|
||||
_ => Set(() => draft.RemoteNamespaceMappings[0].MaxHistoryAssemblyBytesPerRequest = value, "DataMappingLimitInvalid", "mapping"),
|
||||
};
|
||||
DataConnectionValidator.Validate(draft).ShouldContain(x => x.Code == code && x.Context == context, limit);
|
||||
DataConnectionValidator.ValidateDeployed(draft).ShouldContain(x => x.Code == code && x.Context == context, limit);
|
||||
}
|
||||
static (string, string) Set(Action set, string code, string context) { set(); return (code, context); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_scope_revision_includes_the_history_timeout()
|
||||
{
|
||||
var connection = new DataConnection
|
||||
{
|
||||
DataConnectionId = "c", ClusterId = "a", Enabled = true, ConsumerNodeIds = ["n"], SecretScopeClusterId = "a", SecretReference = "s",
|
||||
};
|
||||
var first = DataConnectionScopeRevision.Advance(0, null, [connection]);
|
||||
DataConnectionScopeRevision.Advance(first.Version, first.Fingerprint, [connection]).Version.ShouldBe(first.Version);
|
||||
connection.HistoryTimeoutMilliseconds = 5000;
|
||||
var changed = DataConnectionScopeRevision.Advance(first.Version, first.Fingerprint, [connection]);
|
||||
changed.Fingerprint.ShouldNotBe(first.Fingerprint);
|
||||
changed.Version.ShouldBe(first.Version + 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_adds_the_five_columns_with_defaults_and_widens_the_checks_reversibly()
|
||||
{
|
||||
using var db = new OtOpcUaConfigDbContext(new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
|
||||
.UseSqlServer("Server=127.0.0.1,1;Database=design;Integrated Security=true;TrustServerCertificate=true").Options);
|
||||
var migrations = db.Database.GetMigrations().ToArray();
|
||||
var index = Array.FindIndex(migrations, x => x.EndsWith("_AddDataConnectionHistory", StringComparison.Ordinal));
|
||||
index.ShouldBeGreaterThan(0);
|
||||
migrations[index - 1].ShouldEndWith("_AddDataConnectionScopeState");
|
||||
var migrator = db.GetService<IMigrator>();
|
||||
var up = migrator.GenerateScript(migrations[index - 1], migrations[index]);
|
||||
up.ShouldContain("ALTER TABLE [DataConnection] ADD [HistoryTimeoutMilliseconds] int NOT NULL DEFAULT 30000");
|
||||
up.ShouldContain("ALTER TABLE [DataExport] ADD [MaxConcurrentHistoryReads] int NOT NULL DEFAULT 4");
|
||||
up.ShouldContain("ALTER TABLE [DataExport] ADD [MaxHistoryValuesPerPage] int NOT NULL DEFAULT 10000");
|
||||
up.ShouldContain("ALTER TABLE [DataExport] ADD [MaxHistoryResponseBytes] int NOT NULL DEFAULT 4194304");
|
||||
up.ShouldContain("ALTER TABLE [RemoteNamespaceMapping] ADD [MaxHistoryAssemblyBytesPerRequest] int NOT NULL DEFAULT 16777216");
|
||||
up.ShouldContain("[HistoryTimeoutMilliseconds] > 0");
|
||||
up.ShouldContain("[MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0");
|
||||
up.ShouldContain("[MaxHistoryAssemblyBytesPerRequest] > 0");
|
||||
var down = migrator.GenerateScript(migrations[index], migrations[index - 1]);
|
||||
foreach (var column in new[] { "HistoryTimeoutMilliseconds", "MaxConcurrentHistoryReads", "MaxHistoryValuesPerPage",
|
||||
"MaxHistoryResponseBytes", "MaxHistoryAssemblyBytesPerRequest" })
|
||||
down.ShouldContain($"DROP COLUMN [{column}]");
|
||||
down.ShouldNotContain("DROP TABLE");
|
||||
db.Database.HasPendingModelChanges().ShouldBeFalse();
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -13,7 +13,8 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "X0")]
|
||||
public sealed class GrpcDataReservedOperationAuthoringTests
|
||||
{
|
||||
public static TheoryData<int> ReservedBits => new(32, 64, 128, 256, 512);
|
||||
// H2 implemented 32 (HistoryRead): authoring accepts it (GrpcDataHistoryConfigurationTests). A2 takes the rest.
|
||||
public static TheoryData<int> ReservedBits => new(64, 128, 256, 512);
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ReservedBits))]
|
||||
@@ -65,7 +66,7 @@ public sealed class GrpcDataReservedOperationAuthoringTests
|
||||
.ShouldNotContain(x => x.Code == "DataConnectionOperationsInvalid" || x.Code == "DataExportOperationsInvalid");
|
||||
}
|
||||
|
||||
private static DraftSnapshot Snapshot(DataOperations operations) => new()
|
||||
internal static DraftSnapshot Snapshot(DataOperations operations) => new()
|
||||
{
|
||||
GenerationId = 1, ClusterId = "local",
|
||||
DataConnections = [new DataConnection
|
||||
|
||||
Reference in New Issue
Block a user