[#193] services/object: Support client options in all Object services
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
27fc4d6e01
commit
9148980bd0
14 changed files with 71 additions and 8 deletions
|
@ -18,6 +18,8 @@ type RemoteHeader struct {
|
||||||
keyStorage *util.KeyStorage
|
keyStorage *util.KeyStorage
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteHeadPrm groups remote header operation parameters.
|
// RemoteHeadPrm groups remote header operation parameters.
|
||||||
|
@ -28,10 +30,11 @@ type RemoteHeadPrm struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemoteHeader creates, initializes and returns new RemoteHeader instance.
|
// 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{
|
return &RemoteHeader{
|
||||||
keyStorage: keyStorage,
|
keyStorage: keyStorage,
|
||||||
clientCache: cache,
|
clientCache: cache,
|
||||||
|
clientOpts: opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +68,7 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := h.clientCache.Get(key, addr)
|
c, err := h.clientCache.Get(key, addr, h.clientOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
|
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package headsvc
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
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/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
|
@ -152,3 +153,9 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = l
|
c.log = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientOptions(opts ...client.Option) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.remoteHeader.clientOpts = opts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -29,13 +29,18 @@ type remoteTarget struct {
|
||||||
obj *object.Object
|
obj *object.Object
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteSender represents utility for
|
// RemoteSender represents utility for
|
||||||
// sending an object to a remote host.
|
// sending an object to a remote host.
|
||||||
type RemoteSender struct {
|
type RemoteSender struct {
|
||||||
keyStorage *util.KeyStorage
|
keyStorage *util.KeyStorage
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemotePutPrm groups remote put operation parameters.
|
// RemotePutPrm groups remote put operation parameters.
|
||||||
|
@ -62,7 +67,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := t.clientCache.Get(key, addr)
|
c, err := t.clientCache.Get(key, addr, t.clientOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not create SDK client %s", t, addr)
|
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.
|
// 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{
|
return &RemoteSender{
|
||||||
keyStorage: keyStorage,
|
keyStorage: keyStorage,
|
||||||
clientCache: cache,
|
clientCache: cache,
|
||||||
|
clientOpts: opts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +121,7 @@ func (s *RemoteSender) PutObject(ctx context.Context, p *RemotePutPrm) error {
|
||||||
keyStorage: s.keyStorage,
|
keyStorage: s.keyStorage,
|
||||||
addr: p.node,
|
addr: p.node,
|
||||||
clientCache: s.clientCache,
|
clientCache: s.clientCache,
|
||||||
|
clientOpts: s.clientOpts,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil {
|
if err := t.WriteHeader(object.NewRawFromObject(p.obj)); err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package putsvc
|
||||||
import (
|
import (
|
||||||
"context"
|
"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/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
@ -53,6 +54,8 @@ type cfg struct {
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -148,3 +151,9 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = l
|
c.log = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientOptions(opts ...client.Option) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.clientOpts = opts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -144,6 +144,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
||||||
bearer: prm.common.BearerToken(),
|
bearer: prm.common.BearerToken(),
|
||||||
addr: addr,
|
addr: addr,
|
||||||
clientCache: p.clientCache,
|
clientCache: p.clientCache,
|
||||||
|
clientOpts: p.clientOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,6 +29,8 @@ type remoteRangeWriter struct {
|
||||||
rng *object.Range
|
rng *object.Range
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := r.clientCache.Get(key, addr)
|
c, err := r.clientCache.Get(key, addr, r.clientOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr)
|
return 0, errors.Wrapf(err, "(%T) could not create SDK client %s", r, addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"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/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
|
@ -42,6 +43,8 @@ type cfg struct {
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -184,3 +187,9 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = l
|
c.log = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientOptions(opts ...client.Option) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.clientOpts = opts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -186,6 +186,7 @@ loop:
|
||||||
addr: objAddr,
|
addr: objAddr,
|
||||||
rng: nextRange,
|
rng: nextRange,
|
||||||
clientCache: p.clientCache,
|
clientCache: p.clientCache,
|
||||||
|
clientOpts: p.clientOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ loop:
|
||||||
keyStorage: h.keyStorage,
|
keyStorage: h.keyStorage,
|
||||||
node: addr,
|
node: addr,
|
||||||
clientCache: h.clientCache,
|
clientCache: h.clientCache,
|
||||||
|
clientOpts: h.clientOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ type remoteHasher struct {
|
||||||
node *network.Address
|
node *network.Address
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][]byte)) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := h.clientCache.Get(key, addr)
|
c, err := h.clientCache.Get(key, addr, h.clientOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
|
return errors.Wrapf(err, "(%T) could not create SDK client %s", h, addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
"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-api-go/pkg/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
"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/netmap"
|
||||||
|
@ -48,6 +49,8 @@ type cfg struct {
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -284,3 +287,9 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = l
|
c.log = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientOptions(opts ...client.Option) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.clientOpts = opts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ type remoteStream struct {
|
||||||
addr *network.Address
|
addr *network.Address
|
||||||
|
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := s.clientCache.Get(key, addr)
|
c, err := s.clientCache.Get(key, addr, s.clientOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr)
|
return errors.Wrapf(err, "(%T) could not create SDK client %s", s, addr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"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/container"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||||
|
@ -38,6 +39,8 @@ type cfg struct {
|
||||||
clientCache *cache.ClientCache
|
clientCache *cache.ClientCache
|
||||||
|
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
|
||||||
|
clientOpts []client.Option
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultCfg() *cfg {
|
func defaultCfg() *cfg {
|
||||||
|
@ -116,3 +119,9 @@ func WithLogger(l *logger.Logger) Option {
|
||||||
c.log = l
|
c.log = l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithClientOptions(opts ...client.Option) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.clientOpts = opts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -165,6 +165,7 @@ loop:
|
||||||
keyStorage: p.keyStorage,
|
keyStorage: p.keyStorage,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
clientCache: p.clientCache,
|
clientCache: p.clientCache,
|
||||||
|
clientOpts: p.clientOpts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue