From 0e5410603e85e1b58fbb597f49ee298fdb03fbcb Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 17 Dec 2021 18:55:59 +0300 Subject: [PATCH] [#1048] control: Add `ListShards` implementation to ctrl svc Signed-off-by: Pavel Karpy --- cmd/neofs-node/control.go | 1 + pkg/services/control/server/list_shards.go | 50 ++++++++++++++++++++++ pkg/services/control/server/server.go | 12 ++++++ 3 files changed, 63 insertions(+) create mode 100644 pkg/services/control/server/list_shards.go diff --git a/cmd/neofs-node/control.go b/cmd/neofs-node/control.go index 33f9d9e53c..69b9306049 100644 --- a/cmd/neofs-node/control.go +++ b/cmd/neofs-node/control.go @@ -40,6 +40,7 @@ func initControlService(c *cfg) { return err }), + controlSvc.WithLocalStorage(c.cfgObject.cfgLocalStorage.localStorage), ) lis, err := net.Listen("tcp", endpoint) diff --git a/pkg/services/control/server/list_shards.go b/pkg/services/control/server/list_shards.go new file mode 100644 index 0000000000..e5de3b996a --- /dev/null +++ b/pkg/services/control/server/list_shards.go @@ -0,0 +1,50 @@ +package control + +import ( + "context" + + "github.com/nspcc-dev/neofs-node/pkg/services/control" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (s *Server) ListShards(_ context.Context, req *control.ListShardsRequest) (*control.ListShardsResponse, error) { + // verify request + if err := s.isValidRequest(req); err != nil { + return nil, status.Error(codes.PermissionDenied, err.Error()) + } + + // create and fill response + resp := new(control.ListShardsResponse) + + body := new(control.ListShardsResponse_Body) + resp.SetBody(body) + + info := s.s.DumpInfo() + + shardInfos := make([]*control.ShardInfo, 0, len(info.Shards)) + + for _, shard := range info.Shards { + si := new(control.ShardInfo) + + si.SetID(*shard.ID) + si.SetMetabasePath(shard.MetaBaseInfo.Path) + si.SetBlobstorePath(shard.BlobStorInfo.RootPath) + si.SetWriteCachePath(shard.WriteCacheInfo.Path) + + // FIXME: use real shard mode when there are more than just `read-write` + // after https://github.com/nspcc-dev/neofs-node/issues/1044 + si.SetMode(control.ShardMode_READ_WRITE) + + shardInfos = append(shardInfos, si) + } + + body.SetShards(shardInfos) + + // sign the response + if err := SignMessage(s.key, resp); err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return resp, nil +} diff --git a/pkg/services/control/server/server.go b/pkg/services/control/server/server.go index c6f84b1edf..562e5dc27d 100644 --- a/pkg/services/control/server/server.go +++ b/pkg/services/control/server/server.go @@ -3,6 +3,8 @@ package control import ( "crypto/ecdsa" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" + "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/services/control" ) @@ -49,6 +51,8 @@ type cfg struct { nodeState NodeState delObjHandler DeletedObjectHandler + + s *engine.StorageEngine } func defaultCfg() *cfg { @@ -113,3 +117,11 @@ func WithDeletedObjectHandler(h DeletedObjectHandler) Option { c.delObjHandler = h } } + +// WithLocalStorage returns option to set local storage engine that +// contains information about shards. +func WithLocalStorage(engine *engine.StorageEngine) Option { + return func(c *cfg) { + c.s = engine + } +}