From ac9455634d4c324bc679ba3ce498e8878885497a Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 12:05:09 -0500 Subject: [PATCH] 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. --- .../Entities/DataExport.cs | 6 + .../Entities/RemoteNamespaceMapping.cs | 8 + ...20_AddDataConnectionConditions.Designer.cs | 2012 +++++++++++++++++ ...61124170120_AddDataConnectionConditions.cs | 122 + .../OtOpcUaConfigDbContextModelSnapshot.cs | 22 +- .../OtOpcUaConfigDbContext.cs | 4 +- .../Validation/DataConnectionValidator.cs | 57 +- .../GrpcDataConditionConfigurationTests.cs | 192 ++ ...GrpcDataReservedOperationAuthoringTests.cs | 5 +- 9 files changed, 2418 insertions(+), 10 deletions(-) create mode 100644 src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.Designer.cs create mode 100644 src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.cs create mode 100644 tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataConditionConfigurationTests.cs diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/DataExport.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/DataExport.cs index eacbe4d3d..0a5ec06cc 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/DataExport.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/DataExport.cs @@ -25,5 +25,11 @@ public sealed class DataExport public int MaxHistoryValuesPerPage { get; set; } = 10000; /// H2: response-byte cap; a larger answer is split into bounded chunks (chunk_continues). public int MaxHistoryResponseBytes { get; set; } = 4 * 1024 * 1024; + /// A2: conditions one remote condition scope (subscription root) may carry; a larger scope is refused with + /// Unavailable(ConditionCapacity) before anything is materialised (plan §5.5). + public int MaxConditions { get; set; } = 1000; + /// 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 AlarmAcknowledge. + public bool AllowGalaxyServiceAck { get; set; } public byte[] RowVersion { get; set; } = []; } diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/RemoteNamespaceMapping.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/RemoteNamespaceMapping.cs index 07dbc9391..040471a12 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/RemoteNamespaceMapping.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/RemoteNamespaceMapping.cs @@ -34,5 +34,13 @@ public sealed class RemoteNamespaceMapping public int PublishingIntervalMilliseconds { get; set; } = 1000; /// H2 (used by H3): per-request budget for assembling chunked remote Processed/AtTime answers. public int MaxHistoryAssemblyBytesPerRequest { get; set; } = 16 * 1024 * 1024; + /// A2: conditions this mapping may import; a remote scope over it is Unavailable(ConditionCapacity) (plan §5.5). + public int MaxConditions { get; set; } = 1000; + /// A2: after a disconnect lasting this long, imported conditions report BadNoCommunication. + public int ConditionStaleTimeoutMilliseconds { get; set; } = 30000; + /// A2 (used by A2b): ceiling of one remote condition method call (ack/confirm/shelve). + public int ConditionMethodTimeoutMilliseconds { get; set; } = 5000; + /// A2: how long a condition snapshot may take before the incomplete mapping is Unavailable. + public int ConditionSnapshotTimeoutMilliseconds { get; set; } = 30000; public byte[] RowVersion { get; set; } = []; } diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.Designer.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.Designer.cs new file mode 100644 index 000000000..fa42c73f2 --- /dev/null +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.Designer.cs @@ -0,0 +1,2012 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ZB.MOM.WW.OtOpcUa.Configuration; + +#nullable disable + +namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations +{ + [DbContext(typeof(OtOpcUaConfigDbContext))] + [Migration("20261124170120_AddDataConnectionConditions")] + partial class AddDataConnectionConditions + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FriendlyName") + .HasColumnType("nvarchar(max)"); + + b.Property("Xml") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("DataProtectionKeys", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ApiKey", b => + { + b.Property("ApiKeyRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ApiKeyId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("CreatedUtc") + .HasColumnType("datetime2"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("ExpiresUtc") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Notes") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("Principal") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SecretHash") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.HasKey("ApiKeyRowId"); + + b.HasIndex("ApiKeyId") + .IsUnique() + .HasDatabaseName("UX_ApiKey_ApiKeyId"); + + b.HasIndex("Principal") + .HasDatabaseName("IX_ApiKey_Principal"); + + b.ToTable("ApiKey", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b => + { + b.Property("NodeId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("AkkaPort") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(4053); + + b.Property("ApplicationUri") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("DashboardPort") + .HasColumnType("int"); + + b.Property("DriverConfigOverridesJson") + .HasColumnType("nvarchar(max)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("GrpcPort") + .HasColumnType("int"); + + b.Property("Host") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("LastSeenAt") + .HasColumnType("datetime2(3)"); + + b.Property("MaintenanceMode") + .HasColumnType("bit"); + + b.Property("OpcUaPort") + .HasColumnType("int"); + + b.Property("ServiceLevelBase") + .HasColumnType("tinyint"); + + b.HasKey("NodeId"); + + b.HasIndex("ApplicationUri") + .IsUnique() + .HasDatabaseName("UX_ClusterNode_ApplicationUri"); + + b.HasIndex("ClusterId") + .HasDatabaseName("IX_ClusterNode_ClusterId"); + + b.ToTable("ClusterNode", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeCredential", b => + { + b.Property("CredentialId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Kind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("NodeId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RotatedAt") + .HasColumnType("datetime2(3)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.HasKey("CredentialId"); + + b.HasIndex("Kind", "Value") + .IsUnique() + .HasDatabaseName("UX_ClusterNodeCredential_Value") + .HasFilter("[Enabled] = 1"); + + b.HasIndex("NodeId", "Enabled") + .HasDatabaseName("IX_ClusterNodeCredential_NodeId"); + + b.ToTable("ClusterNodeCredential", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigAuditLog", b => + { + b.Property("AuditId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("AuditId")); + + b.Property("ClusterId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("CorrelationId") + .HasColumnType("uniqueidentifier"); + + b.Property("DetailsJson") + .HasColumnType("nvarchar(max)"); + + b.Property("EventId") + .HasColumnType("uniqueidentifier"); + + b.Property("EventType") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("GenerationId") + .HasColumnType("bigint"); + + b.Property("NodeId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Outcome") + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("Principal") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Timestamp") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.HasKey("AuditId"); + + b.HasIndex("EventId") + .IsUnique() + .HasDatabaseName("UX_ConfigAuditLog_EventId") + .HasFilter("[EventId] IS NOT NULL"); + + b.HasIndex("GenerationId") + .HasDatabaseName("IX_ConfigAuditLog_Generation") + .HasFilter("[GenerationId] IS NOT NULL"); + + b.HasIndex("ClusterId", "Timestamp") + .IsDescending(false, true) + .HasDatabaseName("IX_ConfigAuditLog_Cluster_Time"); + + b.ToTable("ConfigAuditLog", null, t => + { + t.HasCheckConstraint("CK_ConfigAuditLog_DetailsJson_IsJson", "DetailsJson IS NULL OR ISJSON(DetailsJson) = 1"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ConfigEdit", b => + { + b.Property("EditId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("EditedAtUtc") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("EditedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("EntityId") + .HasColumnType("uniqueidentifier"); + + b.Property("EntityType") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ExecutionId") + .HasColumnType("uniqueidentifier"); + + b.Property("FieldsJson") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SourceNode") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("EditId"); + + b.HasIndex("EditedAtUtc") + .HasDatabaseName("IX_ConfigEdit_EditedAt"); + + b.HasIndex("ExecutionId") + .HasDatabaseName("IX_ConfigEdit_Execution") + .HasFilter("[ExecutionId] IS NOT NULL"); + + b.HasIndex("EntityType", "EntityId") + .HasDatabaseName("IX_ConfigEdit_Entity"); + + b.ToTable("ConfigEdit", null, t => + { + t.HasCheckConstraint("CK_ConfigEdit_FieldsJson_IsJson", "ISJSON(FieldsJson) = 1"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DataConnection", b => + { + b.Property("DataConnectionRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AllowedOperations") + .HasColumnType("int"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Consistency") + .HasColumnType("int"); + + b.PrimitiveCollection("ConsumerNodeIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DataConnectionId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.PrimitiveCollection("EligibleTargetNodeIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.PrimitiveCollection("Endpoints") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExpectedClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ExpectedNodeId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("HistoryTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("MaxBatchItems") + .HasColumnType("int"); + + b.Property("MaxMessageBytes") + .HasColumnType("int"); + + b.Property("MaxMonitoredItems") + .HasColumnType("int"); + + b.Property("MaxPageItems") + .HasColumnType("int"); + + b.Property("MaxPendingBytes") + .HasColumnType("bigint"); + + b.Property("MaxStreams") + .HasColumnType("int"); + + b.Property("Revision") + .HasColumnType("bigint"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SecretReference") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("SecretScopeClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("TargetMode") + .HasColumnType("int"); + + b.Property("TimeoutMilliseconds") + .HasColumnType("int"); + + b.HasKey("DataConnectionRowId"); + + b.HasIndex("ClusterId"); + + b.HasIndex("DataConnectionId") + .IsUnique() + .HasFilter("[DataConnectionId] IS NOT NULL"); + + 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 AND [HistoryTimeoutMilliseconds] > 0"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DataConnectionScopeState", b => + { + b.Property("Id") + .HasColumnType("int"); + + b.Property("Fingerprint") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("ScopeVersion") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("DataConnectionScopeState", null, t => + { + t.HasCheckConstraint("CK_DataConnectionScopeState_Singleton", "[Id] = 1 AND [ScopeVersion] >= 0"); + }); + + b.HasData( + new + { + Id = 1, + ScopeVersion = 0L + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DataExport", b => + { + b.Property("DataExportRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AllowGalaxyServiceAck") + .HasColumnType("bit"); + + b.Property("AllowedOperations") + .HasColumnType("int"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("DataExportId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("MaxBatchItems") + .HasColumnType("int"); + + b.Property("MaxConcurrentHistoryReads") + .HasColumnType("int"); + + b.Property("MaxConditions") + .HasColumnType("int"); + + b.Property("MaxHistoryResponseBytes") + .HasColumnType("int"); + + b.Property("MaxHistoryValuesPerPage") + .HasColumnType("int"); + + b.Property("MaxMonitoredItems") + .HasColumnType("int"); + + b.Property("MaxPageItems") + .HasColumnType("int"); + + b.Property("MaxStreams") + .HasColumnType("int"); + + b.Property("PrincipalId") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Realm") + .HasColumnType("int"); + + b.Property("Revision") + .HasColumnType("bigint"); + + b.Property("RootEntityId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RootKind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.HasKey("DataExportRowId"); + + b.HasIndex("ClusterId"); + + b.HasIndex("DataExportId") + .IsUnique() + .HasFilter("[DataExportId] IS NOT NULL"); + + 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 AND [MaxConditions] > 0"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Deployment", b => + { + b.Property("DeploymentId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ArtifactBlob") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("CreatedAtUtc") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("FailureReason") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.Property("RevisionHash") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SealedAtUtc") + .HasColumnType("datetime2(3)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("DeploymentId"); + + b.HasIndex("CreatedAtUtc") + .HasDatabaseName("IX_Deployment_CreatedAt"); + + b.HasIndex("Status") + .HasDatabaseName("IX_Deployment_Status"); + + b.ToTable("Deployment", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Device", b => + { + b.Property("DeviceRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("DeviceConfig") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DeviceId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("DriverInstanceId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.HasKey("DeviceRowId"); + + b.HasIndex("DeviceId") + .IsUnique() + .HasDatabaseName("UX_Device_LogicalId") + .HasFilter("[DeviceId] IS NOT NULL"); + + b.HasIndex("DriverInstanceId") + .HasDatabaseName("IX_Device_Driver"); + + b.HasIndex("DriverInstanceId", "Name") + .IsUnique() + .HasDatabaseName("UX_Device_Driver_Name"); + + b.ToTable("Device", null, t => + { + t.HasCheckConstraint("CK_Device_DeviceConfig_IsJson", "ISJSON(DeviceConfig) = 1"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DriverInstance", b => + { + b.Property("DriverInstanceRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("DriverConfig") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DriverInstanceId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("DriverType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("RawFolderId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ResilienceConfig") + .HasColumnType("nvarchar(max)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.HasKey("DriverInstanceRowId"); + + b.HasIndex("ClusterId") + .HasDatabaseName("IX_DriverInstance_Cluster"); + + b.HasIndex("DriverInstanceId") + .IsUnique() + .HasDatabaseName("UX_DriverInstance_LogicalId") + .HasFilter("[DriverInstanceId] IS NOT NULL"); + + b.HasIndex("RawFolderId") + .HasDatabaseName("IX_DriverInstance_RawFolder"); + + b.HasIndex("ClusterId", "Name") + .IsUnique() + .HasDatabaseName("UX_DriverInstance_ClusterRoot_Name") + .HasFilter("[RawFolderId] IS NULL"); + + b.HasIndex("ClusterId", "RawFolderId", "Name") + .IsUnique() + .HasDatabaseName("UX_DriverInstance_Folder_Name") + .HasFilter("[RawFolderId] IS NOT NULL"); + + b.ToTable("DriverInstance", null, t => + { + t.HasCheckConstraint("CK_DriverInstance_DriverConfig_IsJson", "ISJSON(DriverConfig) = 1"); + + t.HasCheckConstraint("CK_DriverInstance_ResilienceConfig_IsJson", "ResilienceConfig IS NULL OR ISJSON(ResilienceConfig) = 1"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Equipment", b => + { + b.Property("EquipmentRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AssetLocation") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("DeviceManualUri") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("EquipmentClassRef") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("EquipmentId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("EquipmentUuid") + .HasColumnType("uniqueidentifier"); + + b.Property("HardwareRevision") + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("MachineCode") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Manufacturer") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ManufacturerUri") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("Model") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SAPID") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("SerialNumber") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("SoftwareRevision") + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("UnsLineId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("YearOfConstruction") + .HasColumnType("smallint"); + + b.Property("ZTag") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("EquipmentRowId"); + + b.HasIndex("EquipmentId") + .IsUnique() + .HasDatabaseName("UX_Equipment_LogicalId") + .HasFilter("[EquipmentId] IS NOT NULL"); + + b.HasIndex("EquipmentUuid") + .IsUnique() + .HasDatabaseName("UX_Equipment_Uuid"); + + b.HasIndex("MachineCode") + .HasDatabaseName("IX_Equipment_MachineCode"); + + b.HasIndex("SAPID") + .HasDatabaseName("IX_Equipment_SAPID") + .HasFilter("[SAPID] IS NOT NULL"); + + b.HasIndex("UnsLineId") + .HasDatabaseName("IX_Equipment_Line"); + + b.HasIndex("ZTag") + .HasDatabaseName("IX_Equipment_ZTag") + .HasFilter("[ZTag] IS NOT NULL"); + + b.HasIndex("UnsLineId", "Name") + .IsUnique() + .HasDatabaseName("UX_Equipment_LinePath"); + + b.ToTable("Equipment", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ExternalIdReservation", b => + { + b.Property("ReservationId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("EquipmentUuid") + .HasColumnType("uniqueidentifier"); + + b.Property("FirstPublishedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("FirstPublishedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Kind") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("LastPublishedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("ReleaseReason") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("ReleasedAt") + .HasColumnType("datetime2(3)"); + + b.Property("ReleasedBy") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Value") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("ReservationId"); + + b.HasIndex("EquipmentUuid") + .HasDatabaseName("IX_ExternalIdReservation_Equipment"); + + b.HasIndex("Kind", "Value") + .IsUnique() + .HasDatabaseName("UX_ExternalIdReservation_KindValue_Active") + .HasFilter("[ReleasedAt] IS NULL"); + + b.ToTable("ExternalIdReservation", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.LdapGroupRoleMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ClusterId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("CreatedAtUtc") + .HasColumnType("datetime2(3)"); + + b.Property("IsSystemWide") + .HasColumnType("bit"); + + b.Property("LdapGroup") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("Notes") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("Role") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.HasKey("Id"); + + b.HasIndex("ClusterId"); + + b.HasIndex("LdapGroup") + .HasDatabaseName("IX_LdapGroupRoleMapping_Group"); + + b.HasIndex("LdapGroup", "ClusterId") + .IsUnique() + .HasDatabaseName("UX_LdapGroupRoleMapping_Group_Cluster") + .HasFilter("[ClusterId] IS NOT NULL"); + + b.ToTable("LdapGroupRoleMapping", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.NodeAcl", b => + { + b.Property("NodeAclRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("NodeAclId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Notes") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("PermissionFlags") + .HasColumnType("int"); + + b.Property("Principal") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("ScopeId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ScopeKind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.HasKey("NodeAclRowId"); + + b.HasIndex("ClusterId") + .HasDatabaseName("IX_NodeAcl_Cluster"); + + b.HasIndex("NodeAclId") + .IsUnique() + .HasDatabaseName("UX_NodeAcl_LogicalId") + .HasFilter("[NodeAclId] IS NOT NULL"); + + b.HasIndex("Principal") + .HasDatabaseName("IX_NodeAcl_Principal"); + + b.HasIndex("ScopeKind", "ScopeId") + .HasDatabaseName("IX_NodeAcl_Scope") + .HasFilter("[ScopeId] IS NOT NULL"); + + b.HasIndex("ClusterId", "Principal", "ScopeKind", "ScopeId") + .IsUnique() + .HasDatabaseName("UX_NodeAcl_PrincipalScope") + .HasFilter("[ScopeId] IS NOT NULL"); + + b.ToTable("NodeAcl", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.NodeDeploymentState", b => + { + b.Property("NodeId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("DeploymentId") + .HasColumnType("uniqueidentifier"); + + b.Property("AppliedAtUtc") + .HasColumnType("datetime2(3)"); + + b.Property("FailureReason") + .HasMaxLength(2048) + .HasColumnType("nvarchar(2048)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("StartedAtUtc") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("NodeId", "DeploymentId"); + + b.HasIndex("DeploymentId") + .HasDatabaseName("IX_NodeDeploymentState_Deployment"); + + b.HasIndex("Status") + .HasDatabaseName("IX_NodeDeploymentState_Status"); + + b.ToTable("NodeDeploymentState", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.PollGroup", b => + { + b.Property("PollGroupRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("DriverInstanceId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("IntervalMs") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("PollGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.HasKey("PollGroupRowId"); + + b.HasIndex("DriverInstanceId") + .HasDatabaseName("IX_PollGroup_Driver"); + + b.HasIndex("PollGroupId") + .IsUnique() + .HasDatabaseName("UX_PollGroup_LogicalId") + .HasFilter("[PollGroupId] IS NOT NULL"); + + b.ToTable("PollGroup", null, t => + { + t.HasCheckConstraint("CK_PollGroup_IntervalMs_Min", "IntervalMs >= 50"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.RawFolder", b => + { + b.Property("RawFolderRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ParentRawFolderId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RawFolderId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SortOrder") + .HasColumnType("int"); + + b.HasKey("RawFolderRowId"); + + b.HasIndex("ClusterId") + .HasDatabaseName("IX_RawFolder_Cluster"); + + b.HasIndex("RawFolderId") + .IsUnique() + .HasDatabaseName("UX_RawFolder_LogicalId") + .HasFilter("[RawFolderId] IS NOT NULL"); + + b.HasIndex("ClusterId", "Name") + .IsUnique() + .HasDatabaseName("UX_RawFolder_ClusterRoot_Name") + .HasFilter("[ParentRawFolderId] IS NULL"); + + b.HasIndex("ClusterId", "ParentRawFolderId", "Name") + .IsUnique() + .HasDatabaseName("UX_RawFolder_Parent_Name") + .HasFilter("[ParentRawFolderId] IS NOT NULL"); + + b.ToTable("RawFolder", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.RemoteNamespaceMapping", b => + { + b.Property("RemoteNamespaceMappingRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AllowedOperations") + .HasColumnType("int"); + + b.Property("BranchName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("ConditionMethodTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("ConditionSnapshotTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("ConditionStaleTimeoutMilliseconds") + .HasColumnType("int"); + + b.PrimitiveCollection("ConsumerNodeIds") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DataConnectionId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("ExpectedArrayElementKind") + .HasColumnType("int"); + + b.Property("ExpectedValueKind") + .HasColumnType("int"); + + b.Property("LocalParentId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("LocalParentKind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("MaxConditions") + .HasColumnType("int"); + + b.Property("MaxHistoryAssemblyBytesPerRequest") + .HasColumnType("int"); + + b.Property("MaxProjectionDepth") + .HasColumnType("int"); + + b.Property("MaxProjectionNodes") + .HasColumnType("int"); + + b.Property("MetadataLeaseMilliseconds") + .HasColumnType("int"); + + b.Property("PublishingIntervalMilliseconds") + .HasColumnType("int"); + + b.Property("Realm") + .HasColumnType("int"); + + b.Property("RemoteIdentifier") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("RemoteIdentifierKind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("RemoteNamespaceMappingId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RemoteNamespaceUri") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("RemoteRealm") + .HasColumnType("int"); + + b.Property("RemoteRootEntityId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Revision") + .HasColumnType("bigint"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SamplingIntervalMilliseconds") + .HasColumnType("int"); + + b.Property("StaleTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("WriteThrough") + .HasColumnType("bit"); + + b.HasKey("RemoteNamespaceMappingRowId"); + + b.HasIndex("RemoteNamespaceMappingId") + .IsUnique() + .HasFilter("[RemoteNamespaceMappingId] IS NOT NULL"); + + b.HasIndex("ClusterId", "Realm", "LocalParentKind", "LocalParentId", "BranchName") + .IsUnique(); + + 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 AND [MaxConditions] > 0 AND [ConditionStaleTimeoutMilliseconds] > 0 AND [ConditionMethodTimeoutMilliseconds] > 0 AND [ConditionSnapshotTimeoutMilliseconds] > 0"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Script", b => + { + b.Property("ScriptRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("Language") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("ScriptId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("SourceCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SourceHash") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("ScriptRowId"); + + b.HasIndex("ScriptId") + .IsUnique() + .HasDatabaseName("UX_Script_LogicalId") + .HasFilter("[ScriptId] IS NOT NULL"); + + b.HasIndex("SourceHash") + .HasDatabaseName("IX_Script_SourceHash"); + + b.ToTable("Script", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ScriptedAlarm", b => + { + b.Property("ScriptedAlarmRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AlarmType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("EquipmentId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("HistorizeToAveva") + .HasColumnType("bit"); + + b.Property("MessageTemplate") + .IsRequired() + .HasMaxLength(1024) + .HasColumnType("nvarchar(1024)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("PredicateScriptId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Retain") + .HasColumnType("bit"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("ScriptedAlarmId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Severity") + .HasColumnType("int"); + + b.HasKey("ScriptedAlarmRowId"); + + b.HasIndex("PredicateScriptId") + .HasDatabaseName("IX_ScriptedAlarm_Script"); + + b.HasIndex("ScriptedAlarmId") + .IsUnique() + .HasDatabaseName("UX_ScriptedAlarm_LogicalId") + .HasFilter("[ScriptedAlarmId] IS NOT NULL"); + + b.HasIndex("EquipmentId", "Name") + .IsUnique() + .HasDatabaseName("UX_ScriptedAlarm_EquipmentPath"); + + b.ToTable("ScriptedAlarm", null, t => + { + t.HasCheckConstraint("CK_ScriptedAlarm_AlarmType", "AlarmType IN ('AlarmCondition','LimitAlarm','OffNormalAlarm','DiscreteAlarm')"); + + t.HasCheckConstraint("CK_ScriptedAlarm_Severity_Range", "Severity BETWEEN 1 AND 1000"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", b => + { + b.Property("ClusterId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("datetime2(3)") + .HasDefaultValueSql("SYSUTCDATETIME()"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("Enterprise") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2(3)"); + + b.Property("ModifiedBy") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("NodeCount") + .HasColumnType("tinyint"); + + b.Property("Notes") + .HasMaxLength(1024) + .HasColumnType("nvarchar(1024)"); + + b.Property("RedundancyMode") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("Site") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.HasKey("ClusterId"); + + b.HasIndex("Name") + .IsUnique() + .HasDatabaseName("UX_ServerCluster_Name"); + + b.HasIndex("Site") + .HasDatabaseName("IX_ServerCluster_Site"); + + b.ToTable("ServerCluster", null, t => + { + t.HasCheckConstraint("CK_ServerCluster_RedundancyMode_NodeCount", "((NodeCount = 1 AND RedundancyMode = 'None') OR (NodeCount = 2 AND RedundancyMode IN ('Warm', 'Hot')))"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Tag", b => + { + b.Property("TagRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("AccessLevel") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("nvarchar(16)"); + + b.Property("DataType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("DeviceId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("PollGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("TagConfig") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TagGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("TagId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("WriteIdempotent") + .HasColumnType("bit"); + + b.HasKey("TagRowId"); + + b.HasIndex("TagId") + .IsUnique() + .HasDatabaseName("UX_Tag_LogicalId") + .HasFilter("[TagId] IS NOT NULL"); + + b.HasIndex("DeviceId", "Name") + .IsUnique() + .HasDatabaseName("UX_Tag_Device_Name") + .HasFilter("[TagGroupId] IS NULL"); + + b.HasIndex("DeviceId", "TagGroupId") + .HasDatabaseName("IX_Tag_Device"); + + b.HasIndex("DeviceId", "TagGroupId", "Name") + .IsUnique() + .HasDatabaseName("UX_Tag_Group_Name") + .HasFilter("[TagGroupId] IS NOT NULL"); + + b.ToTable("Tag", null, t => + { + t.HasCheckConstraint("CK_Tag_TagConfig_IsJson", "ISJSON(TagConfig) = 1"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.TagGroup", b => + { + b.Property("TagGroupRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("DeviceId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("ParentTagGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SortOrder") + .HasColumnType("int"); + + b.Property("TagGroupId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("TagGroupRowId"); + + b.HasIndex("DeviceId") + .HasDatabaseName("IX_TagGroup_Device"); + + b.HasIndex("TagGroupId") + .IsUnique() + .HasDatabaseName("UX_TagGroup_LogicalId") + .HasFilter("[TagGroupId] IS NOT NULL"); + + b.HasIndex("DeviceId", "Name") + .IsUnique() + .HasDatabaseName("UX_TagGroup_DeviceRoot_Name") + .HasFilter("[ParentTagGroupId] IS NULL"); + + b.HasIndex("DeviceId", "ParentTagGroupId", "Name") + .IsUnique() + .HasDatabaseName("UX_TagGroup_Parent_Name") + .HasFilter("[ParentTagGroupId] IS NOT NULL"); + + b.ToTable("TagGroup", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsArea", b => + { + b.Property("UnsAreaRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ClusterId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("Notes") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("UnsAreaId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("UnsAreaRowId"); + + b.HasIndex("ClusterId") + .HasDatabaseName("IX_UnsArea_Cluster"); + + b.HasIndex("UnsAreaId") + .IsUnique() + .HasDatabaseName("UX_UnsArea_LogicalId") + .HasFilter("[UnsAreaId] IS NOT NULL"); + + b.HasIndex("ClusterId", "Name") + .IsUnique() + .HasDatabaseName("UX_UnsArea_ClusterName"); + + b.ToTable("UnsArea", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsLine", b => + { + b.Property("UnsLineRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("Notes") + .HasMaxLength(512) + .HasColumnType("nvarchar(512)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("UnsAreaId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("UnsLineId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("UnsLineRowId"); + + b.HasIndex("UnsAreaId") + .HasDatabaseName("IX_UnsLine_Area"); + + b.HasIndex("UnsLineId") + .IsUnique() + .HasDatabaseName("UX_UnsLine_LogicalId") + .HasFilter("[UnsLineId] IS NOT NULL"); + + b.HasIndex("UnsAreaId", "Name") + .IsUnique() + .HasDatabaseName("UX_UnsLine_AreaName"); + + b.ToTable("UnsLine", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsTagReference", b => + { + b.Property("UnsTagReferenceRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("DisplayNameOverride") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("EquipmentId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("SortOrder") + .HasColumnType("int"); + + b.Property("TagId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("UnsTagReferenceId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("UnsTagReferenceRowId"); + + b.HasIndex("EquipmentId") + .HasDatabaseName("IX_UnsTagReference_Equipment"); + + b.HasIndex("TagId") + .HasDatabaseName("IX_UnsTagReference_Tag"); + + b.HasIndex("UnsTagReferenceId") + .IsUnique() + .HasDatabaseName("UX_UnsTagReference_LogicalId") + .HasFilter("[UnsTagReferenceId] IS NOT NULL"); + + b.HasIndex("EquipmentId", "TagId") + .IsUnique() + .HasDatabaseName("UX_UnsTagReference_Equip_Tag"); + + b.ToTable("UnsTagReference", (string)null); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.VirtualTag", b => + { + b.Property("VirtualTagRowId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("NEWSEQUENTIALID()"); + + b.Property("ChangeTriggered") + .HasColumnType("bit"); + + b.Property("DataType") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("nvarchar(32)"); + + b.Property("Enabled") + .HasColumnType("bit"); + + b.Property("EquipmentId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("Historize") + .HasColumnType("bit"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("rowversion"); + + b.Property("ScriptId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.Property("TimerIntervalMs") + .HasColumnType("int"); + + b.Property("VirtualTagId") + .HasMaxLength(64) + .HasColumnType("nvarchar(64)"); + + b.HasKey("VirtualTagRowId"); + + b.HasIndex("ScriptId") + .HasDatabaseName("IX_VirtualTag_Script"); + + b.HasIndex("VirtualTagId") + .IsUnique() + .HasDatabaseName("UX_VirtualTag_LogicalId") + .HasFilter("[VirtualTagId] IS NOT NULL"); + + b.HasIndex("EquipmentId", "Name") + .IsUnique() + .HasDatabaseName("UX_VirtualTag_EquipmentPath"); + + b.ToTable("VirtualTag", null, t => + { + t.HasCheckConstraint("CK_VirtualTag_TimerInterval_Min", "TimerIntervalMs IS NULL OR TimerIntervalMs >= 50"); + + t.HasCheckConstraint("CK_VirtualTag_Trigger_AtLeastOne", "ChangeTriggered = 1 OR TimerIntervalMs IS NOT NULL"); + }); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster") + .WithMany("Nodes") + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Cluster"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNodeCredential", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", "Node") + .WithMany("Credentials") + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Node"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DataConnection", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", null) + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DataExport", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", null) + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.DriverInstance", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster") + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Cluster"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.LdapGroupRoleMapping", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster") + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Cluster"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.NodeDeploymentState", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.Deployment", "Deployment") + .WithMany() + .HasForeignKey("DeploymentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", "Node") + .WithMany() + .HasForeignKey("NodeId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Deployment"); + + b.Navigation("Node"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.RawFolder", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", null) + .WithMany("RawFolders") + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.RemoteNamespaceMapping", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", null) + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.UnsArea", b => + { + b.HasOne("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", "Cluster") + .WithMany() + .HasForeignKey("ClusterId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Cluster"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ClusterNode", b => + { + b.Navigation("Credentials"); + }); + + modelBuilder.Entity("ZB.MOM.WW.OtOpcUa.Configuration.Entities.ServerCluster", b => + { + b.Navigation("Nodes"); + + b.Navigation("RawFolders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.cs new file mode 100644 index 000000000..045a9ef05 --- /dev/null +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/20261124170120_AddDataConnectionConditions.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations +{ + /// + public partial class AddDataConnectionConditions : Migration + { + /// + 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( + name: "ConditionMethodTimeoutMilliseconds", + table: "RemoteNamespaceMapping", + type: "int", + nullable: false, + defaultValue: 5000); + + migrationBuilder.AddColumn( + name: "ConditionSnapshotTimeoutMilliseconds", + table: "RemoteNamespaceMapping", + type: "int", + nullable: false, + defaultValue: 30000); + + migrationBuilder.AddColumn( + name: "ConditionStaleTimeoutMilliseconds", + table: "RemoteNamespaceMapping", + type: "int", + nullable: false, + defaultValue: 30000); + + migrationBuilder.AddColumn( + name: "MaxConditions", + table: "RemoteNamespaceMapping", + type: "int", + nullable: false, + defaultValue: 1000); + + migrationBuilder.AddColumn( + name: "AllowGalaxyServiceAck", + table: "DataExport", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + 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"); + } + + /// + 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"); + } + } +} diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/OtOpcUaConfigDbContextModelSnapshot.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/OtOpcUaConfigDbContextModelSnapshot.cs index c68c61ca3..50be4aff1 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/OtOpcUaConfigDbContextModelSnapshot.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Migrations/OtOpcUaConfigDbContextModelSnapshot.cs @@ -491,6 +491,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations .HasColumnType("uniqueidentifier") .HasDefaultValueSql("NEWSEQUENTIALID()"); + b.Property("AllowGalaxyServiceAck") + .HasColumnType("bit"); + b.Property("AllowedOperations") .HasColumnType("int"); @@ -512,6 +515,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations b.Property("MaxConcurrentHistoryReads") .HasColumnType("int"); + b.Property("MaxConditions") + .HasColumnType("int"); + b.Property("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("ConditionMethodTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("ConditionSnapshotTimeoutMilliseconds") + .HasColumnType("int"); + + b.Property("ConditionStaleTimeoutMilliseconds") + .HasColumnType("int"); + b.PrimitiveCollection("ConsumerNodeIds") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -1238,6 +1253,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations .HasMaxLength(32) .HasColumnType("nvarchar(32)"); + b.Property("MaxConditions") + .HasColumnType("int"); + b.Property("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"); }); }); diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/OtOpcUaConfigDbContext.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/OtOpcUaConfigDbContext.cs index 0d3ad26a1..e2d0fd0c8 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/OtOpcUaConfigDbContext.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/OtOpcUaConfigDbContext.cs @@ -136,7 +136,7 @@ public sealed class OtOpcUaConfigDbContext(DbContextOptions(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(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); 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 9d8732799..285874026 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Validation/DataConnectionValidator.cs @@ -12,9 +12,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); A2 adds the alarm bits. + /// and the origin's Implemented(target); A2a adds + /// ; A2b adds the method bits (acknowledge/confirm/shelve). /// - 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 /// Largest RemoteNamespaceMapping.MaxHistoryAssemblyBytesPerRequest (1 GiB). public const int MaxHistoryAssemblyBytesLimit = 1024 * 1024 * 1024; + // A2 bounds (plan §5.5/§6). + /// + /// Largest DataExport.MaxConditions / RemoteNamespaceMapping.MaxConditions: the node manager snapshots at most + /// this many conditions under one Lock hold (OtOpcUaNodeManager.MaxConditionsPerHoldLimit, which this mirrors). + /// + public const int MaxConditionsLimit = 5000; + /// Largest condition stale / method / snapshot timeout (1 h), like . + public const int MaxConditionTimeoutMilliseconds = 3_600_000; + /// Worst-case nodes one imported condition materialises (plan §5.5: 48–49 counted nodes). + public const int NodesPerImportedCondition = 49; + /// Default of the host option DataConnections:MaxImportedConditionNodes (= 2,500 × 49) per consumer node. + public const int DefaultMaxImportedConditionNodes = 122_500; + /// Authoring/deploy-gate validation: an operation bit outside the known set is an error. public static IReadOnlyList 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; } + + /// + /// Non-blocking capacity warnings (plan §5.5/§6): one per consumer node whose enabled + /// mappings could together import more condition nodes (Σ MaxConditions × ) + /// than the host cap DataConnections:MaxImportedConditionNodes. The runtime still admits mappings in deployed order + /// and refuses the ones that would cross the cap (Unavailable(ConditionCapacity)); 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. + /// + public static IReadOnlyList 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(); + } } diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataConditionConfigurationTests.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataConditionConfigurationTests.cs new file mode 100644 index 000000000..e2287d40f --- /dev/null +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataConditionConfigurationTests.cs @@ -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; + +/// A2 schema (plan §6 AddDataConnectionConditions) and authoring rules for remote conditions. +[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 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 + { + // 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)]); + } + + [Fact] + public void Migration_adds_the_six_columns_with_defaults_and_widens_the_checks_reversibly() + { + using var db = new OtOpcUaConfigDbContext(new DbContextOptionsBuilder() + .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(); + 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 nodes, DataOperations operations, int maxConditions = 1000) => new() + { + RemoteNamespaceMappingId = id, ClusterId = "local", DataConnectionId = "connection", Enabled = true, + AllowedOperations = operations, ConsumerNodeIds = nodes, Revision = 1, MaxConditions = maxConditions, + }; +} diff --git a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataReservedOperationAuthoringTests.cs b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataReservedOperationAuthoringTests.cs index d9e852625..ad4dfc86f 100644 --- a/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataReservedOperationAuthoringTests.cs +++ b/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataReservedOperationAuthoringTests.cs @@ -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 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 ReservedBits => new(128, 256, 512); [Theory] [MemberData(nameof(ReservedBits))]