From 9257029da5fb00736d1ac43d5ec89940d0b3e8eb Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Wed, 11 Apr 2018 14:25:02 -0500 Subject: [PATCH] simplify Status endpoint had to update test which was relying on a fake ClusterStatus implementation. Now the status endpoint uses information directly from Cluster.Nodes and Cluster.state - which is what Server (the usual ClusterStatus impl) uses, so it should make no difference for real clusters. --- api.go | 4 ---- handler.go | 17 ++++------------- handler_test.go | 3 ++- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/api.go b/api.go index 7c570b59d..27827fcec 100644 --- a/api.go +++ b/api.go @@ -518,10 +518,6 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo { return api.Holder.Schema() } -func (api *API) Status(ctx context.Context) (proto.Message, error) { - return api.StatusHandler.ClusterStatus() -} - func (api *API) CreateField(ctx context.Context, indexName string, frameName string, field *Field) error { // Retrieve frame by name. f := api.Holder.Frame(indexName, frameName) diff --git a/handler.go b/handler.go index 208c5922f..4ce8560b5 100644 --- a/handler.go +++ b/handler.go @@ -289,20 +289,11 @@ func (h *Handler) handleGetSchema(w http.ResponseWriter, r *http.Request) { // handleGetStatus handles GET /status requests. func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) { - pb, err := h.API.Status(r.Context()) - if err != nil { - h.Logger.Printf("cluster status error: %s", err) - return + status := getStatusResponse{ + State: h.API.State(), + Nodes: h.API.Hosts(r.Context()), } - - cs, ok := pb.(*internal.ClusterStatus) - if !ok { - panic("status is not a status") - } - if err := json.NewEncoder(w).Encode(getStatusResponse{ - State: cs.State, - Nodes: DecodeNodes(cs.Nodes), - }); err != nil { + if err := json.NewEncoder(w).Encode(status); err != nil { h.Logger.Printf("write status response error: %s", err) } } diff --git a/handler_test.go b/handler_test.go index b605a3650..c7d2a80b7 100644 --- a/handler_test.go +++ b/handler_test.go @@ -141,6 +141,7 @@ func TestHandler_Status(t *testing.T) { h := test.NewHandler() h.API.Holder = hldr.Holder h.API.Cluster = test.NewCluster(1) + h.API.Cluster.SetState(pilosa.ClusterStateNormal) h.API.StatusHandler = s s.Handler = h @@ -148,7 +149,7 @@ func TestHandler_Status(t *testing.T) { h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/status", nil)) if w.Code != http.StatusOK { t.Fatalf("unexpected status code: %d", w.Code) - } else if body := w.Body.String(); body != `{"state":"NORMAL","nodes":[{"id":"test-node","uri":{"scheme":"http","host":"localhost","port":10101},"isCoordinator":false}]}`+"\n" { + } else if body := w.Body.String(); body != `{"state":"NORMAL","nodes":[{"id":"node0","uri":{"scheme":"http","host":"host0"},"isCoordinator":false}]}`+"\n" { t.Fatalf("unexpected body: %s", body) } }