From 7c948d3c73bf50fee9fea5e22e21498ed97444b7 Mon Sep 17 00:00:00 2001 From: lemaitre-aneo Date: Thu, 23 May 2024 10:03:08 +0200 Subject: [PATCH 1/5] Remove Grpc.Core --- ...rmoniK.DevelopmentKit.Client.Common.csproj | 3 +- Client/src/Common/Submitter/ChannelPool.cs | 91 ++++++++----------- .../Submitter/ClientServiceConnector.cs | 19 ---- .../ArmoniK.EndToEndTests.Common.csproj | 2 +- ...rmoniK.DevelopmentKit.Worker.Common.csproj | 4 +- 5 files changed, 41 insertions(+), 78 deletions(-) diff --git a/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj b/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj index 990f3414..be849b1d 100644 --- a/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj +++ b/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj @@ -8,8 +8,7 @@ - - + diff --git a/Client/src/Common/Submitter/ChannelPool.cs b/Client/src/Common/Submitter/ChannelPool.cs index 9981a83d..a7db51b0 100644 --- a/Client/src/Common/Submitter/ChannelPool.cs +++ b/Client/src/Common/Submitter/ChannelPool.cs @@ -1,13 +1,13 @@ // This file is part of the ArmoniK project -// +// // Copyright (C) ANEO, 2021-2023. All rights reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,13 +16,11 @@ using System; using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; -using Grpc.Core; +using Grpc.Net.Client; using Microsoft.Extensions.Logging; -#if NET5_0_OR_GREATER -using Grpc.Net.Client; -#endif namespace ArmoniK.DevelopmentKit.Client.Common.Submitter; @@ -31,30 +29,30 @@ namespace ArmoniK.DevelopmentKit.Client.Common.Submitter; /// public sealed class ChannelPool { - private readonly Func channelFactory_; + private readonly Func channelFactory_; private readonly ILogger? logger_; - private readonly ConcurrentBag pool_; + private readonly ConcurrentBag pool_; /// /// Constructs a new channelPool /// /// Function used to create new channels /// loggerFactory used to instantiate a logger for the pool - public ChannelPool(Func channelFactory, + public ChannelPool(Func channelFactory, ILoggerFactory? loggerFactory = null) { channelFactory_ = channelFactory; - pool_ = new ConcurrentBag(); + pool_ = new ConcurrentBag(); logger_ = loggerFactory?.CreateLogger(); } /// /// Get a channel from the pool. If the pool is empty, create a new channel /// - /// A ChannelBase used by nobody else - private ChannelBase AcquireChannel() + /// A GrpcChannel used by nobody else + private GrpcChannel AcquireChannel() { if (pool_.TryTake(out var channel)) { @@ -78,10 +76,10 @@ private ChannelBase AcquireChannel() } /// - /// Release a ChannelBase to the pool that could be reused later by someone else + /// Release a GrpcChannel to the pool that could be reused later by someone else /// /// Channel to release - private void ReleaseChannel(ChannelBase channel) + private void ReleaseChannel(GrpcChannel channel) { if (ShutdownOnFailure(channel)) { @@ -101,47 +99,30 @@ private void ReleaseChannel(ChannelBase channel) /// /// Channel to check the state /// True if the channel has been shut down - private static bool ShutdownOnFailure(ChannelBase channel) + private static bool ShutdownOnFailure(GrpcChannel channel) { try { - switch (channel) - { - case Channel chan: - switch (chan.State) - { - case ChannelState.TransientFailure: - chan.ShutdownAsync() - .Wait(); - return true; - case ChannelState.Shutdown: - return true; - case ChannelState.Idle: - case ChannelState.Connecting: - case ChannelState.Ready: - default: - return false; - } #if NET5_0_OR_GREATER - case GrpcChannel chan: - switch (chan.State) - { - case ConnectivityState.TransientFailure: - chan.ShutdownAsync() - .Wait(); - return true; - case ConnectivityState.Shutdown: - return true; - case ConnectivityState.Idle: - case ConnectivityState.Connecting: - case ConnectivityState.Ready: - default: - return false; - } -#endif + switch (channel.State) + { + case ConnectivityState.TransientFailure: + channel.ShutdownAsync() + .Wait(); + channel.Dispose(); + return true; + case ConnectivityState.Shutdown: + return true; + case ConnectivityState.Idle: + case ConnectivityState.Connecting: + case ConnectivityState.Ready: default: return false; } +#else + _ = channel; + return false; +#endif } catch (InvalidOperationException) { @@ -162,7 +143,7 @@ public ChannelGuard GetChannel() /// Function to be called /// Type of the return type of f /// Value returned by f - public T WithChannel(Func f) + public T WithChannel(Func f) { using var channel = GetChannel(); return f(channel); @@ -176,7 +157,9 @@ public sealed class ChannelGuard : IDisposable /// /// Channel that is used by nobody else /// - private readonly ChannelBase channel_; + [SuppressMessage("Usage", + "CA2213:Disposable fields should be disposed")] + private readonly GrpcChannel channel_; private readonly ChannelPool pool_; @@ -198,8 +181,8 @@ public void Dispose() /// Implicit convert a ChannelGuard into a ChannelBase /// /// ChannelGuard - /// ChannelBase - public static implicit operator ChannelBase(ChannelGuard guard) + /// GrpcChannel + public static implicit operator GrpcChannel(ChannelGuard guard) => guard.channel_; } } diff --git a/Client/src/Common/Submitter/ClientServiceConnector.cs b/Client/src/Common/Submitter/ClientServiceConnector.cs index bc5be60d..a5d19be6 100644 --- a/Client/src/Common/Submitter/ClientServiceConnector.cs +++ b/Client/src/Common/Submitter/ClientServiceConnector.cs @@ -14,8 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; - using ArmoniK.Api.Client.Options; using ArmoniK.Api.Client.Submitter; @@ -49,23 +47,6 @@ public static ChannelPool ControlPlaneConnectionPool(Properties properties, OverrideTargetName = properties.TargetNameOverride, }; - if (properties.ControlPlaneUri.Scheme == Uri.UriSchemeHttps && options.AllowUnsafeConnection && string.IsNullOrEmpty(options.OverrideTargetName)) - { -#if NET5_0_OR_GREATER - var doOverride = !string.IsNullOrEmpty(options.CaCert); -#else - var doOverride = true; -#endif - if (doOverride) - { - // Doing it here once to improve performance - options.OverrideTargetName = GrpcChannelFactory.GetOverrideTargetName(options, - GrpcChannelFactory.GetServerCertificate(properties.ControlPlaneUri, - options)) ?? ""; - } - } - - return new ChannelPool(() => GrpcChannelFactory.CreateChannel(options, loggerFactory?.CreateLogger(typeof(ClientServiceConnector)))); } diff --git a/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj b/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj index 2e059028..3442ae11 100644 --- a/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj +++ b/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj @@ -12,7 +12,7 @@ - + diff --git a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj index b02ba907..d23b8969 100644 --- a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj +++ b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj @@ -8,13 +8,13 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 9960a72f23b130b1719f66e278a7631c3e9b0373 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur <103190315+dbrasseur-aneo@users.noreply.github.com> Date: Wed, 29 May 2024 17:44:59 +0200 Subject: [PATCH 2/5] Added proxy settings to properties --- Client/src/Common/Properties.cs | 37 ++++++++++++++++--- .../Submitter/ClientServiceConnector.cs | 5 +++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Client/src/Common/Properties.cs b/Client/src/Common/Properties.cs index 727eb2a5..214a9fb3 100644 --- a/Client/src/Common/Properties.cs +++ b/Client/src/Common/Properties.cs @@ -1,18 +1,19 @@ // This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2023. All rights reserved. -// +// +// Copyright (C) ANEO, 2021-$CURRENT_YEAR$. All rights reserved. +// // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// using System; @@ -50,6 +51,9 @@ public class Properties private const string SectionClientKey = "ClientKey"; private const string SectionClientCertP12 = "ClientP12"; private const string SectionTargetNameOverride = "EndpointNameOverride"; + private const string SectionProxy = "Proxy"; + private const string SectionProxyUsername = "ProxyUsername"; + private const string SectionProxyPassword = "ProxyPassword"; private const string SectionRetryInitialBackoff = "RetryInitialBackoff"; private const string SectionRetryBackoffMultiplier = "RetryBackoffMultiplier"; @@ -137,7 +141,10 @@ public Properties(IConfiguration configuration, bool? sslValidation = null, TimeSpan retryInitialBackoff = new(), double retryBackoffMultiplier = 0, - TimeSpan retryMaxBackoff = new()) + TimeSpan retryMaxBackoff = new(), + string? proxy = null, + string? proxyUsername = null, + string? proxyPassword = null) { TaskOptions = options; Configuration = configuration; @@ -186,6 +193,9 @@ public Properties(IConfiguration configuration, ClientCertFilePem = clientCertFilePem ?? sectionGrpc[SectionClientCert] ?? string.Empty; ClientKeyFilePem = clientKeyFilePem ?? sectionGrpc[SectionClientKey] ?? string.Empty; ClientP12File = clientP12 ?? sectionGrpc[SectionClientCertP12] ?? string.Empty; + Proxy = proxy ?? sectionGrpc[SectionProxy] ?? string.Empty; + ProxyUsername = proxyUsername ?? sectionGrpc[SectionProxyUsername] ?? string.Empty; + ProxyPassword = proxyPassword ?? sectionGrpc[SectionProxyPassword] ?? string.Empty; if (retryInitialBackoff != TimeSpan.Zero) { @@ -369,4 +379,19 @@ public string ConnectionString /// Max backoff for retries /// public TimeSpan RetryMaxBackoff { get; } = TimeSpan.FromSeconds(30); + + /// + /// Proxy URL + /// + public string Proxy { get; set; } + + /// + /// Username for the proxy + /// + public string ProxyUsername { get; set; } + + /// + /// Password for the proxy + /// + public string ProxyPassword { get; set; } } diff --git a/Client/src/Common/Submitter/ClientServiceConnector.cs b/Client/src/Common/Submitter/ClientServiceConnector.cs index a5d19be6..641bbcc0 100644 --- a/Client/src/Common/Submitter/ClientServiceConnector.cs +++ b/Client/src/Common/Submitter/ClientServiceConnector.cs @@ -45,6 +45,11 @@ public static ChannelPool ControlPlaneConnectionPool(Properties properties, KeyPem = properties.ClientKeyFilePem, Endpoint = properties.ControlPlaneUri.ToString(), OverrideTargetName = properties.TargetNameOverride, + BackoffMultiplier = properties.RetryBackoffMultiplier, + InitialBackOff = properties.RetryInitialBackoff, + Proxy = properties.Proxy, + ProxyUsername = properties.ProxyUsername, + ProxyPassword = properties.ProxyPassword, }; return new ChannelPool(() => GrpcChannelFactory.CreateChannel(options, From 15680db2b24ec2ef4b101f6d7c1ab3152d547933 Mon Sep 17 00:00:00 2001 From: lemaitre-aneo Date: Fri, 31 May 2024 12:17:22 +0200 Subject: [PATCH 3/5] Add net6.0 support back for worker libs --- Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj | 2 +- .../src/Symphony/ArmoniK.DevelopmentKit.Worker.Symphony.csproj | 2 +- Worker/src/Unified/ArmoniK.DevelopmentKit.Worker.Unified.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj index d23b8969..8669ee0d 100644 --- a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj +++ b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0;net8.0 Library True true diff --git a/Worker/src/Symphony/ArmoniK.DevelopmentKit.Worker.Symphony.csproj b/Worker/src/Symphony/ArmoniK.DevelopmentKit.Worker.Symphony.csproj index bf8135dc..614d18b9 100644 --- a/Worker/src/Symphony/ArmoniK.DevelopmentKit.Worker.Symphony.csproj +++ b/Worker/src/Symphony/ArmoniK.DevelopmentKit.Worker.Symphony.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0;net8.0 Library True true diff --git a/Worker/src/Unified/ArmoniK.DevelopmentKit.Worker.Unified.csproj b/Worker/src/Unified/ArmoniK.DevelopmentKit.Worker.Unified.csproj index a055e98d..6210bf83 100644 --- a/Worker/src/Unified/ArmoniK.DevelopmentKit.Worker.Unified.csproj +++ b/Worker/src/Unified/ArmoniK.DevelopmentKit.Worker.Unified.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0;net8.0 Library True true From a9696641d672b8db1899db5ca2895a7e4d84877f Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Tue, 4 Jun 2024 10:18:28 +0200 Subject: [PATCH 4/5] Fixed headers --- Client/src/Common/Properties.cs | 11 +++++------ Client/src/Common/Submitter/ChannelPool.cs | 10 +++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Client/src/Common/Properties.cs b/Client/src/Common/Properties.cs index 214a9fb3..5daf6e43 100644 --- a/Client/src/Common/Properties.cs +++ b/Client/src/Common/Properties.cs @@ -1,19 +1,18 @@ // This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-$CURRENT_YEAR$. All rights reserved. -// +// +// Copyright (C) ANEO, 2021-2024. All rights reserved. +// // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -// using System; diff --git a/Client/src/Common/Submitter/ChannelPool.cs b/Client/src/Common/Submitter/ChannelPool.cs index a7db51b0..6450a5c2 100644 --- a/Client/src/Common/Submitter/ChannelPool.cs +++ b/Client/src/Common/Submitter/ChannelPool.cs @@ -1,13 +1,13 @@ // This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2023. All rights reserved. -// +// +// Copyright (C) ANEO, 2021-2024. All rights reserved. +// // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. From e2c36fd599d662a5ac59995bb7ede261711fddcd Mon Sep 17 00:00:00 2001 From: Nicolas Gruel Date: Thu, 6 Jun 2024 11:00:02 +0200 Subject: [PATCH 5/5] chore: update ArmoniK.APi to 3.18.0 --- Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj | 2 +- .../ArmoniK.EndToEndTests.Common.csproj | 2 +- Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj b/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj index be849b1d..3afdfd79 100644 --- a/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj +++ b/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj @@ -8,7 +8,7 @@ - + diff --git a/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj b/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj index 3442ae11..8cbb879e 100644 --- a/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj +++ b/Tests/ArmoniK.EndToEndTests/ArmoniK.EndToEndTests.Common/ArmoniK.EndToEndTests.Common.csproj @@ -12,7 +12,7 @@ - + diff --git a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj index 8669ee0d..b6cdd6d6 100644 --- a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj +++ b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj @@ -8,7 +8,7 @@ - +