From 718a2fad265eb069562c5091069c113ca79d717c Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 15 Mar 2021 13:53:08 +0300 Subject: [PATCH] [#425] services: Define service interfaces that was removed from API lib Signed-off-by: Leonard Lyubich --- cmd/neofs-node/container.go | 4 ++-- cmd/neofs-node/object.go | 2 +- .../transport/accounting/grpc/service.go | 5 +++-- .../transport/container/grpc/service.go | 5 +++-- pkg/network/transport/netmap/grpc/service.go | 5 +++-- pkg/network/transport/session/grpc/service.go | 5 +++-- pkg/services/accounting/executor.go | 2 +- pkg/services/accounting/response.go | 4 ++-- pkg/services/accounting/server.go | 12 ++++++++++++ pkg/services/accounting/sign.go | 4 ++-- pkg/services/container/executor.go | 4 ++-- pkg/services/container/response.go | 4 ++-- pkg/services/container/server.go | 18 ++++++++++++++++++ pkg/services/container/sign.go | 4 ++-- pkg/services/netmap/executor.go | 2 +- pkg/services/netmap/response.go | 4 ++-- pkg/services/netmap/server.go | 13 +++++++++++++ pkg/services/netmap/sign.go | 4 ++-- pkg/services/object/acl/acl.go | 4 ++-- pkg/services/object/metrics.go | 4 ++-- pkg/services/object/put/v2/service.go | 4 ++-- pkg/services/object/response.go | 2 +- pkg/services/object/server.go | 8 +++++++- pkg/services/object/sign.go | 2 +- pkg/services/object/transport_splitter.go | 2 +- pkg/services/session/executor.go | 2 +- pkg/services/session/response.go | 4 ++-- pkg/services/session/server.go | 12 ++++++++++++ pkg/services/session/sign.go | 4 ++-- 29 files changed, 107 insertions(+), 42 deletions(-) create mode 100644 pkg/services/accounting/server.go create mode 100644 pkg/services/container/server.go create mode 100644 pkg/services/netmap/server.go create mode 100644 pkg/services/session/server.go diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 82fb6763a..3daa4be29 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -125,7 +125,7 @@ func initContainerService(c *cfg) { c.key, containerService.NewResponseService( &usedSpaceService{ - Service: containerService.NewExecutionService(containerMorph.NewExecutor(cnrClient)), + Server: containerService.NewExecutionService(containerMorph.NewExecutor(cnrClient)), loadWriterProvider: loadRouter, loadPlacementBuilder: loadPlacementBuilder, routeBuilder: routeBuilder, @@ -341,7 +341,7 @@ func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontr } type usedSpaceService struct { - containerV2.Service + containerService.Server loadWriterProvider loadcontroller.WriterProvider diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index c8527de97..2f5f19b3d 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -61,7 +61,7 @@ func (c *cfg) MaxObjectSize() uint64 { return sz } -func (s *objectSvc) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (s *objectSvc) Put(ctx context.Context) (objectService.PutObjectStream, error) { return s.put.Put(ctx) } diff --git a/pkg/network/transport/accounting/grpc/service.go b/pkg/network/transport/accounting/grpc/service.go index b2fd0e413..aeb2266bb 100644 --- a/pkg/network/transport/accounting/grpc/service.go +++ b/pkg/network/transport/accounting/grpc/service.go @@ -5,16 +5,17 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/accounting" accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc" + accountingsvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting" ) // Server wraps NeoFS API Accounting service and // provides gRPC Accounting service server interface. type Server struct { - srv accounting.Service + srv accountingsvc.Server } // New creates, initializes and returns Server instance. -func New(c accounting.Service) *Server { +func New(c accountingsvc.Server) *Server { return &Server{ srv: c, } diff --git a/pkg/network/transport/container/grpc/service.go b/pkg/network/transport/container/grpc/service.go index 1323331b1..7511ff2dc 100644 --- a/pkg/network/transport/container/grpc/service.go +++ b/pkg/network/transport/container/grpc/service.go @@ -5,16 +5,17 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/container" containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" + containersvc "github.com/nspcc-dev/neofs-node/pkg/services/container" ) // Server wraps NeoFS API Container service and // provides gRPC Container service server interface. type Server struct { - srv container.Service + srv containersvc.Server } // New creates, initializes and returns Server instance. -func New(c container.Service) *Server { +func New(c containersvc.Server) *Server { return &Server{ srv: c, } diff --git a/pkg/network/transport/netmap/grpc/service.go b/pkg/network/transport/netmap/grpc/service.go index 53cdb7e7a..9d0d3bd47 100644 --- a/pkg/network/transport/netmap/grpc/service.go +++ b/pkg/network/transport/netmap/grpc/service.go @@ -5,16 +5,17 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/netmap" netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" + netmapsvc "github.com/nspcc-dev/neofs-node/pkg/services/netmap" ) // Server wraps NeoFS API Netmap service and // provides gRPC Netmap service server interface. type Server struct { - srv netmap.Service + srv netmapsvc.Server } // New creates, initializes and returns Server instance. -func New(c netmap.Service) *Server { +func New(c netmapsvc.Server) *Server { return &Server{ srv: c, } diff --git a/pkg/network/transport/session/grpc/service.go b/pkg/network/transport/session/grpc/service.go index 31a4fa526..66d3ff77e 100644 --- a/pkg/network/transport/session/grpc/service.go +++ b/pkg/network/transport/session/grpc/service.go @@ -5,16 +5,17 @@ import ( "github.com/nspcc-dev/neofs-api-go/v2/session" sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc" + sessionsvc "github.com/nspcc-dev/neofs-node/pkg/services/session" ) // Server wraps NeoFS API Session service and // provides gRPC Session service server interface. type Server struct { - srv session.Service + srv sessionsvc.Server } // New creates, initializes and returns Server instance. -func New(c session.Service) *Server { +func New(c sessionsvc.Server) *Server { return &Server{ srv: c, } diff --git a/pkg/services/accounting/executor.go b/pkg/services/accounting/executor.go index 0ed5ff4c6..c523369a3 100644 --- a/pkg/services/accounting/executor.go +++ b/pkg/services/accounting/executor.go @@ -16,7 +16,7 @@ type executorSvc struct { } // NewExecutionService wraps ServiceExecutor and returns Accounting Service interface. -func NewExecutionService(exec ServiceExecutor) accounting.Service { +func NewExecutionService(exec ServiceExecutor) Server { return &executorSvc{ exec: exec, } diff --git a/pkg/services/accounting/response.go b/pkg/services/accounting/response.go index db5c55cab..32eb804ad 100644 --- a/pkg/services/accounting/response.go +++ b/pkg/services/accounting/response.go @@ -11,12 +11,12 @@ import ( type responseService struct { respSvc *response.Service - svc accounting.Service + svc Server } // NewResponseService returns accounting service instance that passes internal service // call to response service. -func NewResponseService(accSvc accounting.Service, respSvc *response.Service) accounting.Service { +func NewResponseService(accSvc Server, respSvc *response.Service) Server { return &responseService{ respSvc: respSvc, svc: accSvc, diff --git a/pkg/services/accounting/server.go b/pkg/services/accounting/server.go new file mode 100644 index 000000000..0acd0ae1d --- /dev/null +++ b/pkg/services/accounting/server.go @@ -0,0 +1,12 @@ +package accounting + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/accounting" +) + +// Server is an interface of the NeoFS API Accounting service server +type Server interface { + Balance(context.Context, *accounting.BalanceRequest) (*accounting.BalanceResponse, error) +} diff --git a/pkg/services/accounting/sign.go b/pkg/services/accounting/sign.go index f3545e7e6..82aceec28 100644 --- a/pkg/services/accounting/sign.go +++ b/pkg/services/accounting/sign.go @@ -11,10 +11,10 @@ import ( type signService struct { sigSvc *util.SignService - svc accounting.Service + svc Server } -func NewSignService(key *ecdsa.PrivateKey, svc accounting.Service) accounting.Service { +func NewSignService(key *ecdsa.PrivateKey, svc Server) Server { return &signService{ sigSvc: util.NewUnarySignService(key), svc: svc, diff --git a/pkg/services/container/executor.go b/pkg/services/container/executor.go index 72934f275..f5124da54 100644 --- a/pkg/services/container/executor.go +++ b/pkg/services/container/executor.go @@ -17,13 +17,13 @@ type ServiceExecutor interface { } type executorSvc struct { - container.Service + Server exec ServiceExecutor } // NewExecutionService wraps ServiceExecutor and returns Container Service interface. -func NewExecutionService(exec ServiceExecutor) container.Service { +func NewExecutionService(exec ServiceExecutor) Server { return &executorSvc{ exec: exec, } diff --git a/pkg/services/container/response.go b/pkg/services/container/response.go index 93160215f..d1ca9b8fe 100644 --- a/pkg/services/container/response.go +++ b/pkg/services/container/response.go @@ -11,12 +11,12 @@ import ( type responseService struct { respSvc *response.Service - svc container.Service + svc Server } // NewResponseService returns container service instance that passes internal service // call to response service. -func NewResponseService(cnrSvc container.Service, respSvc *response.Service) container.Service { +func NewResponseService(cnrSvc Server, respSvc *response.Service) Server { return &responseService{ respSvc: respSvc, svc: cnrSvc, diff --git a/pkg/services/container/server.go b/pkg/services/container/server.go new file mode 100644 index 000000000..c1fd24b24 --- /dev/null +++ b/pkg/services/container/server.go @@ -0,0 +1,18 @@ +package container + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/container" +) + +// Server is an interface of the NeoFS API Container service server +type Server interface { + Put(context.Context, *container.PutRequest) (*container.PutResponse, error) + Get(context.Context, *container.GetRequest) (*container.GetResponse, error) + Delete(context.Context, *container.DeleteRequest) (*container.DeleteResponse, error) + List(context.Context, *container.ListRequest) (*container.ListResponse, error) + SetExtendedACL(context.Context, *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) + GetExtendedACL(context.Context, *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) + AnnounceUsedSpace(context.Context, *container.AnnounceUsedSpaceRequest) (*container.AnnounceUsedSpaceResponse, error) +} diff --git a/pkg/services/container/sign.go b/pkg/services/container/sign.go index 47658ad70..7cb729b00 100644 --- a/pkg/services/container/sign.go +++ b/pkg/services/container/sign.go @@ -11,10 +11,10 @@ import ( type signService struct { sigSvc *util.SignService - svc container.Service + svc Server } -func NewSignService(key *ecdsa.PrivateKey, svc container.Service) container.Service { +func NewSignService(key *ecdsa.PrivateKey, svc Server) Server { return &signService{ sigSvc: util.NewUnarySignService(key), svc: svc, diff --git a/pkg/services/netmap/executor.go b/pkg/services/netmap/executor.go index 4600681fc..c8ff14362 100644 --- a/pkg/services/netmap/executor.go +++ b/pkg/services/netmap/executor.go @@ -30,7 +30,7 @@ type NetworkInfo interface { Dump() (*netmap.NetworkInfo, error) } -func NewExecutionService(s NodeState, v *pkg.Version, netInfo NetworkInfo) netmap.Service { +func NewExecutionService(s NodeState, v *pkg.Version, netInfo NetworkInfo) Server { if s == nil || v == nil || netInfo == nil { // this should never happen, otherwise it programmers bug panic("can't create netmap execution service") diff --git a/pkg/services/netmap/response.go b/pkg/services/netmap/response.go index 9fc0e9ef1..81d9f52a3 100644 --- a/pkg/services/netmap/response.go +++ b/pkg/services/netmap/response.go @@ -11,12 +11,12 @@ import ( type responseService struct { respSvc *response.Service - svc netmap.Service + svc Server } // NewResponseService returns netmap service instance that passes internal service // call to response service. -func NewResponseService(nmSvc netmap.Service, respSvc *response.Service) netmap.Service { +func NewResponseService(nmSvc Server, respSvc *response.Service) Server { return &responseService{ respSvc: respSvc, svc: nmSvc, diff --git a/pkg/services/netmap/server.go b/pkg/services/netmap/server.go new file mode 100644 index 000000000..359d2ac90 --- /dev/null +++ b/pkg/services/netmap/server.go @@ -0,0 +1,13 @@ +package netmap + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/netmap" +) + +// Server is an interface of the NeoFS API Netmap service server +type Server interface { + LocalNodeInfo(context.Context, *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) + NetworkInfo(context.Context, *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) +} diff --git a/pkg/services/netmap/sign.go b/pkg/services/netmap/sign.go index 4c7a60212..adff8548a 100644 --- a/pkg/services/netmap/sign.go +++ b/pkg/services/netmap/sign.go @@ -11,10 +11,10 @@ import ( type signService struct { sigSvc *util.SignService - svc netmap.Service + svc Server } -func NewSignService(key *ecdsa.PrivateKey, svc netmap.Service) netmap.Service { +func NewSignService(key *ecdsa.PrivateKey, svc Server) Server { return &signService{ sigSvc: util.NewUnarySignService(key), svc: svc, diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index 85330753d..61c98f4e1 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -34,7 +34,7 @@ type ( putStreamBasicChecker struct { source *Service - next object.PutObjectStreamer + next objectSvc.PutObjectStream *eACLCfg } @@ -174,7 +174,7 @@ func (b Service) Get(request *object.GetRequest, stream objectSvc.GetObjectStrea }) } -func (b Service) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (b Service) Put(ctx context.Context) (objectSvc.PutObjectStream, error) { streamer, err := b.next.Put(ctx) return putStreamBasicChecker{ diff --git a/pkg/services/object/metrics.go b/pkg/services/object/metrics.go index 73ea995e3..a8f5c274b 100644 --- a/pkg/services/object/metrics.go +++ b/pkg/services/object/metrics.go @@ -21,7 +21,7 @@ type ( } putStreamMetric struct { - stream object.PutObjectStreamer + stream PutObjectStream metrics MetricRegister start time.Time } @@ -69,7 +69,7 @@ func (m MetricCollector) Get(req *object.GetRequest, stream GetObjectStream) err }) } -func (m MetricCollector) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (m MetricCollector) Put(ctx context.Context) (PutObjectStream, error) { t := time.Now() defer func() { m.metrics.IncPutReqCounter() diff --git a/pkg/services/object/put/v2/service.go b/pkg/services/object/put/v2/service.go index d8d80cc08..9cdebabe7 100644 --- a/pkg/services/object/put/v2/service.go +++ b/pkg/services/object/put/v2/service.go @@ -3,7 +3,7 @@ package putsvc import ( "context" - objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" + "github.com/nspcc-dev/neofs-node/pkg/services/object" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" "github.com/pkg/errors" ) @@ -34,7 +34,7 @@ func NewService(opts ...Option) *Service { } // Put calls internal service and returns v2 object streamer. -func (s *Service) Put(ctx context.Context) (objectV2.PutObjectStreamer, error) { +func (s *Service) Put(ctx context.Context) (object.PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { return nil, errors.Wrapf(err, "(%T) could not open object put stream", s) diff --git a/pkg/services/object/response.go b/pkg/services/object/response.go index 948bb0dc4..4fef5d101 100644 --- a/pkg/services/object/response.go +++ b/pkg/services/object/response.go @@ -72,7 +72,7 @@ func (s *putStreamResponser) CloseAndRecv() (*object.PutResponse, error) { return r.(*object.PutResponse), nil } -func (s *ResponseService) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (s *ResponseService) Put(ctx context.Context) (PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { return nil, errors.Wrap(err, "could not create Put object streamer") diff --git a/pkg/services/object/server.go b/pkg/services/object/server.go index 3c6a6e278..54ee7f4a4 100644 --- a/pkg/services/object/server.go +++ b/pkg/services/object/server.go @@ -25,11 +25,17 @@ type SearchStream interface { Send(*object.SearchResponse) error } +// PutObjectStream is an interface of NeoFS API v2 compatible client's object streamer. +type PutObjectStream interface { + Send(*object.PutRequest) error + CloseAndRecv() (*object.PutResponse, error) +} + // ServiceServer is an interface of utility // serving v2 Object service. type ServiceServer interface { Get(*object.GetRequest, GetObjectStream) error - Put(context.Context) (object.PutObjectStreamer, error) + Put(context.Context) (PutObjectStream, error) Head(context.Context, *object.HeadRequest) (*object.HeadResponse, error) Search(*object.SearchRequest, SearchStream) error Delete(context.Context, *object.DeleteRequest) (*object.DeleteResponse, error) diff --git a/pkg/services/object/sign.go b/pkg/services/object/sign.go index 0b9e3ff0c..2f3704139 100644 --- a/pkg/services/object/sign.go +++ b/pkg/services/object/sign.go @@ -80,7 +80,7 @@ func (s *putStreamSigner) CloseAndRecv() (*object.PutResponse, error) { return r.(*object.PutResponse), nil } -func (s *SignService) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (s *SignService) Put(ctx context.Context) (PutObjectStream, error) { stream, err := s.svc.Put(ctx) if err != nil { return nil, errors.Wrap(err, "could not create Put object streamer") diff --git a/pkg/services/object/transport_splitter.go b/pkg/services/object/transport_splitter.go index 1753abe0c..b3c486476 100644 --- a/pkg/services/object/transport_splitter.go +++ b/pkg/services/object/transport_splitter.go @@ -87,7 +87,7 @@ func (c *TransportSplitter) Get(req *object.GetRequest, stream GetObjectStream) }) } -func (c TransportSplitter) Put(ctx context.Context) (object.PutObjectStreamer, error) { +func (c TransportSplitter) Put(ctx context.Context) (PutObjectStream, error) { return c.next.Put(ctx) } diff --git a/pkg/services/session/executor.go b/pkg/services/session/executor.go index 520af4f1f..4aaeeda20 100644 --- a/pkg/services/session/executor.go +++ b/pkg/services/session/executor.go @@ -16,7 +16,7 @@ type executorSvc struct { } // NewExecutionService wraps ServiceExecutor and returns Session Service interface. -func NewExecutionService(exec ServiceExecutor) session.Service { +func NewExecutionService(exec ServiceExecutor) Server { return &executorSvc{ exec: exec, } diff --git a/pkg/services/session/response.go b/pkg/services/session/response.go index 044e4ef75..42671704d 100644 --- a/pkg/services/session/response.go +++ b/pkg/services/session/response.go @@ -11,12 +11,12 @@ import ( type responseService struct { respSvc *response.Service - svc session.Service + svc Server } // NewResponseService returns session service instance that passes internal service // call to response service. -func NewResponseService(ssSvc session.Service, respSvc *response.Service) session.Service { +func NewResponseService(ssSvc Server, respSvc *response.Service) Server { return &responseService{ respSvc: respSvc, svc: ssSvc, diff --git a/pkg/services/session/server.go b/pkg/services/session/server.go new file mode 100644 index 000000000..cd8e1d602 --- /dev/null +++ b/pkg/services/session/server.go @@ -0,0 +1,12 @@ +package session + +import ( + "context" + + "github.com/nspcc-dev/neofs-api-go/v2/session" +) + +// Server is an interface of the NeoFS API Session service server +type Server interface { + Create(context.Context, *session.CreateRequest) (*session.CreateResponse, error) +} diff --git a/pkg/services/session/sign.go b/pkg/services/session/sign.go index c318b1b9d..9519691ef 100644 --- a/pkg/services/session/sign.go +++ b/pkg/services/session/sign.go @@ -11,10 +11,10 @@ import ( type signService struct { sigSvc *util.SignService - svc session.Service + svc Server } -func NewSignService(key *ecdsa.PrivateKey, svc session.Service) session.Service { +func NewSignService(key *ecdsa.PrivateKey, svc Server) Server { return &signService{ sigSvc: util.NewUnarySignService(key), svc: svc,