forked from TrueCloudLab/frostfs-sdk-go
[#312] client/netmap: Simplify NetMapSnapshot
implementaiton
Make flat set of instructions similar to `ObjectDelete` operation. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
664392afc2
commit
89124d442d
1 changed files with 41 additions and 35 deletions
|
@ -2,10 +2,14 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
|
||||||
|
v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/signature"
|
||||||
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/version"
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
||||||
)
|
)
|
||||||
|
@ -199,7 +203,6 @@ func (c *Client) NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (*ResNetwo
|
||||||
|
|
||||||
// PrmNetMapSnapshot groups parameters of NetMapSnapshot operation.
|
// PrmNetMapSnapshot groups parameters of NetMapSnapshot operation.
|
||||||
type PrmNetMapSnapshot struct {
|
type PrmNetMapSnapshot struct {
|
||||||
prmCommonMeta
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResNetMapSnapshot groups resulting values of NetMapSnapshot operation.
|
// ResNetMapSnapshot groups resulting values of NetMapSnapshot operation.
|
||||||
|
@ -228,50 +231,53 @@ func (x ResNetMapSnapshot) NetMap() netmap.NetMap {
|
||||||
//
|
//
|
||||||
// Return statuses:
|
// Return statuses:
|
||||||
// - global (see Client docs).
|
// - global (see Client docs).
|
||||||
func (c *Client) NetMapSnapshot(ctx context.Context, prm PrmNetMapSnapshot) (*ResNetMapSnapshot, error) {
|
func (c *Client) NetMapSnapshot(ctx context.Context, _ PrmNetMapSnapshot) (*ResNetMapSnapshot, error) {
|
||||||
// check context
|
// check context
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
panic(panicMsgMissingContext)
|
panic(panicMsgMissingContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// form request body
|
||||||
|
var body v2netmap.SnapshotRequestBody
|
||||||
|
|
||||||
|
// form meta header
|
||||||
|
var meta v2session.RequestMetaHeader
|
||||||
|
|
||||||
// form request
|
// form request
|
||||||
var req v2netmap.SnapshotRequest
|
var req v2netmap.SnapshotRequest
|
||||||
|
req.SetBody(&body)
|
||||||
|
c.prepareRequest(&req, &meta)
|
||||||
|
|
||||||
// init call context
|
err := signature.SignServiceMessage(&c.prm.key, &req)
|
||||||
|
if err != nil {
|
||||||
var (
|
return nil, fmt.Errorf("sign request: %w", err)
|
||||||
cc contextCall
|
|
||||||
res ResNetMapSnapshot
|
|
||||||
)
|
|
||||||
|
|
||||||
c.initCallContext(&cc)
|
|
||||||
cc.meta = prm.prmCommonMeta
|
|
||||||
cc.req = &req
|
|
||||||
cc.statusRes = &res
|
|
||||||
cc.call = func() (responseV2, error) {
|
|
||||||
return rpcapi.NetMapSnapshot(&c.c, &req, client.WithContext(ctx))
|
|
||||||
}
|
|
||||||
cc.result = func(r responseV2) {
|
|
||||||
resp := r.(*v2netmap.SnapshotResponse)
|
|
||||||
|
|
||||||
const fieldNetMap = "network map"
|
|
||||||
|
|
||||||
netMapV2 := resp.GetBody().NetMap()
|
|
||||||
if netMapV2 == nil {
|
|
||||||
cc.err = newErrMissingResponseField(fieldNetMap)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cc.err = res.netMap.ReadFromV2(*netMapV2)
|
|
||||||
if cc.err != nil {
|
|
||||||
cc.err = newErrInvalidResponseField(fieldNetMap, cc.err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process call
|
resp, err := rpcapi.NetMapSnapshot(&c.c, &req, client.WithContext(ctx))
|
||||||
if !cc.processCall() {
|
if err != nil {
|
||||||
return nil, cc.err
|
return nil, fmt.Errorf("rpc failure: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var res ResNetMapSnapshot
|
||||||
|
res.st, err = c.processResponse(resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !apistatus.IsSuccessful(res.st) {
|
||||||
|
return &res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldNetMap = "network map"
|
||||||
|
|
||||||
|
netMapV2 := resp.GetBody().NetMap()
|
||||||
|
if netMapV2 == nil {
|
||||||
|
return nil, newErrMissingResponseField(fieldNetMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = res.netMap.ReadFromV2(*netMapV2)
|
||||||
|
if err != nil {
|
||||||
|
return nil, newErrInvalidResponseField(fieldNetMap, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
|
|
Loading…
Reference in a new issue