raft_server_handlers.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package weed_server
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/pb"
  4. "github.com/seaweedfs/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. }
  24. func (s *RaftServer) HealthzHandler(w http.ResponseWriter, r *http.Request) {
  25. _, err := s.topo.Leader()
  26. if err != nil {
  27. w.WriteHeader(http.StatusServiceUnavailable)
  28. } else {
  29. w.WriteHeader(http.StatusOK)
  30. }
  31. }
  32. func (s *RaftServer) StatsRaftHandler(w http.ResponseWriter, r *http.Request) {
  33. if s.RaftHashicorp == nil {
  34. writeJsonQuiet(w, r, http.StatusNotFound, nil)
  35. return
  36. }
  37. writeJsonQuiet(w, r, http.StatusOK, s.RaftHashicorp.Stats())
  38. }