From 52ffa9f1642fdee6c94a677c3202c55c9a654845 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 12 Jan 2024 10:05:29 +0300 Subject: [PATCH] [#891] getSvc: Refactor Get service V2 creation Use arguments for mandatory fields. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/object.go | 13 ++-- pkg/services/object/get/v2/get_range_hash.go | 2 +- pkg/services/object/get/v2/service.go | 68 +++++--------------- 3 files changed, 24 insertions(+), 59 deletions(-) diff --git a/cmd/frostfs-node/object.go b/cmd/frostfs-node/object.go index a47ea2654..2d18f82a3 100644 --- a/cmd/frostfs-node/object.go +++ b/cmd/frostfs-node/object.go @@ -372,13 +372,12 @@ func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Tra func createGetServiceV2(c *cfg, sGet *getsvc.Service, keyStorage *util.KeyStorage) *getsvcV2.Service { return getsvcV2.NewService( - getsvcV2.WithInternalService(sGet), - getsvcV2.WithKeyStorage(keyStorage), - getsvcV2.WithEpochSource(c.netMapSource), - getsvcV2.WithClientSource(c.clientCache), - getsvcV2.WithContainerSource(c.cfgObject.cnrSource), - getsvcV2.WithNetmapSource(c.netMapSource), - getsvcV2.WithNetmapAnnouncedKeys(c), + sGet, + keyStorage, + c.clientCache, + c.netMapSource, + c, + c.cfgObject.cnrSource, getsvcV2.WithLogger(c.log), ) } diff --git a/pkg/services/object/get/v2/get_range_hash.go b/pkg/services/object/get/v2/get_range_hash.go index d2ed16ebf..0054f0e9f 100644 --- a/pkg/services/object/get/v2/get_range_hash.go +++ b/pkg/services/object/get/v2/get_range_hash.go @@ -71,7 +71,7 @@ func (s *Service) needToForwardGetRangeHashRequest(req *objectV2.GetRangeHashReq return result, fmt.Errorf("(%T) could not get container: %w", s, err) } - epoch, err := s.epochSource.Epoch() + epoch, err := s.netmapSource.Epoch() if err != nil { return result, fmt.Errorf("(%T) could not get epoch: %w", s, err) } diff --git a/pkg/services/object/get/v2/service.go b/pkg/services/object/get/v2/service.go index 07fe9b42a..bcdc4120e 100644 --- a/pkg/services/object/get/v2/service.go +++ b/pkg/services/object/get/v2/service.go @@ -24,10 +24,6 @@ type Service struct { // Option represents Service constructor option. type Option func(*cfg) -type epochSource interface { - Epoch() (uint64, error) -} - type clientSource interface { Get(info clientcore.NodeInfo) (clientcore.MultiAddressClient, error) } @@ -37,8 +33,6 @@ type cfg struct { keyStorage *objutil.KeyStorage - epochSource epochSource - clientSource clientSource netmapSource netmap.Source @@ -51,8 +45,23 @@ type cfg struct { } // NewService constructs Service instance from provided options. -func NewService(opts ...Option) *Service { - c := new(cfg) +func NewService(svc *getsvc.Service, + keyStorage *objutil.KeyStorage, + clientSource clientSource, + netmapSource netmap.Source, + announcedKeys netmap.AnnouncedKeys, + contSource container.Source, + opts ...Option, +) *Service { + c := &cfg{ + svc: svc, + keyStorage: keyStorage, + clientSource: clientSource, + netmapSource: netmapSource, + announcedKeys: announcedKeys, + contSource: contSource, + log: &logger.Logger{Logger: zap.L()}, + } for i := range opts { opts[i](c) @@ -123,49 +132,6 @@ func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV return resp, err } -func WithInternalService(v *getsvc.Service) Option { - return func(c *cfg) { - c.svc = v - } -} - -// WithKeyStorage returns option to set local private key storage. -func WithKeyStorage(ks *objutil.KeyStorage) Option { - return func(c *cfg) { - c.keyStorage = ks - } -} - -func WithEpochSource(es epochSource) Option { - return func(c *cfg) { - c.epochSource = es - } -} - -func WithClientSource(cs clientSource) Option { - return func(c *cfg) { - c.clientSource = cs - } -} - -func WithNetmapSource(ns netmap.Source) Option { - return func(c *cfg) { - c.netmapSource = ns - } -} - -func WithNetmapAnnouncedKeys(ak netmap.AnnouncedKeys) Option { - return func(c *cfg) { - c.announcedKeys = ak - } -} - -func WithContainerSource(cs container.Source) Option { - return func(c *cfg) { - c.contSource = cs - } -} - func WithLogger(l *logger.Logger) Option { return func(c *cfg) { c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Get V2 service"))}