You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

3 months ago
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandRaftClusterPs{})
  11. }
  12. type commandRaftClusterPs struct {
  13. }
  14. func (c *commandRaftClusterPs) Name() string {
  15. return "cluster.raft.ps"
  16. }
  17. func (c *commandRaftClusterPs) Help() string {
  18. return `check current raft cluster status
  19. cluster.raft.ps
  20. `
  21. }
  22. func (c *commandRaftClusterPs) HasTag(CommandTag) bool {
  23. return false
  24. }
  25. func (c *commandRaftClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  26. raftClusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  27. if err = raftClusterPsCommand.Parse(args); err != nil {
  28. return nil
  29. }
  30. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  31. resp, err := client.RaftListClusterServers(context.Background(), &master_pb.RaftListClusterServersRequest{})
  32. if err != nil {
  33. return fmt.Errorf("raft list cluster: %v", err)
  34. }
  35. fmt.Fprintf(writer, "the raft cluster has %d servers\n", len(resp.ClusterServers))
  36. for _, server := range resp.ClusterServers {
  37. suffrage := server.Suffrage
  38. if server.IsLeader {
  39. suffrage = "Leader"
  40. }
  41. fmt.Fprintf(writer, " * %s %s (%s)\n", server.Id, server.Address, suffrage)
  42. }
  43. return nil
  44. })
  45. return err
  46. }