feat: call the HTTP API to get master state information

This commit is contained in:
徐聪
2022-07-15 15:33:53 +08:00
parent 17617ee13e
commit f2799aef53
4 changed files with 51 additions and 11 deletions

View File

@@ -135,10 +135,6 @@ type CommonResponseBody struct {
}
type APIGetWorkersRequestBody struct {
ID string `json:"id"`
State int32 `json:"state"`
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
}
type APIGetWorkersResponseBody struct {
@@ -146,6 +142,14 @@ type APIGetWorkersResponseBody struct {
Data []boomer.WorkerNode `json:"data"`
}
type APIGetMasterRequestBody struct {
}
type APIGetMasterResponseBody struct {
ServerStatus
Data map[string]interface{} `json:"data"`
}
type apiHandler struct {
boomer *HRPBoomer
}
@@ -321,6 +325,16 @@ func (api *apiHandler) GetWorkersInfo(w http.ResponseWriter, r *http.Request) {
writeJSON(w, body, http.StatusOK)
}
func (api *apiHandler) GetMasterInfo(w http.ResponseWriter, r *http.Request) {
resp := &APIGetMasterResponseBody{
ServerStatus: EnumAPIResponseSuccess,
Data: api.boomer.GetMasterInfo(),
}
body, _ := json.Marshal(resp)
writeJSON(w, body, http.StatusOK)
}
func (api *apiHandler) Handler() http.Handler {
mux := http.NewServeMux()
@@ -330,6 +344,7 @@ func (api *apiHandler) Handler() http.Handler {
mux.HandleFunc("/stop", methods(api.Stop, "GET"))
mux.HandleFunc("/quit", methods(api.Quit, "GET"))
mux.HandleFunc("/workers", methods(api.GetWorkersInfo, "GET"))
mux.HandleFunc("/master", methods(api.GetMasterInfo, "GET"))
return mux
}