From e3ad3c296510ab08132c73d372de9173a852eb52 Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Thu, 18 May 2023 13:08:05 +0300 Subject: [PATCH] [#283] cli: Move control healthcheck command under control ir Signed-off-by: Alejandro Lopez --- .../modules/control/healthcheck.go | 41 ++++------------- cmd/frostfs-cli/modules/control/ir.go | 2 + .../modules/control/ir_healthcheck.go | 44 +++++++++++++++++++ 3 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 cmd/frostfs-cli/modules/control/ir_healthcheck.go diff --git a/cmd/frostfs-cli/modules/control/healthcheck.go b/cmd/frostfs-cli/modules/control/healthcheck.go index 8d18a5c11..097fba540 100644 --- a/cmd/frostfs-cli/modules/control/healthcheck.go +++ b/cmd/frostfs-cli/modules/control/healthcheck.go @@ -1,15 +1,10 @@ package control import ( - "crypto/ecdsa" - rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "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" - ircontrol "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir" - ircontrolsrv "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir/server" - "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" "github.com/spf13/cobra" ) @@ -19,8 +14,8 @@ const ( var healthCheckCmd = &cobra.Command{ Use: "healthcheck", - Short: "Health check of the FrostFS node", - Long: "Health check of the FrostFS node. Checks storage node by default, use --ir flag to work with Inner Ring.", + Short: "Health check for FrostFS storage nodes", + Long: "Health check for FrostFS storage nodes.", Run: healthCheck, } @@ -29,18 +24,18 @@ func initControlHealthCheckCmd() { flags := healthCheckCmd.Flags() flags.Bool(healthcheckIRFlag, false, "Communicate with IR node") + _ = flags.MarkDeprecated(healthcheckIRFlag, "for health check of inner ring nodes, use the 'control ir healthcheck' command instead.") } -func healthCheck(cmd *cobra.Command, _ []string) { - pk := key.Get(cmd) - - cli := getClient(cmd, pk) - +func healthCheck(cmd *cobra.Command, args []string) { if isIR, _ := cmd.Flags().GetBool(healthcheckIRFlag); isIR { - healthCheckIR(cmd, pk, cli) + irHealthCheck(cmd, args) return } + pk := key.Get(cmd) + cli := getClient(cmd, pk) + req := new(control.HealthCheckRequest) req.SetBody(new(control.HealthCheckRequest_Body)) @@ -59,23 +54,3 @@ func healthCheck(cmd *cobra.Command, _ []string) { cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus()) cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) } - -func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) { - req := new(ircontrol.HealthCheckRequest) - - req.SetBody(new(ircontrol.HealthCheckRequest_Body)) - - err := ircontrolsrv.SignMessage(key, req) - commonCmd.ExitOnErr(cmd, "could not sign request: %w", err) - - var resp *ircontrol.HealthCheckResponse - err = c.ExecRaw(func(client *rawclient.Client) error { - resp, err = ircontrol.HealthCheck(client, req) - return err - }) - commonCmd.ExitOnErr(cmd, "rpc error: %w", err) - - verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) - - cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) -} diff --git a/cmd/frostfs-cli/modules/control/ir.go b/cmd/frostfs-cli/modules/control/ir.go index ae3f8502c..396d5d0a5 100644 --- a/cmd/frostfs-cli/modules/control/ir.go +++ b/cmd/frostfs-cli/modules/control/ir.go @@ -11,7 +11,9 @@ var irCmd = &cobra.Command{ func initControlIRCmd() { irCmd.AddCommand(tickEpochCmd) irCmd.AddCommand(removeNodeCmd) + irCmd.AddCommand(irHealthCheckCmd) initControlIRTickEpochCmd() initControlIRRemoveNodeCmd() + initControlIRHealthCheckCmd() } diff --git a/cmd/frostfs-cli/modules/control/ir_healthcheck.go b/cmd/frostfs-cli/modules/control/ir_healthcheck.go new file mode 100644 index 000000000..e70538ce2 --- /dev/null +++ b/cmd/frostfs-cli/modules/control/ir_healthcheck.go @@ -0,0 +1,44 @@ +package control + +import ( + rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" + commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" + ircontrol "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir" + ircontrolsrv "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir/server" + "github.com/spf13/cobra" +) + +var irHealthCheckCmd = &cobra.Command{ + Use: "healthcheck", + Short: "Health check for FrostFS inner ring nodes", + Long: "Health check for FrostFS inner ring nodes.", + Run: irHealthCheck, +} + +func initControlIRHealthCheckCmd() { + initControlFlags(irHealthCheckCmd) +} + +func irHealthCheck(cmd *cobra.Command, _ []string) { + pk := key.Get(cmd) + cli := getClient(cmd, pk) + + req := new(ircontrol.HealthCheckRequest) + + req.SetBody(new(ircontrol.HealthCheckRequest_Body)) + + err := ircontrolsrv.SignMessage(pk, req) + commonCmd.ExitOnErr(cmd, "could not sign request: %w", err) + + var resp *ircontrol.HealthCheckResponse + err = cli.ExecRaw(func(client *rawclient.Client) error { + resp, err = ircontrol.HealthCheck(client, req) + return err + }) + commonCmd.ExitOnErr(cmd, "rpc error: %w", err) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) +}