293 lines
33 KiB
Plaintext
293 lines
33 KiB
Plaintext
@page "/clusters/{ClusterId}/data-connections"
|
|
@attribute [Authorize(Policy = AdminUiPolicies.AuthenticatedRead)]
|
|
@rendermode RenderMode.InteractiveServer
|
|
@using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
|
@using ZB.MOM.WW.OtOpcUa.Configuration.Validation
|
|
@using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections
|
|
@using ZB.MOM.WW.OtOpcUa.Commons.OpcUa
|
|
@using ZB.MOM.WW.OtOpcUa.Commons.Interfaces
|
|
@using ZB.MOM.WW.OtOpcUa.Commons.Types
|
|
@inject DataConnectionAdminService Service
|
|
@inject IFleetDiagnosticsClient Diagnostics
|
|
|
|
<PageErrorBoundary>
|
|
<PageTitle>Data connections · OtOpcUa</PageTitle>
|
|
<div class="page-head"><h1>Data connections · <span class="mono">@ClusterId</span></h1></div>
|
|
<ClusterNav ClusterId="@ClusterId" ActiveTab="data" />
|
|
<p>Connections are directional. Exports grant a peer access to local data; mappings place remote data under a local Raw or UNS parent.</p>
|
|
<section class="panel notice">Changes are saved as drafts. Deploy them from <a href="/deployments">Deployments</a>; saving alone does not start or stop an import. Runtime status is unavailable until reported by a node.</section>
|
|
@if (_snapshot is null) { <p>Loading…</p> }
|
|
else
|
|
{
|
|
@if (_error is not null) { <div class="alert alert-danger" role="alert">@_error</div> }
|
|
@if (_message is not null) { <div class="alert alert-success" role="status">@_message</div> }
|
|
<section class="panel mt-3">
|
|
<h2 class="panel-head">Connections</h2>
|
|
<div class="p-3">
|
|
@if (!ConnectionRows.Any()) { <p class="text-muted">No draft, applied, or observed connections.</p> }
|
|
@foreach (var row in ConnectionRows)
|
|
{
|
|
<div class="d-flex flex-wrap gap-2 align-items-center mb-2"><strong>@row.Id</strong>@if (row.Draft is { } draft) { <span class="chip chip-idle">Draft: @(draft.Enabled ? "enabled" : "disabled")</span> } else { <span class="chip chip-warn">Removed from draft</span> }@if (!_live.Any(x => Same(x.Row.ConnectionId, row.Id))) { <span>Runtime: unavailable</span> }
|
|
@foreach (var live in _live.Where(x => Same(x.Row.ConnectionId, row.Id)))
|
|
{
|
|
<div class="w-100 small data-connection-diagnostics"><strong>@live.NodeId: @DataConnectionDiagnostics.State(live.Row.State)</strong> · revision @live.Row.Revision · endpoint @DataConnectionDiagnostics.Endpoint(live.Row.SelectedEndpoint)
|
|
@if (live.Row.Serving is { } serving) { <span> · serving @serving.NodeId · role @serving.Role · incarnation @serving.Incarnation</span> }
|
|
<div>Streams @live.Row.ActiveStreams · calls @live.Row.ActiveCalls · retained import views @Measure(live.Row.SourceCount) · registrations @Measure(live.Row.RegistrationCount) · resets @Measure(live.Row.ResetCount) · coalesced notices @Measure(live.Row.CoalescedCount) · overflows @Measure(live.Row.OverflowCount)</div>
|
|
<div>Writes succeeded @Measure(live.Row.WriteSucceededCount) · rejected @Measure(live.Row.WriteRejectedCount) · failed @Measure(live.Row.WriteFailedCount) · unconfirmed @Measure(live.Row.WriteUnconfirmedCount) · unknown @Measure(live.Row.WriteUnknownCount)</div>
|
|
<div>Last observed sample bound @Time(live.Row.LastSampleAtUtc) (age upper bound @DataConnectionDiagnostics.SampleAge(live.Row)) · metadata lease expires @Time(live.Row.MetadataLeaseExpiresAtUtc) · last handshake @Time(live.Row.LastVerifiedAtUtc) · observed @live.Row.AsOfUtc.ToString("u") · artifact @live.Row.ArtifactRevision · protocol @(live.Row.ProtocolMajor is { } major && live.Row.ProtocolMinor is { } minor ? $"{major}.{minor}" : "unavailable")</div>
|
|
<div class="data-connection-history">Negotiated features @DataConnectionDiagnostics.Features(live.Row.NegotiatedFeatures) · origin history @DataConnectionDiagnostics.HistoryServed(live.Row) · projected history reads @DataConnectionDiagnostics.HistoryCounts(live.Row.HistoryReadsGood, live.Row.HistoryReadsUncertain, live.Row.HistoryReadsBad) · open remote continuations (local sessions) @Measure(live.Row.OpenRemoteContinuations)</div>
|
|
<div class="@(DataConnectionDiagnostics.HasDrops(live.Row.DroppedUnknownOperations, live.Row.MappingsWithDroppedOperations) ? "notice data-connection-dropped" : "data-connection-dropped")">Dropped unknown operation bits: connection @DataConnectionDiagnostics.DroppedBits(live.Row.DroppedUnknownOperations) · mappings with dropped bits @Measure(live.Row.MappingsWithDroppedOperations)@if (DataConnectionDiagnostics.HasDrops(live.Row.DroppedUnknownOperations, live.Row.MappingsWithDroppedOperations)) { <span> — this node's build is older than a feature authored here; the dropped bits grant nothing until the node is upgraded.</span> }</div></div>
|
|
}
|
|
@foreach (var applied in _applied.Where(x => Same(x.ConnectionId, row.Id))) { <span class="small">@applied.NodeId: last applied revision @applied.Revision (@(applied.Enabled ? "enabled" : "disabled"))</span> }
|
|
@if (row.Draft is { } editable) { <AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-outline-primary" @onclick="() => Edit(editable)">Edit</button></AuthorizeView> }</div>
|
|
}
|
|
<AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-primary" @onclick="NewConnection">New connection</button></AuthorizeView>
|
|
</div>
|
|
</section>
|
|
<section class="panel mt-3">
|
|
<h2 class="panel-head">Origin evidence by node</h2><div class="p-3">
|
|
@if (!_nodeSnapshots.Any()) { <p class="text-muted">No node has reported.</p> }
|
|
@foreach (var (nodeId, node) in _nodeSnapshots)
|
|
{
|
|
<div class="small mb-2 data-connection-origin"><strong>@nodeId</strong>
|
|
@if (node.OriginHistory is { } origin)
|
|
{
|
|
<span> · remote history @(origin.Available ? "served" : "no historian backend") · peer history sessions @origin.Sessions · open origin continuations @origin.OpenContinuations · history items answered @DataConnectionDiagnostics.HistoryCounts(origin.ReadsGood, origin.ReadsUncertain, origin.ReadsBad)@(origin.NoPeerTrafficYet ? " · no peer has called since start" : "")</span>
|
|
}
|
|
else { <span> · remote history evidence unavailable</span> }
|
|
@if (node.DroppedExportOperations is { } dropped)
|
|
{
|
|
@if (dropped.Count == 0) { <span> · dropped unknown export bits: none</span> }
|
|
else
|
|
{
|
|
<div class="notice" role="note">Exports with dropped unknown operation bits: @string.Join("; ", dropped.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase).Select(x => $"{x.Key}: {DataConnectionDiagnostics.DroppedBits(x.Value)}")) — this node's build is older than a feature authored here; the dropped bits grant nothing until the node is upgraded.</div>
|
|
}
|
|
}
|
|
else { <span> · dropped unknown export bits unavailable</span> }
|
|
</div>
|
|
}
|
|
</div>
|
|
</section>
|
|
<section class="panel mt-3">
|
|
<h2 class="panel-head">Exports</h2><div class="p-3">
|
|
@if (!Exports.Any()) { <p class="text-muted">No export grants have been authored.</p> }
|
|
@foreach (var e in Exports) { <div class="d-flex flex-wrap gap-2 align-items-center mb-2"><strong>@e.DataExportId</strong><span>@e.Realm · @e.RootKind · @e.PrincipalId</span><span class="chip chip-idle">Draft: @(e.Enabled ? "enabled" : "disabled")</span><AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-outline-primary" @onclick="() => Edit(e)">Edit</button></AuthorizeView></div> }
|
|
<AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-primary" @onclick="NewExport">New export</button></AuthorizeView></div>
|
|
</section>
|
|
<section class="panel mt-3"><h2 class="panel-head">Mappings</h2><div class="p-3">
|
|
@if (!Mappings.Any()) { <p class="text-muted">No remote branches have been mapped.</p> }
|
|
@foreach (var w in DataOperationAuthoring.ConditionCapacityWarnings(_snapshot!, ClusterId)) { <div class="notice mb-2" role="note">@w</div> }
|
|
@foreach (var m in Mappings) { <div class="d-flex flex-wrap gap-2 align-items-center mb-2"><strong>@m.RemoteNamespaceMappingId</strong><span>@m.Realm · @m.BranchName via @m.DataConnectionId</span><span class="chip chip-idle">Draft: @(m.Enabled ? "enabled" : "disabled")</span><AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-outline-primary" @onclick="() => Edit(m)">Edit</button></AuthorizeView></div> }
|
|
<AuthorizeView Policy="@AdminUiPolicies.ConfigEditor"><button class="btn btn-sm btn-primary" @onclick="NewMapping">New mapping</button></AuthorizeView></div>
|
|
</section>
|
|
<AuthorizeView Policy="@AdminUiPolicies.ConfigEditor">
|
|
@if (_deleteCandidate is not null)
|
|
{
|
|
<section class="panel notice mt-3" role="alert"><p>Delete this draft? The change takes effect only after deployment.</p><button class="btn btn-danger btn-sm me-2" @onclick="() => Delete(_deleteCandidate)">Confirm delete</button><button class="btn btn-outline-secondary btn-sm" @onclick="() => _deleteCandidate = null">Keep draft</button></section>
|
|
}
|
|
@if (_connection is not null)
|
|
{
|
|
var c = _connection.Value;
|
|
<section class="panel mt-3"><h2 class="panel-head">Connection draft</h2><div class="p-3">
|
|
<label class="form-label" for="connection-id">Connection ID</label><input id="connection-id" class="form-control mb-2" @bind="c.DataConnectionId" disabled="@(c.DataConnectionRowId != Guid.Empty)" />
|
|
<label class="form-label" for="target-cluster">Expected cluster ID</label><input id="target-cluster" class="form-control mb-2" @bind="c.ExpectedClusterId" />
|
|
<label class="form-label" for="target-mode">Target</label><select id="target-mode" class="form-select mb-2" @bind="c.TargetMode" @bind:after="() => TargetChanged(c)"><option value="@DataTargetMode.Node">Node</option><option value="@DataTargetMode.Cluster">Cluster</option></select>
|
|
@if (c.TargetMode == DataTargetMode.Node) { <label class="form-label" for="target-node">Expected node ID</label><input id="target-node" class="form-control mb-2" @bind="c.ExpectedNodeId" /> }
|
|
else { <label class="form-label" for="eligible">Eligible target node IDs, one per line</label><textarea id="eligible" class="form-control mb-2" @bind="_connection.EligibleNodes"></textarea> }
|
|
<label class="form-label" for="consistency">Consistency</label><select id="consistency" class="form-select mb-2" @bind="c.Consistency"><option value="@DataConsistency.Primary">Primary</option><option value="@DataConsistency.ReadyReplica">Ready replica</option></select>
|
|
<label class="form-label" for="endpoints">HTTPS endpoints, one per line</label><textarea id="endpoints" class="form-control mb-2" @bind="_connection.Endpoints"></textarea>
|
|
<label class="form-label" for="secret-ref">Secret reference</label><input id="secret-ref" class="form-control mb-2" placeholder="secret:data/…" @bind="c.SecretReference" /><div class="form-text">Reference only; never enter a key or secret value.</div>
|
|
<fieldset><legend class="fs-6">Consumer nodes</legend>@foreach (var n in Nodes) { <label class="me-3"><input type="checkbox" checked="@c.ConsumerNodeIds.Contains(n.NodeId)" @onchange="e => Toggle(c.ConsumerNodeIds, n.NodeId, (bool)e.Value!)" /> @n.NodeId</label> }</fieldset>
|
|
@Operations(c.AllowedOperations, v => c.AllowedOperations = v)
|
|
<label class="form-label" for="history-timeout">History call timeout (ms)</label><input id="history-timeout" type="number" min="1" max="@DataConnectionValidator.MaxHistoryTimeoutMilliseconds" class="form-control mb-2" @bind="c.HistoryTimeoutMilliseconds" /><div class="form-text">Each remote HistoryRead call is bounded by the caller's remaining deadline and this, and in addition by the origin's <span class="mono">DataConnections:UnaryTimeout</span> (30 s by default): a larger value has no effect past it.</div>
|
|
<label><input type="checkbox" @bind="c.Enabled" /> Enabled in next deployment</label>
|
|
@Actions(c, c.DataConnectionRowId != Guid.Empty)
|
|
</div></section>
|
|
}
|
|
@if (_export is not null)
|
|
{
|
|
var e = _export;
|
|
<section class="panel mt-3"><h2 class="panel-head">Export draft</h2><div class="p-3">
|
|
<label class="form-label" for="export-id">Export ID</label><input id="export-id" class="form-control mb-2" @bind="e.DataExportId" disabled="@(e.DataExportRowId != Guid.Empty)" />
|
|
<label class="form-label" for="principal">Peer principal</label><input id="principal" class="form-control mb-2" @bind="e.PrincipalId" />
|
|
<label class="form-label" for="export-realm">Realm</label><select id="export-realm" class="form-select mb-2" @bind="e.Realm"><option value="@DataRealm.Raw">Raw</option><option value="@DataRealm.Uns">UNS</option></select>
|
|
<label class="form-label" for="export-root">Local export root</label><select id="export-root" class="form-select mb-2" value="@(e.RootKind + "|" + e.RootEntityId)" @onchange="args => SetExportRoot(e, args.Value?.ToString())"><option value="">Choose a root</option>@foreach (var p in ExportRoots(e.Realm)) { <option value="@p.Value">@p.Label</option> }</select>
|
|
@Operations(e.AllowedOperations, v => e.AllowedOperations = v)
|
|
<label class="form-label" for="export-history-reads">Concurrent history reads per peer</label><input id="export-history-reads" type="number" min="1" max="@DataConnectionValidator.MaxConcurrentHistoryReadsLimit" class="form-control mb-2" @bind="e.MaxConcurrentHistoryReads" />
|
|
<label class="form-label" for="export-history-page">History values per page</label><input id="export-history-page" type="number" min="1" max="@DataConnectionValidator.MaxHistoryValuesPerPageLimit" class="form-control mb-2" @bind="e.MaxHistoryValuesPerPage" />
|
|
<label class="form-label" for="export-history-bytes">History response bytes</label><input id="export-history-bytes" type="number" min="@DataConnectionValidator.MinHistoryResponseBytesLimit" max="@DataConnectionValidator.MaxHistoryResponseBytesLimit" class="form-control mb-2" @bind="e.MaxHistoryResponseBytes" /><div class="form-text">Larger answers are sent in bounded chunks.</div>
|
|
<label class="form-label" for="export-max-conditions">Conditions per alarm subscription</label><input id="export-max-conditions" type="number" min="1" max="@DataConnectionValidator.MaxConditionsLimit" class="form-control mb-2" @bind="e.MaxConditions" /><div class="form-text">A remote AlarmSubscribe scope with more conditions than this is refused (ConditionCapacity) before anything is imported.</div>
|
|
<label class="d-block"><input id="export-galaxy-ack" type="checkbox" @bind="e.AllowGalaxyServiceAck" disabled="@(!e.AllowedOperations.HasFlag(DataOperations.AlarmAcknowledge) && !e.AllowGalaxyServiceAck)" /> Allow remote acknowledge of Galaxy alarms</label><div class="form-text">Galaxy-sourced alarms are acknowledged under this peer's API-key Galaxy ack identity (provision <code>otopcua/apikeys/<keyId>/galaxy-ack-user</code> and <code>…/galaxy-ack-password</code> on this cluster). Requires AlarmAcknowledge.</div>
|
|
<label><input type="checkbox" @bind="e.Enabled" /> Enabled in next deployment</label>@Actions(e, e.DataExportRowId != Guid.Empty)
|
|
</div></section>
|
|
}
|
|
@if (_mapping is not null)
|
|
{
|
|
var m = _mapping.Value;
|
|
<section class="panel mt-3"><h2 class="panel-head">Mapping draft</h2><div class="p-3">
|
|
<label class="form-label" for="mapping-id">Mapping ID</label><input id="mapping-id" class="form-control mb-2" @bind="m.RemoteNamespaceMappingId" disabled="@(m.RemoteNamespaceMappingRowId != Guid.Empty)" />
|
|
<label class="form-label" for="mapping-connection">Connection</label><select id="mapping-connection" class="form-select mb-2" @bind="m.DataConnectionId"><option value="">Choose a connection</option>@foreach (var c in Connections) { <option value="@c.DataConnectionId">@c.DataConnectionId</option> }</select>
|
|
<label class="form-label" for="mapping-realm">Realm</label><select id="mapping-realm" class="form-select mb-2" @bind="m.Realm" @bind:after="() => SetRealm(m)"><option value="@DataRealm.Raw">Raw</option><option value="@DataRealm.Uns">UNS</option></select>
|
|
<label class="form-label" for="mapping-parent">Local parent</label><select id="mapping-parent" class="form-select mb-2" value="@(m.LocalParentKind + "|" + m.LocalParentId)" @onchange="args => SetParent(m, args.Value?.ToString())"><option value="">Choose a parent</option>@foreach (var p in Parents(m.Realm)) { <option value="@p.Value">@p.Label</option> }</select>
|
|
<label class="form-label" for="branch">Branch name</label><input id="branch" class="form-control mb-2" @bind="m.BranchName" />
|
|
<label class="form-label" for="remote-root">Remote root entity</label><select id="remote-root" class="form-select mb-2" @bind="m.RemoteRootEntityId"><option value="">Choose a root</option>@foreach (var p in RemoteRoots(m)) { <option value="@p.Id">@p.Label</option> }</select><div class="form-text">The picker uses the configured target cluster. For a separately managed cluster, enter its root ID below.</div><label class="form-label" for="remote-root-id">Remote root ID</label><input id="remote-root-id" class="form-control mb-2" @bind="m.RemoteRootEntityId" />
|
|
<label class="form-label" for="identifier-kind">Remote canonical identifier kind</label><input id="identifier-kind" class="form-control mb-2" @bind="m.RemoteIdentifierKind" />
|
|
<label class="form-label" for="identifier">Remote canonical identifier</label><input id="identifier" class="form-control mb-2" @bind="m.RemoteIdentifier" />
|
|
<fieldset><legend class="fs-6">Consumer nodes</legend>@foreach (var n in Nodes) { <label class="me-3"><input type="checkbox" checked="@m.ConsumerNodeIds.Contains(n.NodeId)" @onchange="e => Toggle(m.ConsumerNodeIds, n.NodeId, (bool)e.Value!)" /> @n.NodeId</label> }</fieldset>
|
|
@Operations(m.AllowedOperations, v => m.AllowedOperations = v)
|
|
<label class="form-label" for="mapping-history-bytes">History assembly bytes per request</label><input id="mapping-history-bytes" type="number" min="1" max="@DataConnectionValidator.MaxHistoryAssemblyBytesLimit" class="form-control mb-2" @bind="m.MaxHistoryAssemblyBytesPerRequest" />
|
|
<label class="form-label" for="mapping-max-conditions">Maximum imported conditions</label><input id="mapping-max-conditions" type="number" min="1" max="@DataConnectionValidator.MaxConditionsLimit" class="form-control mb-2" @bind="m.MaxConditions" /><div class="form-text">A remote alarm scope larger than this makes the mapping's alarms Unavailable (ConditionCapacity); each imported condition materialises up to @DataConnectionValidator.NodesPerImportedCondition nodes.</div>
|
|
<label class="form-label" for="mapping-condition-stale">Condition stale timeout (ms)</label><input id="mapping-condition-stale" type="number" min="1" max="@DataConnectionValidator.MaxConditionTimeoutMilliseconds" class="form-control mb-2" @bind="m.ConditionStaleTimeoutMilliseconds" />
|
|
<label class="form-label" for="mapping-condition-method">Condition method timeout (ms)</label><input id="mapping-condition-method" type="number" min="1" max="@DataConnectionValidator.MaxConditionTimeoutMilliseconds" class="form-control mb-2" @bind="m.ConditionMethodTimeoutMilliseconds" />
|
|
<label class="form-label" for="mapping-condition-snapshot">Condition snapshot timeout (ms)</label><input id="mapping-condition-snapshot" type="number" min="1" max="@DataConnectionValidator.MaxConditionTimeoutMilliseconds" class="form-control mb-2" @bind="m.ConditionSnapshotTimeoutMilliseconds" />
|
|
<div><label><input type="checkbox" @bind="m.WriteThrough" /> Allow write-through</label></div><label><input type="checkbox" @bind="m.Enabled" /> Enabled in next deployment</label>@Actions(m, m.RemoteNamespaceMappingRowId != Guid.Empty)
|
|
</div></section>
|
|
}
|
|
</AuthorizeView>
|
|
}
|
|
</PageErrorBoundary>
|
|
|
|
@code {
|
|
[Parameter] public string ClusterId { get; set; } = "";
|
|
private DraftSnapshot? _snapshot;
|
|
private DataConnectionEditorModel? _connection;
|
|
private DataExport? _export;
|
|
private RemoteMappingEditorModel? _mapping;
|
|
private string? _error, _message;
|
|
private object? _deleteCandidate;
|
|
private IReadOnlyList<AppliedConnection> _applied = [];
|
|
private List<(string NodeId, DataConnectionDiagnosticsSnapshot Row)> _live = [];
|
|
private List<(string NodeId, NodeDiagnosticsSnapshot Snapshot)> _nodeSnapshots = [];
|
|
private IReadOnlyList<ConnectionDisplayRow> ConnectionRows => DataConnectionDiagnostics.Rows(Connections, _applied.Select(x => x.ConnectionId), _live.Select(x => x.Row.ConnectionId));
|
|
private IEnumerable<DataConnection> Connections => _snapshot!.DataConnections.Where(x => Same(x.ClusterId, ClusterId));
|
|
private IEnumerable<DataExport> Exports => _snapshot!.DataExports.Where(x => Same(x.ClusterId, ClusterId));
|
|
private IEnumerable<RemoteNamespaceMapping> Mappings => _snapshot!.RemoteNamespaceMappings.Where(x => Same(x.ClusterId, ClusterId));
|
|
private IEnumerable<ClusterNode> Nodes => _snapshot!.ClusterNodes.Where(x => Same(x.ClusterId, ClusterId) && x.Enabled);
|
|
protected override async Task OnInitializedAsync() => await Reload();
|
|
private async Task Reload()
|
|
{
|
|
_snapshot = await Service.LoadAsync(); _applied = await Service.LoadAppliedAsync(ClusterId);
|
|
var observations = await Task.WhenAll(Nodes.Select(async node =>
|
|
{
|
|
try { return (node.NodeId, Snapshot: (NodeDiagnosticsSnapshot?)await Diagnostics.GetDiagnosticsAsync(NodeId.Parse($"{node.Host}:{node.AkkaPort}"), CancellationToken.None)); }
|
|
catch (Exception) { return (node.NodeId, Snapshot: (NodeDiagnosticsSnapshot?)null); }
|
|
}));
|
|
_nodeSnapshots = observations.Where(x => x.Snapshot is not null).Select(x => (x.NodeId, x.Snapshot!)).ToList();
|
|
_live = observations.Where(x => x.Snapshot?.DataConnections is not null)
|
|
.SelectMany(x => x.Snapshot!.DataConnections!.Select(row => (x.NodeId, row))).ToList();
|
|
}
|
|
private static string Measure<T>(T? value) where T : struct => value?.ToString() ?? "unavailable";
|
|
private static string Time(DateTime? value) => value?.ToString("u") ?? "unavailable";
|
|
private static bool Same(string? a, string? b) => string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
|
|
private static T Clone<T>(T value) => System.Text.Json.JsonSerializer.Deserialize<T>(System.Text.Json.JsonSerializer.Serialize(value))!;
|
|
private void Clear() { _connection = null; _export = null; _mapping = null; _deleteCandidate = null; _error = null; _message = null; }
|
|
private void NewConnection() { Clear(); _connection = new(); _connection.Value.ClusterId = ClusterId; _connection.Value.SecretScopeClusterId = ClusterId; }
|
|
private void NewExport() { Clear(); _export = new() { ClusterId = ClusterId, Realm = DataRealm.Raw, AllowedOperations = DataOperations.Browse | DataOperations.Metadata | DataOperations.Read | DataOperations.Subscribe }; }
|
|
private void NewMapping() { Clear(); _mapping = new(); _mapping.Value.ClusterId = ClusterId; SetRealm(_mapping.Value); }
|
|
private void Edit(DataConnection c) { Clear(); _connection = new() { Value = Clone(c) }; }
|
|
private void Edit(DataExport e) { Clear(); _export = Clone(e); }
|
|
private void Edit(RemoteNamespaceMapping m) { Clear(); _mapping = new() { Value = Clone(m) }; }
|
|
private static void Toggle(List<string> ids, string id, bool on) { if (on && !ids.Contains(id)) ids.Add(id); else if (!on) ids.Remove(id); }
|
|
private static void TargetChanged(DataConnection c) { if (c.TargetMode == DataTargetMode.Cluster) c.ExpectedNodeId = null; else c.EligibleTargetNodeIds.Clear(); }
|
|
private static void SetRealm(RemoteNamespaceMapping m) { m.RemoteRealm = m.Realm; m.RemoteNamespaceUri = m.Realm == DataRealm.Raw ? V3NodeIds.RawNamespaceUri : V3NodeIds.UnsNamespaceUri; }
|
|
private static void SetParent(RemoteNamespaceMapping m, string? value) { var p = (value ?? "").Split('|', 2); m.LocalParentKind = p[0]; m.LocalParentId = p.Length > 1 ? p[1] : ""; }
|
|
private static void SetExportRoot(DataExport e, string? value) { var p = (value ?? "").Split('|', 2); e.RootKind = p[0]; e.RootEntityId = p.Length > 1 ? p[1] : ""; }
|
|
private IEnumerable<(string Value, string Label)> Parents(DataRealm realm)
|
|
{
|
|
yield return ($"Cluster|{ClusterId}", "Cluster root");
|
|
if (realm == DataRealm.Raw)
|
|
{
|
|
foreach (var x in _snapshot!.RawFolders.Where(x => Same(x.ClusterId, ClusterId))) yield return ($"RawFolder|{x.RawFolderId}", $"Folder: {x.Name} ({x.RawFolderId})");
|
|
foreach (var x in _snapshot.DriverInstances.Where(x => Same(x.ClusterId, ClusterId))) yield return ($"RawDriver|{x.DriverInstanceId}", $"Driver: {x.Name} ({x.DriverInstanceId})");
|
|
var drivers = _snapshot.DriverInstances.Where(x => Same(x.ClusterId, ClusterId)).Select(x => x.DriverInstanceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var devices = _snapshot.Devices.Where(x => drivers.Contains(x.DriverInstanceId)).ToList();
|
|
foreach (var x in devices) yield return ($"RawDevice|{x.DeviceId}", $"Device: {x.Name} ({x.DeviceId})");
|
|
var ids = devices.Select(x => x.DeviceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var x in _snapshot.TagGroups.Where(x => ids.Contains(x.DeviceId))) yield return ($"RawTagGroup|{x.TagGroupId}", $"Tag group: {x.Name} ({x.TagGroupId})");
|
|
}
|
|
else if (realm == DataRealm.Uns)
|
|
{
|
|
var areas = _snapshot!.UnsAreas.Where(x => Same(x.ClusterId, ClusterId)).ToList();
|
|
foreach (var x in areas) yield return ($"UnsArea|{x.UnsAreaId}", $"Area: {x.Name} ({x.UnsAreaId})");
|
|
var areaIds = areas.Select(x => x.UnsAreaId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var lines = _snapshot.UnsLines.Where(x => areaIds.Contains(x.UnsAreaId)).ToList();
|
|
foreach (var x in lines) yield return ($"UnsLine|{x.UnsLineId}", $"Line: {x.Name} ({x.UnsLineId})");
|
|
var lineIds = lines.Select(x => x.UnsLineId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var x in _snapshot.Equipment.Where(x => lineIds.Contains(x.UnsLineId))) yield return ($"Equipment|{x.EquipmentId}", $"Equipment: {x.Name} ({x.EquipmentId})");
|
|
}
|
|
}
|
|
private IEnumerable<(string Value, string Label)> ExportRoots(DataRealm realm)
|
|
{
|
|
foreach (var parent in Parents(realm)) yield return parent;
|
|
if (realm == DataRealm.Raw)
|
|
{
|
|
var drivers = _snapshot!.DriverInstances.Where(x => Same(x.ClusterId, ClusterId)).Select(x => x.DriverInstanceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var devices = _snapshot.Devices.Where(x => drivers.Contains(x.DriverInstanceId)).Select(x => x.DeviceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var tag in _snapshot.Tags.Where(x => devices.Contains(x.DeviceId))) yield return ($"RawTag|{tag.TagId}", $"Tag: {tag.Name} ({tag.TagId})");
|
|
}
|
|
else if (realm == DataRealm.Uns)
|
|
{
|
|
var areas = _snapshot!.UnsAreas.Where(x => Same(x.ClusterId, ClusterId)).Select(x => x.UnsAreaId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var lines = _snapshot.UnsLines.Where(x => areas.Contains(x.UnsAreaId)).Select(x => x.UnsLineId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var equipment = _snapshot.Equipment.Where(x => lines.Contains(x.UnsLineId)).Select(x => x.EquipmentId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var tag in _snapshot.VirtualTags.Where(x => equipment.Contains(x.EquipmentId))) yield return ($"VirtualTag|{tag.VirtualTagId}", $"Virtual tag: {tag.Name} ({tag.VirtualTagId})");
|
|
foreach (var tag in _snapshot.UnsTagReferences.Where(x => equipment.Contains(x.EquipmentId))) yield return ($"UnsTagReference|{tag.UnsTagReferenceId}", $"Tag reference: {tag.UnsTagReferenceId}");
|
|
}
|
|
}
|
|
private IEnumerable<(string Id, string Label)> RemoteRoots(RemoteNamespaceMapping mapping)
|
|
{
|
|
var target = Connections.FirstOrDefault(x => Same(x.DataConnectionId, mapping.DataConnectionId))?.ExpectedClusterId;
|
|
if (string.IsNullOrEmpty(target)) yield break;
|
|
yield return (target, "Cluster root: " + target);
|
|
if (mapping.Realm == DataRealm.Raw)
|
|
{
|
|
foreach (var x in _snapshot!.RawFolders.Where(x => Same(x.ClusterId, target))) yield return (x.RawFolderId, $"Folder: {x.Name} ({x.RawFolderId})");
|
|
var drivers = _snapshot.DriverInstances.Where(x => Same(x.ClusterId, target)).ToList();
|
|
foreach (var x in drivers) yield return (x.DriverInstanceId, $"Driver: {x.Name} ({x.DriverInstanceId})");
|
|
var driverIds = drivers.Select(x => x.DriverInstanceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var devices = _snapshot.Devices.Where(x => driverIds.Contains(x.DriverInstanceId)).ToList();
|
|
foreach (var x in devices) yield return (x.DeviceId, $"Device: {x.Name} ({x.DeviceId})");
|
|
var deviceIds = devices.Select(x => x.DeviceId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var x in _snapshot.TagGroups.Where(x => deviceIds.Contains(x.DeviceId))) yield return (x.TagGroupId, $"Tag group: {x.Name} ({x.TagGroupId})");
|
|
foreach (var x in _snapshot.Tags.Where(x => deviceIds.Contains(x.DeviceId))) yield return (x.TagId, $"Tag: {x.Name} ({x.TagId})");
|
|
}
|
|
else
|
|
{
|
|
var areas = _snapshot!.UnsAreas.Where(x => Same(x.ClusterId, target)).ToList();
|
|
foreach (var x in areas) yield return (x.UnsAreaId, $"Area: {x.Name} ({x.UnsAreaId})");
|
|
var areaIds = areas.Select(x => x.UnsAreaId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
var lines = _snapshot.UnsLines.Where(x => areaIds.Contains(x.UnsAreaId)).ToList();
|
|
foreach (var x in lines) yield return (x.UnsLineId, $"Line: {x.Name} ({x.UnsLineId})");
|
|
var lineIds = lines.Select(x => x.UnsLineId).ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var x in _snapshot.Equipment.Where(x => lineIds.Contains(x.UnsLineId))) yield return (x.EquipmentId, $"Equipment: {x.Name} ({x.EquipmentId})");
|
|
}
|
|
}
|
|
private RenderFragment Operations(DataOperations current, Action<DataOperations> set) => builder =>
|
|
{
|
|
builder.OpenElement(0, "fieldset"); builder.OpenElement(1, "legend"); builder.AddAttribute(2, "class", "fs-6"); builder.AddContent(3, "Allowed operations"); builder.CloseElement();
|
|
foreach (var bit in DataOperationAuthoring.AuthorableOperations)
|
|
{
|
|
builder.OpenElement(4, "label"); builder.AddAttribute(5, "class", "me-3"); builder.OpenElement(6, "input"); builder.AddAttribute(7, "type", "checkbox"); builder.AddAttribute(8, "checked", current.HasFlag(bit));
|
|
builder.AddAttribute(9, "onchange", EventCallback.Factory.Create<ChangeEventArgs>(this, args => set((bool)args.Value! ? current | bit : current & ~bit))); builder.CloseElement(); builder.AddContent(10, " " + DataOperationAuthoring.Label(bit)); builder.CloseElement();
|
|
}
|
|
if (DataOperationAuthoring.FeatureBitBanner(current) is { } banner)
|
|
{
|
|
// Plan §4.3: the X0-everywhere rule is procedural, so the editor reminds whenever a post-v1 bit is ticked.
|
|
builder.OpenElement(11, "div"); builder.AddAttribute(12, "class", "notice mt-2"); builder.AddAttribute(13, "role", "note");
|
|
builder.AddContent(14, banner); builder.CloseElement();
|
|
}
|
|
builder.CloseElement();
|
|
};
|
|
private RenderFragment Actions(object row, bool existing) => builder =>
|
|
{
|
|
builder.OpenElement(0, "div"); builder.AddAttribute(1, "class", "d-flex gap-2 mt-3");
|
|
builder.OpenElement(2, "button"); builder.AddAttribute(3, "class", "btn btn-primary"); builder.AddAttribute(4, "onclick", EventCallback.Factory.Create(this, () => Save(row))); builder.AddContent(5, "Save draft"); builder.CloseElement();
|
|
builder.OpenElement(6, "button"); builder.AddAttribute(7, "class", "btn btn-outline-secondary"); builder.AddAttribute(8, "onclick", EventCallback.Factory.Create(this, Clear)); builder.AddContent(9, "Cancel"); builder.CloseElement();
|
|
if (existing) { builder.OpenElement(10, "button"); builder.AddAttribute(11, "class", "btn btn-outline-danger"); builder.AddAttribute(12, "onclick", EventCallback.Factory.Create(this, () => _deleteCandidate = row)); builder.AddContent(13, "Delete draft"); builder.CloseElement(); }
|
|
builder.CloseElement();
|
|
};
|
|
private async Task Save(object row) { try { await Service.SaveAsync(ClusterId, row); Clear(); await Reload(); _message = "Draft saved. Deploy to apply it."; } catch (Exception ex) { _error = ex is UnauthorizedAccessException or InvalidOperationException ? ex.Message : "Could not save the draft. It may have changed; reload and try again."; } }
|
|
private async Task Delete(object? row) { try { if (row is null) return; await Service.DeleteAsync(ClusterId, row); Clear(); await Reload(); _message = "Draft deleted. Deploy to apply the change."; } catch (Exception ex) { _error = ex is UnauthorizedAccessException or InvalidOperationException ? ex.Message : "Could not delete the draft. Reload and try again."; } }
|
|
}
|