47d148daf9
`Scripts.razor` rendered a hash prefix as `@s.SourceHash[..12]…`. `SourceHash`
is a plain nvarchar(64) with no length floor, so any value shorter than 12
characters threw ArgumentOutOfRangeException out of BuildRenderTree — unhandled
in Blazor, which takes the WHOLE page to an HTTP 500, not just the offending
row. Live-reproduced on docker-dev, where two Script rows carry `h1` and
`h-abs-hr200`: /scripts was a hard 500.
New `Components/Shared/DisplayText.Abbreviate(string?, int)`:
- null/blank renders the Admin UI's em-dash placeholder rather than throwing;
- a value already within budget renders verbatim with NO ellipsis, so the
display never implies text that isn't there (the old markup appended "…"
unconditionally, outside the slice — `h1` would have shown as `h1…`);
- a maxLength < 1 is clamped, so a display bug cannot become a page crash.
Applied to every unguarded range-operator slice over a DB-sourced string found
by sweeping the AdminUI for `[..N]`:
Scripts.razor SourceHash (the reported crash)
Certificates.razor Thumbprint (read off the on-disk store)
Deployments.razor x2 RevisionHash
Clusters/ClusterOverview.razor RevisionHash
The other `[..N]` hits are safe and untouched: Guid.ToString("N") slices
(always 32 chars) and the `Length > 60 ? [..60]` ternaries that self-guard.
NOTE — the issue text blamed the docker-dev seed; that was wrong and is
corrected on #504. `seed-clusters.sql` inserts only ServerCluster, ClusterNode
and LdapGroupRoleMapping. The short-hash rows came from earlier live-gate
authoring. A freshly seeded rig is fine; the trigger is any Script row that did
not go through ScriptEdit / UnsTreeService.HashSource — REST-API authored,
hand-inserted, or migrated in.
Tests: 14 new in DisplayTextTests, covering the short/null/blank/clamped cases
and a never-throws sweep over every value x budget combination. AdminUI suite
739/739.
Live-verified on docker-dev (AdminUI has no bUnit): /scripts 500 -> 200 across
both central nodes, rendering `hash=h1` and `hash=h-abs-hr200` in full;
/deployments still truncates 64-char hashes at 12 with the ellipsis;
/certificates and /clusters/MAIN unchanged.
140 lines
5.9 KiB
Plaintext
140 lines
5.9 KiB
Plaintext
@page "/clusters/{ClusterId}"
|
|
@attribute [Authorize(Policy = AdminUiPolicies.AuthenticatedRead)]
|
|
@rendermode RenderMode.InteractiveServer
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
|
@inject IDbContextFactory<OtOpcUaConfigDbContext> DbFactory
|
|
@inject NavigationManager Nav
|
|
|
|
@if (!_loaded)
|
|
{
|
|
<p>Loading…</p>
|
|
}
|
|
else if (_cluster is null)
|
|
{
|
|
<section class="panel notice rise" style="animation-delay:.02s">
|
|
Cluster <span class="mono">@ClusterId</span> was not found.
|
|
<a class="ms-2" href="/clusters">Back to list</a>.
|
|
</section>
|
|
}
|
|
else
|
|
{
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<div>
|
|
<h4 class="mb-0">@_cluster.Name</h4>
|
|
<span class="mono text-muted">@_cluster.ClusterId</span>
|
|
@if (!_cluster.Enabled) { <span class="chip chip-idle ms-2">Disabled</span> }
|
|
</div>
|
|
<div class="d-flex gap-2">
|
|
<a href="/clusters/@ClusterId/edit" class="btn btn-outline-secondary btn-sm">Edit cluster</a>
|
|
<a href="/deployments" class="btn btn-outline-primary btn-sm">Deployments</a>
|
|
</div>
|
|
</div>
|
|
|
|
<ClusterNav ClusterId="@ClusterId" ActiveTab="overview" />
|
|
|
|
<section class="card-grid rise" style="animation-delay:.08s">
|
|
<div class="metric-card">
|
|
<div class="panel-head">Cluster details</div>
|
|
<div class="kv"><span class="k">Enterprise / Site</span><span class="v">@_cluster.Enterprise / @_cluster.Site</span></div>
|
|
<div class="kv"><span class="k">Redundancy</span><span class="v">@_cluster.RedundancyMode (@_cluster.NodeCount node@(_cluster.NodeCount == 1 ? "" : "s"))</span></div>
|
|
<div class="kv"><span class="k">Created</span><span class="v">@_cluster.CreatedAt.ToString("u") by @_cluster.CreatedBy</span></div>
|
|
@if (_cluster.ModifiedAt is not null)
|
|
{
|
|
<div class="kv"><span class="k">Modified</span><span class="v">@_cluster.ModifiedAt?.ToString("u") by @(_cluster.ModifiedBy ?? "—")</span></div>
|
|
}
|
|
@if (!string.IsNullOrWhiteSpace(_cluster.Notes))
|
|
{
|
|
<div class="kv"><span class="k">Notes</span><span class="v">@_cluster.Notes</span></div>
|
|
}
|
|
</div>
|
|
|
|
<div class="metric-card">
|
|
<div class="panel-head">Last deployment</div>
|
|
@if (_lastDeployment is null)
|
|
{
|
|
<div class="kv"><span class="k">Status</span><span class="v text-muted">none — cluster has never been deployed</span></div>
|
|
}
|
|
else
|
|
{
|
|
<div class="kv"><span class="k">Revision</span><span class="v mono">@DisplayText.Abbreviate(_lastDeployment.RevisionHash, 16)</span></div>
|
|
<div class="kv"><span class="k">Status</span><span class="v">@_lastDeployment.Status</span></div>
|
|
<div class="kv"><span class="k">Created</span><span class="v">@_lastDeployment.CreatedAtUtc.ToString("u")</span></div>
|
|
@if (_lastDeployment.SealedAtUtc is not null)
|
|
{
|
|
<div class="kv"><span class="k">Sealed</span><span class="v">@_lastDeployment.SealedAtUtc?.ToString("u")</span></div>
|
|
}
|
|
}
|
|
</div>
|
|
</section>
|
|
|
|
<section class="panel rise mt-3" style="animation-delay:.14s">
|
|
<div class="panel-head d-flex align-items-center">
|
|
<span>Nodes</span>
|
|
<a href="/clusters/@ClusterId/nodes/new" class="btn btn-sm btn-outline-primary ms-auto">New node</a>
|
|
</div>
|
|
@if (_nodes is null || _nodes.Count == 0)
|
|
{
|
|
<div style="padding:1rem" class="text-muted">No nodes registered.</div>
|
|
}
|
|
else
|
|
{
|
|
<div class="table-wrap">
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Node ID</th>
|
|
<th>Host</th>
|
|
<th>OPC UA port</th>
|
|
<th>ApplicationUri</th>
|
|
<th class="num">ServiceLevel base</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var n in _nodes)
|
|
{
|
|
<tr>
|
|
<td><span class="mono">@n.NodeId</span></td>
|
|
<td>@n.Host</td>
|
|
<td class="num">@n.OpcUaPort</td>
|
|
<td><span class="mono small">@n.ApplicationUri</span></td>
|
|
<td class="num">@n.ServiceLevelBase</td>
|
|
<td><a href="/clusters/@ClusterId/nodes/@n.NodeId" class="btn btn-sm btn-outline-primary">Edit</a></td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
</section>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string ClusterId { get; set; } = "";
|
|
|
|
private bool _loaded;
|
|
private ServerCluster? _cluster;
|
|
private List<ClusterNode>? _nodes;
|
|
private Deployment? _lastDeployment;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await using var db = await DbFactory.CreateDbContextAsync();
|
|
_cluster = await db.ServerClusters.AsNoTracking()
|
|
.FirstOrDefaultAsync(c => c.ClusterId == ClusterId);
|
|
if (_cluster is not null)
|
|
{
|
|
_nodes = await db.ClusterNodes.AsNoTracking()
|
|
.Where(n => n.ClusterId == ClusterId)
|
|
.OrderBy(n => n.NodeId)
|
|
.ToListAsync();
|
|
_lastDeployment = await db.Deployments.AsNoTracking()
|
|
.OrderByDescending(d => d.CreatedAtUtc)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
_loaded = true;
|
|
}
|
|
}
|