aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_cluster_raft_ps.go
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2022-04-10 23:00:05 -0700
committerGitHub <noreply@github.com>2022-04-10 23:00:05 -0700
commita87f57e47c9a39c7f431448ac1f99954a30151da (patch)
tree0d142482d59098ffc4a481cb73d7c91803e4aff8 /weed/shell/command_cluster_raft_ps.go
parentc6ec5269f4b34d79ab8e13050623501b8befda32 (diff)
parent931cb9e5818b202c3855321c9b12a6149d121ffa (diff)
downloadseaweedfs-a87f57e47c9a39c7f431448ac1f99954a30151da.tar.xz
seaweedfs-a87f57e47c9a39c7f431448ac1f99954a30151da.zip
Merge pull request #2868 from kmlebedev/hashicorp_raft
hashicorp raft
Diffstat (limited to 'weed/shell/command_cluster_raft_ps.go')
-rw-r--r--weed/shell/command_cluster_raft_ps.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/weed/shell/command_cluster_raft_ps.go b/weed/shell/command_cluster_raft_ps.go
new file mode 100644
index 000000000..ea868db06
--- /dev/null
+++ b/weed/shell/command_cluster_raft_ps.go
@@ -0,0 +1,51 @@
+package shell
+
+import (
+ "context"
+ "flag"
+ "fmt"
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "io"
+)
+
+func init() {
+ Commands = append(Commands, &commandRaftClusterPs{})
+}
+
+type commandRaftClusterPs struct {
+}
+
+func (c *commandRaftClusterPs) Name() string {
+ return "cluster.raft.ps"
+}
+
+func (c *commandRaftClusterPs) Help() string {
+ return `check current raft cluster status
+
+ cluster.raft.ps
+`
+}
+
+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 {
+ fmt.Fprintf(writer, " * %s %s (%s)\n", server.Id, server.Address, server.Suffrage)
+ }
+
+ return nil
+ })
+
+ return err
+
+}