Form1 design unchanged; only MfApi restart and certificate recognition remain active. Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
3.4 KiB
C#
94 lines
3.4 KiB
C#
using ZA.CoreService.ESBCertificateManager.Models;
|
|
|
|
namespace ZA.CoreService.ESBCertificateManager.Services;
|
|
|
|
/// <summary>
|
|
/// Orchestriert nur noch Container-Neustart (kein Deploy/TLS/SQL).
|
|
/// </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();
|
|
results.Add(await RestartTargetOnlyAsync(target, logger, progress, cancellationToken));
|
|
}
|
|
|
|
DateTimeOffset finishedAt = DateTimeOffset.Now;
|
|
DeploymentRunResult runResult = new()
|
|
{
|
|
TargetResults = results,
|
|
StartedAt = startedAt,
|
|
FinishedAt = finishedAt,
|
|
CertificateFilePath = string.Empty,
|
|
CertificateFingerprint = string.Empty
|
|
};
|
|
|
|
logger.Write(
|
|
$"Neustart beendet. Erfolg={runResult.OverallSuccess}; Dauer={(finishedAt - startedAt).TotalSeconds:F1}s; Log={logger.LogFilePath}");
|
|
|
|
return runResult;
|
|
}
|
|
|
|
private async Task<TargetStepResult> RestartTargetOnlyAsync(
|
|
DeploymentTarget target,
|
|
RunLogger logger,
|
|
IProgress<TargetProgressUpdate>? progress,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
List<string> steps = [];
|
|
DateTimeOffset targetStart = DateTimeOffset.Now;
|
|
progress?.Report(new TargetProgressUpdate(target.Id, "Neustart…", false));
|
|
|
|
(bool restartOk, string restartStatus, string? restartDetail) =
|
|
await _restartExecutor.ExecuteAsync(target, cancellationToken);
|
|
|
|
steps.Add($"{restartStatus}: {restartDetail}");
|
|
logger.Write($"[{target.Name}] Restart: {restartStatus} | {restartDetail}");
|
|
|
|
TargetStepResult targetResult = new()
|
|
{
|
|
TargetId = target.Id,
|
|
TargetName = target.Name,
|
|
Success = restartOk,
|
|
StatusText = restartStatus,
|
|
Detail = restartDetail,
|
|
Steps = steps,
|
|
StartedAt = targetStart,
|
|
FinishedAt = DateTimeOffset.Now,
|
|
CopySucceeded = true,
|
|
RestartSucceeded = restartOk,
|
|
TlsSucceeded = true,
|
|
ObservedFingerprint = null
|
|
};
|
|
|
|
progress?.Report(new TargetProgressUpdate(target.Id, restartStatus, restartOk));
|
|
return targetResult;
|
|
}
|
|
}
|
|
|
|
public readonly record struct TargetProgressUpdate(int TargetId, string StatusText, bool? SuccessHint);
|