From 6c8014cb361e8434a1ede4b2411c49b73097ae77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 9 Feb 2024 15:39:33 +0100 Subject: [PATCH 1/6] docs: add missing xml-doc --- .../ArmoniK.Api.Client/Options/GrpcClient.cs | 3 +++ .../Utils/GrpcChannelProvider.cs | 15 +++++++++++++++ .../ArmoniK.Api.Common/Options/GrpcChannel.cs | 7 +++++-- .../Utils/ApplicationLifeTimeManager.cs | 8 ++++++++ .../ArmoniK.Api.Worker/Utils/WorkerServer.cs | 2 +- .../ArmoniK.Api.Worker/Worker/TaskHandler.cs | 14 ++++++++++++++ .../Worker/WorkerStreamWrapper.cs | 18 +++++++++++++++++- 7 files changed, 63 insertions(+), 4 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Client/Options/GrpcClient.cs b/packages/csharp/ArmoniK.Api.Client/Options/GrpcClient.cs index 159f2938e..8b60ae5e6 100644 --- a/packages/csharp/ArmoniK.Api.Client/Options/GrpcClient.cs +++ b/packages/csharp/ArmoniK.Api.Client/Options/GrpcClient.cs @@ -36,6 +36,9 @@ namespace ArmoniK.Api.Client.Options [PublicAPI] public class GrpcClient { + /// + /// Path to the section containing the values in the configuration object + /// public const string SettingSection = nameof(GrpcClient); /// diff --git a/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs b/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs index dd409d248..6d5a24653 100644 --- a/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs +++ b/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs @@ -37,6 +37,9 @@ namespace ArmoniK.Api.Common.Channel.Utils; +/// +/// Provides a built gRPC Channel from given options +/// [UsedImplicitly] public sealed class GrpcChannelProvider : IAsyncDisposable { @@ -46,6 +49,12 @@ public sealed class GrpcChannelProvider : IAsyncDisposable private NetworkStream? networkStream_; private Socket? socket_; + /// + /// Instantiate a that creates a gRPC channel + /// + /// Options to configure the creation of the gRPC channel + /// Logger that will produce logs + /// when address is empty public GrpcChannelProvider(GrpcChannel options, ILogger logger) { @@ -56,6 +65,7 @@ public GrpcChannelProvider(GrpcChannel options, address_); } + /// public async ValueTask DisposeAsync() { socket_?.Close(); @@ -114,6 +124,11 @@ await socket_.ConnectAsync(udsEndPoint, }); } + /// + /// Access the created gRPC Channel + /// + /// The created gRPC Channel + /// when socket type is unknown public ChannelBase Get() { switch (options_.SocketType) diff --git a/packages/csharp/ArmoniK.Api.Common/Options/GrpcChannel.cs b/packages/csharp/ArmoniK.Api.Common/Options/GrpcChannel.cs index 7c16e7f23..5ba786101 100644 --- a/packages/csharp/ArmoniK.Api.Common/Options/GrpcChannel.cs +++ b/packages/csharp/ArmoniK.Api.Common/Options/GrpcChannel.cs @@ -25,16 +25,19 @@ namespace ArmoniK.Api.Common.Options; +/// +/// Options to configure a channel from gRPC +/// [PublicAPI] public class GrpcChannel { /// - /// Address or path of the resource used to communicate for this Grpc Channel + /// Address or path of the resource used to communicate for this gRPC Channel /// public string Address { get; set; } = "/tmp/armonik.sock"; /// - /// Type of Grpc Socket used + /// Type of gRPC Socket used /// public GrpcSocketType SocketType { get; set; } = GrpcSocketType.UnixDomainSocket; } diff --git a/packages/csharp/ArmoniK.Api.Worker/Utils/ApplicationLifeTimeManager.cs b/packages/csharp/ArmoniK.Api.Worker/Utils/ApplicationLifeTimeManager.cs index 87f94f1f7..f8a4d0307 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Utils/ApplicationLifeTimeManager.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Utils/ApplicationLifeTimeManager.cs @@ -26,11 +26,19 @@ namespace ArmoniK.Api.Worker.Utils; +/// +/// Wrapper to add nice logs during application lifetime +/// public class ApplicationLifeTimeManager { private readonly IHostApplicationLifetime lifetime_; private readonly ILogger logger_; + /// + /// Instantiate a wrapper to add nice logs during application lifetime + /// + /// Logger that will produce logs + /// Application lifetime to attach events public ApplicationLifeTimeManager(ILogger logger, IHostApplicationLifetime lifetime) { diff --git a/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs b/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs index aaeaa7495..7ffd84fa3 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs @@ -113,7 +113,7 @@ public static WebApplication Create(Action(); - if (computePlanOptions.WorkerChannel == null) + if (computePlanOptions?.WorkerChannel == null) { throw new Exception($"{nameof(computePlanOptions.WorkerChannel)} options should not be null"); } diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs index c13820e6e..5973eb9f6 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs @@ -111,6 +111,9 @@ public IEnumerable Values => dataDependencies_.Select(key => this[key]); } +/// +/// Task handler that unifies task execution and calls to the Agent +/// public class TaskHandler : ITaskHandler { private readonly CancellationToken cancellationToken_; @@ -120,6 +123,14 @@ public class TaskHandler : ITaskHandler private readonly ILoggerFactory loggerFactory_; + /// + /// Instantiate task handler that unifies task execution and calls to the Agent + /// + /// Task execution request + /// Client to the agent + /// Logger factory used to create loggers + /// Token used to cancel the execution of the method + /// when payload is not found public TaskHandler(ProcessRequest processRequest, Agent.AgentClient client, ILoggerFactory loggerFactory, @@ -153,6 +164,9 @@ public TaskHandler(ProcessRequest processRequest, } } + /// + /// Communication token used to identify requests + /// public string Token { get; } /// diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs index efd4b17aa..4f7dda8b7 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs @@ -38,14 +38,22 @@ namespace ArmoniK.Api.Worker.Worker; +/// +/// Wrapper implementation that provide a simpler interface to use for tasks implementations in C# +/// [PublicAPI] public class WorkerStreamWrapper : gRPC.V1.Worker.Worker.WorkerBase, IAsyncDisposable { private readonly ChannelBase channel_; private readonly Agent.AgentClient client_; + private readonly ILogger logger_; private readonly ILoggerFactory loggerFactory_; - public ILogger logger_; + /// + /// Instantiate a simpler interface to use for tasks implementations + /// + /// LoggerFactory to create loggers + /// gRPC channel provider to create channels with the Agent public WorkerStreamWrapper(ILoggerFactory loggerFactory, GrpcChannelProvider provider) { @@ -87,6 +95,14 @@ public sealed override async Task Process(ProcessRequest reques }; } + /// + /// User defined computations + /// + /// Handler to access input data and task capabilities + /// + /// The output of the computational task + /// + /// when method is not overwritten public virtual Task Process(ITaskHandler taskHandler) => throw new RpcException(new Status(StatusCode.Unimplemented, "")); From f0e025bb697ac464fad18748c5635fc1715e06e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 9 Feb 2024 15:55:49 +0100 Subject: [PATCH 2/6] docs: typo --- .../ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs | 2 +- packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs b/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs index 6d5a24653..956389813 100644 --- a/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs +++ b/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs @@ -125,7 +125,7 @@ await socket_.ConnectAsync(udsEndPoint, } /// - /// Access the created gRPC Channel + /// Access to the created gRPC Channel /// /// The created gRPC Channel /// when socket type is unknown diff --git a/packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs b/packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs index 77f842734..6b8f52698 100644 --- a/packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs +++ b/packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs @@ -31,6 +31,9 @@ namespace ArmoniK.Api.Common.Options; [PublicAPI] public class ComputePlane { + /// + /// Path to the section containing the values in the configuration object + /// public const string SettingSection = nameof(ComputePlane); /// From 33bb1a81ead9d2be6c61edb02026c987095e4a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 9 Feb 2024 17:07:36 +0100 Subject: [PATCH 3/6] fix: logger should stay public --- .../Worker/WorkerStreamWrapper.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs index 4f7dda8b7..0643b6462 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs @@ -44,10 +44,15 @@ namespace ArmoniK.Api.Worker.Worker; [PublicAPI] public class WorkerStreamWrapper : gRPC.V1.Worker.Worker.WorkerBase, IAsyncDisposable { - private readonly ChannelBase channel_; - private readonly Agent.AgentClient client_; - private readonly ILogger logger_; - private readonly ILoggerFactory loggerFactory_; + private readonly ChannelBase channel_; + private readonly Agent.AgentClient client_; + private readonly ILoggerFactory loggerFactory_; + + /// + /// Logger used for printing logs during task execution + /// + [PublicAPI] + public ILogger logger_; /// /// Instantiate a simpler interface to use for tasks implementations From 00b40a1bab8211f0faa0162eaa653dd2a67bdf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 9 Feb 2024 17:13:52 +0100 Subject: [PATCH 4/6] refactor: TaskRequestExtensions should be internal --- .../ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs index dc17ed174..63006ecb8 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs @@ -29,12 +29,9 @@ using Google.Protobuf; -using JetBrains.Annotations; - namespace ArmoniK.Api.Worker.Worker; -[PublicAPI] -public static class TaskRequestExtensions +internal static class TaskRequestExtensions { public static IEnumerable ToRequestStream(this IEnumerable taskRequests, TaskOptions? taskOptions, From d31fa896f73cc533289087495052af4ff284d7d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 9 Feb 2024 17:21:17 +0100 Subject: [PATCH 5/6] docs: xml-doc for ServiceConfigExt --- .../Utils/ServiceConfigExt.cs | 42 ++++++++++++++++++- .../Worker/TaskRequestExtensions.cs | 4 +- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Client/Utils/ServiceConfigExt.cs b/packages/csharp/ArmoniK.Api.Client/Utils/ServiceConfigExt.cs index 62a68a424..2590975df 100644 --- a/packages/csharp/ArmoniK.Api.Client/Utils/ServiceConfigExt.cs +++ b/packages/csharp/ArmoniK.Api.Client/Utils/ServiceConfigExt.cs @@ -1,6 +1,6 @@ // This file is part of the ArmoniK project // -// Copyright (C) ANEO, 2021-2023. All rights reserved. +// Copyright (C) ANEO, 2021-2024. All rights reserved. // W. Kirschenmann // J. Gurhem // D. Dubuc @@ -33,6 +33,9 @@ namespace ArmoniK.Api.Client.Utils { + /// + /// Extensions for configuring services + /// public static class ServiceConfigExt { private const string MaxAttemptsPropertyName = "maxAttempts"; @@ -46,9 +49,23 @@ public static class ServiceConfigExt private const string MethodPropertyName = "method"; private const string RetryPolicyPropertyName = "retryPolicy"; + /// + /// Convert to JSON + /// + /// Input config + /// + /// A string containing the config in JSON format + /// public static string ToJson(this ServiceConfig config) => JsonConvert.SerializeObject(config.ToDict()); + /// + /// Convert to dictionary + /// + /// Input service config + /// + /// A dictionary containing the service config + /// public static Dictionary ToDict(this ServiceConfig config) => new() { @@ -56,6 +73,13 @@ public static Dictionary ToDict(this ServiceConfig config) .ToArray(), }; + /// + /// Convert to dictionary + /// + /// Input method config + /// + /// A dictionary containing the method config + /// public static Dictionary ToDict(this MethodConfig config) { var dict = new Dictionary @@ -71,6 +95,13 @@ public static Dictionary ToDict(this MethodConfig config) return dict; } + /// + /// Convert to dictionary + /// + /// Input method name + /// + /// A dictionary containing the method name + /// public static Dictionary ToDict(this MethodName methodName) { var dict = new Dictionary(); @@ -87,6 +118,13 @@ public static Dictionary ToDict(this MethodName methodName) return dict; } + /// + /// Convert to dictionary + /// + /// Input retry policy + /// + /// A dictionary containing the retry policy + /// public static Dictionary ToDict(this RetryPolicy retryPolicy) { var dict = new Dictionary(); @@ -122,7 +160,7 @@ public static Dictionary ToDict(this RetryPolicy retryPolicy) return dict; } - public static string ToSimpleString(this Duration duration) + private static string ToSimpleString(this Duration duration) => duration.Seconds + (duration.Nanos > 0 ? $".{duration.Nanos: D9}s" : "s"); diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs index 63006ecb8..df11abeeb 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs @@ -1,6 +1,6 @@ // This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2022. All rights reserved. +// +// Copyright (C) ANEO, 2021-2024. All rights reserved. // W. Kirschenmann // J. Gurhem // D. Dubuc From 4202dd340a0d808409bf7db0211702879d9e256e Mon Sep 17 00:00:00 2001 From: lemaitre-aneo <91961298+lemaitre-aneo@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:01:46 +0100 Subject: [PATCH 6/6] is null --- packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs b/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs index 7ffd84fa3..d2b955aa5 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs @@ -113,7 +113,7 @@ public static WebApplication Create(Action(); - if (computePlanOptions?.WorkerChannel == null) + if (computePlanOptions?.WorkerChannel is null) { throw new Exception($"{nameof(computePlanOptions.WorkerChannel)} options should not be null"); }