From 4773497d2c2a96990cd68e841675405db26353cb Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 6 Mar 2019 12:10:45 -0800 Subject: [PATCH] add back "/cluster/status" fix https://github.com/chrislusf/seaweedfs/issues/870 --- weed/command/master.go | 1 + weed/command/server.go | 1 + weed/server/raft_server_handlers.go | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 weed/server/raft_server_handlers.go diff --git a/weed/command/master.go b/weed/command/master.go index cc6818967..4207a331c 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -97,6 +97,7 @@ func runMaster(cmd *Command, args []string) bool { raftServer := weed_server.NewRaftServer(security.LoadClientTLS(viper.Sub("grpc"), "master"), peers, myMasterAddress, *metaFolder, ms.Topo, *mpulse) ms.SetRaftServer(raftServer) + r.HandleFunc("/cluster/status", raftServer.StatusHandler).Methods("GET") // starting grpc server grpcPort := *mport + 10000 diff --git a/weed/command/server.go b/weed/command/server.go index d625dd732..32b9f6987 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -187,6 +187,7 @@ func runServer(cmd *Command, args []string) bool { raftServer := weed_server.NewRaftServer(security.LoadClientTLS(viper.Sub("grpc"), "master"), peers, myMasterAddress, *masterMetaFolder, ms.Topo, *pulseSeconds) ms.SetRaftServer(raftServer) + r.HandleFunc("/cluster/status", raftServer.StatusHandler).Methods("GET") // starting grpc server grpcPort := *masterPort + 10000 diff --git a/weed/server/raft_server_handlers.go b/weed/server/raft_server_handlers.go new file mode 100644 index 000000000..fd38cb977 --- /dev/null +++ b/weed/server/raft_server_handlers.go @@ -0,0 +1,22 @@ +package weed_server + +import ( + "net/http" +) + +type ClusterStatusResult struct { + IsLeader bool `json:"IsLeader,omitempty"` + Leader string `json:"Leader,omitempty"` + Peers []string `json:"Peers,omitempty"` +} + +func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) { + ret := ClusterStatusResult{ + IsLeader: s.topo.IsLeader(), + Peers: s.Peers(), + } + if leader, e := s.topo.Leader(); e == nil { + ret.Leader = leader + } + writeJsonQuiet(w, r, http.StatusOK, ret) +}