2023-05-18 10:08:05 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
2024-07-08 15:04:30 +00:00
|
|
|
"os"
|
|
|
|
|
2023-05-18 10:08:05 +00:00
|
|
|
rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
2024-07-08 15:04:30 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
2023-05-18 10:08:05 +00:00
|
|
|
"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)
|
2024-07-08 15:04:30 +00:00
|
|
|
flags := irHealthCheckCmd.Flags()
|
|
|
|
flags.BoolP(commonflags.QuietFlag, commonflags.QuietFlagShorthand, false, commonflags.QuietFlagUsage)
|
2023-05-18 10:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
2024-07-08 15:04:30 +00:00
|
|
|
if quietFlag, _ := cmd.Flags().GetBool(commonflags.QuietFlag); quietFlag {
|
|
|
|
if resp.GetBody().GetHealthStatus() == ircontrol.HealthStatus_READY {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2023-05-18 10:08:05 +00:00
|
|
|
|
|
|
|
cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus())
|
|
|
|
}
|