forked from TrueCloudLab/frostfs-node
[#294] searchsvc: Refactor service constructor
Pass required deps as args. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
ec9b738465
commit
e8091101c7
2 changed files with 27 additions and 61 deletions
|
@ -334,16 +334,14 @@ func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Trav
|
||||||
ls := c.cfgObject.cfgLocalStorage.localStorage
|
ls := c.cfgObject.cfgLocalStorage.localStorage
|
||||||
|
|
||||||
return searchsvc.New(
|
return searchsvc.New(
|
||||||
searchsvc.WithLogger(c.log),
|
ls,
|
||||||
searchsvc.WithLocalStorageEngine(ls),
|
coreConstructor,
|
||||||
searchsvc.WithClientConstructor(coreConstructor),
|
|
||||||
searchsvc.WithTraverserGenerator(
|
|
||||||
traverseGen.WithTraverseOptions(
|
traverseGen.WithTraverseOptions(
|
||||||
placement.WithoutSuccessTracking(),
|
placement.WithoutSuccessTracking(),
|
||||||
),
|
),
|
||||||
),
|
c.netMapSource,
|
||||||
searchsvc.WithNetMapSource(c.netMapSource),
|
keyStorage,
|
||||||
searchsvc.WithKeyStorage(keyStorage),
|
searchsvc.WithLogger(c.log),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,17 +55,28 @@ type cfg struct {
|
||||||
keyStore *util.KeyStorage
|
keyStore *util.KeyStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
|
||||||
return &cfg{
|
|
||||||
log: &logger.Logger{Logger: zap.L()},
|
|
||||||
clientConstructor: new(clientConstructorWrapper),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates, initializes and returns utility serving
|
// New creates, initializes and returns utility serving
|
||||||
// Object.Get service requests.
|
// Object.Get service requests.
|
||||||
func New(opts ...Option) *Service {
|
func New(e *engine.StorageEngine,
|
||||||
c := defaultCfg()
|
cc ClientConstructor,
|
||||||
|
tg *util.TraverserGenerator,
|
||||||
|
ns netmap.Source,
|
||||||
|
ks *util.KeyStorage,
|
||||||
|
opts ...Option) *Service {
|
||||||
|
c := &cfg{
|
||||||
|
log: &logger.Logger{Logger: zap.L()},
|
||||||
|
clientConstructor: &clientConstructorWrapper{
|
||||||
|
constructor: cc,
|
||||||
|
},
|
||||||
|
localStorage: &storageEngineWrapper{
|
||||||
|
storage: e,
|
||||||
|
},
|
||||||
|
traverserGenerator: (*traverseGeneratorWrapper)(tg),
|
||||||
|
currentEpochReceiver: &nmSrcWrapper{
|
||||||
|
nmSrc: ns,
|
||||||
|
},
|
||||||
|
keyStore: ks,
|
||||||
|
}
|
||||||
|
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
opts[i](c)
|
opts[i](c)
|
||||||
|
@ -82,46 +93,3 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Search service"))}
|
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Search service"))}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLocalStorageEngine returns option to set local storage
|
|
||||||
// instance.
|
|
||||||
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.localStorage = &storageEngineWrapper{
|
|
||||||
storage: e,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithClientConstructor returns option to set constructor of remote node clients.
|
|
||||||
func WithClientConstructor(v ClientConstructor) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.clientConstructor.(*clientConstructorWrapper).constructor = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTraverserGenerator returns option to set generator of
|
|
||||||
// placement traverser to get the objects from containers.
|
|
||||||
func WithTraverserGenerator(t *util.TraverserGenerator) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.traverserGenerator = (*traverseGeneratorWrapper)(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithNetMapSource returns option to set network
|
|
||||||
// map storage to receive current network state.
|
|
||||||
func WithNetMapSource(nmSrc netmap.Source) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.currentEpochReceiver = &nmSrcWrapper{
|
|
||||||
nmSrc: nmSrc,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithKeyStorage returns option to set private
|
|
||||||
// key storage for session tokens and node key.
|
|
||||||
func WithKeyStorage(store *util.KeyStorage) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.keyStore = store
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue