Deployment Manager (WP-1–8, WP-16): - DeploymentService: full pipeline (flatten→validate→send→track→audit) - OperationLockManager: per-instance concurrency control - StateTransitionValidator: Enabled/Disabled/NotDeployed transition matrix - ArtifactDeploymentService: broadcast to all sites with per-site results - Deployment identity (GUID + revision hash), idempotency, staleness detection - Instance lifecycle commands (disable/enable/delete) with deduplication Store-and-Forward (WP-9–15): - StoreAndForwardStorage: SQLite persistence, 3 categories, no max buffer - StoreAndForwardService: fixed-interval retry, transient-only buffering, parking - ReplicationService: async best-effort to standby (fire-and-forget) - Parked message management (query/retry/discard from central) - Messages survive instance deletion, S&F drains on disable 620 tests pass (+79 new), zero warnings.
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using ScadaLink.Commons.Types.Enums;
|
|
|
|
namespace ScadaLink.DeploymentManager;
|
|
|
|
/// <summary>
|
|
/// WP-4: State transition matrix for instance lifecycle.
|
|
///
|
|
/// State | Deploy | Disable | Enable | Delete
|
|
/// ----------|--------|---------|--------|-------
|
|
/// NotDeploy | OK | NO | NO | NO
|
|
/// Enabled | OK | OK | NO | OK
|
|
/// Disabled | OK* | NO | OK | OK
|
|
///
|
|
/// * Deploy on a Disabled instance also enables it.
|
|
/// </summary>
|
|
public static class StateTransitionValidator
|
|
{
|
|
public static bool CanDeploy(InstanceState currentState) =>
|
|
currentState is InstanceState.NotDeployed or InstanceState.Enabled or InstanceState.Disabled;
|
|
|
|
public static bool CanDisable(InstanceState currentState) =>
|
|
currentState == InstanceState.Enabled;
|
|
|
|
public static bool CanEnable(InstanceState currentState) =>
|
|
currentState == InstanceState.Disabled;
|
|
|
|
public static bool CanDelete(InstanceState currentState) =>
|
|
currentState is InstanceState.Enabled or InstanceState.Disabled;
|
|
|
|
/// <summary>
|
|
/// Returns a human-readable error message if the transition is invalid, or null if valid.
|
|
/// </summary>
|
|
public static string? ValidateTransition(InstanceState currentState, string operation)
|
|
{
|
|
var allowed = operation.ToLowerInvariant() switch
|
|
{
|
|
"deploy" => CanDeploy(currentState),
|
|
"disable" => CanDisable(currentState),
|
|
"enable" => CanEnable(currentState),
|
|
"delete" => CanDelete(currentState),
|
|
_ => false
|
|
};
|
|
|
|
if (allowed) return null;
|
|
|
|
return $"Operation '{operation}' is not allowed when instance is in state '{currentState}'.";
|
|
}
|
|
}
|