raft_server_handlers.go 732 B

123456789101112131415161718192021222324252627
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb"
  4. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  5. "net/http"
  6. )
  7. type ClusterStatusResult struct {
  8. IsLeader bool `json:"IsLeader,omitempty"`
  9. Leader pb.ServerAddress `json:"Leader,omitempty"`
  10. Peers []string `json:"Peers,omitempty"`
  11. MaxVolumeId needle.VolumeId `json:"MaxVolumeId,omitempty"`
  12. }
  13. func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) {
  14. ret := ClusterStatusResult{
  15. IsLeader: s.topo.IsLeader(),
  16. Peers: s.Peers(),
  17. MaxVolumeId: s.topo.GetMaxVolumeId(),
  18. }
  19. if leader, e := s.topo.Leader(); e == nil {
  20. ret.Leader = leader
  21. }
  22. writeJsonQuiet(w, r, http.StatusOK, ret)
  23. }