forked from TrueCloudLab/frostfs-node
[#505] morph/container: Change get container API
Make `Get` method of the wrapper over Container contract's client to accept binary container ID. Create `Get` function similar to the previous `Get` variation. Use this function in Container service server in the place where `Get` method was used. Additionally implement `AsContainerSource` function which allows to simply compose container Source interface from the wrapper. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6310535b3c
commit
83c27f6e8a
6 changed files with 33 additions and 19 deletions
|
@ -42,7 +42,9 @@ func initContainerService(c *cfg) {
|
||||||
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
|
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
c.cfgObject.cnrStorage = newCachedContainerStorage(wrap) // use RPC node as source of containers (with caching)
|
cnrSrc := wrapper.AsContainerSource(wrap)
|
||||||
|
|
||||||
|
c.cfgObject.cnrStorage = newCachedContainerStorage(cnrSrc) // use RPC node as source of containers (with caching)
|
||||||
c.cfgObject.cnrClient = wrap
|
c.cfgObject.cnrClient = wrap
|
||||||
|
|
||||||
localMetrics := &localStorageLoad{
|
localMetrics := &localStorageLoad{
|
||||||
|
@ -63,7 +65,7 @@ func initContainerService(c *cfg) {
|
||||||
loadPlacementBuilder := &loadPlacementBuilder{
|
loadPlacementBuilder := &loadPlacementBuilder{
|
||||||
log: c.log,
|
log: c.log,
|
||||||
nmSrc: c.cfgNetmap.wrapper,
|
nmSrc: c.cfgNetmap.wrapper,
|
||||||
cnrSrc: wrap,
|
cnrSrc: cnrSrc,
|
||||||
}
|
}
|
||||||
|
|
||||||
routeBuilder := placementrouter.New(placementrouter.Prm{
|
routeBuilder := placementrouter.New(placementrouter.Prm{
|
||||||
|
|
|
@ -436,7 +436,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
settlementDeps := &settlementDeps{
|
settlementDeps := &settlementDeps{
|
||||||
globalConfig: globalConfig,
|
globalConfig: globalConfig,
|
||||||
log: server.log,
|
log: server.log,
|
||||||
cnrSrc: cnrClient,
|
cnrSrc: cntWrapper.AsContainerSource(cnrClient),
|
||||||
auditClient: server.auditClient,
|
auditClient: server.auditClient,
|
||||||
nmSrc: nmClient,
|
nmSrc: nmClient,
|
||||||
clientCache: clientCache,
|
clientCache: clientCache,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
"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/morph/client/container/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/network"
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/audit"
|
"github.com/nspcc-dev/neofs-node/pkg/services/audit"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/storagegroup"
|
||||||
|
@ -49,7 +50,7 @@ func (ap *Processor) processStartAudit(epoch uint64) {
|
||||||
auditCtx, ap.prevAuditCanceler = context.WithCancel(context.Background())
|
auditCtx, ap.prevAuditCanceler = context.WithCancel(context.Background())
|
||||||
|
|
||||||
for i := range containers {
|
for i := range containers {
|
||||||
cnr, err := ap.containerClient.Get(containers[i]) // get container structure
|
cnr, err := wrapper.Get(ap.containerClient, containers[i]) // get container structure
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("can't get container info, ignore",
|
log.Error("can't get container info, ignore",
|
||||||
zap.Stringer("cid", containers[i]),
|
zap.Stringer("cid", containers[i]),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -58,7 +59,7 @@ func (cp *Processor) checkEACLOwnership(binTable []byte, key *keys.PublicKey) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive owner of the related container
|
// receive owner of the related container
|
||||||
cnr, err := cp.cnrClient.Get(table.CID())
|
cnr, err := wrapper.Get(cp.cnrClient, table.CID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not receive the container: %w", err)
|
return fmt.Errorf("could not receive the container: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,24 +67,34 @@ func (w *Wrapper) Put(cnr, key, sig []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get reads the container from NeoFS system by identifier
|
type containerSource Wrapper
|
||||||
|
|
||||||
|
func (x *containerSource) Get(cid *container.ID) (*container.Container, error) {
|
||||||
|
return Get((*Wrapper)(x), cid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AsContainerSource provides container Source interface
|
||||||
|
// from Wrapper instance.
|
||||||
|
func AsContainerSource(w *Wrapper) core.Source {
|
||||||
|
return (*containerSource)(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get marshals container ID, and passes it to Wrapper's Get method.
|
||||||
|
//
|
||||||
|
// Returns error if cid is nil.
|
||||||
|
func Get(w *Wrapper, cid *container.ID) (*container.Container, error) {
|
||||||
|
return w.Get(cid.ToV2().GetValue())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get reads the container from NeoFS system by binary identifier
|
||||||
// through Container contract call.
|
// through Container contract call.
|
||||||
//
|
//
|
||||||
// If an empty slice is returned for the requested identifier,
|
// If an empty slice is returned for the requested identifier,
|
||||||
// storage.ErrNotFound error is returned.
|
// storage.ErrNotFound error is returned.
|
||||||
func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) {
|
func (w *Wrapper) Get(cid []byte) (*container.Container, error) {
|
||||||
if cid == nil {
|
var args client.GetArgs
|
||||||
return nil, errNilArgument
|
|
||||||
}
|
|
||||||
|
|
||||||
args := client.GetArgs{}
|
args.SetCID(cid)
|
||||||
|
|
||||||
v2 := cid.ToV2()
|
|
||||||
if v2 == nil {
|
|
||||||
return nil, errUnsupported // use other major version if there any
|
|
||||||
}
|
|
||||||
|
|
||||||
args.SetCID(v2.GetValue())
|
|
||||||
|
|
||||||
// ask RPC neo node to get serialized container
|
// ask RPC neo node to get serialized container
|
||||||
rpcAnswer, err := w.client.Get(args)
|
rpcAnswer, err := w.client.Get(args)
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteReques
|
||||||
func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody) (*container.GetResponseBody, error) {
|
func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody) (*container.GetResponseBody, error) {
|
||||||
cid := containerSDK.NewIDFromV2(body.GetContainerID())
|
cid := containerSDK.NewIDFromV2(body.GetContainerID())
|
||||||
|
|
||||||
cnr, err := s.wrapper.Get(cid)
|
cnr, err := wrapper.Get(s.wrapper, cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue