forked from TrueCloudLab/frostfs-node
[#891] getSvc: Refactor Get service V2 creation
Use arguments for mandatory fields. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
394f086fe2
commit
52ffa9f164
3 changed files with 24 additions and 59 deletions
|
@ -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),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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"))}
|
||||
|
|
Loading…
Reference in a new issue