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.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.Common.Channel/Utils/GrpcChannelProvider.cs b/packages/csharp/ArmoniK.Api.Common.Channel/Utils/GrpcChannelProvider.cs index dd409d248..956389813 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 to 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/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); /// 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..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"); } 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/TaskRequestExtensions.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs index dc17ed174..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 @@ -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, diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs index efd4b17aa..0643b6462 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs @@ -38,14 +38,27 @@ 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 ILoggerFactory loggerFactory_; - public ILogger logger_; - + 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 + /// + /// LoggerFactory to create loggers + /// gRPC channel provider to create channels with the Agent public WorkerStreamWrapper(ILoggerFactory loggerFactory, GrpcChannelProvider provider) { @@ -87,6 +100,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, ""));