feat(grpc-data): A2a AddDataConnectionConditions schema; authoring accepts AlarmSubscribe
Migration per plan 6: DataExport.MaxConditions (1000), AllowGalaxyServiceAck (false); RemoteNamespaceMapping.MaxConditions (1000), ConditionStaleTimeoutMilliseconds (30000), ConditionMethodTimeoutMilliseconds (5000), ConditionSnapshotTimeoutMilliseconds (30000); NOT NULL with SQL defaults, check constraints widened. Validator known set grows by AlarmSubscribe (method bits stay rejected); condition limits bounded (MaxConditions <= 5000 = the node manager's per-hold clamp, timeouts <= 1 h); AllowGalaxyServiceAck only with AlarmAcknowledge; non-blocking ConditionCapacityWarnings when a consumer node's alarm mappings' MaxConditions x 49 exceed MaxImportedConditionNodes.
This commit is contained in:
@@ -25,5 +25,11 @@ public sealed class DataExport
|
||||
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;
|
||||
/// <summary>A2: conditions one remote condition scope (subscription root) may carry; a larger scope is refused with
|
||||
/// <c>Unavailable(ConditionCapacity)</c> before anything is materialised (plan §5.5).</summary>
|
||||
public int MaxConditions { get; set; } = 1000;
|
||||
/// <summary>A2 (used by A2b): per-export opt-in for remote acknowledgement of Galaxy conditions, which execute as the
|
||||
/// origin's service identity (plan §5.6, Q2). Valid only with <c>AlarmAcknowledge</c>.</summary>
|
||||
public bool AllowGalaxyServiceAck { get; set; }
|
||||
public byte[] RowVersion { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -34,5 +34,13 @@ public sealed class RemoteNamespaceMapping
|
||||
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;
|
||||
/// <summary>A2: conditions this mapping may import; a remote scope over it is <c>Unavailable(ConditionCapacity)</c> (plan §5.5).</summary>
|
||||
public int MaxConditions { get; set; } = 1000;
|
||||
/// <summary>A2: after a disconnect lasting this long, imported conditions report <c>BadNoCommunication</c>.</summary>
|
||||
public int ConditionStaleTimeoutMilliseconds { get; set; } = 30000;
|
||||
/// <summary>A2 (used by A2b): ceiling of one remote condition method call (ack/confirm/shelve).</summary>
|
||||
public int ConditionMethodTimeoutMilliseconds { get; set; } = 5000;
|
||||
/// <summary>A2: how long a condition snapshot may take before the incomplete mapping is <c>Unavailable</c>.</summary>
|
||||
public int ConditionSnapshotTimeoutMilliseconds { get; set; } = 30000;
|
||||
public byte[] RowVersion { get; set; } = [];
|
||||
}
|
||||
|
||||
+2012
File diff suppressed because it is too large
Load Diff
+122
@@ -0,0 +1,122 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDataConnectionConditions : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// A2 (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). AllowGalaxyServiceAck defaults to false.
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_RemoteNamespaceMapping_Limits",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_DataExport_Limits",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ConditionMethodTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 5000);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ConditionSnapshotTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 30000);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ConditionStaleTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 30000);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxConditions",
|
||||
table: "RemoteNamespaceMapping",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 1000);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AllowGalaxyServiceAck",
|
||||
table: "DataExport",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "MaxConditions",
|
||||
table: "DataExport",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 1000);
|
||||
|
||||
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 AND [MaxConditions] > 0 AND [ConditionStaleTimeoutMilliseconds] > 0 AND [ConditionMethodTimeoutMilliseconds] > 0 AND [ConditionSnapshotTimeoutMilliseconds] > 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 AND [MaxConditions] > 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.DropColumn(
|
||||
name: "ConditionMethodTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ConditionSnapshotTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ConditionStaleTimeoutMilliseconds",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxConditions",
|
||||
table: "RemoteNamespaceMapping");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AllowGalaxyServiceAck",
|
||||
table: "DataExport");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "MaxConditions",
|
||||
table: "DataExport");
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-2
@@ -491,6 +491,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
.HasColumnType("uniqueidentifier")
|
||||
.HasDefaultValueSql("NEWSEQUENTIALID()");
|
||||
|
||||
b.Property<bool>("AllowGalaxyServiceAck")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("AllowedOperations")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -512,6 +515,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
b.Property<int>("MaxConcurrentHistoryReads")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxConditions")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxHistoryResponseBytes")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -564,7 +570,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 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 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 AND [MaxConditions] > 0");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1210,6 +1216,15 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("nvarchar(64)");
|
||||
|
||||
b.Property<int>("ConditionMethodTimeoutMilliseconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ConditionSnapshotTimeoutMilliseconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ConditionStaleTimeoutMilliseconds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.PrimitiveCollection<string>("ConsumerNodeIds")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@@ -1238,6 +1253,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("nvarchar(32)");
|
||||
|
||||
b.Property<int>("MaxConditions")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("MaxHistoryAssemblyBytesPerRequest")
|
||||
.HasColumnType("int");
|
||||
|
||||
@@ -1312,7 +1330,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 AND [MaxHistoryAssemblyBytesPerRequest] > 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 AND [MaxConditions] > 0 AND [ConditionStaleTimeoutMilliseconds] > 0 AND [ConditionMethodTimeoutMilliseconds] > 0 AND [ConditionSnapshotTimeoutMilliseconds] > 0");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0"));
|
||||
"[Revision] > 0 AND [MaxBatchItems] > 0 AND [MaxPageItems] > 0 AND [MaxMonitoredItems] > 0 AND [MaxStreams] > 0 AND [MaxConcurrentHistoryReads] > 0 AND [MaxHistoryValuesPerPage] > 0 AND [MaxHistoryResponseBytes] > 0 AND [MaxConditions] > 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 AND [MaxHistoryAssemblyBytesPerRequest] > 0"));
|
||||
"[Revision] > 0 AND [MaxProjectionNodes] > 0 AND [MaxProjectionDepth] > 0 AND [MetadataLeaseMilliseconds] > 0 AND [StaleTimeoutMilliseconds] > 0 AND [SamplingIntervalMilliseconds] > 0 AND [PublishingIntervalMilliseconds] > 0 AND [MaxHistoryAssemblyBytesPerRequest] > 0 AND [MaxConditions] > 0 AND [ConditionStaleTimeoutMilliseconds] > 0 AND [ConditionMethodTimeoutMilliseconds] > 0 AND [ConditionSnapshotTimeoutMilliseconds] > 0"));
|
||||
e.HasKey(x => x.RemoteNamespaceMappingRowId);
|
||||
e.Property(x => x.RemoteNamespaceMappingRowId).HasDefaultValueSql("NEWSEQUENTIALID()");
|
||||
e.Property(x => x.RemoteNamespaceMappingId).HasMaxLength(64);
|
||||
|
||||
@@ -12,9 +12,10 @@ public static class DataConnectionValidator
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <see cref="DataOperationSets.Understood"/> and the origin's <c>Implemented(target)</c>; A2a adds
|
||||
/// <see cref="DataOperations.AlarmSubscribe"/>; A2b adds the method bits (acknowledge/confirm/shelve).
|
||||
/// </summary>
|
||||
private const DataOperations KnownOperations = DataOperationSets.V1 | DataOperations.HistoryRead;
|
||||
private const DataOperations KnownOperations = DataOperationSets.V1 | DataOperations.HistoryRead | DataOperations.AlarmSubscribe;
|
||||
private static readonly StringComparer Ids = StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
// H2 upper bounds: keep derived capacities (sessions x reads x batch, remainder budgets) far from int overflow.
|
||||
@@ -31,6 +32,19 @@ public static class DataConnectionValidator
|
||||
/// <summary>Largest <c>RemoteNamespaceMapping.MaxHistoryAssemblyBytesPerRequest</c> (1 GiB).</summary>
|
||||
public const int MaxHistoryAssemblyBytesLimit = 1024 * 1024 * 1024;
|
||||
|
||||
// A2 bounds (plan §5.5/§6).
|
||||
/// <summary>
|
||||
/// Largest <c>DataExport.MaxConditions</c> / <c>RemoteNamespaceMapping.MaxConditions</c>: the node manager snapshots at most
|
||||
/// this many conditions under one <c>Lock</c> hold (<c>OtOpcUaNodeManager.MaxConditionsPerHoldLimit</c>, which this mirrors).
|
||||
/// </summary>
|
||||
public const int MaxConditionsLimit = 5000;
|
||||
/// <summary>Largest condition stale / method / snapshot timeout (1 h), like <see cref="MaxHistoryTimeoutMilliseconds"/>.</summary>
|
||||
public const int MaxConditionTimeoutMilliseconds = 3_600_000;
|
||||
/// <summary>Worst-case nodes one imported condition materialises (plan §5.5: 48–49 counted nodes).</summary>
|
||||
public const int NodesPerImportedCondition = 49;
|
||||
/// <summary>Default of the host option <c>DataConnections:MaxImportedConditionNodes</c> (= 2,500 × 49) per consumer node.</summary>
|
||||
public const int DefaultMaxImportedConditionNodes = 122_500;
|
||||
|
||||
/// <summary>Authoring/deploy-gate validation: an operation bit outside the known set is an error.</summary>
|
||||
public static IReadOnlyList<ValidationError> Validate(DraftSnapshot draft) => Validate(draft, deployed: false);
|
||||
|
||||
@@ -61,6 +75,7 @@ public static class DataConnectionValidator
|
||||
list.Distinct(Ids).Count() == list.Count && list.All(id => draft.ClusterNodes.Any(n =>
|
||||
Same(n.NodeId, id) && Same(n.ClusterId, owner) && n.Enabled));
|
||||
}
|
||||
static bool ConditionTimeout(int milliseconds) => milliseconds > 0 && milliseconds <= MaxConditionTimeoutMilliseconds;
|
||||
bool ValidSegment(string? value, DataRealm realm) => realm == DataRealm.Uns
|
||||
? UnsSegment.IsValid(value)
|
||||
: value is not null && value.Length <= 128 && RawPaths.ValidateSegment(value) is null;
|
||||
@@ -291,7 +306,10 @@ public static class DataConnectionValidator
|
||||
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.MaxHistoryAssemblyBytesPerRequest <= 0 || mapping.MaxHistoryAssemblyBytesPerRequest > MaxHistoryAssemblyBytesLimit)
|
||||
mapping.MaxHistoryAssemblyBytesPerRequest <= 0 || mapping.MaxHistoryAssemblyBytesPerRequest > MaxHistoryAssemblyBytesLimit ||
|
||||
mapping.MaxConditions <= 0 || mapping.MaxConditions > MaxConditionsLimit ||
|
||||
!ConditionTimeout(mapping.ConditionStaleTimeoutMilliseconds) || !ConditionTimeout(mapping.ConditionMethodTimeoutMilliseconds) ||
|
||||
!ConditionTimeout(mapping.ConditionSnapshotTimeoutMilliseconds))
|
||||
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))
|
||||
@@ -305,9 +323,40 @@ public static class DataConnectionValidator
|
||||
if (export.MaxBatchItems <= 0 || export.MaxPageItems <= 0 || export.MaxMonitoredItems <= 0 || export.MaxStreams <= 0 ||
|
||||
export.MaxConcurrentHistoryReads <= 0 || export.MaxConcurrentHistoryReads > MaxConcurrentHistoryReadsLimit ||
|
||||
export.MaxHistoryValuesPerPage <= 0 || export.MaxHistoryValuesPerPage > MaxHistoryValuesPerPageLimit ||
|
||||
export.MaxHistoryResponseBytes < MinHistoryResponseBytesLimit || export.MaxHistoryResponseBytes > MaxHistoryResponseBytesLimit)
|
||||
export.MaxHistoryResponseBytes < MinHistoryResponseBytesLimit || export.MaxHistoryResponseBytes > MaxHistoryResponseBytesLimit ||
|
||||
export.MaxConditions <= 0 || export.MaxConditions > MaxConditionsLimit)
|
||||
Add("DataExportLimitInvalid", id, "Export limits must be positive.");
|
||||
// A2 (plan §5.6 Q2): the Galaxy service-identity ack opt-in means nothing without the acknowledge grant. The RAW
|
||||
// bits are checked in both modes: at authoring AlarmAcknowledge is still outside the known set (A2b), so the flag
|
||||
// must stay false; a deployed row from a newer central that carries both is tolerated (the flag is inert here).
|
||||
if (export.AllowGalaxyServiceAck && !export.AllowedOperations.HasFlag(DataOperations.AlarmAcknowledge))
|
||||
Add("DataExportGalaxyAckInvalid", id, "Galaxy service acknowledgement can be allowed only on an export that grants AlarmAcknowledge.");
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Non-blocking capacity warnings (plan §5.5/§6): one per consumer node whose enabled <see cref="DataOperations.AlarmSubscribe"/>
|
||||
/// mappings could together import more condition nodes (Σ <c>MaxConditions</c> × <see cref="NodesPerImportedCondition"/>)
|
||||
/// than the host cap <c>DataConnections:MaxImportedConditionNodes</c>. The runtime still admits mappings in deployed order
|
||||
/// and refuses the ones that would cross the cap (<c>Unavailable(ConditionCapacity)</c>); this only says so up front. The
|
||||
/// validator's error list has no warning channel, so these are returned separately and never block authoring or deploy.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<ValidationError> ConditionCapacityWarnings(DraftSnapshot draft,
|
||||
int maxImportedConditionNodes = DefaultMaxImportedConditionNodes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(draft);
|
||||
return draft.RemoteNamespaceMappings
|
||||
.Where(m => m.Enabled && m.AllowedOperations.HasFlag(DataOperations.AlarmSubscribe))
|
||||
.SelectMany(m => m.ConsumerNodeIds.Distinct(Ids).Select(node => (Node: node, Nodes: (long)Math.Max(0, m.MaxConditions) * NodesPerImportedCondition)))
|
||||
.GroupBy(x => x.Node, Ids)
|
||||
.Select(g => (Node: g.Key, Total: g.Sum(x => x.Nodes)))
|
||||
.Where(x => x.Total > maxImportedConditionNodes)
|
||||
.OrderBy(x => x.Node, StringComparer.OrdinalIgnoreCase)
|
||||
.Select(x => new ValidationError("DataConditionCapacityWarning",
|
||||
$"Consumer node {x.Node}: its alarm mappings' MaxConditions × {NodesPerImportedCondition} = {x.Total} condition nodes exceeds " +
|
||||
$"DataConnections:MaxImportedConditionNodes ({maxImportedConditionNodes}); mappings past the cap will be Unavailable (ConditionCapacity).",
|
||||
x.Node))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
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>A2 schema (plan §6 <c>AddDataConnectionConditions</c>) and authoring rules for remote conditions.</summary>
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "A2")]
|
||||
public sealed class GrpcDataConditionConfigurationTests
|
||||
{
|
||||
private const DataOperations Alarms = DataOperations.Read | DataOperations.AlarmSubscribe;
|
||||
|
||||
[Fact]
|
||||
public void Authoring_accepts_AlarmSubscribe_on_connections_exports_and_mappings()
|
||||
{
|
||||
var errors = DataConnectionValidator.Validate(GrpcDataReservedOperationAuthoringTests.Snapshot(Alarms));
|
||||
errors.ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(128)]
|
||||
[InlineData(256)]
|
||||
[InlineData(512)]
|
||||
public void The_method_bits_stay_unauthorable_until_A2b(int bit)
|
||||
{
|
||||
var errors = DataConnectionValidator.Validate(GrpcDataReservedOperationAuthoringTests.Snapshot(Alarms | (DataOperations)bit));
|
||||
errors.ShouldContain(x => x.Code == "DataConnectionOperationsInvalid");
|
||||
errors.ShouldContain(x => x.Code == "DataExportOperationsInvalid");
|
||||
errors.ShouldContain(x => x.Code == "DataMappingOperationsInvalid");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_mapping_AlarmSubscribe_bit_must_be_granted_by_its_connection()
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(DataOperations.Read);
|
||||
draft.RemoteNamespaceMappings[0].AllowedOperations = Alarms;
|
||||
DataConnectionValidator.Validate(draft).ShouldContain(x => x.Code == "DataMappingOperationsInvalid" && x.Context == "mapping");
|
||||
DataConnectionValidator.ValidateDeployed(draft).ShouldContain(x => x.Code == "DataMappingOperationsInvalid", "understood since A2a");
|
||||
draft.DataConnections[0].AllowedOperations = Alarms;
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code == "DataMappingOperationsInvalid");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void New_entities_carry_the_plans_defaults()
|
||||
{
|
||||
var export = new DataExport();
|
||||
export.MaxConditions.ShouldBe(1000);
|
||||
export.AllowGalaxyServiceAck.ShouldBeFalse();
|
||||
var mapping = new RemoteNamespaceMapping();
|
||||
mapping.MaxConditions.ShouldBe(1000);
|
||||
mapping.ConditionStaleTimeoutMilliseconds.ShouldBe(30000);
|
||||
mapping.ConditionMethodTimeoutMilliseconds.ShouldBe(5000);
|
||||
mapping.ConditionSnapshotTimeoutMilliseconds.ShouldBe(30000);
|
||||
}
|
||||
|
||||
public static TheoryData<string, int> OutOfRange => new()
|
||||
{
|
||||
{ "export.MaxConditions", 0 }, { "export.MaxConditions", -1 }, { "export.MaxConditions", DataConnectionValidator.MaxConditionsLimit + 1 },
|
||||
{ "mapping.MaxConditions", 0 }, { "mapping.MaxConditions", DataConnectionValidator.MaxConditionsLimit + 1 },
|
||||
{ "mapping.ConditionStaleTimeoutMilliseconds", 0 }, { "mapping.ConditionStaleTimeoutMilliseconds", 3_600_001 },
|
||||
{ "mapping.ConditionMethodTimeoutMilliseconds", -1 }, { "mapping.ConditionMethodTimeoutMilliseconds", 3_600_001 },
|
||||
{ "mapping.ConditionSnapshotTimeoutMilliseconds", 0 }, { "mapping.ConditionSnapshotTimeoutMilliseconds", 3_600_001 },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(OutOfRange))]
|
||||
public void Condition_limits_are_bounded_at_authoring_and_on_a_deployed_artifact(string limit, int value)
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(Alarms);
|
||||
var export = draft.DataExports[0];
|
||||
var mapping = draft.RemoteNamespaceMappings[0];
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code.EndsWith("LimitInvalid", StringComparison.Ordinal));
|
||||
var (code, context) = limit switch
|
||||
{
|
||||
"export.MaxConditions" => Set(() => export.MaxConditions = value, "DataExportLimitInvalid", "export"),
|
||||
"mapping.MaxConditions" => Set(() => mapping.MaxConditions = value, "DataMappingLimitInvalid", "mapping"),
|
||||
"mapping.ConditionStaleTimeoutMilliseconds" => Set(() => mapping.ConditionStaleTimeoutMilliseconds = value, "DataMappingLimitInvalid", "mapping"),
|
||||
"mapping.ConditionMethodTimeoutMilliseconds" => Set(() => mapping.ConditionMethodTimeoutMilliseconds = value, "DataMappingLimitInvalid", "mapping"),
|
||||
_ => Set(() => mapping.ConditionSnapshotTimeoutMilliseconds = 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_upper_bounds_themselves_are_accepted()
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(Alarms);
|
||||
draft.DataExports[0].MaxConditions = DataConnectionValidator.MaxConditionsLimit;
|
||||
var mapping = draft.RemoteNamespaceMappings[0];
|
||||
mapping.MaxConditions = DataConnectionValidator.MaxConditionsLimit;
|
||||
mapping.ConditionStaleTimeoutMilliseconds = mapping.ConditionMethodTimeoutMilliseconds = mapping.ConditionSnapshotTimeoutMilliseconds =
|
||||
DataConnectionValidator.MaxConditionTimeoutMilliseconds;
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code.EndsWith("LimitInvalid", StringComparison.Ordinal));
|
||||
DataConnectionValidator.MaxConditionsLimit.ShouldBe(5000, "mirrors OtOpcUaNodeManager.MaxConditionsPerHoldLimit");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllowGalaxyServiceAck_requires_AlarmAcknowledge_so_it_cannot_be_authored_before_A2b()
|
||||
{
|
||||
var draft = GrpcDataReservedOperationAuthoringTests.Snapshot(Alarms);
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code == "DataExportGalaxyAckInvalid");
|
||||
draft.DataExports[0].AllowGalaxyServiceAck = true;
|
||||
DataConnectionValidator.Validate(draft).ShouldContain(x => x.Code == "DataExportGalaxyAckInvalid" && x.Context == "export");
|
||||
DataConnectionValidator.ValidateDeployed(draft).ShouldContain(x => x.Code == "DataExportGalaxyAckInvalid" && x.Context == "export");
|
||||
// With the acknowledge grant: authoring still refuses the (A2b) bit itself, but not the flag; a deployed row from a
|
||||
// newer central carrying both is tolerated (the bit is ignored, the flag is inert).
|
||||
draft.DataExports[0].AllowedOperations = Alarms | DataOperations.AlarmAcknowledge;
|
||||
var authored = DataConnectionValidator.Validate(draft);
|
||||
authored.ShouldContain(x => x.Code == "DataExportOperationsInvalid");
|
||||
authored.ShouldNotContain(x => x.Code == "DataExportGalaxyAckInvalid");
|
||||
DataConnectionValidator.ValidateDeployed(draft).ShouldNotContain(x => x.Code == "DataExportOperationsInvalid" || x.Code == "DataExportGalaxyAckInvalid");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_consumer_node_over_the_imported_condition_cap_gets_a_warning_not_an_error()
|
||||
{
|
||||
var mappings = new List<RemoteNamespaceMapping>
|
||||
{
|
||||
// 2 × 1000 × 49 = 98,000 ≤ 122,500 for node-a: quiet.
|
||||
Mapping("mapping-1", ["node-a"], Alarms), Mapping("mapping-2", ["NODE-A", "node-b"], Alarms),
|
||||
};
|
||||
var draft = new DraftSnapshot { GenerationId = 1, ClusterId = "local", RemoteNamespaceMappings = mappings };
|
||||
DataConnectionValidator.ConditionCapacityWarnings(draft).ShouldBeEmpty();
|
||||
// A third alarm mapping on node-a: 147,000 > 122,500 ⇒ one warning for node-a (ids case-insensitive), none for node-b.
|
||||
mappings.Add(Mapping("mapping-3", ["node-a"], Alarms));
|
||||
// Mappings without AlarmSubscribe, and disabled ones, import no conditions and are not counted.
|
||||
mappings.Add(Mapping("no-alarms", ["node-b"], DataOperations.Read, maxConditions: 5000));
|
||||
var disabled = Mapping("disabled", ["node-b"], Alarms, maxConditions: 5000);
|
||||
disabled.Enabled = false;
|
||||
mappings.Add(disabled);
|
||||
var warning = DataConnectionValidator.ConditionCapacityWarnings(draft).ShouldHaveSingleItem();
|
||||
warning.Code.ShouldBe("DataConditionCapacityWarning");
|
||||
warning.Context.ShouldBe("node-a", StringCompareShould.IgnoreCase);
|
||||
warning.Message.ShouldContain("147000");
|
||||
warning.Message.ShouldContain("122500");
|
||||
DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code == "DataConditionCapacityWarning", "never blocks authoring");
|
||||
// The host cap is a parameter (DataConnections:MaxImportedConditionNodes).
|
||||
DataConnectionValidator.ConditionCapacityWarnings(draft, 200_000).ShouldBeEmpty();
|
||||
DataConnectionValidator.ConditionCapacityWarnings(draft, 49_000).Count.ShouldBe(1, "node-b at exactly the cap is not over it");
|
||||
DataConnectionValidator.ConditionCapacityWarnings(draft, 48_999).Count.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_scope_revision_does_not_include_the_condition_limits()
|
||||
{
|
||||
// Plan §6 / H2 review: limits ride the artifact's entity JSON, not the trust-scope fingerprint. The A2 limits live on
|
||||
// exports and mappings, which the scope revision never reads: its only input is the connection rows.
|
||||
var parameters = typeof(DataConnectionScopeRevision).GetMethod(nameof(DataConnectionScopeRevision.Advance))!.GetParameters();
|
||||
parameters.Select(p => p.ParameterType).ShouldBe([typeof(long), typeof(string), typeof(IEnumerable<DataConnection>)]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_adds_the_six_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("_AddDataConnectionConditions", StringComparison.Ordinal));
|
||||
index.ShouldBeGreaterThan(0);
|
||||
migrations[index - 1].ShouldEndWith("_AddDataConnectionHistory");
|
||||
var migrator = db.GetService<IMigrator>();
|
||||
var up = migrator.GenerateScript(migrations[index - 1], migrations[index]);
|
||||
up.ShouldContain("ALTER TABLE [DataExport] ADD [MaxConditions] int NOT NULL DEFAULT 1000");
|
||||
up.ShouldContain("ALTER TABLE [DataExport] ADD [AllowGalaxyServiceAck] bit NOT NULL DEFAULT CAST(0 AS bit)");
|
||||
up.ShouldContain("ALTER TABLE [RemoteNamespaceMapping] ADD [MaxConditions] int NOT NULL DEFAULT 1000");
|
||||
up.ShouldContain("ALTER TABLE [RemoteNamespaceMapping] ADD [ConditionStaleTimeoutMilliseconds] int NOT NULL DEFAULT 30000");
|
||||
up.ShouldContain("ALTER TABLE [RemoteNamespaceMapping] ADD [ConditionMethodTimeoutMilliseconds] int NOT NULL DEFAULT 5000");
|
||||
up.ShouldContain("ALTER TABLE [RemoteNamespaceMapping] ADD [ConditionSnapshotTimeoutMilliseconds] int NOT NULL DEFAULT 30000");
|
||||
up.ShouldContain("[MaxHistoryResponseBytes] > 0 AND [MaxConditions] > 0");
|
||||
up.ShouldContain("[MaxConditions] > 0 AND [ConditionStaleTimeoutMilliseconds] > 0 AND [ConditionMethodTimeoutMilliseconds] > 0 AND [ConditionSnapshotTimeoutMilliseconds] > 0");
|
||||
up.ShouldNotContain("[DataConnection]", Case.Sensitive, "no DataConnection column in A2");
|
||||
var down = migrator.GenerateScript(migrations[index], migrations[index - 1]);
|
||||
foreach (var column in new[] { "MaxConditions", "AllowGalaxyServiceAck", "ConditionStaleTimeoutMilliseconds",
|
||||
"ConditionMethodTimeoutMilliseconds", "ConditionSnapshotTimeoutMilliseconds" })
|
||||
down.ShouldContain($"DROP COLUMN [{column}]");
|
||||
down.ShouldNotContain("DROP TABLE");
|
||||
db.Database.HasPendingModelChanges().ShouldBeFalse();
|
||||
}
|
||||
|
||||
private static RemoteNamespaceMapping Mapping(string id, List<string> nodes, DataOperations operations, int maxConditions = 1000) => new()
|
||||
{
|
||||
RemoteNamespaceMappingId = id, ClusterId = "local", DataConnectionId = "connection", Enabled = true,
|
||||
AllowedOperations = operations, ConsumerNodeIds = nodes, Revision = 1, MaxConditions = maxConditions,
|
||||
};
|
||||
}
|
||||
+3
-2
@@ -13,8 +13,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
|
||||
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "X0")]
|
||||
public sealed class GrpcDataReservedOperationAuthoringTests
|
||||
{
|
||||
// H2 implemented 32 (HistoryRead): authoring accepts it (GrpcDataHistoryConfigurationTests). A2 takes the rest.
|
||||
public static TheoryData<int> ReservedBits => new(64, 128, 256, 512);
|
||||
// H2 implemented 32 (HistoryRead) and A2a 64 (AlarmSubscribe): authoring accepts them (GrpcDataHistoryConfigurationTests,
|
||||
// GrpcDataConditionConfigurationTests). A2b takes the method bits.
|
||||
public static TheoryData<int> ReservedBits => new(128, 256, 512);
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ReservedBits))]
|
||||
|
||||
Reference in New Issue
Block a user