Browse Source

add back "/cluster/status"

fix https://github.com/chrislusf/seaweedfs/issues/870
pull/878/head
Chris Lu 6 years ago
parent
commit
4773497d2c
  1. 1
      weed/command/master.go
  2. 1
      weed/command/server.go
  3. 22
      weed/server/raft_server_handlers.go

1
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

1
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

22
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)
}
Loading…
Cancel
Save