Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.SiteRuntime/SiteRuntimeOptionsValidator.cs
T
Joseph Doherty 605e56829e chore(config): retire ReplicationEnabled, make legacy db paths migration-only
LocalDb Phase 2 deleted the bespoke replicators, so three config keys changed
meaning or died outright:

- ScadaBridge:StoreAndForward:ReplicationEnabled is fully dead. Deleted the
  property, its 10 config entries, and the 5 test references.
- SqliteDbPath / SiteDbPath are now migration-only: they name the legacy files
  SiteLocalDbLegacyMigrator drains at boot, not live databases. Both mandatory
  rules are relaxed accordingly (StartupValidator's Site-only Require, and the
  S&F validator's non-empty rule) — an absent value now means "nothing to
  migrate", so an already-migrated node can drop the key. DatabaseOptions-
  Validator still rejects a present-but-blank value.
- SiteRuntime:ConfigFetchRetryCount's only reader was SiteReplicationActor.
  Deleted with its validator rule.

The two path keys stay present in every config, now with a comment explaining
why: removing them would strand un-migrated data on a node that has not yet
started once.

Both relaxations are pinned by the inverse of the test they replace
(Site_MissingSiteDbPath_IsAccepted..., EmptySqliteDbPath_IsAccepted...), each
verified to fail with the old rule restored.

Note: deploy/wonder-app-vd03/appsettings.Site.json is under a gitignored
deploy/ tree, so its edit is local-only and must be repeated on the box.

Claude-Session: https://claude.ai/code/session_01BL2Vu1ESDQ9SCN4gVKkdts
2026-07-20 04:35:11 -04:00

66 lines
3.6 KiB
C#

using ZB.MOM.WW.Configuration;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime;
/// <summary>
/// Validates <see cref="SiteRuntimeOptions"/> at startup. These values size the
/// staggered Instance-Actor startup batches, the dedicated script-execution thread
/// pool, and the site-wide Akka stream's per-subscriber buffer; a zero or negative
/// count either creates a degenerate thread scheduler / stream stage or trips an
/// <see cref="ArgumentOutOfRangeException"/> deep inside actor construction with an
/// opaque message that never names the offending config key. Registered with
/// <c>ValidateOnStart()</c> so a bad <c>ScadaBridge:SiteRuntime</c> section fails
/// fast at boot with a clear, key-naming message.
/// </summary>
public sealed class SiteRuntimeOptionsValidator : OptionsValidatorBase<SiteRuntimeOptions>
{
/// <inheritdoc />
protected override void Validate(ValidationBuilder builder, SiteRuntimeOptions options)
{
builder.RequireThat(options.StartupBatchSize > 0,
$"ScadaBridge:SiteRuntime:StartupBatchSize must be greater than 0 " +
$"(was {options.StartupBatchSize}); it sizes each staggered Instance-Actor startup batch.");
builder.RequireThat(options.StartupBatchDelayMs >= 0,
$"ScadaBridge:SiteRuntime:StartupBatchDelayMs must be >= 0 " +
$"(was {options.StartupBatchDelayMs}); it is the inter-batch startup delay.");
builder.RequireThat(options.MaxScriptCallDepth > 0,
$"ScadaBridge:SiteRuntime:MaxScriptCallDepth must be greater than 0 " +
$"(was {options.MaxScriptCallDepth}); it bounds recursive CallScript/CallShared depth.");
builder.RequireThat(options.ScriptExecutionTimeoutSeconds > 0,
$"ScadaBridge:SiteRuntime:ScriptExecutionTimeoutSeconds must be greater than 0 " +
$"(was {options.ScriptExecutionTimeoutSeconds}).");
builder.RequireThat(options.StreamBufferSize > 0,
$"ScadaBridge:SiteRuntime:StreamBufferSize must be greater than 0 " +
$"(was {options.StreamBufferSize}); it is the per-subscriber site-stream buffer size.");
builder.RequireThat(options.ScriptExecutionThreadCount > 0,
$"ScadaBridge:SiteRuntime:ScriptExecutionThreadCount must be greater than 0 " +
$"(was {options.ScriptExecutionThreadCount}); it sizes the dedicated script-execution scheduler.");
builder.RequireThat(options.MirroredAlarmCapPerSource > 0,
$"ScadaBridge:SiteRuntime:MirroredAlarmCapPerSource must be greater than 0 " +
$"(was {options.MirroredAlarmCapPerSource}).");
builder.RequireThat(options.NativeAlarmRetryIntervalMs > 0,
$"ScadaBridge:SiteRuntime:NativeAlarmRetryIntervalMs must be greater than 0 " +
$"(was {options.NativeAlarmRetryIntervalMs}).");
builder.RequireThat(options.ConfigFetchTimeoutSeconds > 0,
$"ScadaBridge:SiteRuntime:ConfigFetchTimeoutSeconds must be greater than 0 " +
$"(was {options.ConfigFetchTimeoutSeconds}).");
builder.RequireThat(options.TagSubscribeRetryIntervalMs > 0,
$"ScadaBridge:SiteRuntime:TagSubscribeRetryIntervalMs must be greater than 0 " +
$"(was {options.TagSubscribeRetryIntervalMs}); a zero interval hot-loops the tag-subscribe " +
"retry and a negative one throws inside the Instance Actor's retry scheduling.");
builder.RequireThat(options.StuckScriptGraceMs >= 0,
$"ScadaBridge:SiteRuntime:StuckScriptGraceMs must be >= 0 " +
$"(was {options.StuckScriptGraceMs}); a negative grace throws inside the stuck-script watchdog's delay.");
}
}