diff --git a/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj b/Client/src/Common/ArmoniK.DevelopmentKit.Client.Common.csproj index 990f3414..3afdfd79 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/Properties.cs b/Client/src/Common/Properties.cs index 727eb2a5..5daf6e43 100644 --- a/Client/src/Common/Properties.cs +++ b/Client/src/Common/Properties.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. // // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. @@ -50,6 +50,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 +140,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 +192,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 +378,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/ChannelPool.cs b/Client/src/Common/Submitter/ChannelPool.cs index 9981a83d..6450a5c2 100644 --- a/Client/src/Common/Submitter/ChannelPool.cs +++ b/Client/src/Common/Submitter/ChannelPool.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. // // Licensed under the Apache License, Version 2.0 (the "License") // you may not use this file except in compliance with the License. @@ -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..641bbcc0 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; @@ -47,25 +45,13 @@ 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, }; - 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..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 b02ba907..b6cdd6d6 100644 --- a/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj +++ b/Worker/src/Common/ArmoniK.DevelopmentKit.Worker.Common.csproj @@ -1,20 +1,20 @@ - net8.0 + net6.0;net8.0 Library True true - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive 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