[#946] ir: Refactor usage of NeoFS API client

The client needs of the IR application are very limited and rarely change.
Interface changes of the client library should not affect the operation of
various application packages, if they do not change their requirements for
the provided functionality. To localize the use of the base client and
facilitate further support, an auxiliary package is implemented that will
only be used by the IR application.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-10-27 15:12:05 +03:00 committed by LeL
parent 49c9dbfba8
commit 88e37ea372
7 changed files with 416 additions and 66 deletions

View file

@ -7,7 +7,8 @@ import (
"fmt"
"time"
SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/client"
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
@ -24,11 +25,6 @@ type (
InnerRingSize() int
}
// NeoFSClientCache is an interface for cache of neofs RPC clients
NeoFSClientCache interface {
Get(client.NodeInfo) (SDKClient.Client, error)
}
TaskManager interface {
PushTask(*audit.Task) error
@ -42,8 +38,7 @@ type (
log *zap.Logger
pool *ants.Pool
irList Indexer
clientCache NeoFSClientCache
key *ecdsa.PrivateKey
sgSrc SGSource
searchTimeout time.Duration
containerClient *wrapContainer.Wrapper
@ -60,7 +55,7 @@ type (
NetmapClient *wrapNetmap.Wrapper
ContainerClient *wrapContainer.Wrapper
IRList Indexer
ClientCache NeoFSClientCache
SGSource SGSource
RPCSearchTimeout time.Duration
TaskManager TaskManager
Reporter audit.Reporter
@ -68,6 +63,48 @@ type (
}
)
// SearchSGPrm groups the parameters which are formed by Processor to search the storage group objects.
type SearchSGPrm struct {
ctx context.Context
id *cid.ID
info client.NodeInfo
}
// Context returns context to use for network communication.
func (x SearchSGPrm) Context() context.Context {
return x.ctx
}
// CID returns identifier of the container to search SG in.
func (x SearchSGPrm) CID() *cid.ID {
return x.id
}
// NodeInfo returns information about storage node to communicate with.
func (x SearchSGPrm) NodeInfo() client.NodeInfo {
return x.info
}
// SearchSGDst groups target values which Processor expects from SG searching to process.
type SearchSGDst struct {
ids []*object.ID
}
// WriteIDList writes list of identifiers of storage group objects stored in the container.
func (x *SearchSGDst) WriteIDList(ids []*object.ID) {
x.ids = ids
}
// SGSource is a storage group information source interface.
type SGSource interface {
// Lists storage group objects in the container. Formed list must be written to destination.
//
// Must return any error encountered which did not allow to form the list.
ListSG(*SearchSGDst, SearchSGPrm) error
}
type epochAuditReporter struct {
epoch uint64
@ -86,8 +123,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/audit: logger is not set")
case p.IRList == nil:
return nil, errors.New("ir/audit: global state is not set")
case p.ClientCache == nil:
return nil, errors.New("ir/audit: neofs RPC client cache is not set")
case p.SGSource == nil:
return nil, errors.New("ir/audit: SG source is not set")
case p.TaskManager == nil:
return nil, errors.New("ir/audit: audit task manager is not set")
case p.Reporter == nil:
@ -106,8 +143,7 @@ func New(p *Params) (*Processor, error) {
pool: pool,
containerClient: p.ContainerClient,
irList: p.IRList,
clientCache: p.ClientCache,
key: p.Key,
sgSrc: p.SGSource,
searchTimeout: p.RPCSearchTimeout,
netmapClient: p.NetmapClient,
taskManager: p.TaskManager,