frostfs-node/cmd/frostfs-cli/modules/control/healthcheck.go
Airat Arifullin 9b13a18aac [#1479] go.mod: Bump frostfs-sdk-go version
* Update version within go.mod;
* Fix deprecated frostfs-api-go/v2 package and use frostfs-sdk-go/api
  instead.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-11-08 10:43:19 +03:00

66 lines
1.9 KiB
Go

package control
import (
"os"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
"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"
rawclient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
"github.com/spf13/cobra"
)
const (
healthcheckIRFlag = "ir"
)
var healthCheckCmd = &cobra.Command{
Use: "healthcheck",
Short: "Health check for FrostFS storage nodes",
Long: "Health check for FrostFS storage nodes.",
Run: healthCheck,
}
func initControlHealthCheckCmd() {
initControlFlags(healthCheckCmd)
flags := healthCheckCmd.Flags()
flags.Bool(healthcheckIRFlag, false, "Communicate with IR node")
flags.BoolP(commonflags.QuietFlag, commonflags.QuietFlagShorthand, false, commonflags.QuietFlagUsage)
_ = flags.MarkDeprecated(healthcheckIRFlag, "for health check of inner ring nodes, use the 'control ir healthcheck' command instead.")
}
func healthCheck(cmd *cobra.Command, args []string) {
if isIR, _ := cmd.Flags().GetBool(healthcheckIRFlag); isIR {
irHealthCheck(cmd, args)
return
}
pk := key.Get(cmd)
cli := getClient(cmd, pk)
req := new(control.HealthCheckRequest)
req.SetBody(new(control.HealthCheckRequest_Body))
signRequest(cmd, pk, req)
var resp *control.HealthCheckResponse
var err error
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.HealthCheck(client, req)
return err
})
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
if quietFlag, _ := cmd.Flags().GetBool(commonflags.QuietFlag); quietFlag {
if resp.GetBody().GetHealthStatus() == control.HealthStatus_READY {
return
}
os.Exit(1)
}
cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus())
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
}