Phase 0 WP-0.10–0.12: Host skeleton, options classes, sample configs, and execution framework

- WP-0.10: Role-based Host startup (Central=WebApplication, Site=generic Host),
  15 component AddXxx() extension methods, MapCentralUI/MapInboundAPI stubs
- WP-0.11: 12 per-component options classes with config binding
- WP-0.12: Sample appsettings for central and site topologies
- Add execution procedure and checklist template to generate_plans.md
- Add phase-0-checklist.md for execution tracking
- Resolve all 21 open questions from plan generation
- Update IDataConnection with batch ops and IAsyncDisposable
57 tests pass, zero warnings.
This commit is contained in:
Joseph Doherty
2026-03-16 18:59:07 -04:00
parent 22e1eba58a
commit 8c2091dc0a
72 changed files with 1289 additions and 194 deletions

View File

@@ -0,0 +1,8 @@
namespace ScadaLink.Host;
public class DatabaseOptions
{
public string? ConfigurationDb { get; set; }
public string? MachineDataDb { get; set; }
public string? SiteDbPath { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace ScadaLink.Host;
public class LoggingOptions
{
public string MinimumLevel { get; set; } = "Information";
}

View File

@@ -0,0 +1,9 @@
namespace ScadaLink.Host;
public class NodeOptions
{
public string Role { get; set; } = string.Empty;
public string NodeHostname { get; set; } = string.Empty;
public string? SiteId { get; set; }
public int RemotingPort { get; set; } = 8081;
}

View File

@@ -1,2 +1,106 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using ScadaLink.CentralUI;
using ScadaLink.ClusterInfrastructure;
using ScadaLink.Communication;
using ScadaLink.ConfigurationDatabase;
using ScadaLink.DataConnectionLayer;
using ScadaLink.DeploymentManager;
using ScadaLink.ExternalSystemGateway;
using ScadaLink.HealthMonitoring;
using ScadaLink.Host;
using ScadaLink.InboundAPI;
using ScadaLink.NotificationService;
using ScadaLink.Security;
using ScadaLink.SiteEventLogging;
using ScadaLink.SiteRuntime;
using ScadaLink.StoreAndForward;
using ScadaLink.TemplateEngine;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"}.json", optional: true)
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
var role = configuration["ScadaLink:Node:Role"]
?? throw new InvalidOperationException("ScadaLink:Node:Role is required");
if (role.Equals("Central", StringComparison.OrdinalIgnoreCase))
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddConfiguration(configuration);
// Shared components
builder.Services.AddClusterInfrastructure();
builder.Services.AddCommunication();
builder.Services.AddHealthMonitoring();
builder.Services.AddExternalSystemGateway();
builder.Services.AddNotificationService();
// Central-only components
builder.Services.AddTemplateEngine();
builder.Services.AddDeploymentManager();
builder.Services.AddSecurity();
builder.Services.AddCentralUI();
builder.Services.AddInboundAPI();
builder.Services.AddConfigurationDatabase();
// Options binding
BindSharedOptions(builder.Services, builder.Configuration);
builder.Services.Configure<SecurityOptions>(builder.Configuration.GetSection("ScadaLink:Security"));
builder.Services.Configure<InboundApiOptions>(builder.Configuration.GetSection("ScadaLink:InboundApi"));
var app = builder.Build();
app.MapCentralUI();
app.MapInboundAPI();
await app.RunAsync();
}
else if (role.Equals("Site", StringComparison.OrdinalIgnoreCase))
{
var builder = Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args);
builder.ConfigureAppConfiguration(config => config.AddConfiguration(configuration));
builder.ConfigureServices((context, services) =>
{
// Shared components
services.AddClusterInfrastructure();
services.AddCommunication();
services.AddHealthMonitoring();
services.AddExternalSystemGateway();
services.AddNotificationService();
// Site-only components
services.AddSiteRuntime();
services.AddDataConnectionLayer();
services.AddStoreAndForward();
services.AddSiteEventLogging();
// Options binding
BindSharedOptions(services, context.Configuration);
services.Configure<DataConnectionOptions>(context.Configuration.GetSection("ScadaLink:DataConnection"));
services.Configure<StoreAndForwardOptions>(context.Configuration.GetSection("ScadaLink:StoreAndForward"));
services.Configure<SiteEventLogOptions>(context.Configuration.GetSection("ScadaLink:SiteEventLog"));
});
var host = builder.Build();
await host.RunAsync();
}
else
{
throw new InvalidOperationException($"Unknown role: {role}. Must be 'Central' or 'Site'.");
}
static void BindSharedOptions(IServiceCollection services, IConfiguration config)
{
services.Configure<NodeOptions>(config.GetSection("ScadaLink:Node"));
services.Configure<ClusterOptions>(config.GetSection("ScadaLink:Cluster"));
services.Configure<DatabaseOptions>(config.GetSection("ScadaLink:Database"));
services.Configure<CommunicationOptions>(config.GetSection("ScadaLink:Communication"));
services.Configure<HealthMonitoringOptions>(config.GetSection("ScadaLink:HealthMonitoring"));
services.Configure<NotificationOptions>(config.GetSection("ScadaLink:Notification"));
services.Configure<LoggingOptions>(config.GetSection("ScadaLink:Logging"));
}
/// <summary>
/// Exposes the auto-generated Program class for test infrastructure (e.g. WebApplicationFactory).
/// </summary>
public partial class Program { }

View File

@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

View File

@@ -0,0 +1,50 @@
{
"ScadaLink": {
"Node": {
"Role": "Central",
"NodeHostname": "central-node1",
"RemotingPort": 8081
},
"Cluster": {
"SeedNodes": [
"akka.tcp://scadalink@central-node1:8081",
"akka.tcp://scadalink@central-node2:8081"
],
"SplitBrainResolverStrategy": "keep-oldest",
"StableAfter": "00:00:15",
"HeartbeatInterval": "00:00:02",
"FailureDetectionThreshold": "00:00:10",
"MinNrOfMembers": 1
},
"Database": {
"ConfigurationDb": "Server=localhost,1433;Database=ScadaLink_Config;User Id=sa;Password=YourPassword;TrustServerCertificate=True",
"MachineDataDb": "Server=localhost,1433;Database=ScadaLink_MachineData;User Id=sa;Password=YourPassword;TrustServerCertificate=True"
},
"Security": {
"LdapServer": "localhost",
"LdapPort": 3893,
"LdapUseTls": false,
"JwtSigningKey": "CHANGE-ME-development-signing-key-at-least-32-chars",
"JwtExpiryMinutes": 15,
"IdleTimeoutMinutes": 30
},
"Communication": {
"DeploymentTimeout": "00:02:00",
"LifecycleTimeout": "00:00:30",
"QueryTimeout": "00:00:30",
"TransportHeartbeatInterval": "00:00:05",
"TransportFailureThreshold": "00:00:15"
},
"HealthMonitoring": {
"ReportInterval": "00:00:30",
"OfflineTimeout": "00:01:00"
},
"InboundApi": {
"DefaultMethodTimeout": "00:00:30"
},
"Notification": {},
"Logging": {
"MinimumLevel": "Information"
}
}
}

View File

@@ -0,0 +1,53 @@
{
"ScadaLink": {
"Node": {
"Role": "Site",
"NodeHostname": "site-a-node1",
"SiteId": "SiteA",
"RemotingPort": 8082
},
"Cluster": {
"SeedNodes": [
"akka.tcp://scadalink@site-a-node1:8082",
"akka.tcp://scadalink@site-a-node2:8082"
],
"SplitBrainResolverStrategy": "keep-oldest",
"StableAfter": "00:00:15",
"HeartbeatInterval": "00:00:02",
"FailureDetectionThreshold": "00:00:10",
"MinNrOfMembers": 1
},
"Database": {
"SiteDbPath": "./data/scadalink.db"
},
"DataConnection": {
"ReconnectInterval": "00:00:05",
"TagResolutionRetryInterval": "00:00:10",
"WriteTimeout": "00:00:30"
},
"StoreAndForward": {
"SqliteDbPath": "./data/store-and-forward.db",
"ReplicationEnabled": true
},
"Communication": {
"DeploymentTimeout": "00:02:00",
"LifecycleTimeout": "00:00:30",
"QueryTimeout": "00:00:30",
"TransportHeartbeatInterval": "00:00:05",
"TransportFailureThreshold": "00:00:15"
},
"HealthMonitoring": {
"ReportInterval": "00:00:30",
"OfflineTimeout": "00:01:00"
},
"SiteEventLog": {
"RetentionDays": 30,
"MaxStorageMb": 1024,
"PurgeScheduleCron": "0 2 * * *"
},
"Notification": {},
"Logging": {
"MinimumLevel": "Information"
}
}
}

View File

@@ -0,0 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}