From 8fc88487db0157ff47cd7361fedcc64affb049f6 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 13 Sep 2022 13:33:14 +0300 Subject: [PATCH] [#1731] neofs-cli: Add `control shards evacuate` command Signed-off-by: Evgenii Stratonikov --- .../modules/control/evacuate_shard.go | 55 +++++++++++++++++++ cmd/neofs-cli/modules/control/shards.go | 2 + 2 files changed, 57 insertions(+) create mode 100644 cmd/neofs-cli/modules/control/evacuate_shard.go diff --git a/cmd/neofs-cli/modules/control/evacuate_shard.go b/cmd/neofs-cli/modules/control/evacuate_shard.go new file mode 100644 index 000000000..f92e63b4f --- /dev/null +++ b/cmd/neofs-cli/modules/control/evacuate_shard.go @@ -0,0 +1,55 @@ +package control + +import ( + "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 evacuateShardCmd = &cobra.Command{ + Use: "evacuate", + Short: "Evacuate objects from shard", + Long: "Evacuate objects from shard to other shards", + Run: evacuateShard, +} + +func evacuateShard(cmd *cobra.Command, _ []string) { + pk := key.Get(cmd) + + req := &control.EvacuateShardRequest{Body: new(control.EvacuateShardRequest_Body)} + req.Body.Shard_ID = getShardID(cmd) + req.Body.IgnoreErrors, _ = cmd.Flags().GetBool(dumpIgnoreErrorsFlag) + + signRequest(cmd, pk, req) + + cli := getClient(cmd, pk) + + var resp *control.EvacuateShardResponse + var err error + err = cli.ExecRaw(func(client *client.Client) error { + resp, err = control.EvacuateShard(client, req) + return err + }) + common.ExitOnErr(cmd, "rpc error: %w", err) + + cmd.Printf("Objects moved: %d\n", resp.GetBody().GetCount()) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + cmd.Println("Shard has successfully been evacuated.") +} + +func initControlEvacuateShardCmd() { + commonflags.InitWithoutRPC(evacuateShardCmd) + + flags := evacuateShardCmd.Flags() + flags.String(controlRPC, controlRPCDefault, controlRPCUsage) + flags.String(shardIDFlag, "", "Shard ID in base58 encoding") + flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects") + + _ = evacuateShardCmd.MarkFlagRequired(shardIDFlag) + _ = evacuateShardCmd.MarkFlagRequired(controlRPC) +} diff --git a/cmd/neofs-cli/modules/control/shards.go b/cmd/neofs-cli/modules/control/shards.go index 91543412c..228703ea7 100644 --- a/cmd/neofs-cli/modules/control/shards.go +++ b/cmd/neofs-cli/modules/control/shards.go @@ -15,9 +15,11 @@ func initControlShardsCmd() { shardsCmd.AddCommand(setShardModeCmd) shardsCmd.AddCommand(dumpShardCmd) shardsCmd.AddCommand(restoreShardCmd) + shardsCmd.AddCommand(evacuateShardCmd) initControlShardsListCmd() initControlSetShardModeCmd() initControlDumpShardCmd() initControlRestoreShardCmd() + initControlEvacuateShardCmd() }