[#24] Client: Implement pool part2
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
c9a75ea025
commit
ee20798379
63 changed files with 801 additions and 526 deletions
|
@ -39,7 +39,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
internal AccountingService.AccountingServiceClient? AccountingServiceClient { get; set; }
|
||||
|
||||
internal EnvironmentContext ClientCtx { get; set; }
|
||||
internal ClientContext ClientCtx { get; set; }
|
||||
|
||||
public static IFrostFSClient GetInstance(IOptions<ClientSettings> clientOptions, GrpcChannelOptions? channelOptions = null)
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
var ecdsaKey = settings.Value.Key.LoadWif();
|
||||
FrostFsOwner.FromKey(ecdsaKey);
|
||||
|
||||
ClientCtx = new EnvironmentContext(
|
||||
ClientCtx = new ClientContext(
|
||||
client: this,
|
||||
key: ecdsaKey,
|
||||
owner: FrostFsOwner.FromKey(ecdsaKey),
|
||||
|
@ -108,13 +108,13 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private FrostFSClient(IOptions<ClientSettings> options, GrpcChannelOptions? channelOptions)
|
||||
{
|
||||
var clientSettings = (options?.Value) ?? throw new ArgumentException("Options must be initialized");
|
||||
var clientSettings = (options?.Value) ?? throw new ArgumentNullException(nameof(options), "Options value must be initialized");
|
||||
|
||||
clientSettings.Validate();
|
||||
|
||||
var channel = InitGrpcChannel(clientSettings.Host, channelOptions);
|
||||
|
||||
ClientCtx = new EnvironmentContext(
|
||||
ClientCtx = new ClientContext(
|
||||
this,
|
||||
key: null,
|
||||
owner: null,
|
||||
|
@ -127,7 +127,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private FrostFSClient(IOptions<SingleOwnerClientSettings> options, GrpcChannelOptions? channelOptions)
|
||||
{
|
||||
var clientSettings = (options?.Value) ?? throw new ArgumentException("Options must be initialized");
|
||||
var clientSettings = (options?.Value) ?? throw new ArgumentNullException(nameof(options), "Options value must be initialized");
|
||||
|
||||
clientSettings.Validate();
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
var channel = InitGrpcChannel(clientSettings.Host, channelOptions);
|
||||
|
||||
ClientCtx = new EnvironmentContext(
|
||||
ClientCtx = new ClientContext(
|
||||
this,
|
||||
key: ecdsaKey,
|
||||
owner: FrostFsOwner.FromKey(ecdsaKey),
|
||||
|
@ -146,14 +146,17 @@ public class FrostFSClient : IFrostFSClient
|
|||
// CheckFrostFsVersionSupport(new Context { Timeout = TimeSpan.FromSeconds(20) });
|
||||
}
|
||||
|
||||
internal FrostFSClient(WrapperPrm prm)
|
||||
internal FrostFSClient(WrapperPrm prm, SessionCache cache)
|
||||
{
|
||||
ClientCtx = new EnvironmentContext(
|
||||
ClientCtx = new ClientContext(
|
||||
client: this,
|
||||
key: prm.Key,
|
||||
owner: FrostFsOwner.FromKey(prm.Key!),
|
||||
channel: InitGrpcChannel(prm.Address, null), //prm.GrpcChannelOptions),
|
||||
version: new FrostFsVersion(2, 13));
|
||||
version: new FrostFsVersion(2, 13))
|
||||
{
|
||||
SessionCache = cache
|
||||
};
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -363,10 +366,10 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private async void CheckFrostFsVersionSupport(CallContext? ctx = default)
|
||||
{
|
||||
var args = new PrmNodeInfo { Context = ctx };
|
||||
var args = new PrmNodeInfo(ctx);
|
||||
|
||||
if (ctx?.Version == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Version));
|
||||
throw new ArgumentNullException(nameof(ctx), "Version must be initialized");
|
||||
|
||||
var service = GetNetmapService(args);
|
||||
var localNodeInfo = await service.GetLocalNodeInfoAsync(args).ConfigureAwait(false);
|
||||
|
@ -378,18 +381,16 @@ public class FrostFSClient : IFrostFSClient
|
|||
}
|
||||
}
|
||||
|
||||
private CallInvoker? SetupEnvironment(IContext ctx)
|
||||
private CallInvoker? SetupClientContext(IContext ctx)
|
||||
{
|
||||
if (isDisposed)
|
||||
throw new InvalidObjectException("Client is disposed.");
|
||||
throw new FrostFsInvalidObjectException("Client is disposed.");
|
||||
|
||||
ctx.Context ??= new CallContext();
|
||||
|
||||
if (ctx.Context.Key == null)
|
||||
if (ctx.Context!.Key == null)
|
||||
{
|
||||
if (ClientCtx.Key == null)
|
||||
{
|
||||
throw new InvalidObjectException("Key is not initialized.");
|
||||
throw new ArgumentNullException(nameof(ctx), "Key is not initialized.");
|
||||
}
|
||||
|
||||
ctx.Context.Key = ClientCtx.Key.ECDsaKey;
|
||||
|
@ -404,24 +405,23 @@ public class FrostFSClient : IFrostFSClient
|
|||
{
|
||||
if (ClientCtx.Version == null)
|
||||
{
|
||||
throw new InvalidObjectException("Version is not initialized.");
|
||||
throw new ArgumentNullException(nameof(ctx), "Version is not initialized.");
|
||||
}
|
||||
|
||||
ctx.Context.Version = ClientCtx.Version;
|
||||
}
|
||||
|
||||
CallInvoker? callInvoker = null;
|
||||
if (ctx.Context.Interceptors != null && ctx.Context.Interceptors.Count > 0)
|
||||
{
|
||||
foreach (var interceptor in ctx.Context.Interceptors)
|
||||
{
|
||||
callInvoker = AddInvoker(callInvoker, interceptor);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var interceptor in ctx.Context.Interceptors)
|
||||
callInvoker = AddInvoker(callInvoker, interceptor);
|
||||
|
||||
if (ctx.Context.Callback != null)
|
||||
callInvoker = AddInvoker(callInvoker, new MetricsInterceptor(ctx.Context.Callback));
|
||||
|
||||
if (ctx.Context.PoolErrorHandler != null)
|
||||
callInvoker = AddInvoker(callInvoker, new ErrorInterceptor(ctx.Context.PoolErrorHandler));
|
||||
|
||||
return callInvoker;
|
||||
|
||||
CallInvoker AddInvoker(CallInvoker? callInvoker, Interceptor interceptor)
|
||||
|
@ -429,7 +429,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
if (callInvoker == null)
|
||||
callInvoker = ClientCtx.Channel.Intercept(interceptor);
|
||||
else
|
||||
callInvoker.Intercept(interceptor);
|
||||
callInvoker = callInvoker.Intercept(interceptor);
|
||||
|
||||
return callInvoker;
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private NetmapServiceProvider GetNetmapService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = NetmapServiceClient ?? (callInvoker != null
|
||||
? new NetmapService.NetmapServiceClient(callInvoker)
|
||||
: new NetmapService.NetmapServiceClient(ClientCtx.Channel));
|
||||
|
@ -447,7 +447,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private SessionServiceProvider GetSessionService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = SessionServiceClient ?? (callInvoker != null
|
||||
? new SessionService.SessionServiceClient(callInvoker)
|
||||
: new SessionService.SessionServiceClient(ClientCtx.Channel));
|
||||
|
@ -457,7 +457,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private ApeManagerServiceProvider GetApeManagerService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = ApeManagerServiceClient ?? (callInvoker != null
|
||||
? new APEManagerService.APEManagerServiceClient(callInvoker)
|
||||
: new APEManagerService.APEManagerServiceClient(ClientCtx.Channel));
|
||||
|
@ -467,7 +467,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private AccountingServiceProvider GetAccouningService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = AccountingServiceClient ?? (callInvoker != null
|
||||
? new AccountingService.AccountingServiceClient(callInvoker)
|
||||
: new AccountingService.AccountingServiceClient(ClientCtx.Channel));
|
||||
|
@ -477,7 +477,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private ContainerServiceProvider GetContainerService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = ContainerServiceClient ?? (callInvoker != null
|
||||
? new ContainerService.ContainerServiceClient(callInvoker)
|
||||
: new ContainerService.ContainerServiceClient(ClientCtx.Channel));
|
||||
|
@ -487,7 +487,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private ObjectServiceProvider GetObjectService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = ObjectServiceClient ?? (callInvoker != null
|
||||
? new ObjectService.ObjectServiceClient(callInvoker)
|
||||
: new ObjectService.ObjectServiceClient(ClientCtx.Channel));
|
||||
|
@ -497,7 +497,7 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
private AccountingServiceProvider GetAccountService(IContext ctx)
|
||||
{
|
||||
var callInvoker = SetupEnvironment(ctx);
|
||||
var callInvoker = SetupClientContext(ctx);
|
||||
var client = AccountingServiceClient ?? (callInvoker != null
|
||||
? new AccountingService.AccountingServiceClient(callInvoker)
|
||||
: new AccountingService.AccountingServiceClient(ClientCtx.Channel));
|
||||
|
@ -527,19 +527,12 @@ public class FrostFSClient : IFrostFSClient
|
|||
|
||||
public async Task<string?> Dial(CallContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prm = new PrmBalance { Context = ctx };
|
||||
var prm = new PrmBalance(ctx);
|
||||
|
||||
var service = GetAccouningService(prm);
|
||||
var balance = await service.GetBallance(prm).ConfigureAwait(false);
|
||||
var service = GetAccouningService(prm);
|
||||
_ = await service.GetBallance(prm).ConfigureAwait(false);
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (FrostFsException ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool RestartIfUnhealthy(CallContext ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue