feat: add GrpcPort config to NodeOptions with startup validation
This commit is contained in:
@@ -6,4 +6,5 @@ public class NodeOptions
|
|||||||
public string NodeHostname { get; set; } = string.Empty;
|
public string NodeHostname { get; set; } = string.Empty;
|
||||||
public string? SiteId { get; set; }
|
public string? SiteId { get; set; }
|
||||||
public int RemotingPort { get; set; } = 8081;
|
public int RemotingPort { get; set; } = 8081;
|
||||||
|
public int GrpcPort { get; set; } = 8083;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public static class StartupValidator
|
|||||||
|
|
||||||
if (role == "Site")
|
if (role == "Site")
|
||||||
{
|
{
|
||||||
|
var grpcPortStr = nodeSection["GrpcPort"];
|
||||||
|
if (grpcPortStr != null && (!int.TryParse(grpcPortStr, out var gp) || gp < 1 || gp > 65535))
|
||||||
|
errors.Add("ScadaLink:Node:GrpcPort must be 1-65535");
|
||||||
|
|
||||||
var dbSection = configuration.GetSection("ScadaLink:Database");
|
var dbSection = configuration.GetSection("ScadaLink:Database");
|
||||||
if (string.IsNullOrEmpty(dbSection["SiteDbPath"]))
|
if (string.IsNullOrEmpty(dbSection["SiteDbPath"]))
|
||||||
errors.Add("ScadaLink:Database:SiteDbPath required for Site nodes");
|
errors.Add("ScadaLink:Database:SiteDbPath required for Site nodes");
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"Role": "Site",
|
"Role": "Site",
|
||||||
"NodeHostname": "localhost",
|
"NodeHostname": "localhost",
|
||||||
"SiteId": "site-a",
|
"SiteId": "site-a",
|
||||||
"RemotingPort": 8082
|
"RemotingPort": 8082,
|
||||||
|
"GrpcPort": 8083
|
||||||
},
|
},
|
||||||
"Cluster": {
|
"Cluster": {
|
||||||
"SeedNodes": [
|
"SeedNodes": [
|
||||||
|
|||||||
@@ -217,6 +217,43 @@ public class StartupValidatorTests
|
|||||||
Assert.Contains("SeedNodes must have at least 2 entries", ex.Message);
|
Assert.Contains("SeedNodes must have at least 2 entries", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("0")]
|
||||||
|
[InlineData("-1")]
|
||||||
|
[InlineData("65536")]
|
||||||
|
[InlineData("abc")]
|
||||||
|
public void Site_InvalidGrpcPort_FailsValidation(string grpcPort)
|
||||||
|
{
|
||||||
|
var values = ValidSiteConfig();
|
||||||
|
values["ScadaLink:Node:GrpcPort"] = grpcPort;
|
||||||
|
var config = BuildConfig(values);
|
||||||
|
|
||||||
|
var ex = Assert.Throws<InvalidOperationException>(() => StartupValidator.Validate(config));
|
||||||
|
Assert.Contains("GrpcPort must be 1-65535", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Site_ValidGrpcPort_PassesValidation()
|
||||||
|
{
|
||||||
|
var values = ValidSiteConfig();
|
||||||
|
values["ScadaLink:Node:GrpcPort"] = "8083";
|
||||||
|
var config = BuildConfig(values);
|
||||||
|
|
||||||
|
var ex = Record.Exception(() => StartupValidator.Validate(config));
|
||||||
|
Assert.Null(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Central_InvalidGrpcPort_NotValidated()
|
||||||
|
{
|
||||||
|
var values = ValidCentralConfig();
|
||||||
|
values["ScadaLink:Node:GrpcPort"] = "0";
|
||||||
|
var config = BuildConfig(values);
|
||||||
|
|
||||||
|
var ex = Record.Exception(() => StartupValidator.Validate(config));
|
||||||
|
Assert.Null(ex);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MultipleErrors_AllReported()
|
public void MultipleErrors_AllReported()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user