@page "/deployments" @using Microsoft.AspNetCore.Components.Authorization @using Microsoft.EntityFrameworkCore @using Microsoft.Extensions.Logging @using ZB.MOM.WW.OtOpcUa.Commons.Interfaces @using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin @using ZB.MOM.WW.OtOpcUa.Configuration @using ZB.MOM.WW.OtOpcUa.Configuration.Entities @using ZB.MOM.WW.OtOpcUa.Configuration.Enums @attribute [Authorize(Policy = AdminUiPolicies.ConfigEditor)] @inject IDbContextFactory DbFactory @inject IAdminOperationsClient AdminOps @inject AuthenticationStateProvider AuthState @inject ZB.MOM.WW.OtOpcUa.AdminUI.Deployments.DeploymentDriftProbe DriftProbe @inject ILogger Logger @rendermode InteractiveServer @implements IDisposable Deployments · OtOpcUa

Deployments

@* lmxopcua#903: the chip says nothing about sync until a composition taken after this page opened has answered — first render shows "Checking…", never a verdict carried over from an earlier load. *@ @switch (_driftState) { case DriftState.Checking: Checking for changes… break; case DriftState.Drift: Configuration drift break; case DriftState.InSync: In sync break; case DriftState.Failed: Drift check failed Refresh status to retry. See the host log for details. break; }
Last fetched: @if (_loading && _hasLoaded) { Reading deployment history… } View per-node application status
@if (_requestedDeploymentId is { } requested) {

Requested deployment: @requested

@if (_requestedRevisionHash is not null) {

Requested revision: @_requestedRevisionHash

} } @if (_loadError is not null) {
} @if (_deployments.Count > 0) {
@foreach (var d in _deployments) { @* #601: Sealed + a reason = sealed with a degraded address-space apply on some node(s). *@ }
Deployment Revision Status Created by Created (UTC) Sealed (UTC)
@Short(d.DeploymentId) @DisplayText.Abbreviate(d.RevisionHash, 12) @(d.Status == DeploymentStatus.Sealed && !string.IsNullOrEmpty(d.FailureReason) ? "Sealed (degraded)" : d.Status.ToString()) @if (!string.IsNullOrEmpty(d.FailureReason)) { } @d.CreatedBy @d.CreatedAtUtc.ToString("u") @(d.SealedAtUtc?.ToString("u") ?? "—")
}
@code { // Blob-free projection: the Deployment entity carries a varbinary(max) ArtifactBlob (a whole-fleet // gzip config snapshot), which materialising the full entity would drag across the wire 50 times // over just to render six scalar columns. private sealed record DeploymentRow( Guid DeploymentId, string RevisionHash, DeploymentStatus Status, string CreatedBy, DateTime CreatedAtUtc, DateTime? SealedAtUtc, string? FailureReason); private IReadOnlyList _deployments = Array.Empty(); private bool _busy, _refreshing, _requestPending, _requestResultUnavailable; private bool _loading = true, _hasLoaded, _disposed; private bool _initialDriftPending = true; private StartDeploymentOutcome? _requestOutcome; private Guid? _requestedDeploymentId; private string? _requestMessage, _loadError, _requestedRevisionHash; private DateTime? _lastFetchedUtc; private readonly CancellationTokenSource _reads = new(); private enum DriftState { None, Checking, Drift, InSync, Failed } private DriftState _driftState; // A newly accepted request never borrows another historical deployment's terminal status. private DeploymentRow? FeedbackRow => _requestOutcome == StartDeploymentOutcome.Accepted ? _deployments.FirstOrDefault(d => d.DeploymentId == _requestedDeploymentId) : _deployments.FirstOrDefault(); protected override async Task OnInitializedAsync() => await ReloadAsync(); protected override async Task OnAfterRenderAsync(bool firstRender) { // Compose only after interactive attachment, as before; serialize it with user actions. if (!_initialDriftPending || _disposed || !_hasLoaded || _busy || _refreshing) return; _initialDriftPending = false; _refreshing = true; StateHasChanged(); try { await RefreshDriftAsync(); } finally { _refreshing = false; if (!_disposed) StateHasChanged(); } } private async Task RefreshDriftAsync() { if (_disposed) return; _initialDriftPending = false; var latestSealed = _deployments.FirstOrDefault(d => d.Status == DeploymentStatus.Sealed); if (latestSealed is null) { _driftState = DriftState.None; return; } try { var drift = await DriftProbe.GetDriftAsync(latestSealed.RevisionHash, _reads.Token); if (_disposed) return; _driftState = drift switch { true => DriftState.Drift, false => DriftState.InSync, null => DriftState.None, }; } catch (OperationCanceledException) when (_disposed) { } catch (Exception ex) { if (_disposed) return; Logger.LogWarning(ex, "Deployments: drift check against revision {RevisionHash} failed.", latestSealed.RevisionHash); _driftState = DriftState.Failed; } } private async Task ReloadAsync() { if (_disposed) return false; var cancellation = _reads.Token; _loading = true; _loadError = null; StateHasChanged(); try { await using var db = await DbFactory.CreateDbContextAsync(cancellation); var rows = await db.Deployments .AsNoTracking() .OrderByDescending(d => d.CreatedAtUtc) .Select(d => new DeploymentRow( d.DeploymentId, d.RevisionHash, d.Status, d.CreatedBy, d.CreatedAtUtc, d.SealedAtUtc, d.FailureReason)) .Take(50) .ToListAsync(cancellation); if (_disposed) return false; _deployments = rows; _hasLoaded = true; _lastFetchedUtc = DateTime.UtcNow; // Only these successful rows establish the next drift check's context. _driftState = rows.Any(d => d.Status == DeploymentStatus.Sealed) ? DriftState.Checking : DriftState.None; return true; } catch (OperationCanceledException) when (_disposed) { return false; } catch (Exception ex) { if (!_disposed) { _loadError = ex.Message; Logger.LogWarning(ex, "Deployments: history refresh failed; preserving last successful rows."); } return false; } finally { _loading = false; } } private async Task RefreshStatusAsync() { if (_disposed || _busy || _refreshing || _loading) return; _refreshing = true; try { if (await ReloadAsync()) await RefreshDriftAsync(); } finally { _refreshing = false; } } private async Task StartDeploymentAsync() { if (_disposed || _busy || _refreshing || _loading || !_hasLoaded) return; _busy = _requestPending = true; _requestOutcome = null; _requestedDeploymentId = null; _requestedRevisionHash = null; _requestMessage = null; _requestResultUnavailable = false; try { var auth = await AuthState.GetAuthenticationStateAsync(); if (_disposed) return; var createdBy = auth.User.Identity?.Name ?? "(anonymous)"; // A dispatched mutation continues if the view closes; only history reads use page cancellation. var result = await AdminOps.StartDeploymentAsync(createdBy: createdBy, ct: CancellationToken.None); if (_disposed) return; _requestPending = false; _requestOutcome = result.Outcome; _requestMessage = result.Message; _requestedDeploymentId = result.Outcome == StartDeploymentOutcome.Accepted ? result.DeploymentId?.Value : null; _requestedRevisionHash = result.Outcome == StartDeploymentOutcome.Accepted ? result.RevisionHash?.Value : null; // A failed follow-up read cannot retroactively turn an accepted request into rejection. if (await ReloadAsync()) await RefreshDriftAsync(); } catch (Exception ex) { if (_disposed) return; _requestResultUnavailable = true; _requestMessage = ex.Message; Logger.LogWarning(ex, "Deployments: request result could not be confirmed."); } finally { _busy = _requestPending = false; } } private static string Short(Guid id) => id.ToString("N")[..8]; /// Stops view-owned reads without cancelling an already-dispatched deployment request. public void Dispose() { if (_disposed) return; _disposed = true; _reads.Cancel(); _reads.Dispose(); } }