seaweedfs/weed/shell/command_cluster_raft_ps.go

60 lines
1.3 KiB
Go
Raw Normal View History

2022-04-06 18:23:53 +08:00
package shell
import (
"context"
"flag"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
2022-04-06 18:23:53 +08:00
"io"
)
func init() {
Commands = append(Commands, &commandRaftClusterPs{})
}
type commandRaftClusterPs struct {
}
func (c *commandRaftClusterPs) Name() string {
2022-04-11 13:50:01 +08:00
return "cluster.raft.ps"
2022-04-06 18:23:53 +08:00
}
func (c *commandRaftClusterPs) Help() string {
return `check current raft cluster status
2022-04-11 13:50:01 +08:00
cluster.raft.ps
2022-04-06 18:23:53 +08:00
`
}
2024-09-30 01:38:22 +08:00
func (c *commandRaftClusterPs) HasTag(CommandTag) bool {
return false
}
2022-04-06 18:23:53 +08:00
func (c *commandRaftClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
raftClusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
if err = raftClusterPsCommand.Parse(args); err != nil {
return nil
}
err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
resp, err := client.RaftListClusterServers(context.Background(), &master_pb.RaftListClusterServersRequest{})
if err != nil {
return fmt.Errorf("raft list cluster: %v", err)
}
fmt.Fprintf(writer, "the raft cluster has %d servers\n", len(resp.ClusterServers))
for _, server := range resp.ClusterServers {
2022-10-06 22:10:41 +08:00
suffrage := server.Suffrage
if server.IsLeader {
suffrage = "Leader"
}
fmt.Fprintf(writer, " * %s %s (%s)\n", server.Id, server.Address, suffrage)
2022-04-06 18:23:53 +08:00
}
return nil
})
return err
}