2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
objutil "github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2020-11-23 11:22:32 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MaxSizeSource interface {
|
2020-10-22 14:20:59 +00:00
|
|
|
// MaxObjectSize returns maximum payload size
|
|
|
|
// of physically stored object in system.
|
|
|
|
//
|
|
|
|
// Must return 0 if value can not be obtained.
|
2020-09-21 14:31:31 +00:00
|
|
|
MaxObjectSize() uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type ClientConstructor interface {
|
2022-01-13 15:01:50 +00:00
|
|
|
Get(client.NodeInfo) (client.MultiAddressClient, error)
|
2021-03-23 18:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
type cfg struct {
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *objutil.KeyStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
maxSizeSrc MaxSizeSource
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
localStore ObjectStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
cnrSrc container.Source
|
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
|
|
|
|
2021-09-24 10:36:54 +00:00
|
|
|
remotePool, localPool util.WorkerPool
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
netmapKeys netmap.AnnouncedKeys
|
2020-09-29 12:38:35 +00:00
|
|
|
|
|
|
|
fmtValidator *object.FormatValidator
|
2020-10-03 10:14:09 +00:00
|
|
|
|
|
|
|
fmtValidatorOpts []object.FormatValidatorOption
|
2020-10-21 15:11:50 +00:00
|
|
|
|
|
|
|
networkState netmap.State
|
2020-11-18 13:03:31 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor ClientConstructor
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
log *logger.Logger
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2021-10-12 11:55:49 +00:00
|
|
|
remotePool: util.NewPseudoWorkerPool(),
|
|
|
|
localPool: util.NewPseudoWorkerPool(),
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(opts ...Option) *Service {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
2020-10-03 10:14:09 +00:00
|
|
|
c.fmtValidator = object.NewFormatValidator(c.fmtValidatorOpts...)
|
|
|
|
|
2020-09-21 14:31:31 +00:00
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Service) Put(ctx context.Context) (*Streamer, error) {
|
|
|
|
return &Streamer{
|
|
|
|
cfg: p.cfg,
|
|
|
|
ctx: ctx,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
func WithKeyStorage(v *objutil.KeyStorage) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2020-09-29 16:44:59 +00:00
|
|
|
c.keyStorage = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMaxSizeSource(v MaxSizeSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.maxSizeSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
func WithObjectStorage(v ObjectStorage) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.localStore = 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 13:34:39 +00:00
|
|
|
func WithWorkerPools(remote util.WorkerPool) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-10-08 13:34:39 +00:00
|
|
|
c.remotePool = remote
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
func WithNetmapKeys(v netmap.AnnouncedKeys) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-09-06 12:17:14 +00:00
|
|
|
c.netmapKeys = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-03 10:14:09 +00:00
|
|
|
|
2020-10-21 15:11:50 +00:00
|
|
|
func WithNetworkState(v netmap.State) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.networkState = v
|
2021-02-15 08:28:42 +00:00
|
|
|
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithNetState(v))
|
2020-10-21 15:11:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:03:31 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-11-18 13:03:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-23 18:40:36 +00:00
|
|
|
c.clientConstructor = v
|
2020-11-18 13:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|