[#1793] node: Serve `NetmapService.NetmapSnapshot` RPC

There is no more need to serve the same request on Control API.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/fyrchik/neofs-adm-fix-commands
Leonard Lyubich 2022-09-17 16:37:01 +04:00 committed by fyrchik
parent 59de20fbba
commit 485a5418d2
33 changed files with 653 additions and 1238 deletions

View File

@ -4,6 +4,8 @@ Changelog for NeoFS Node
## [Unreleased] - Anmado (안마도, 鞍馬島)
### Added
- Serving `NetmapService.NetmapSnapshot` RPC (#1793)
- `netmap snapshot` command of NeoFS CLI (#1793)
- Changelog updates CI step (#1808)
- Validate storage node configuration before node startup (#1805)
@ -18,10 +20,13 @@ Changelog for NeoFS Node
### Removed
- Remove WIF and NEP2 support in `neofs-cli`'s --wallet flag (#1128)
- Remove --generate-key option in `neofs-cli container delete` (#1692)
- Serving `ControlService.NetmapSnapshot` RPC (#1793)
- `control netmap-snapshot` command of NeoFS CLI (#1793)
### Updated
### Updating from v0.32.0
Replace using the `control netmap-snapshot` command with `netmap snapshot` one in NeoFS CLI.
## [0.32.0] - 2022-09-14 - Pungdo (풍도, 楓島)

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.2
// protoc v3.21.6
// source: cmd/neofs-adm/internal/modules/morph/internal/types.proto
package internal

View File

@ -272,6 +272,29 @@ func NodeInfo(prm NodeInfoPrm) (res NodeInfoRes, err error) {
return
}
// NetMapSnapshotPrm groups parameters of NetMapSnapshot operation.
type NetMapSnapshotPrm struct {
commonPrm
}
// NetMapSnapshotRes groups the resulting values of NetMapSnapshot operation.
type NetMapSnapshotRes struct {
cliRes *client.ResNetMapSnapshot
}
// NetMap returns current local snapshot of the NeoFS network map.
func (x NetMapSnapshotRes) NetMap() netmap.NetMap {
return x.cliRes.NetMap()
}
// NetMapSnapshot requests current network view of the remote server.
//
// Returns any error which prevented the operation from completing correctly in error return.
func NetMapSnapshot(prm NetMapSnapshotPrm) (res NetMapSnapshotRes, err error) {
res.cliRes, err = prm.cli.NetMapSnapshot(context.Background(), client.PrmNetMapSnapshot{})
return
}
// CreateSessionPrm groups parameters of CreateSession operation.
type CreateSessionPrm struct {
commonPrm

View File

@ -30,7 +30,6 @@ func init() {
healthCheckCmd,
setNetmapStatusCmd,
dropObjectsCmd,
snapshotCmd,
shardsCmd,
synchronizeTreeCmd,
)
@ -38,7 +37,6 @@ func init() {
initControlHealthCheckCmd()
initControlSetNetmapStatusCmd()
initControlDropObjectsCmd()
initControlSnapshotCmd()
initControlShardsCmd()
initControlSynchronizeTreeCmd()
}

View File

@ -1,74 +0,0 @@
package control
import (
"github.com/mr-tron/base58"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
)
const (
netmapSnapshotJSONFlag = commonflags.JSON
)
var snapshotCmd = &cobra.Command{
Use: "netmap-snapshot",
Short: "Get network map snapshot",
Long: "Get network map snapshot",
Run: func(cmd *cobra.Command, args []string) {
pk := key.Get(cmd)
req := new(control.NetmapSnapshotRequest)
req.SetBody(new(control.NetmapSnapshotRequest_Body))
signRequest(cmd, pk, req)
cli := getClient(cmd, pk)
var resp *control.NetmapSnapshotResponse
var err error
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.NetmapSnapshot(client, req)
return err
})
common.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
isJSON, _ := cmd.Flags().GetBool(netmapSnapshotJSONFlag)
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), isJSON)
},
}
func initControlSnapshotCmd() {
commonflags.InitWithoutRPC(snapshotCmd)
flags := snapshotCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.Bool(netmapSnapshotJSONFlag, false, "print netmap structure in JSON format")
}
func prettyPrintNetmap(cmd *cobra.Command, nm *control.Netmap, jsonEncoding bool) {
if jsonEncoding {
common.PrettyPrintJSON(cmd, nm, "netmap")
return
}
cmd.Println("Epoch:", nm.GetEpoch())
for i, node := range nm.GetNodes() {
cmd.Printf("Node %d: %s %s %v\n", i+1,
base58.Encode(node.GetPublicKey()),
node.GetState(),
node.GetAddresses(),
)
for _, attr := range node.GetAttributes() {
cmd.Printf("\t%s: %s\n", attr.GetKey(), attr.GetValue())
}
}
}

View File

@ -22,9 +22,11 @@ func init() {
getEpochCmd,
nodeInfoCmd,
netInfoCmd,
snapshotCmd,
)
initGetEpochCmd()
initNetInfoCmd()
initNodeInfoCmd()
initSnapshotCmd()
}

View File

@ -0,0 +1,63 @@
package netmap
import (
"encoding/hex"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/spf13/cobra"
)
var snapshotCmd = &cobra.Command{
Use: "snapshot",
Short: "Request current local snapshot of the network map",
Long: `Request current local snapshot of the network map`,
Run: func(cmd *cobra.Command, args []string) {
p := key.GetOrGenerate(cmd)
cli := internalclient.GetSDKClientByFlag(cmd, p, commonflags.RPC)
var prm internalclient.NetMapSnapshotPrm
prm.SetClient(cli)
res, err := internalclient.NetMapSnapshot(prm)
common.ExitOnErr(cmd, "rpc error: %w", err)
prettyPrintNetMap(cmd, res.NetMap())
},
}
func initSnapshotCmd() {
commonflags.Init(snapshotCmd)
commonflags.InitAPI(snapshotCmd)
}
func prettyPrintNetMap(cmd *cobra.Command, nm netmap.NetMap) {
cmd.Println("Epoch:", nm.Epoch())
nodes := nm.Nodes()
for i := range nodes {
var strState string
switch {
case nodes[i].IsOnline():
strState = "ONLINE"
case nodes[i].IsOffline():
strState = "OFFLINE"
}
cmd.Printf("Node %d: %s %s ", i+1, hex.EncodeToString(nodes[i].PublicKey()), strState)
netmap.IterateNetworkEndpoints(nodes[i], func(endpoint string) {
cmd.Printf("%s ", endpoint)
})
cmd.Println()
nodes[i].IterateAttributes(func(key, value string) {
cmd.Printf("\t%s: %s\n", key, value)
})
}
}

View File

@ -6,6 +6,7 @@ import (
"net"
"path/filepath"
"sync"
atomicstd "sync/atomic"
"time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
@ -134,6 +135,13 @@ type cfg struct {
persistate *state.PersistentStorage
netMapSource netmapCore.Source
// current network map
netMap atomicstd.Value // type netmap.NetMap
}
func (c *cfg) ProcessCurrentNetMap(f func(netmap.NetMap)) {
f(c.netMap.Load().(netmap.NetMap))
}
type cfgGRPC struct {

View File

@ -286,6 +286,8 @@ func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) {
return nil, err
}
c.netMap.Store(*nm)
nmNodes := nm.Nodes()
for i := range nmNodes {
if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) {

4
go.mod
View File

@ -17,9 +17,9 @@ require (
github.com/nspcc-dev/hrw v1.0.9
github.com/nspcc-dev/neo-go v0.99.2
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b // indirect
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220827080658-9e17cdfc7647
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220919124434-cf868188ef9c
github.com/nspcc-dev/neofs-contract v0.15.5
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220914073456-f75a5feba335
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220922065107-8e3173eacd23
github.com/nspcc-dev/tzhash v1.6.1
github.com/panjf2000/ants/v2 v2.4.0
github.com/paulmach/orb v0.2.2

8
go.sum
View File

@ -453,8 +453,8 @@ github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b h1:J7
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b/go.mod h1:23bBw0v6pBYcrWs8CBEEDIEDJNbcFoIh8pGGcf2Vv8s=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.11.1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs=
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220827080658-9e17cdfc7647 h1:00JDCprdZG15n8z58EaFvJlmvZ4uESUii8MSzk869JM=
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220827080658-9e17cdfc7647/go.mod h1:NAaDfOnFWIbAFkTj7pNQ+cknVue0JbdeRT9QQaeBCEY=
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220919124434-cf868188ef9c h1:YZwtBY9uypaShbe/NLhosDanIfxt8VhQlSLYUeFIWv8=
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220919124434-cf868188ef9c/go.mod h1:DRIr0Ic1s+6QgdqmNFNLIqMqd7lNMJfYwkczlm1hDtM=
github.com/nspcc-dev/neofs-contract v0.15.3/go.mod h1:BXVZUZUJxrmmDETglXHI8+5DSgn84B9y5DoSWqEjYCs=
github.com/nspcc-dev/neofs-contract v0.15.5 h1:6Fsr1VRaG1klCWipWWPHvVkKaVS85tcxxsNDbvVB2zk=
github.com/nspcc-dev/neofs-contract v0.15.5/go.mod h1:gN5bo2TlMvLbySImmg76DVj3jVmYgti2VVlQ+h/tcr0=
@ -465,8 +465,8 @@ github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09f
github.com/nspcc-dev/neofs-crypto v0.4.0/go.mod h1:6XJ8kbXgOfevbI2WMruOtI+qUJXNwSGM/E9eClXxPHs=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4=
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220914073456-f75a5feba335 h1:Rj6lGjHW26NdsqEPUQYdKSlXl1TMFh2YFQQJIZdeeOI=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220914073456-f75a5feba335/go.mod h1:2UqI14Aib8VPUmsxKB5q8q51LY9zO/FyRSAVLeXXqLE=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220922065107-8e3173eacd23 h1:LhLIUt1CxIjacCBU9bntf3CW3RsjXpCECaoQFrK2tbE=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220922065107-8e3173eacd23/go.mod h1:lJ1K24ZW5MsUrAi2741cs8/gZ/jj61ilHe2NyfMuYMs=
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=

View File

@ -28,7 +28,12 @@ func (c *Client) GetNetMapByEpoch(epoch uint64) (*netmap.NetMap, error) {
epochSnapshotMethod, err)
}
return unmarshalNetmap(res, epochSnapshotMethod)
nm, err := unmarshalNetmap(res, epochSnapshotMethod)
if err == nil {
nm.SetEpoch(epoch)
}
return nm, err
}
// GetCandidates receives information list about candidates

View File

@ -52,3 +52,18 @@ func (s *Server) NetworkInfo(ctx context.Context, req *netmapGRPC.NetworkInfoReq
return resp.ToGRPCMessage().(*netmapGRPC.NetworkInfoResponse), nil
}
// NetmapSnapshot converts gRPC request message and passes it to internal netmap service.
func (s *Server) NetmapSnapshot(ctx context.Context, req *netmapGRPC.NetmapSnapshotRequest) (*netmapGRPC.NetmapSnapshotResponse, error) {
snapshotReq := new(netmap.SnapshotRequest)
if err := snapshotReq.FromGRPCMessage(req); err != nil {
return nil, err
}
resp, err := s.srv.Snapshot(ctx, snapshotReq)
if err != nil {
return nil, err
}
return resp.ToGRPCMessage().(*netmapGRPC.NetmapSnapshotResponse), nil
}

View File

@ -33,26 +33,6 @@ func (w *healthCheckResponseWrapper) FromGRPCMessage(m grpc.Message) error {
return nil
}
type netmapSnapshotResponseWrapper struct {
message.Message
m *NetmapSnapshotResponse
}
func (w *netmapSnapshotResponseWrapper) ToGRPCMessage() grpc.Message {
return w.m
}
func (w *netmapSnapshotResponseWrapper) FromGRPCMessage(m grpc.Message) error {
var ok bool
w.m, ok = m.(*NetmapSnapshotResponse)
if !ok {
return message.NewUnexpectedMessageType(m, w.m)
}
return nil
}
type setNetmapStatusResponseWrapper struct {
message.Message
m *SetNetmapStatusResponse

View File

@ -1,16 +1,17 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.5
// protoc v3.21.6
// source: pkg/services/control/ir/service.proto
package control
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)
const (

View File

@ -1,13 +1,14 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.5
// - protoc v3.21.6
// source: pkg/services/control/ir/service.proto
package control
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"

View File

@ -1,16 +1,17 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.5
// protoc v3.21.6
// source: pkg/services/control/ir/types.proto
package control
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)
const (

View File

@ -9,7 +9,6 @@ const serviceName = "control.ControlService"
const (
rpcHealthCheck = "HealthCheck"
rpcNetmapSnapshot = "NetmapSnapshot"
rpcSetNetmapStatus = "SetNetmapStatus"
rpcDropObjects = "DropObjects"
rpcListShards = "ListShards"
@ -42,28 +41,6 @@ func HealthCheck(
return wResp.m, nil
}
// NetmapSnapshot executes ControlService.NetmapSnapshot RPC.
func NetmapSnapshot(
cli *client.Client,
req *NetmapSnapshotRequest,
opts ...client.CallOption,
) (*NetmapSnapshotResponse, error) {
wResp := &netmapSnapshotResponseWrapper{
m: new(NetmapSnapshotResponse),
}
wReq := &requestWrapper{
m: req,
}
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcNetmapSnapshot), wReq, wResp, opts...)
if err != nil {
return nil, err
}
return wResp.m, nil
}
// SetNetmapStatus executes ControlService.SetNetmapStatus RPC.
func SetNetmapStatus(
cli *client.Client,

View File

@ -1,91 +0,0 @@
package control
import (
"context"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
netmapAPI "github.com/nspcc-dev/neofs-sdk-go/netmap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// NetmapSnapshot reads network map snapshot from Netmap storage.
func (s *Server) NetmapSnapshot(ctx context.Context, req *control.NetmapSnapshotRequest) (*control.NetmapSnapshotResponse, error) {
// verify request
if err := s.isValidRequest(req); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
// get current epoch
epoch, err := s.netMapSrc.Epoch()
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
apiNetMap, err := s.netMapSrc.GetNetMapByEpoch(epoch)
if err != nil {
return nil, status.Error(codes.NotFound, err.Error())
}
nm := new(control.Netmap)
nm.SetEpoch(epoch)
nm.SetNodes(nodesFromAPI(apiNetMap.Nodes()))
// create and fill response
resp := new(control.NetmapSnapshotResponse)
body := new(control.NetmapSnapshotResponse_Body)
resp.SetBody(body)
body.SetNetmap(nm)
// sign the response
if err := SignMessage(s.key, resp); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return resp, nil
}
func nodesFromAPI(apiNodes []netmapAPI.NodeInfo) []*control.NodeInfo {
nodes := make([]*control.NodeInfo, 0, len(apiNodes))
for i := range apiNodes {
node := new(control.NodeInfo)
node.SetPublicKey(apiNodes[i].PublicKey())
addrs := make([]string, 0, apiNodes[i].NumberOfNetworkEndpoints())
netmapAPI.IterateNetworkEndpoints(apiNodes[i], func(s string) {
addrs = append(addrs, s)
})
node.SetAddresses(addrs)
node.SetAttributes(attributesFromAPI(apiNodes[i]))
switch {
default:
node.SetState(control.NetmapStatus_STATUS_UNDEFINED)
case apiNodes[i].IsOnline():
node.SetState(control.NetmapStatus_ONLINE)
case apiNodes[i].IsOffline():
node.SetState(control.NetmapStatus_OFFLINE)
}
nodes = append(nodes, node)
}
return nodes
}
func attributesFromAPI(apiNode netmapAPI.NodeInfo) []*control.NodeInfo_Attribute {
attrs := make([]*control.NodeInfo_Attribute, 0, apiNode.NumberOfAttributes())
apiNode.IterateAttributes(func(key, value string) {
a := new(control.NodeInfo_Attribute)
a.SetKey(key)
a.SetValue(value)
attrs = append(attrs, a)
})
return attrs
}

View File

@ -28,27 +28,6 @@ func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) {
}
}
// SetBody sets get netmap snapshot request body.
func (x *NetmapSnapshotRequest) SetBody(v *NetmapSnapshotRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetNetmap sets structure of the current network map.
func (x *NetmapSnapshotResponse_Body) SetNetmap(v *Netmap) {
if x != nil {
x.Netmap = v
}
}
// SetBody sets get netmap snapshot response body.
func (x *NetmapSnapshotResponse) SetBody(v *NetmapSnapshotResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetStatus sets new storage node status in NeoFS network map.
func (x *SetNetmapStatusRequest_Body) SetStatus(v NetmapStatus) {
if x != nil {

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,6 @@ service ControlService {
// Performs health check of the storage node.
rpc HealthCheck (HealthCheckRequest) returns (HealthCheckResponse);
// Returns network map snapshot of the current NeoFS epoch.
rpc NetmapSnapshot (NetmapSnapshotRequest) returns (NetmapSnapshotResponse);
// Sets status of the storage node in NeoFS network map.
rpc SetNetmapStatus (SetNetmapStatusRequest) returns (SetNetmapStatusResponse);
@ -70,34 +67,6 @@ message HealthCheckResponse {
Signature signature = 2;
}
// Get netmap snapshot request.
message NetmapSnapshotRequest {
// Get netmap snapshot request body.
message Body {
}
// Body of get netmap snapshot request message.
Body body = 1;
// Body signature.
Signature signature = 2;
}
// Get netmap snapshot request.
message NetmapSnapshotResponse {
// Get netmap snapshot response body
message Body {
// Structure of the requested network map.
Netmap netmap = 1 [json_name = "netmap"];
}
// Body of get netmap snapshot response message.
Body body = 1;
// Body signature.
Signature signature = 2;
}
// Set netmap status request.
message SetNetmapStatusRequest {
// Set netmap status request body.

View File

@ -1,13 +1,14 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.5
// - protoc v3.21.6
// source: pkg/services/control/service.proto
package control
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@ -24,8 +25,6 @@ const _ = grpc.SupportPackageIsVersion7
type ControlServiceClient interface {
// Performs health check of the storage node.
HealthCheck(ctx context.Context, in *HealthCheckRequest, opts ...grpc.CallOption) (*HealthCheckResponse, error)
// Returns network map snapshot of the current NeoFS epoch.
NetmapSnapshot(ctx context.Context, in *NetmapSnapshotRequest, opts ...grpc.CallOption) (*NetmapSnapshotResponse, error)
// Sets status of the storage node in NeoFS network map.
SetNetmapStatus(ctx context.Context, in *SetNetmapStatusRequest, opts ...grpc.CallOption) (*SetNetmapStatusResponse, error)
// Mark objects to be removed from node's local object storage.
@ -61,15 +60,6 @@ func (c *controlServiceClient) HealthCheck(ctx context.Context, in *HealthCheckR
return out, nil
}
func (c *controlServiceClient) NetmapSnapshot(ctx context.Context, in *NetmapSnapshotRequest, opts ...grpc.CallOption) (*NetmapSnapshotResponse, error) {
out := new(NetmapSnapshotResponse)
err := c.cc.Invoke(ctx, "/control.ControlService/NetmapSnapshot", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *controlServiceClient) SetNetmapStatus(ctx context.Context, in *SetNetmapStatusRequest, opts ...grpc.CallOption) (*SetNetmapStatusResponse, error) {
out := new(SetNetmapStatusResponse)
err := c.cc.Invoke(ctx, "/control.ControlService/SetNetmapStatus", in, out, opts...)
@ -148,8 +138,6 @@ func (c *controlServiceClient) EvacuateShard(ctx context.Context, in *EvacuateSh
type ControlServiceServer interface {
// Performs health check of the storage node.
HealthCheck(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error)
// Returns network map snapshot of the current NeoFS epoch.
NetmapSnapshot(context.Context, *NetmapSnapshotRequest) (*NetmapSnapshotResponse, error)
// Sets status of the storage node in NeoFS network map.
SetNetmapStatus(context.Context, *SetNetmapStatusRequest) (*SetNetmapStatusResponse, error)
// Mark objects to be removed from node's local object storage.
@ -175,9 +163,6 @@ type UnimplementedControlServiceServer struct {
func (UnimplementedControlServiceServer) HealthCheck(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method HealthCheck not implemented")
}
func (UnimplementedControlServiceServer) NetmapSnapshot(context.Context, *NetmapSnapshotRequest) (*NetmapSnapshotResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method NetmapSnapshot not implemented")
}
func (UnimplementedControlServiceServer) SetNetmapStatus(context.Context, *SetNetmapStatusRequest) (*SetNetmapStatusResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetNetmapStatus not implemented")
}
@ -232,24 +217,6 @@ func _ControlService_HealthCheck_Handler(srv interface{}, ctx context.Context, d
return interceptor(ctx, in, info, handler)
}
func _ControlService_NetmapSnapshot_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(NetmapSnapshotRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ControlServiceServer).NetmapSnapshot(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/control.ControlService/NetmapSnapshot",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ControlServiceServer).NetmapSnapshot(ctx, req.(*NetmapSnapshotRequest))
}
return interceptor(ctx, in, info, handler)
}
func _ControlService_SetNetmapStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetNetmapStatusRequest)
if err := dec(in); err != nil {
@ -405,10 +372,6 @@ var ControlService_ServiceDesc = grpc.ServiceDesc{
MethodName: "HealthCheck",
Handler: _ControlService_HealthCheck_Handler,
},
{
MethodName: "NetmapSnapshot",
Handler: _ControlService_NetmapSnapshot_Handler,
},
{
MethodName: "SetNetmapStatus",
Handler: _ControlService_SetNetmapStatus_Handler,

View File

@ -157,157 +157,6 @@ func (x *HealthCheckResponse) SetSignature(sig *Signature) {
x.Signature = sig
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *NetmapSnapshotRequest_Body) StableSize() (size int) {
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NetmapSnapshotRequest_Body) StableMarshal(buf []byte) []byte {
return buf
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *NetmapSnapshotRequest) StableSize() (size int) {
size += proto.NestedStructureSize(1, x.Body)
size += proto.NestedStructureSize(2, x.Signature)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NetmapSnapshotRequest) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(1, buf[offset:], x.Body)
offset += proto.NestedStructureMarshal(2, buf[offset:], x.Signature)
return buf
}
// ReadSignedData fills buf with signed data of x.
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *NetmapSnapshotRequest) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SignedDataSize returns size of the request signed data in bytes.
//
// Structures with the same field values have the same signed data size.
func (x *NetmapSnapshotRequest) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf), nil
}
func (x *NetmapSnapshotRequest) SetSignature(sig *Signature) {
x.Signature = sig
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *NetmapSnapshotResponse_Body) StableSize() (size int) {
size += proto.NestedStructureSize(1, x.Netmap)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NetmapSnapshotResponse_Body) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(1, buf[offset:], x.Netmap)
return buf
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.
func (x *NetmapSnapshotResponse) StableSize() (size int) {
size += proto.NestedStructureSize(1, x.Body)
size += proto.NestedStructureSize(2, x.Signature)
return size
}
// StableMarshal marshals x in protobuf binary format with stable field order.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *NetmapSnapshotResponse) StableMarshal(buf []byte) []byte {
if x == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, x.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(1, buf[offset:], x.Body)
offset += proto.NestedStructureMarshal(2, buf[offset:], x.Signature)
return buf
}
// ReadSignedData fills buf with signed data of x.
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *NetmapSnapshotResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SignedDataSize returns size of the request signed data in bytes.
//
// Structures with the same field values have the same signed data size.
func (x *NetmapSnapshotResponse) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf), nil
}
func (x *NetmapSnapshotResponse) SetSignature(sig *Signature) {
x.Signature = sig
}
// StableSize returns the size of x in protobuf format.
//
// Structures with the same field values have the same binary size.

View File

@ -33,30 +33,6 @@ func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bo
b1.GetHealthStatus() == b2.GetHealthStatus()
}
func TestNetmapSnapshotResponse_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateNetmapSnapshotResponseBody(),
new(control.NetmapSnapshotResponse_Body),
func(m1, m2 protoMessage) bool {
return equalNetmapSnapshotResponseBodies(
m1.(*control.NetmapSnapshotResponse_Body),
m2.(*control.NetmapSnapshotResponse_Body),
)
},
)
}
func generateNetmapSnapshotResponseBody() *control.NetmapSnapshotResponse_Body {
body := new(control.NetmapSnapshotResponse_Body)
body.SetNetmap(generateNetmap())
return body
}
func equalNetmapSnapshotResponseBodies(b1, b2 *control.NetmapSnapshotResponse_Body) bool {
return equalNetmaps(b1.GetNetmap(), b2.GetNetmap())
}
func TestSetNetmapStatusRequest_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateSetNetmapStatusRequestBody(),

View File

@ -1,16 +1,17 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.5
// protoc v3.21.6
// source: pkg/services/control/types.proto
package control
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
)
const (

View File

@ -26,6 +26,10 @@ type NodeState interface {
// Must return current node state
// in NeoFS API v2 NodeInfo structure.
LocalNodeInfo() (*netmap.NodeInfo, error)
// ProcessCurrentNetMap passes current local network map of the storage node
// into the given handler.
ProcessCurrentNetMap(func(netmapSDK.NetMap))
}
// NetworkInfo encapsulates source of the
@ -123,3 +127,19 @@ func (s *executorSvc) NetworkInfo(
return resp, nil
}
func (s *executorSvc) Snapshot(_ context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
var nmV2 netmap.NetMap
s.state.ProcessCurrentNetMap(func(netMap netmapSDK.NetMap) {
netMap.WriteToV2(&nmV2)
})
body := new(netmap.SnapshotResponseBody)
body.SetNetMap(&nmV2)
resp := new(netmap.SnapshotResponse)
resp.SetBody(body)
return resp, nil
}

View File

@ -48,3 +48,16 @@ func (s *responseService) NetworkInfo(ctx context.Context, req *netmap.NetworkIn
return resp.(*netmap.NetworkInfoResponse), nil
}
func (s *responseService) Snapshot(ctx context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
resp, err := s.respSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Snapshot(ctx, req.(*netmap.SnapshotRequest))
},
)
if err != nil {
return nil, err
}
return resp.(*netmap.SnapshotResponse), nil
}

View File

@ -10,4 +10,5 @@ import (
type Server interface {
LocalNodeInfo(context.Context, *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error)
NetworkInfo(context.Context, *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error)
Snapshot(context.Context, *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error)
}

View File

@ -54,3 +54,19 @@ func (s *signService) NetworkInfo(ctx context.Context, req *netmap.NetworkInfoRe
return resp.(*netmap.NetworkInfoResponse), nil
}
func (s *signService) Snapshot(ctx context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Snapshot(ctx, req.(*netmap.SnapshotRequest))
},
func() util.ResponseMessage {
return new(netmap.SnapshotResponse)
},
)
if err != nil {
return nil, err
}
return resp.(*netmap.SnapshotResponse), nil
}

View File

@ -4,7 +4,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.4
// protoc v3.21.6
// source: pkg/services/tree/service.proto
package tree

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.4
// - protoc v3.21.6
// source: pkg/services/tree/service.proto
package tree

View File

@ -4,7 +4,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.21.4
// protoc v3.21.6
// source: pkg/services/tree/types.proto
package tree