Skip to content

Commit

Permalink
Feat/control service object list (#2933)
Browse files Browse the repository at this point in the history
Closes #2853.
  • Loading branch information
roman-khimov authored Sep 19, 2024
2 parents 4f22042 + e0af43c commit a1db57f
Show file tree
Hide file tree
Showing 25 changed files with 1,230 additions and 544 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog for NeoFS Node
- More effective FSTree writer for HDDs, new configuration options for it (#2814)
- New health status `INITIALIZING_NETWORK` in inner ring (#2934)
- Expose health status of inner ring via Prometheus (#2934)
- `neofs-cli control object list` command (#2853)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dep:
protoc:
@GOPRIVATE=github.com/nspcc-dev go mod vendor
# Install specific version for protobuf lib
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go install -v
@go list -f '{{.Path}}/...@{{.Version}}' -m google.golang.org/protobuf | xargs go install -v
@GOBIN=$(abspath $(BIN)) go install -mod=mod -v github.com/nspcc-dev/neofs-api-go/v2/util/protogen
# Protoc generate
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
Expand Down
18 changes: 18 additions & 0 deletions cmd/neofs-cli/modules/control/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package control

import (
"github.com/spf13/cobra"
)

var objectCmd = &cobra.Command{
Use: "object",
Short: "Direct object operations with storage engine",
}

func initControlObjectsCmd() {
objectCmd.AddCommand(listObjectsCmd)
objectCmd.AddCommand(objectStatusCmd)

initControlObjectsListCmd()
initObjectStatusFlags()
}
47 changes: 47 additions & 0 deletions cmd/neofs-cli/modules/control/object_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package control

import (
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"
)

var listObjectsCmd = &cobra.Command{
Use: "list",
Short: "Get list of all objects in the storage node",
Long: "Get list of all objects in the storage node",
Args: cobra.NoArgs,
Run: listObjects,
}

func initControlObjectsListCmd() {
initControlFlags(listObjectsCmd)
}

func listObjects(cmd *cobra.Command, _ []string) {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

pk := key.Get(cmd)

req := &control.ListObjectsRequest{
Body: &control.ListObjectsRequest_Body{},
}
signRequest(cmd, pk, req)

cli := getClient(ctx, cmd)

err := cli.ExecRaw(func(client *rawclient.Client) error {
return control.ListObjects(client, req, func(r *control.ListObjectsResponse) {
verifyResponse(cmd, r.GetSignature(), r.GetBody())

for _, address := range r.GetBody().GetObjectAddress() {
cmd.Println(string(address))
}
})
})
common.ExitOnErr(cmd, "rpc error: %w", err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (

const objectFlag = "object"

var objectCmd = &cobra.Command{
Use: "object",
Short: "Direct object operations with storage engine",
}

var objectStatusCmd = &cobra.Command{
Use: "status",
Short: "Check current object status",
Expand Down
6 changes: 1 addition & 5 deletions cmd/neofs-cli/modules/control/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const (
)

func init() {
objectCmd.AddCommand(
objectStatusCmd,
)

Cmd.AddCommand(
healthCheckCmd,
setNetmapStatusCmd,
Expand All @@ -45,5 +41,5 @@ func init() {
initControlDropObjectsCmd()
initControlShardsCmd()
initControlSynchronizeTreeCmd()
initObjectStatusFlags()
initControlObjectsCmd()
}
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func add(cmd *cobra.Command, _ []string) {
meta, err := parseMeta(cmd)
common.ExitOnErr(cmd, "meta data parsing: %w", err)

cli, err := _client(ctx)
cli, err := _client()
common.ExitOnErr(cmd, "client: %w", err)

rawCID := make([]byte, sha256.Size)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/add_by_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func addByPath(cmd *cobra.Command, _ []string) {

tid, _ := cmd.Flags().GetString(treeIDFlagKey)

cli, err := _client(ctx)
cli, err := _client()
common.ExitOnErr(cmd, "client: %w", err)

rawCID := make([]byte, sha256.Size)
Expand Down
14 changes: 3 additions & 11 deletions cmd/neofs-cli/modules/tree/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package tree

import (
"context"
"strings"
"time"

"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/pkg/network"
Expand All @@ -15,26 +13,20 @@ import (

// _client returns grpc Tree service client. Should be removed
// after making Tree API public.
func _client(ctx context.Context) (tree.TreeServiceClient, error) {
func _client() (tree.TreeServiceClient, error) {
var netAddr network.Address
err := netAddr.FromString(viper.GetString(commonflags.RPC))
if err != nil {
return nil, err
}

opts := make([]grpc.DialOption, 1, 2)
opts[0] = grpc.WithBlock()
opts := make([]grpc.DialOption, 0, 1)

if !strings.HasPrefix(netAddr.URIAddr(), "grpcs:") {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

// a default connection establishing timeout
const defaultClientConnectTimeout = time.Second * 2

ctx, cancel := context.WithTimeout(ctx, defaultClientConnectTimeout)
cc, err := grpc.DialContext(ctx, netAddr.URIAddr(), opts...)
cancel()
cc, err := grpc.NewClient(netAddr.URIAddr(), opts...)

return tree.NewTreeServiceClient(cc), err
}
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/get_by_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getByPath(cmd *cobra.Command, _ []string) {

tid, _ := cmd.Flags().GetString(treeIDFlagKey)

cli, err := _client(ctx)
cli, err := _client()
common.ExitOnErr(cmd, "client: %w", err)

rawCID := make([]byte, sha256.Size)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func list(cmd *cobra.Command, _ []string) {
err := cnr.DecodeString(cidString)
common.ExitOnErr(cmd, "decode container ID string: %w", err)

cli, err := _client(ctx)
cli, err := _client()
common.ExitOnErr(cmd, "client: %w", err)

rawCID := make([]byte, sha256.Size)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
golang.org/x/sync v0.6.0
golang.org/x/sys v0.18.0
golang.org/x/term v0.18.0
google.golang.org/grpc v1.62.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -50,7 +50,6 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
Expand Down Expand Up @@ -95,7 +94,7 @@ require (
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down Expand Up @@ -284,18 +280,16 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
19 changes: 19 additions & 0 deletions pkg/services/control/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ func (w *listShardsResponseWrapper) FromGRPCMessage(m grpc.Message) error {
return nil
}

type listObjectsResponseWrapper struct {
m *ListObjectsResponse
}

func (w *listObjectsResponseWrapper) ToGRPCMessage() grpc.Message {
return w.m
}

func (w *listObjectsResponseWrapper) FromGRPCMessage(m grpc.Message) error {
var ok bool

w.m, ok = m.(*ListObjectsResponse)
if !ok {
return message.NewUnexpectedMessageType(m, w.m)
}

return nil
}

type setShardModeResponseWrapper struct {
m *SetShardModeResponse
}
Expand Down
37 changes: 37 additions & 0 deletions pkg/services/control/rpc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package control

import (
"errors"
"io"

"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-api-go/v2/rpc/common"
)
Expand All @@ -12,6 +15,7 @@ const (
rpcSetNetmapStatus = "SetNetmapStatus"
rpcDropObjects = "DropObjects"
rpcListShards = "ListShards"
rpcListObjects = "ListObjects"
rpcSetShardMode = "SetShardMode"
rpcDumpShard = "DumpShard"
rpcRestoreShard = "RestoreShard"
Expand Down Expand Up @@ -107,6 +111,39 @@ func ListShards(
return wResp.m, nil
}

// ListObjects executes ControlService.ListObjects RPC.
func ListObjects(
cli *client.Client,
req *ListObjectsRequest,
handleResp func(*ListObjectsResponse),
opts ...client.CallOption,
) error {
wReq := &requestWrapper{
m: req,
}

stream, err := client.OpenServerStream(cli, common.CallMethodInfoServerStream(serviceName, rpcListObjects), wReq, opts...)
if err != nil {
return err
}

for {
wResp := &listObjectsResponseWrapper{
m: new(ListObjectsResponse),
}
err = stream.ReadMessage(wResp)
if errors.Is(err, io.EOF) {
break
}
if err != nil {
return err
}
handleResp(wResp.m)
}

return nil
}

// SetShardMode executes ControlService.SetShardMode RPC.
func SetShardMode(
cli *client.Client,
Expand Down
Loading

0 comments on commit a1db57f

Please sign in to comment.