64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
58 lines
2.5 KiB
C#
58 lines
2.5 KiB
C#
using Akka.Actor;
|
|
using Microsoft.Extensions.Options;
|
|
using ZB.MOM.WW.OtOpcUa.Cluster;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Fleet;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.Types;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients;
|
|
|
|
/// <summary>
|
|
/// <see cref="IFleetDiagnosticsClient"/> backed by an Akka <see cref="ActorSelection"/> against
|
|
/// the target node's <c>DriverHostActor</c> at <c>akka.tcp://otopcua@<host>:<port>/user/driver-host</c>.
|
|
/// Sends <see cref="GetDiagnostics"/>; expects a <see cref="NodeDiagnosticsSnapshot"/> reply.
|
|
///
|
|
/// On timeout or any other failure (peer down, GetDiagnostics handler missing) returns an
|
|
/// empty snapshot so the UI degrades to "no data" instead of throwing.
|
|
/// </summary>
|
|
public sealed class FleetDiagnosticsClient : IFleetDiagnosticsClient
|
|
{
|
|
private static readonly TimeSpan AskTimeout = TimeSpan.FromSeconds(3);
|
|
|
|
private readonly ActorSystem _system;
|
|
private readonly string _systemName;
|
|
|
|
/// <summary>Initializes a new FleetDiagnosticsClient with the given actor system and cluster options.</summary>
|
|
/// <param name="system">The Akka actor system.</param>
|
|
/// <param name="options">Cluster configuration options.</param>
|
|
public FleetDiagnosticsClient(ActorSystem system, IOptions<AkkaClusterOptions> options)
|
|
{
|
|
_system = system;
|
|
_systemName = options.Value.SystemName;
|
|
}
|
|
|
|
/// <summary>Gets diagnostics for a cluster node.</summary>
|
|
/// <param name="nodeId">The node identifier to query.</param>
|
|
/// <param name="ct">Cancellation token.</param>
|
|
/// <returns>Diagnostics snapshot for the node, or an empty snapshot if the query fails.</returns>
|
|
public async Task<NodeDiagnosticsSnapshot> GetDiagnosticsAsync(NodeId nodeId, CancellationToken ct)
|
|
{
|
|
var selection = _system.ActorSelection($"akka.tcp://{_systemName}@{nodeId.Value}/user/driver-host");
|
|
try
|
|
{
|
|
using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
|
linked.CancelAfter(AskTimeout);
|
|
return await selection.Ask<NodeDiagnosticsSnapshot>(
|
|
new GetDiagnostics(CorrelationId.NewId()), AskTimeout, linked.Token);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new NodeDiagnosticsSnapshot(
|
|
nodeId,
|
|
CurrentRevision: null,
|
|
Drivers: Array.Empty<DriverInstanceDiagnostics>(),
|
|
AsOfUtc: DateTime.UtcNow);
|
|
}
|
|
}
|
|
}
|