[#xx] cli: Add command node services

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-09-06 11:47:09 +03:00
parent 054e3ef3d3
commit d6eb50822a
3 changed files with 74 additions and 0 deletions

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -12,6 +12,7 @@ import (
containerCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/container" containerCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/container"
controlCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/control" controlCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/control"
netmapCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/netmap" 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" objectCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/object"
sessionCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/session" sessionCli "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/session"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/tree" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/tree"
@ -86,6 +87,7 @@ func init() {
rootCmd.AddCommand(containerCli.Cmd) rootCmd.AddCommand(containerCli.Cmd)
rootCmd.AddCommand(tree.Cmd) rootCmd.AddCommand(tree.Cmd)
rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{})) rootCmd.AddCommand(gendoc.Command(rootCmd, gendoc.Options{}))
rootCmd.AddCommand(node.Cmd)
} }
func entryPoint(cmd *cobra.Command, _ []string) { func entryPoint(cmd *cobra.Command, _ []string) {