feat(adminui): Reconnect/Restart on DriverStatusPanel (DriverOperator-gated)
- RestartDriver / ReconnectDriver messages + AdminOperationsActor handlers (broadcast via driver-control DPS topic; audited via ConfigEdits). - DriverHostActor subscribes to driver-control; locates the matching child DriverInstanceActor and stops+respawns it (Restart) or sends it a ForceReconnect internal message (Reconnect — re-enters Reconnecting state without full stop). DriverInstanceSpec constructor call uses named args to handle the full 6-parameter signature. - New DriverOperator authorization policy mapped to DriverOperator or FleetAdmin role; documented in docs/security.md. Map LDAP group via GroupToRole (e.g. "ot-driver-operator": "DriverOperator"). - DriverStatusPanel renders Reconnect + Restart buttons when the user holds the DriverOperator policy (hidden otherwise). Restart requires an in-page Razor confirm block (no JS confirm, keeps SignalR event loop unblocked). Both buttons show a spinner and are disabled during in-flight; result chip auto-clears after 8s. Username sourced from AuthenticationStateProvider. Reconnect resolves to "ForceReconnect" (re-enter Reconnecting, not full stop+respawn) — transport drops and retries while actor and in-memory state are preserved. All DriverInstanceActor states handle ForceReconnect safely (no-op when already in transition).
This commit is contained in:
+148
-1
@@ -1,11 +1,17 @@
|
||||
@* Live driver-status panel — subscribes to /hubs/driverstatus and shows state chip,
|
||||
last-success age, 5-min error count, and last error message.
|
||||
Enabled=false renders a static "Disabled" notice and never opens the hub.
|
||||
Reconnect/Restart buttons are Phase 8 (Task 8.3). *@
|
||||
DriverOperator-gated Reconnect/Restart buttons appear for authorised users. *@
|
||||
@implements IAsyncDisposable
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using ZB.MOM.WW.OtOpcUa.Commons.Interfaces
|
||||
@using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin
|
||||
@using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers
|
||||
@inject NavigationManager Nav
|
||||
@inject AuthenticationStateProvider AuthState
|
||||
@inject IAuthorizationService AuthorizationService
|
||||
@inject IAdminOperationsClient AdminOps
|
||||
|
||||
<section class="panel rise mt-3" style="animation-delay:.04s; @(_stale ? "opacity:0.5;" : "")">
|
||||
<div class="panel-head d-flex align-items-center gap-2">
|
||||
@@ -66,11 +72,71 @@
|
||||
</details>
|
||||
}
|
||||
}
|
||||
|
||||
@* --- Reconnect / Restart action buttons (DriverOperator-gated) --- *@
|
||||
@if (_canOperate && Enabled)
|
||||
{
|
||||
<div class="d-flex gap-2 align-items-center mt-3">
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-outline-secondary"
|
||||
disabled="@_busyReconnect"
|
||||
@onclick="ReconnectAsync"
|
||||
title="Re-establish driver transport without restarting the actor">
|
||||
@if (_busyReconnect)
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm me-1"></span>
|
||||
<span>Reconnecting…</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Reconnect</span>
|
||||
}
|
||||
</button>
|
||||
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-outline-danger"
|
||||
disabled="@_busyRestart"
|
||||
@onclick="() => _showRestartConfirm = true"
|
||||
title="Stop and respawn the driver actor — briefly interrupts active subscriptions">
|
||||
@if (_busyRestart)
|
||||
{
|
||||
<span class="spinner-border spinner-border-sm me-1"></span>
|
||||
<span>Restarting…</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Restart</span>
|
||||
}
|
||||
</button>
|
||||
|
||||
@if (_opResultMessage is not null)
|
||||
{
|
||||
<span class="chip @(_opResultOk ? "chip-ok" : "chip-bad")" style="font-size:0.8rem">@_opResultMessage</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@* Inline confirm dialog for Restart (no JS confirm — keeps SignalR event loop unblocked) *@
|
||||
@if (_showRestartConfirm)
|
||||
{
|
||||
<div class="mt-2 p-2 border rounded" style="background:var(--surface-raised,#fff); border-color:var(--bad,#dc3545)!important; max-width:420px; font-size:0.9rem">
|
||||
<p class="mb-2" style="color:var(--ink)">
|
||||
Restart driver <code>@DriverInstanceId</code>?<br />
|
||||
<span style="color:var(--ink-soft)">This briefly interrupts active subscriptions and clears in-memory state.</span>
|
||||
</p>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-sm btn-danger" @onclick="RestartConfirmedAsync">Confirm restart</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" @onclick="() => _showRestartConfirm = false">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public string DriverInstanceId { get; set; } = "";
|
||||
/// <summary>Cluster identifier forwarded in Reconnect/Restart messages for audit.</summary>
|
||||
[Parameter] public string ClusterId { get; set; } = "";
|
||||
[Parameter] public bool Enabled { get; set; } = true;
|
||||
|
||||
private HubConnection? _hub;
|
||||
@@ -81,8 +147,26 @@
|
||||
private string? _error;
|
||||
private System.Threading.Timer? _timer;
|
||||
|
||||
// Authorization
|
||||
private bool _canOperate;
|
||||
private string? _currentUserName;
|
||||
|
||||
// Action state
|
||||
private bool _busyReconnect;
|
||||
private bool _busyRestart;
|
||||
private bool _showRestartConfirm;
|
||||
private string? _opResultMessage;
|
||||
private bool _opResultOk;
|
||||
private System.Timers.Timer? _opResultClearTimer;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Check DriverOperator authorization so buttons only render for permitted users.
|
||||
var auth = await AuthState.GetAuthenticationStateAsync();
|
||||
_currentUserName = auth.User.Identity?.Name ?? auth.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value ?? "unknown";
|
||||
var authResult = await AuthorizationService.AuthorizeAsync(auth.User, null, "DriverOperator");
|
||||
_canOperate = authResult.Succeeded;
|
||||
|
||||
if (!Enabled)
|
||||
return;
|
||||
|
||||
@@ -122,9 +206,72 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReconnectAsync()
|
||||
{
|
||||
_busyReconnect = true;
|
||||
_opResultMessage = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var result = await AdminOps.AskAsync<ReconnectDriverResult>(
|
||||
new ReconnectDriver(ClusterId, DriverInstanceId, _currentUserName ?? "unknown", Guid.NewGuid()),
|
||||
new System.Threading.CancellationTokenSource(TimeSpan.FromSeconds(15)).Token);
|
||||
ShowOpResult(result.Ok, result.Ok ? "Reconnect dispatched" : (result.Message ?? "Failed"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowOpResult(false, ex.Message.Length > 60 ? ex.Message[..60] + "…" : ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busyReconnect = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RestartConfirmedAsync()
|
||||
{
|
||||
_showRestartConfirm = false;
|
||||
_busyRestart = true;
|
||||
_opResultMessage = null;
|
||||
StateHasChanged();
|
||||
try
|
||||
{
|
||||
var result = await AdminOps.AskAsync<RestartDriverResult>(
|
||||
new RestartDriver(ClusterId, DriverInstanceId, _currentUserName ?? "unknown", Guid.NewGuid()),
|
||||
new System.Threading.CancellationTokenSource(TimeSpan.FromSeconds(15)).Token);
|
||||
ShowOpResult(result.Ok, result.Ok ? "Restart dispatched" : (result.Message ?? "Failed"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowOpResult(false, ex.Message.Length > 60 ? ex.Message[..60] + "…" : ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busyRestart = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOpResult(bool ok, string message)
|
||||
{
|
||||
_opResultOk = ok;
|
||||
_opResultMessage = message;
|
||||
// Auto-clear the result chip after 8 s.
|
||||
_opResultClearTimer?.Dispose();
|
||||
_opResultClearTimer = new System.Timers.Timer(8_000) { AutoReset = false };
|
||||
_opResultClearTimer.Elapsed += async (_, _) =>
|
||||
{
|
||||
_opResultMessage = null;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
};
|
||||
_opResultClearTimer.Start();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
_opResultClearTimer?.Dispose();
|
||||
if (_hub is not null)
|
||||
await _hub.DisposeAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user