2019-03-06 20:10:45 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
2019-03-06 20:10:45 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ClusterStatusResult struct {
|
2021-09-13 05:47:52 +00:00
|
|
|
IsLeader bool `json:"IsLeader,omitempty"`
|
|
|
|
Leader pb.ServerAddress `json:"Leader,omitempty"`
|
|
|
|
Peers []string `json:"Peers,omitempty"`
|
|
|
|
MaxVolumeId needle.VolumeId `json:"MaxVolumeId,omitempty"`
|
2019-03-06 20:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ret := ClusterStatusResult{
|
2020-10-04 16:56:17 +00:00
|
|
|
IsLeader: s.topo.IsLeader(),
|
|
|
|
Peers: s.Peers(),
|
|
|
|
MaxVolumeId: s.topo.GetMaxVolumeId(),
|
2019-03-06 20:10:45 +00:00
|
|
|
}
|
2020-10-04 16:56:17 +00:00
|
|
|
|
2019-03-06 20:10:45 +00:00
|
|
|
if leader, e := s.topo.Leader(); e == nil {
|
|
|
|
ret.Leader = leader
|
|
|
|
}
|
|
|
|
writeJsonQuiet(w, r, http.StatusOK, ret)
|
|
|
|
}
|
2022-04-04 14:16:06 +00:00
|
|
|
|
2022-07-30 17:26:56 +00:00
|
|
|
func (s *RaftServer) HealthzHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
_, err := s.topo.Leader()
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 14:16:06 +00:00
|
|
|
func (s *RaftServer) StatsRaftHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if s.RaftHashicorp == nil {
|
|
|
|
writeJsonQuiet(w, r, http.StatusNotFound, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
writeJsonQuiet(w, r, http.StatusOK, s.RaftHashicorp.Stats())
|
|
|
|
}
|