Files
123123/ZA.CoreService.ESBCertificateManager/Services/DeploymentOrchestrator.cs
T
GizzlerandCursor 12eebfc78a Simplify app to certificate recognition and MfApi restart only.
Remove XApi, WinRM, LocalCmd, HTTP API, TLS probe, SQL deploy model, and deploy UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 11:06:10 +02:00

72 lines
2.6 KiB
C#

using ZA.CoreService.ESBCertificateManager.Models;
namespace ZA.CoreService.ESBCertificateManager.Services;
/// <summary>
/// Nur Container-Neustart (kein Deploy, kein TLS, kein XApi).
/// </summary>
public sealed class DeploymentOrchestrator
{
private readonly RestartExecutor _restartExecutor;
private readonly PreflightValidator _preflightValidator = new();
private readonly AppSettings _settings;
public DeploymentOrchestrator(AppSettings settings)
{
_settings = settings;
_restartExecutor = new RestartExecutor(settings.SonicConnections);
}
public PreflightValidationResult ValidateRestartOnly(IReadOnlyList<DeploymentTarget> selectedTargets)
=> _preflightValidator.ValidateRestartOnly(selectedTargets);
public async Task<DeploymentRunResult> RestartOnlyAsync(
IReadOnlyList<DeploymentTarget> selectedTargets,
IProgress<TargetProgressUpdate>? progress,
CancellationToken cancellationToken = default)
{
DateTimeOffset startedAt = DateTimeOffset.Now;
List<TargetStepResult> results = [];
using RunLogger logger = new(_settings.LogDirectory);
logger.Write($"Neustart gestartet für {selectedTargets.Count} Ziel(e).");
foreach (DeploymentTarget target in selectedTargets)
{
cancellationToken.ThrowIfCancellationRequested();
DateTimeOffset targetStart = DateTimeOffset.Now;
progress?.Report(new TargetProgressUpdate(target.Id, $"Neustart {target.ContainerName}…", null));
(bool ok, string status, string? detail) =
await _restartExecutor.ExecuteAsync(target, cancellationToken);
logger.Write($"[{target.Name}] {status} | {detail}");
progress?.Report(new TargetProgressUpdate(target.Id, status, ok));
results.Add(new TargetStepResult
{
TargetId = target.Id,
TargetName = target.Name,
Success = ok,
StatusText = status,
Detail = detail,
StartedAt = targetStart,
FinishedAt = DateTimeOffset.Now
});
}
DateTimeOffset finishedAt = DateTimeOffset.Now;
DeploymentRunResult runResult = new()
{
TargetResults = results,
StartedAt = startedAt,
FinishedAt = finishedAt
};
logger.Write(
$"Neustart beendet. Erfolg={runResult.OverallSuccess}; Dauer={(finishedAt - startedAt).TotalSeconds:F1}s; Log={logger.LogFilePath}");
return runResult;
}
}