Add configurable non-transparent OPC UA server redundancy
Separates ApplicationUri from namespace identity so each instance in a redundant pair has a unique server URI while sharing the same Galaxy namespace. Exposes RedundancySupport, ServerUriArray, and dynamic ServiceLevel through the standard OPC UA server object. ServiceLevel is computed from role (Primary/Secondary) and runtime health (MXAccess and DB connectivity). Adds CLI redundancy command, second deployed service instance, and 31 new tests including paired-server integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -236,5 +236,81 @@ namespace ZB.MOM.WW.LmxOpcUa.Tests.Configuration
|
||||
config.Security.AutoAcceptClientCertificates.ShouldBe(false);
|
||||
config.Security.MinimumCertificateKeySize.ShouldBe(4096);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Redundancy_Section_BindsFromJson()
|
||||
{
|
||||
var config = LoadFromJson();
|
||||
config.Redundancy.Enabled.ShouldBe(false);
|
||||
config.Redundancy.Mode.ShouldBe("Warm");
|
||||
config.Redundancy.Role.ShouldBe("Primary");
|
||||
config.Redundancy.ServiceLevelBase.ShouldBe(200);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Redundancy_Section_BindsCustomValues()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new[]
|
||||
{
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:Enabled", "true"),
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:Mode", "Hot"),
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:Role", "Secondary"),
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:ServiceLevelBase", "180"),
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:ServerUris:0", "urn:a"),
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("Redundancy:ServerUris:1", "urn:b"),
|
||||
})
|
||||
.Build();
|
||||
|
||||
var config = new AppConfiguration();
|
||||
configuration.GetSection("Redundancy").Bind(config.Redundancy);
|
||||
|
||||
config.Redundancy.Enabled.ShouldBe(true);
|
||||
config.Redundancy.Mode.ShouldBe("Hot");
|
||||
config.Redundancy.Role.ShouldBe("Secondary");
|
||||
config.Redundancy.ServiceLevelBase.ShouldBe(180);
|
||||
config.Redundancy.ServerUris.Count.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validator_RedundancyEnabled_NoApplicationUri_ReturnsFalse()
|
||||
{
|
||||
var config = new AppConfiguration();
|
||||
config.Redundancy.Enabled = true;
|
||||
config.Redundancy.ServerUris.Add("urn:a");
|
||||
config.Redundancy.ServerUris.Add("urn:b");
|
||||
// OpcUa.ApplicationUri is null
|
||||
ConfigurationValidator.ValidateAndLog(config).ShouldBe(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validator_InvalidServiceLevelBase_ReturnsFalse()
|
||||
{
|
||||
var config = new AppConfiguration();
|
||||
config.Redundancy.ServiceLevelBase = 0;
|
||||
ConfigurationValidator.ValidateAndLog(config).ShouldBe(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OpcUa_ApplicationUri_DefaultsToNull()
|
||||
{
|
||||
var config = new OpcUaConfiguration();
|
||||
config.ApplicationUri.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OpcUa_ApplicationUri_BindsFromConfig()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(new[]
|
||||
{
|
||||
new System.Collections.Generic.KeyValuePair<string, string>("OpcUa:ApplicationUri", "urn:test:app"),
|
||||
})
|
||||
.Build();
|
||||
|
||||
var config = new OpcUaConfiguration();
|
||||
configuration.GetSection("OpcUa").Bind(config);
|
||||
config.ApplicationUri.ShouldBe("urn:test:app");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user