diff --git a/cmd/frostfs-cli/modules/node/root.go b/cmd/frostfs-cli/modules/node/root.go new file mode 100644 index 000000000..11b2eb15c --- /dev/null +++ b/cmd/frostfs-cli/modules/node/root.go @@ -0,0 +1,32 @@ +package node + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" + "github.com/spf13/cobra" +) + +// Cmd represents the container command. +var Cmd = &cobra.Command{ + Use: "node", + Short: "Operations related to node state", + Long: "Operations related to node state", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + // bind exactly that cmd's flags to + // the viper before execution + commonflags.Bind(cmd) + commonflags.BindAPI(cmd) + }, +} + +func init() { + nodeChildCommand := []*cobra.Command{ + nodeServicesCmd, + } + Cmd.AddCommand(nodeChildCommand...) + + initNodeServicesCmd() + + for _, nodeCommand := range nodeChildCommand { + commonflags.InitAPI(nodeCommand) + } +} diff --git a/cmd/frostfs-cli/modules/node/services.go b/cmd/frostfs-cli/modules/node/services.go new file mode 100644 index 000000000..e2d2d6000 --- /dev/null +++ b/cmd/frostfs-cli/modules/node/services.go @@ -0,0 +1,40 @@ +package node + +import ( + "context" + + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +var nodeServicesCmd = &cobra.Command{ + Use: "services", + Short: "Show services state for node", + Long: "Show services state for node.", + Run: func(cmd *cobra.Command, args []string) { + var a network.Address + err := a.FromString(viper.GetViper().GetString(commonflags.RPC)) + common.ExitOnErr(cmd, "unable to parse RPC endpoint", err) + + cc, err := grpc.DialContext(context.Background(), a.URIAddr(), grpc.WithTransportCredentials(insecure.NewCredentials())) + common.ExitOnErr(cmd, "unable to create client connection", err) + + treeClient := tree.NewTreeServiceClient(cc) + resp, err := treeClient.Healthcheck(context.Background(), new(tree.HealthcheckRequest)) + status := "available" + if err != nil || resp == nil { + status = "N/A" + } + cmd.Printf("tree service status: %s\n", status) + }, +} + +func initNodeServicesCmd() { + commonflags.Init(nodeServicesCmd) +} diff --git a/cmd/frostfs-cli/modules/root.go b/cmd/frostfs-cli/modules/root.go index 808bd6d07..f75d5c9f7 100644 --- a/cmd/frostfs-cli/modules/root.go +++ b/cmd/frostfs-cli/modules/root.go @@ -12,6 +12,7 @@ import ( containerCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/container" controlCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/control" netmapCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/netmap" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/node" objectCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/object" sessionCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/session" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/tree" @@ -86,6 +87,7 @@ func init() { rootCmd.AddCommand(containerCli.Cmd) rootCmd.AddCommand(tree.Cmd) rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{})) + rootCmd.AddCommand(node.Cmd) } func entryPoint(cmd *cobra.Command, _ []string) {