From 17f5463389f54f083b6ead323e80d61f137101b7 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 13 Mar 2024 10:40:44 +0300 Subject: [PATCH] [#1043] cli: Add reset evacuation status command Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-cli/modules/control/evacuation.go | 32 ++++++++++++ docs/evacuation.md | 2 + pkg/services/control/rpc.go | 52 ++++++++++++------- 3 files changed, 67 insertions(+), 19 deletions(-) diff --git a/cmd/frostfs-cli/modules/control/evacuation.go b/cmd/frostfs-cli/modules/control/evacuation.go index 1d192aa50..6fa5ed75c 100644 --- a/cmd/frostfs-cli/modules/control/evacuation.go +++ b/cmd/frostfs-cli/modules/control/evacuation.go @@ -53,6 +53,13 @@ var stopEvacuationShardCmd = &cobra.Command{ Run: stopEvacuateShardStatus, } +var resetEvacuationStatusShardCmd = &cobra.Command{ + Use: "reset", + Short: "Reset evacuate objects from shard status", + Long: "Reset evacuate objects from shard to other shards status", + Run: resetEvacuateShardStatus, +} + func startEvacuateShard(cmd *cobra.Command, _ []string) { pk := key.Get(cmd) @@ -152,6 +159,29 @@ func stopEvacuateShardStatus(cmd *cobra.Command, _ []string) { cmd.Println("Evacuation stopped.") } +func resetEvacuateShardStatus(cmd *cobra.Command, _ []string) { + pk := key.Get(cmd) + req := &control.ResetShardEvacuationStatusRequest{ + Body: &control.ResetShardEvacuationStatusRequest_Body{}, + } + + signRequest(cmd, pk, req) + + cli := getClient(cmd, pk) + + var resp *control.ResetShardEvacuationStatusResponse + var err error + err = cli.ExecRaw(func(client *client.Client) error { + resp, err = control.ResetShardEvacuationStatus(client, req) + return err + }) + commonCmd.ExitOnErr(cmd, "Reset shards evacuation status failed, rpc error: %w", err) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + cmd.Println("Shards evacuation status has been reset.") +} + func waitEvacuateCompletion(cmd *cobra.Command, pk *ecdsa.PrivateKey, cli *clientSDK.Client, printProgress, printCompleted bool) { const statusPollingInterval = 1 * time.Second const reportIntervalSeconds = 5 @@ -323,10 +353,12 @@ func initControlEvacuationShardCmd() { evacuationShardCmd.AddCommand(startEvacuationShardCmd) evacuationShardCmd.AddCommand(getEvacuationShardStatusCmd) evacuationShardCmd.AddCommand(stopEvacuationShardCmd) + evacuationShardCmd.AddCommand(resetEvacuationStatusShardCmd) initControlStartEvacuationShardCmd() initControlFlags(getEvacuationShardStatusCmd) initControlFlags(stopEvacuationShardCmd) + initControlFlags(resetEvacuationStatusShardCmd) } func initControlStartEvacuationShardCmd() { diff --git a/docs/evacuation.md b/docs/evacuation.md index 1bccc87bf..602e32e9b 100644 --- a/docs/evacuation.md +++ b/docs/evacuation.md @@ -20,6 +20,8 @@ Only one running evacuation process is allowed on the node at a time. `frostfs-cli control shards evacuation status` prints evacuation process status. +`frostfs-cli control shards evacuation reset` resets evacuation process status. + See commands `--help` output for detailed description. ## Examples diff --git a/pkg/services/control/rpc.go b/pkg/services/control/rpc.go index 877bb63c2..b07b10274 100644 --- a/pkg/services/control/rpc.go +++ b/pkg/services/control/rpc.go @@ -8,25 +8,26 @@ import ( const serviceName = "control.ControlService" const ( - rpcHealthCheck = "HealthCheck" - rpcSetNetmapStatus = "SetNetmapStatus" - rpcDropObjects = "DropObjects" - rpcListShards = "ListShards" - rpcSetShardMode = "SetShardMode" - rpcSynchronizeTree = "SynchronizeTree" - rpcEvacuateShard = "EvacuateShard" - rpcStartShardEvacuation = "StartShardEvacuation" - rpcGetShardEvacuationStatus = "GetShardEvacuationStatus" - rpcStopShardEvacuation = "StopShardEvacuation" - rpcFlushCache = "FlushCache" - rpcDoctor = "Doctor" - rpcAddChainLocalOverride = "AddChainLocalOverride" - rpcGetChainLocalOverride = "GetChainLocalOverride" - rpcListChainLocalOverrides = "ListChainLocalOverrides" - rpcRemoveChainLocalOverride = "RemoveChainLocalOverride" - rpcSealWriteCache = "SealWriteCache" - rpcListTargetsLocalOverrides = "ListTargetsLocalOverrides" - rpcDetachShards = "DetachShards" + rpcHealthCheck = "HealthCheck" + rpcSetNetmapStatus = "SetNetmapStatus" + rpcDropObjects = "DropObjects" + rpcListShards = "ListShards" + rpcSetShardMode = "SetShardMode" + rpcSynchronizeTree = "SynchronizeTree" + rpcEvacuateShard = "EvacuateShard" + rpcStartShardEvacuation = "StartShardEvacuation" + rpcGetShardEvacuationStatus = "GetShardEvacuationStatus" + rpcResetShardEvacuationStatus = "ResetShardEvacuationStatus" + rpcStopShardEvacuation = "StopShardEvacuation" + rpcFlushCache = "FlushCache" + rpcDoctor = "Doctor" + rpcAddChainLocalOverride = "AddChainLocalOverride" + rpcGetChainLocalOverride = "GetChainLocalOverride" + rpcListChainLocalOverrides = "ListChainLocalOverrides" + rpcRemoveChainLocalOverride = "RemoveChainLocalOverride" + rpcSealWriteCache = "SealWriteCache" + rpcListTargetsLocalOverrides = "ListTargetsLocalOverrides" + rpcDetachShards = "DetachShards" ) // HealthCheck executes ControlService.HealthCheck RPC. @@ -190,6 +191,19 @@ func StopShardEvacuation(cli *client.Client, req *StopShardEvacuationRequest, op return wResp.message, nil } +// ResetShardEvacuationStatus executes ControlService.ResetShardEvacuationStatus RPC. +func ResetShardEvacuationStatus(cli *client.Client, req *ResetShardEvacuationStatusRequest, opts ...client.CallOption) (*ResetShardEvacuationStatusResponse, error) { + wResp := newResponseWrapper[ResetShardEvacuationStatusResponse]() + wReq := &requestWrapper{m: req} + + err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcResetShardEvacuationStatus), wReq, wResp, opts...) + if err != nil { + return nil, err + } + + return wResp.message, nil +} + // FlushCache executes ControlService.FlushCache RPC. func FlushCache(cli *client.Client, req *FlushCacheRequest, opts ...client.CallOption) (*FlushCacheResponse, error) { wResp := newResponseWrapper[FlushCacheResponse]()