[#60] cli: Add await
flag to control set-status
All checks were successful
DCO action / DCO (pull_request) Successful in 24m11s
Build / Build Components (1.21) (pull_request) Successful in 29m53s
Tests and linters / gopls check (pull_request) Successful in 29m20s
Vulncheck / Vulncheck (pull_request) Successful in 29m28s
Build / Build Components (1.22) (pull_request) Successful in 31m21s
Tests and linters / Staticcheck (pull_request) Successful in 35m29s
Pre-commit hooks / Pre-commit (pull_request) Successful in 38m33s
Tests and linters / Lint (pull_request) Successful in 2m29s
Tests and linters / Tests (1.21) (pull_request) Successful in 3m37s
Tests and linters / Tests (1.22) (pull_request) Successful in 13m55s
Tests and linters / Tests with -race (pull_request) Successful in 6m1s
All checks were successful
DCO action / DCO (pull_request) Successful in 24m11s
Build / Build Components (1.21) (pull_request) Successful in 29m53s
Tests and linters / gopls check (pull_request) Successful in 29m20s
Vulncheck / Vulncheck (pull_request) Successful in 29m28s
Build / Build Components (1.22) (pull_request) Successful in 31m21s
Tests and linters / Staticcheck (pull_request) Successful in 35m29s
Pre-commit hooks / Pre-commit (pull_request) Successful in 38m33s
Tests and linters / Lint (pull_request) Successful in 2m29s
Tests and linters / Tests (1.21) (pull_request) Successful in 3m37s
Tests and linters / Tests (1.22) (pull_request) Successful in 13m55s
Tests and linters / Tests with -race (pull_request) Successful in 6m1s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
a83eeddb1d
commit
46732b61d7
2 changed files with 67 additions and 0 deletions
|
@ -50,6 +50,9 @@ const (
|
|||
|
||||
TracingFlag = "trace"
|
||||
TracingFlagUsage = "Generate trace ID and print it."
|
||||
|
||||
AwaitFlag = "await"
|
||||
AwaitFlagUsage = "Wait for the operation to complete"
|
||||
)
|
||||
|
||||
// Init adds common flags to the command:
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
||||
|
@ -9,6 +12,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||||
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -18,8 +22,13 @@ const (
|
|||
netmapStatusOnline = "online"
|
||||
netmapStatusOffline = "offline"
|
||||
netmapStatusMaintenance = "maintenance"
|
||||
|
||||
maxSetStatusMaxWaitTime = 30 * time.Minute
|
||||
setStatusWaitTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
var errNetmapStatusAwaitFailed = errors.New("netmap status hasn't changed for 30 minutes")
|
||||
|
||||
var setNetmapStatusCmd = &cobra.Command{
|
||||
Use: "set-status",
|
||||
Short: "Set status of the storage node in FrostFS network map",
|
||||
|
@ -43,6 +52,8 @@ func initControlSetNetmapStatusCmd() {
|
|||
|
||||
flags.BoolP(commonflags.ForceFlag, commonflags.ForceFlagShorthand, false,
|
||||
"Force turning to local maintenance")
|
||||
|
||||
flags.Bool(commonflags.AwaitFlag, false, commonflags.AwaitFlagUsage)
|
||||
}
|
||||
|
||||
func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
||||
|
@ -56,15 +67,19 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
|||
}
|
||||
}
|
||||
|
||||
await, _ := cmd.Flags().GetBool(commonflags.AwaitFlag)
|
||||
var targetStatus control.NetmapStatus
|
||||
switch st, _ := cmd.Flags().GetString(netmapStatusFlag); st {
|
||||
default:
|
||||
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("unsupported status %s", st))
|
||||
case netmapStatusOnline:
|
||||
body.SetStatus(control.NetmapStatus_ONLINE)
|
||||
printIgnoreForce(control.NetmapStatus_ONLINE)
|
||||
targetStatus = control.NetmapStatus_ONLINE
|
||||
case netmapStatusOffline:
|
||||
body.SetStatus(control.NetmapStatus_OFFLINE)
|
||||
printIgnoreForce(control.NetmapStatus_OFFLINE)
|
||||
targetStatus = control.NetmapStatus_OFFLINE
|
||||
case netmapStatusMaintenance:
|
||||
body.SetStatus(control.NetmapStatus_MAINTENANCE)
|
||||
|
||||
|
@ -72,6 +87,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
|||
body.SetForceMaintenance()
|
||||
common.PrintVerbose(cmd, "Local maintenance will be forced.")
|
||||
}
|
||||
targetStatus = control.NetmapStatus_MAINTENANCE
|
||||
}
|
||||
|
||||
req := new(control.SetNetmapStatusRequest)
|
||||
|
@ -92,4 +108,52 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
|||
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
||||
|
||||
cmd.Println("Network status update request successfully sent.")
|
||||
|
||||
if await {
|
||||
awaitSetNetmapStatus(cmd, pk, cli, targetStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func awaitSetNetmapStatus(cmd *cobra.Command, pk *ecdsa.PrivateKey, cli *client.Client, targetStatus control.NetmapStatus) {
|
||||
req := &control.GetNetmapStatusRequest{
|
||||
Body: &control.GetNetmapStatusRequest_Body{},
|
||||
}
|
||||
signRequest(cmd, pk, req)
|
||||
var epoch uint64
|
||||
var status control.NetmapStatus
|
||||
startTime := time.Now()
|
||||
cmd.Println("Wait until epoch and netmap status change...")
|
||||
for {
|
||||
var resp *control.GetNetmapStatusResponse
|
||||
var err error
|
||||
err = cli.ExecRaw(func(client *rawclient.Client) error {
|
||||
resp, err = control.GetNetmapStatus(client, req)
|
||||
return err
|
||||
})
|
||||
commonCmd.ExitOnErr(cmd, "failed to get current netmap status: %w", err)
|
||||
|
||||
if epoch == 0 {
|
||||
epoch = resp.GetBody().GetEpoch()
|
||||
}
|
||||
|
||||
status = resp.GetBody().GetStatus()
|
||||
if resp.GetBody().GetEpoch() > epoch {
|
||||
epoch = resp.GetBody().GetEpoch()
|
||||
cmd.Printf("Epoch changed to %d\n", resp.GetBody().GetEpoch())
|
||||
}
|
||||
|
||||
if status == targetStatus {
|
||||
break
|
||||
}
|
||||
|
||||
if time.Since(startTime) > maxSetStatusMaxWaitTime {
|
||||
commonCmd.ExitOnErr(cmd, "failed to wait netmap status: %w", errNetmapStatusAwaitFailed)
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(setStatusWaitTimeout)
|
||||
|
||||
cmd.Printf("Current netmap status '%s', target status '%s'\n", status.String(), targetStatus.String())
|
||||
}
|
||||
cmd.Printf("Netmap status changed to '%s' successfully.\n", status.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue