2022-05-23 16:26:27 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
2024-07-08 15:04:30 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
2023-03-07 13:38:26 +00:00
|
|
|
"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"
|
2024-11-07 14:32:10 +00:00
|
|
|
rawclient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
2022-05-23 16:26:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
healthcheckIRFlag = "ir"
|
|
|
|
)
|
|
|
|
|
|
|
|
var healthCheckCmd = &cobra.Command{
|
|
|
|
Use: "healthcheck",
|
2023-05-18 10:08:05 +00:00
|
|
|
Short: "Health check for FrostFS storage nodes",
|
|
|
|
Long: "Health check for FrostFS storage nodes.",
|
2022-05-23 16:26:27 +00:00
|
|
|
Run: healthCheck,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlHealthCheckCmd() {
|
2022-10-17 15:37:15 +00:00
|
|
|
initControlFlags(healthCheckCmd)
|
2022-05-23 16:26:27 +00:00
|
|
|
|
|
|
|
flags := healthCheckCmd.Flags()
|
|
|
|
flags.Bool(healthcheckIRFlag, false, "Communicate with IR node")
|
2024-07-08 15:04:30 +00:00
|
|
|
flags.BoolP(commonflags.QuietFlag, commonflags.QuietFlagShorthand, false, commonflags.QuietFlagUsage)
|
2023-05-18 10:08:05 +00:00
|
|
|
_ = flags.MarkDeprecated(healthcheckIRFlag, "for health check of inner ring nodes, use the 'control ir healthcheck' command instead.")
|
2022-05-23 16:26:27 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 10:08:05 +00:00
|
|
|
func healthCheck(cmd *cobra.Command, args []string) {
|
2022-05-23 16:26:27 +00:00
|
|
|
if isIR, _ := cmd.Flags().GetBool(healthcheckIRFlag); isIR {
|
2023-05-18 10:08:05 +00:00
|
|
|
irHealthCheck(cmd, args)
|
2022-05-23 16:26:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 10:08:05 +00:00
|
|
|
pk := key.Get(cmd)
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
|
2022-05-23 16:26:27 +00:00
|
|
|
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
|
|
|
|
})
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-05-23 16:26:27 +00:00
|
|
|
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
2024-07-08 15:04:30 +00:00
|
|
|
if quietFlag, _ := cmd.Flags().GetBool(commonflags.QuietFlag); quietFlag {
|
|
|
|
if resp.GetBody().GetHealthStatus() == control.HealthStatus_READY {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-05-23 16:26:27 +00:00
|
|
|
|
|
|
|
cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus())
|
|
|
|
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
|
|
|
}
|