Skip to content

Commit

Permalink
docs: add missing xml-doc (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem authored Feb 13, 2024
2 parents e66e34d + 4202dd3 commit 2a623f1
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 16 deletions.
3 changes: 3 additions & 0 deletions packages/csharp/ArmoniK.Api.Client/Options/GrpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace ArmoniK.Api.Client.Options
[PublicAPI]
public class GrpcClient
{
/// <summary>
/// Path to the section containing the values in the configuration object
/// </summary>
public const string SettingSection = nameof(GrpcClient);

/// <summary>
Expand Down
42 changes: 40 additions & 2 deletions packages/csharp/ArmoniK.Api.Client/Utils/ServiceConfigExt.cs
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
// J. Gurhem <[email protected]>
// D. Dubuc <[email protected]>
Expand Down Expand Up @@ -33,6 +33,9 @@

namespace ArmoniK.Api.Client.Utils
{
/// <summary>
/// Extensions for configuring services
/// </summary>
public static class ServiceConfigExt
{
private const string MaxAttemptsPropertyName = "maxAttempts";
Expand All @@ -46,16 +49,37 @@ public static class ServiceConfigExt
private const string MethodPropertyName = "method";
private const string RetryPolicyPropertyName = "retryPolicy";

/// <summary>
/// Convert <see cref="ServiceConfig" /> to JSON
/// </summary>
/// <param name="config">Input config</param>
/// <returns>
/// A string containing the config in JSON format
/// </returns>
public static string ToJson(this ServiceConfig config)
=> JsonConvert.SerializeObject(config.ToDict());

/// <summary>
/// Convert <see cref="ServiceConfig" /> to dictionary
/// </summary>
/// <param name="config">Input service config</param>
/// <returns>
/// A dictionary containing the service config
/// </returns>
public static Dictionary<string, object> ToDict(this ServiceConfig config)
=> new()
{
[MethodConfigPropertyName] = config.MethodConfigs.Select(methodConfig => methodConfig.ToDict())
.ToArray(),
};

/// <summary>
/// Convert <see cref="MethodConfig" /> to dictionary
/// </summary>
/// <param name="config">Input method config</param>
/// <returns>
/// A dictionary containing the method config
/// </returns>
public static Dictionary<string, object> ToDict(this MethodConfig config)
{
var dict = new Dictionary<string, object>
Expand All @@ -71,6 +95,13 @@ public static Dictionary<string, object> ToDict(this MethodConfig config)
return dict;
}

/// <summary>
/// Convert <see cref="MethodName" /> to dictionary
/// </summary>
/// <param name="methodName">Input method name</param>
/// <returns>
/// A dictionary containing the method name
/// </returns>
public static Dictionary<string, string> ToDict(this MethodName methodName)
{
var dict = new Dictionary<string, string>();
Expand All @@ -87,6 +118,13 @@ public static Dictionary<string, string> ToDict(this MethodName methodName)
return dict;
}

/// <summary>
/// Convert <see cref="RetryPolicy" /> to dictionary
/// </summary>
/// <param name="retryPolicy">Input retry policy</param>
/// <returns>
/// A dictionary containing the retry policy
/// </returns>
public static Dictionary<string, object> ToDict(this RetryPolicy retryPolicy)
{
var dict = new Dictionary<string, object>();
Expand Down Expand Up @@ -122,7 +160,7 @@ public static Dictionary<string, object> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@

namespace ArmoniK.Api.Common.Channel.Utils;

/// <summary>
/// Provides a built gRPC Channel from given options
/// </summary>
[UsedImplicitly]
public sealed class GrpcChannelProvider : IAsyncDisposable
{
Expand All @@ -46,6 +49,12 @@ public sealed class GrpcChannelProvider : IAsyncDisposable
private NetworkStream? networkStream_;
private Socket? socket_;

/// <summary>
/// Instantiate a <see cref="GrpcChannelProvider" /> that creates a gRPC channel
/// </summary>
/// <param name="options">Options to configure the creation of the gRPC channel</param>
/// <param name="logger">Logger that will produce logs</param>
/// <exception cref="InvalidOperationException">when address is empty</exception>
public GrpcChannelProvider(GrpcChannel options,
ILogger<GrpcChannelProvider> logger)
{
Expand All @@ -56,6 +65,7 @@ public GrpcChannelProvider(GrpcChannel options,
address_);
}

/// <inheritdoc />
public async ValueTask DisposeAsync()
{
socket_?.Close();
Expand Down Expand Up @@ -114,6 +124,11 @@ await socket_.ConnectAsync(udsEndPoint,
});
}

/// <summary>
/// Access to the created gRPC Channel
/// </summary>
/// <returns>The created gRPC Channel</returns>
/// <exception cref="InvalidOperationException">when socket type is unknown</exception>
public ChannelBase Get()
{
switch (options_.SocketType)
Expand Down
3 changes: 3 additions & 0 deletions packages/csharp/ArmoniK.Api.Common/Options/ComputePlane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace ArmoniK.Api.Common.Options;
[PublicAPI]
public class ComputePlane
{
/// <summary>
/// Path to the section containing the values in the configuration object
/// </summary>
public const string SettingSection = nameof(ComputePlane);

/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions packages/csharp/ArmoniK.Api.Common/Options/GrpcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@

namespace ArmoniK.Api.Common.Options;

/// <summary>
/// Options to configure a channel from gRPC
/// </summary>
[PublicAPI]
public class GrpcChannel
{
/// <summary>
/// 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
/// </summary>
public string Address { get; set; } = "/tmp/armonik.sock";

/// <summary>
/// Type of Grpc Socket used
/// Type of gRPC Socket used
/// </summary>
public GrpcSocketType SocketType { get; set; } = GrpcSocketType.UnixDomainSocket;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@

namespace ArmoniK.Api.Worker.Utils;

/// <summary>
/// Wrapper to add nice logs during application lifetime
/// </summary>
public class ApplicationLifeTimeManager
{
private readonly IHostApplicationLifetime lifetime_;
private readonly ILogger<ApplicationLifeTimeManager> logger_;

/// <summary>
/// Instantiate a wrapper to add nice logs during application lifetime
/// </summary>
/// <param name="logger">Logger that will produce logs</param>
/// <param name="lifetime">Application lifetime to attach events</param>
public ApplicationLifeTimeManager(ILogger<ApplicationLifeTimeManager> logger,
IHostApplicationLifetime lifetime)
{
Expand Down
2 changes: 1 addition & 1 deletion packages/csharp/ArmoniK.Api.Worker/Utils/WorkerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static WebApplication Create<T>(Action<IServiceCollection, IConfiguration
var computePlanOptions = builder.Configuration.GetRequiredSection(ComputePlane.SettingSection)
.Get<ComputePlane>();

if (computePlanOptions.WorkerChannel == null)
if (computePlanOptions?.WorkerChannel is null)
{
throw new Exception($"{nameof(computePlanOptions.WorkerChannel)} options should not be null");
}
Expand Down
14 changes: 14 additions & 0 deletions packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public IEnumerable<byte[]> Values
=> dataDependencies_.Select(key => this[key]);
}

/// <summary>
/// Task handler that unifies task execution and calls to the Agent
/// </summary>
public class TaskHandler : ITaskHandler
{
private readonly CancellationToken cancellationToken_;
Expand All @@ -120,6 +123,14 @@ public class TaskHandler : ITaskHandler
private readonly ILoggerFactory loggerFactory_;


/// <summary>
/// Instantiate task handler that unifies task execution and calls to the Agent
/// </summary>
/// <param name="processRequest">Task execution request</param>
/// <param name="client">Client to the agent</param>
/// <param name="loggerFactory">Logger factory used to create loggers</param>
/// <param name="cancellationToken">Token used to cancel the execution of the method</param>
/// <exception cref="InvalidOperationException">when payload is not found</exception>
public TaskHandler(ProcessRequest processRequest,
Agent.AgentClient client,
ILoggerFactory loggerFactory,
Expand Down Expand Up @@ -153,6 +164,9 @@ public TaskHandler(ProcessRequest processRequest,
}
}

/// <summary>
/// Communication token used to identify requests
/// </summary>
public string Token { get; }

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
// J. Gurhem <[email protected]>
// D. Dubuc <[email protected]>
Expand Down Expand Up @@ -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<CreateTaskRequest> ToRequestStream(this IEnumerable<TaskRequest> taskRequests,
TaskOptions? taskOptions,
Expand Down
31 changes: 26 additions & 5 deletions packages/csharp/ArmoniK.Api.Worker/Worker/WorkerStreamWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@

namespace ArmoniK.Api.Worker.Worker;

/// <summary>
/// Wrapper implementation that provide a simpler interface to use for tasks implementations in C#
/// </summary>
[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<WorkerStreamWrapper> logger_;

private readonly ChannelBase channel_;
private readonly Agent.AgentClient client_;
private readonly ILoggerFactory loggerFactory_;

/// <summary>
/// Logger used for printing logs during task execution
/// </summary>
[PublicAPI]
public ILogger<WorkerStreamWrapper> logger_;

/// <summary>
/// Instantiate a simpler interface to use for tasks implementations
/// </summary>
/// <param name="loggerFactory">LoggerFactory to create loggers</param>
/// <param name="provider">gRPC channel provider to create channels with the Agent</param>
public WorkerStreamWrapper(ILoggerFactory loggerFactory,
GrpcChannelProvider provider)
{
Expand Down Expand Up @@ -87,6 +100,14 @@ public sealed override async Task<ProcessReply> Process(ProcessRequest reques
};
}

/// <summary>
/// User defined computations
/// </summary>
/// <param name="taskHandler">Handler to access input data and task capabilities</param>
/// <returns>
/// The output of the computational task
/// </returns>
/// <exception cref="RpcException">when method is not overwritten</exception>
public virtual Task<Output> Process(ITaskHandler taskHandler)
=> throw new RpcException(new Status(StatusCode.Unimplemented,
""));
Expand Down

0 comments on commit 2a623f1

Please sign in to comment.