[#193] services/object: Support client options in all Object services

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2020-11-23 15:59:06 +03:00 committed by Alex Vanin
parent 27fc4d6e01
commit 9148980bd0
14 changed files with 71 additions and 8 deletions

View File

@ -18,6 +18,8 @@ type RemoteHeader struct {
keyStorage *util.KeyStorage
clientCache *cache.ClientCache
clientOpts []client.Option
}
// RemoteHeadPrm groups remote header operation parameters.
@ -28,10 +30,11 @@ type RemoteHeadPrm struct {
}
// NewRemoteHeader creates, initializes and returns new RemoteHeader instance.
func NewRemoteHeader(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteHeader {
func NewRemoteHeader(keyStorage *util.KeyStorage, cache *cache.ClientCache, opts ...client.Option) *RemoteHeader {
return &RemoteHeader{
keyStorage: keyStorage,
clientCache: cache,
clientOpts: opts,
}
}
@ -65,7 +68,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
return nil, err
}
c, err := h.clientCache.Get(key, addr)
c, err := h.clientCache.Get(key, addr, h.clientOpts...)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
}

View File

@ -3,6 +3,7 @@ package headsvc
import (
"context"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -152,3 +153,9 @@ func WithLogger(l *logger.Logger) Option {
c.log = l
}
}
func WithClientOptions(opts ...client.Option) Option {
return func(c *cfg) {
c.remoteHeader.clientOpts = opts
}
}

View File

@ -29,13 +29,18 @@ type remoteTarget struct {
obj *object.Object
clientCache *cache.ClientCache
clientOpts []client.Option
}
// RemoteSender represents utility for
// sending an object to a remote host.
type RemoteSender struct {
keyStorage *util.KeyStorage
keyStorage *util.KeyStorage
clientCache *cache.ClientCache
clientOpts []client.Option
}
// RemotePutPrm groups remote put operation parameters.
@ -62,7 +67,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
return nil, err
}
c, err := t.clientCache.Get(key, addr)
c, err := t.clientCache.Get(key, addr, t.clientOpts...)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr)
}
@ -83,10 +88,11 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
}
// NewRemoteSender creates, initializes and returns new RemoteSender instance.
func NewRemoteSender(keyStorage *util.KeyStorage, cache *cache.ClientCache) *RemoteSender {
func NewRemoteSender(keyStorage *util.KeyStorage, cache *cache.ClientCache, opts ...client.Option) *RemoteSender {
return &RemoteSender{
keyStorage: keyStorage,
clientCache: cache,
clientOpts: opts,
}
}
@ -115,6 +121,7 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
keyStorage: s.keyStorage,
addr: p.node,
clientCache: s.clientCache,
clientOpts: s.clientOpts,
}
if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil {

View File

@ -3,6 +3,7 @@ package putsvc
import (
"context"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
@ -53,6 +54,8 @@ type cfg struct {
clientCache *cache.ClientCache
log *logger.Logger
clientOpts []client.Option
}
func defaultCfg() *cfg {
@ -148,3 +151,9 @@ func WithLogger(l *logger.Logger) Option {
c.log = l
}
}
func WithClientOptions(opts ...client.Option) Option {
return func(c *cfg) {
c.clientOpts = opts
}
}

View File

@ -144,6 +144,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
bearer: prm.common.BearerToken(),
addr: addr,
clientCache: p.clientCache,
clientOpts: p.clientOpts,
}
}
},

View File

@ -29,6 +29,8 @@ type remoteRangeWriter struct {
rng *object.Range
clientCache *cache.ClientCache
clientOpts []client.Option
}
func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
@ -42,7 +44,7 @@ func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
return 0, err
}
c, err := r.clientCache.Get(key, addr)
c, err := r.clientCache.Get(key, addr, r.clientOpts...)
if err != nil {
return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr)
}

View File

@ -4,6 +4,7 @@ import (
"context"
"sync"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -42,6 +43,8 @@ type cfg struct {
clientCache *cache.ClientCache
log *logger.Logger
clientOpts []client.Option
}
func defaultCfg() *cfg {
@ -184,3 +187,9 @@ func WithLogger(l *logger.Logger) Option {
c.log = l
}
}
func WithClientOptions(opts ...client.Option) Option {
return func(c *cfg) {
c.clientOpts = opts
}
}

View File

@ -186,6 +186,7 @@ loop:
addr: objAddr,
rng: nextRange,
clientCache: p.clientCache,
clientOpts: p.clientOpts,
}
}

View File

@ -115,6 +115,7 @@ loop:
keyStorage: h.keyStorage,
node: addr,
clientCache: h.clientCache,
clientOpts: h.clientOpts,
}
}

View File

@ -18,6 +18,8 @@ type remoteHasher struct {
node *network.Address
clientCache *cache.ClientCache
clientOpts []client.Option
}
func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][]byte)) error {
@ -31,7 +33,7 @@ func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][
return err
}
c, err := h.clientCache.Get(key, addr)
c, err := h.clientCache.Get(key, addr, h.clientOpts...)
if err != nil {
return errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
}

View File

@ -7,6 +7,7 @@ import (
"io"
"github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -48,6 +49,8 @@ type cfg struct {
clientCache *cache.ClientCache
log *logger.Logger
clientOpts []client.Option
}
func defaultCfg() *cfg {
@ -284,3 +287,9 @@ func WithLogger(l *logger.Logger) Option {
c.log = l
}
}
func WithClientOptions(opts ...client.Option) Option {
return func(c *cfg) {
c.clientOpts = opts
}
}

View File

@ -19,6 +19,8 @@ type remoteStream struct {
addr *network.Address
clientCache *cache.ClientCache
clientOpts []client.Option
}
func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error {
@ -32,7 +34,7 @@ func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error
return err
}
c, err := s.clientCache.Get(key, addr)
c, err := s.clientCache.Get(key, addr, s.clientOpts...)
if err != nil {
return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr)
}

View File

@ -4,6 +4,7 @@ import (
"context"
"sync"
"github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/container"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
@ -38,6 +39,8 @@ type cfg struct {
clientCache *cache.ClientCache
log *logger.Logger
clientOpts []client.Option
}
func defaultCfg() *cfg {
@ -116,3 +119,9 @@ func WithLogger(l *logger.Logger) Option {
c.log = l
}
}
func WithClientOptions(opts ...client.Option) Option {
return func(c *cfg) {
c.clientOpts = opts
}
}

View File

@ -165,6 +165,7 @@ loop:
keyStorage: p.keyStorage,
addr: addr,
clientCache: p.clientCache,
clientOpts: p.clientOpts,
}
}