From 6f552c859904890b4ba03c4c498e908f18ea4045 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 1 Feb 2021 14:59:35 +0300 Subject: [PATCH] [#328] container/load: Implement WriterProvider on API client Implement wrapper over API client on app-side that passes used space values to it. Values are buffered on Put call and sent on Close call. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/container.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 9c8ad17d1..44b00f88c 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -1,6 +1,9 @@ package main import ( + "context" + + apiClient "github.com/nspcc-dev/neofs-api-go/pkg/client" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" "github.com/nspcc-dev/neofs-node/pkg/morph/client" @@ -8,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc" containerService "github.com/nspcc-dev/neofs-node/pkg/services/container" + loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller" containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "go.uber.org/zap" @@ -66,3 +70,32 @@ func (w *morphLoadWriter) Put(a containerSDK.UsedSpaceAnnouncement) error { func (*morphLoadWriter) Close() error { return nil } + +type remoteLoadAnnounceWriterProvider struct { + client *apiClient.Client +} + +func (p *remoteLoadAnnounceWriterProvider) InitWriter(ctx context.Context) (loadcontroller.Writer, error) { + return &remoteLoadAnnounceWriter{ + ctx: ctx, + client: p.client, + }, nil +} + +type remoteLoadAnnounceWriter struct { + ctx context.Context + + client *apiClient.Client + + buf []containerSDK.UsedSpaceAnnouncement +} + +func (r *remoteLoadAnnounceWriter) Put(a containerSDK.UsedSpaceAnnouncement) error { + r.buf = append(r.buf, a) + + return nil +} + +func (r *remoteLoadAnnounceWriter) Close() error { + return r.client.AnnounceContainerUsedSpace(r.ctx, r.buf) +}