frostfs-node/pkg/services/audit/taskmanager/manager.go
Leonard Lyubich 03e3afb0e8 [#255] services/audit: Define interface of container communicator
Define interface of the container communicator which methods are going to be
used in audit checks. Make innerring Server to implement this interface.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-12-25 16:49:27 +03:00

81 lines
1.6 KiB
Go

package audittask
import (
"github.com/nspcc-dev/neofs-node/pkg/services/audit"
"github.com/nspcc-dev/neofs-node/pkg/services/audit/auditor"
"github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
)
// Manager represents an entity performing data audit tasks.
type Manager struct {
*cfg
ch chan *audit.Task
}
// Option is a Manager's constructor option.
type Option func(*cfg)
type cfg struct {
queueCap uint32
log *logger.Logger
ctxPrm auditor.ContextPrm
reporter audit.Reporter
workerPool util.WorkerPool
}
func defaultCfg() *cfg {
return &cfg{
log: zap.L(),
}
}
// New creates, initializes and returns new Manager instance.
func New(opts ...Option) *Manager {
c := defaultCfg()
for i := range opts {
opts[i](c)
}
return &Manager{
cfg: c,
}
}
// WithLogger returns option to specify Manager's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "Audit task manager"))
c.ctxPrm.SetLogger(l)
}
}
// WithWorkerPool returns option to set worker pool
// for task execution.
func WithWorkerPool(p util.WorkerPool) Option {
return func(c *cfg) {
c.workerPool = p
}
}
// WithQueueCapacity returns option to set task queue capacity.
func WithQueueCapacity(cap uint32) Option {
return func(c *cfg) {
c.queueCap = cap
}
}
// WithContainerCommunicator returns option to set component of communication
// with container nodes.
func WithContainerCommunicator(cnrCom auditor.ContainerCommunicator) Option {
return func(c *cfg) {
c.ctxPrm.SetContainerCommunicator(cnrCom)
}
}