From f022499e7f2041eca4e90e00cef8721b80abd365 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 26 May 2026 05:17:58 -0400 Subject: [PATCH] feat(adminui): IAdminOperationsClient backed by ClusterSingletonProxy --- .../Clients/AdminOperationsClient.cs | 33 +++++++++++++++++++ .../Clients/ServiceCollectionExtensions.cs | 14 ++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs create mode 100644 src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs new file mode 100644 index 0000000..b73503a --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/AdminOperationsClient.cs @@ -0,0 +1,33 @@ +using Akka.Actor; +using Akka.Hosting; +using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; +using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin; +using ZB.MOM.WW.OtOpcUa.Commons.Types; +using ZB.MOM.WW.OtOpcUa.ControlPlane; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients; + +/// +/// backed by the cluster singleton registered in +/// AddOtOpcUaControlPlane. Resolves the singleton proxy from +/// at construction time; each call Asks the proxy with a 10s timeout. +/// +public sealed class AdminOperationsClient : IAdminOperationsClient +{ + private static readonly TimeSpan AskTimeout = TimeSpan.FromSeconds(10); + + private readonly IActorRef _proxy; + + public AdminOperationsClient(ActorRegistry registry) + { + _proxy = registry.Get(); + } + + public async Task StartDeploymentAsync(string createdBy, CancellationToken ct) + { + var msg = new StartDeployment(createdBy, CorrelationId.NewId()); + using var linked = CancellationTokenSource.CreateLinkedTokenSource(ct); + linked.CancelAfter(AskTimeout); + return await _proxy.Ask(msg, AskTimeout, linked.Token); + } +} diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..39c96c5 --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Clients/ServiceCollectionExtensions.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.DependencyInjection; +using ZB.MOM.WW.OtOpcUa.Commons.Interfaces; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddOtOpcUaAdminClients(this IServiceCollection services) + { + services.AddScoped(); + services.AddScoped(); + return services; + } +}