forked from TrueCloudLab/frostfs-node
[#1048] cli: Add shard list
operation
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
284188f8f9
commit
f5a9735e1c
2 changed files with 88 additions and 3 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/mr-tron/base58"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
||||||
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
|
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
|
||||||
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
||||||
|
@ -47,6 +48,19 @@ var setNetmapStatusCmd = &cobra.Command{
|
||||||
Run: setNetmapStatus,
|
Run: setNetmapStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var listShardsCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "List shards of the storage node",
|
||||||
|
Long: "List shards of the storage node",
|
||||||
|
Run: listShards,
|
||||||
|
}
|
||||||
|
|
||||||
|
var shardsCmd = &cobra.Command{
|
||||||
|
Use: "shards",
|
||||||
|
Short: "Operations with storage node's shards",
|
||||||
|
Long: "Operations with storage node's shards",
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
netmapStatusFlag = "status"
|
netmapStatusFlag = "status"
|
||||||
|
|
||||||
|
@ -82,6 +96,14 @@ func initControlHealthCheckCmd() {
|
||||||
flags.BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
flags.BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initControlShardsListCmd() {
|
||||||
|
initCommonFlagsWithoutRPC(listShardsCmd)
|
||||||
|
|
||||||
|
flags := listShardsCmd.Flags()
|
||||||
|
|
||||||
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||||
|
}
|
||||||
|
|
||||||
func initControlSetNetmapStatusCmd() {
|
func initControlSetNetmapStatusCmd() {
|
||||||
initCommonFlagsWithoutRPC(setNetmapStatusCmd)
|
initCommonFlagsWithoutRPC(setNetmapStatusCmd)
|
||||||
|
|
||||||
|
@ -124,17 +146,21 @@ func initControlSnapshotCmd() {
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(controlCmd)
|
rootCmd.AddCommand(controlCmd)
|
||||||
|
|
||||||
|
shardsCmd.AddCommand(listShardsCmd)
|
||||||
|
|
||||||
controlCmd.AddCommand(
|
controlCmd.AddCommand(
|
||||||
healthCheckCmd,
|
healthCheckCmd,
|
||||||
setNetmapStatusCmd,
|
setNetmapStatusCmd,
|
||||||
dropObjectsCmd,
|
dropObjectsCmd,
|
||||||
snapshotCmd,
|
snapshotCmd,
|
||||||
|
shardsCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
initControlHealthCheckCmd()
|
initControlHealthCheckCmd()
|
||||||
initControlSetNetmapStatusCmd()
|
initControlSetNetmapStatusCmd()
|
||||||
initControlDropObjectsCmd()
|
initControlDropObjectsCmd()
|
||||||
initControlSnapshotCmd()
|
initControlSnapshotCmd()
|
||||||
|
initControlShardsListCmd()
|
||||||
}
|
}
|
||||||
|
|
||||||
func healthCheck(cmd *cobra.Command, _ []string) {
|
func healthCheck(cmd *cobra.Command, _ []string) {
|
||||||
|
@ -335,6 +361,34 @@ var snapshotCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listShards(cmd *cobra.Command, _ []string) {
|
||||||
|
key, err := getKey()
|
||||||
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
|
req := new(control.ListShardsRequest)
|
||||||
|
req.SetBody(new(control.ListShardsRequest_Body))
|
||||||
|
|
||||||
|
err = controlSvc.SignMessage(key, req)
|
||||||
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
||||||
|
|
||||||
|
cli, err := getControlSDKClient(key)
|
||||||
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
|
resp, err := control.ListShards(cli.Raw(), req)
|
||||||
|
exitOnErr(cmd, errf("rpc error: %w", err))
|
||||||
|
|
||||||
|
sign := resp.GetSignature()
|
||||||
|
err = signature.VerifyDataWithSource(
|
||||||
|
resp,
|
||||||
|
func() ([]byte, []byte) {
|
||||||
|
return sign.GetKey(), sign.GetSign()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
exitOnErr(cmd, errf("invalid response signature: %w", err))
|
||||||
|
|
||||||
|
prettyPrintShards(cmd, resp.GetBody().GetShards())
|
||||||
|
}
|
||||||
|
|
||||||
// getControlSDKClient is the same getSDKClient but with
|
// getControlSDKClient is the same getSDKClient but with
|
||||||
// another RPC endpoint flag.
|
// another RPC endpoint flag.
|
||||||
func getControlSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
func getControlSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
||||||
|
@ -359,3 +413,34 @@ func getControlSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
||||||
|
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) {
|
||||||
|
for _, i := range ii {
|
||||||
|
var mode string
|
||||||
|
|
||||||
|
switch i.GetMode() {
|
||||||
|
case control.ShardMode_READ_WRITE:
|
||||||
|
mode = "read-write"
|
||||||
|
case control.ShardMode_READ_ONLY:
|
||||||
|
mode = "read-only"
|
||||||
|
default:
|
||||||
|
mode = "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
pathPrinter := func(name, path string) string {
|
||||||
|
if path == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s: %s\n", name, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Shard %s:\nMode: %s\n"+
|
||||||
|
pathPrinter("Metabase", i.GetMetabasePath())+
|
||||||
|
pathPrinter("Blobstor", i.GetBlobstorPath())+
|
||||||
|
pathPrinter("Write-cache", i.GetWritecachePath())+"\n",
|
||||||
|
base58.Encode(i.Shard_ID),
|
||||||
|
mode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -329,7 +329,7 @@ func (x *ShardInfo) SetMetabasePath(v string) {
|
||||||
|
|
||||||
// SetBlobstorePath sets path to shard's blobstore.
|
// SetBlobstorePath sets path to shard's blobstore.
|
||||||
func (x *ShardInfo) SetBlobstorePath(v string) {
|
func (x *ShardInfo) SetBlobstorePath(v string) {
|
||||||
x.BlobstorePath = v
|
x.BlobstorPath = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWriteCachePath sets path to shard's write-cache.
|
// SetWriteCachePath sets path to shard's write-cache.
|
||||||
|
@ -364,7 +364,7 @@ func (x *ShardInfo) StableSize() int {
|
||||||
|
|
||||||
size += proto.BytesSize(shardInfoIDFNum, x.Shard_ID)
|
size += proto.BytesSize(shardInfoIDFNum, x.Shard_ID)
|
||||||
size += proto.StringSize(shardInfoMetabaseFNum, x.MetabasePath)
|
size += proto.StringSize(shardInfoMetabaseFNum, x.MetabasePath)
|
||||||
size += proto.StringSize(shardInfoBlobstoreFNum, x.BlobstorePath)
|
size += proto.StringSize(shardInfoBlobstoreFNum, x.BlobstorPath)
|
||||||
size += proto.StringSize(shardInfoWriteCacheFNum, x.WritecachePath)
|
size += proto.StringSize(shardInfoWriteCacheFNum, x.WritecachePath)
|
||||||
size += proto.EnumSize(shardInfoModeFNum, int32(x.Mode))
|
size += proto.EnumSize(shardInfoModeFNum, int32(x.Mode))
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ func (x *ShardInfo) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
|
|
||||||
offset += n
|
offset += n
|
||||||
|
|
||||||
n, err = proto.StringMarshal(shardInfoBlobstoreFNum, buf[offset:], x.BlobstorePath)
|
n, err = proto.StringMarshal(shardInfoBlobstoreFNum, buf[offset:], x.BlobstorPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue