forked from TrueCloudLab/frostfs-node
[#294] putsvc: Refactor service constructor
Pass required deps as args. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
1420b8b9ea
commit
800a685e84
2 changed files with 30 additions and 70 deletions
|
@ -313,14 +313,14 @@ func createPutSvc(c *cfg, keyStorage *util.KeyStorage) *putsvc.Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
return putsvc.NewService(
|
return putsvc.NewService(
|
||||||
putsvc.WithKeyStorage(keyStorage),
|
keyStorage,
|
||||||
putsvc.WithClientConstructor(c.putClientCache),
|
c.putClientCache,
|
||||||
putsvc.WithMaxSizeSource(newCachedMaxObjectSizeSource(c)),
|
newCachedMaxObjectSizeSource(c),
|
||||||
putsvc.WithObjectStorage(os),
|
os,
|
||||||
putsvc.WithContainerSource(c.cfgObject.cnrSource),
|
c.cfgObject.cnrSource,
|
||||||
putsvc.WithNetworkMapSource(c.netMapSource),
|
c.netMapSource,
|
||||||
putsvc.WithNetmapKeys(c),
|
c,
|
||||||
putsvc.WithNetworkState(c.cfgNetmap.state),
|
c.cfgNetmap.state,
|
||||||
putsvc.WithWorkerPools(c.cfgObject.pool.putRemote, c.cfgObject.pool.putLocal),
|
putsvc.WithWorkerPools(c.cfgObject.pool.putRemote, c.cfgObject.pool.putLocal),
|
||||||
putsvc.WithLogger(c.log),
|
putsvc.WithLogger(c.log),
|
||||||
)
|
)
|
||||||
|
|
|
@ -46,8 +46,6 @@ type cfg struct {
|
||||||
|
|
||||||
fmtValidator *object.FormatValidator
|
fmtValidator *object.FormatValidator
|
||||||
|
|
||||||
fmtValidatorOpts []object.FormatValidatorOption
|
|
||||||
|
|
||||||
networkState netmap.State
|
networkState netmap.State
|
||||||
|
|
||||||
clientConstructor ClientConstructor
|
clientConstructor ClientConstructor
|
||||||
|
@ -55,22 +53,34 @@ type cfg struct {
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func NewService(ks *objutil.KeyStorage,
|
||||||
return &cfg{
|
cc ClientConstructor,
|
||||||
|
ms MaxSizeSource,
|
||||||
|
os ObjectStorage,
|
||||||
|
cs container.Source,
|
||||||
|
ns netmap.Source,
|
||||||
|
nk netmap.AnnouncedKeys,
|
||||||
|
nst netmap.State,
|
||||||
|
opts ...Option) *Service {
|
||||||
|
c := &cfg{
|
||||||
remotePool: util.NewPseudoWorkerPool(),
|
remotePool: util.NewPseudoWorkerPool(),
|
||||||
localPool: util.NewPseudoWorkerPool(),
|
localPool: util.NewPseudoWorkerPool(),
|
||||||
log: &logger.Logger{Logger: zap.L()},
|
log: &logger.Logger{Logger: zap.L()},
|
||||||
|
keyStorage: ks,
|
||||||
|
clientConstructor: cc,
|
||||||
|
maxSizeSrc: ms,
|
||||||
|
localStore: os,
|
||||||
|
cnrSrc: cs,
|
||||||
|
netMapSrc: ns,
|
||||||
|
netmapKeys: nk,
|
||||||
|
networkState: nst,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func NewService(opts ...Option) *Service {
|
|
||||||
c := defaultCfg()
|
|
||||||
|
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
opts[i](c)
|
opts[i](c)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.fmtValidator = object.NewFormatValidator(c.fmtValidatorOpts...)
|
c.fmtValidator = object.NewFormatValidator(object.WithLockSource(os), object.WithNetState(nst))
|
||||||
|
|
||||||
return &Service{
|
return &Service{
|
||||||
cfg: c,
|
cfg: c,
|
||||||
|
@ -83,62 +93,12 @@ func (p *Service) Put() (*Streamer, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithKeyStorage(v *objutil.KeyStorage) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.keyStorage = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithMaxSizeSource(v MaxSizeSource) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.maxSizeSrc = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithObjectStorage(v ObjectStorage) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.localStore = v
|
|
||||||
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithLockSource(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithContainerSource(v container.Source) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.cnrSrc = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithNetworkMapSource(v netmap.Source) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.netMapSrc = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithWorkerPools(remote, local util.WorkerPool) Option {
|
func WithWorkerPools(remote, local util.WorkerPool) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.remotePool, c.localPool = remote, local
|
c.remotePool, c.localPool = remote, local
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithNetmapKeys(v netmap.AnnouncedKeys) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.netmapKeys = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithNetworkState(v netmap.State) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.networkState = v
|
|
||||||
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithNetState(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithClientConstructor(v ClientConstructor) Option {
|
|
||||||
return func(c *cfg) {
|
|
||||||
c.clientConstructor = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithLogger(l *logger.Logger) Option {
|
func WithLogger(l *logger.Logger) Option {
|
||||||
return func(c *cfg) {
|
return func(c *cfg) {
|
||||||
c.log = l
|
c.log = l
|
||||||
|
|
Loading…
Reference in a new issue