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.

51 lines
1.2 KiB

  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/chrislusf/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) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. raftClusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  24. if err = raftClusterPsCommand.Parse(args); err != nil {
  25. return nil
  26. }
  27. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  28. resp, err := client.RaftListClusterServers(context.Background(), &master_pb.RaftListClusterServersRequest{})
  29. if err != nil {
  30. return fmt.Errorf("raft list cluster: %v", err)
  31. }
  32. fmt.Fprintf(writer, "the raft cluster has %d servers\n", len(resp.ClusterServers))
  33. for _, server := range resp.ClusterServers {
  34. fmt.Fprintf(writer, " * %s %s (%s)\n", server.Id, server.Address, server.Suffrage)
  35. }
  36. return nil
  37. })
  38. return err
  39. }