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.
This commit is contained in:
Matthew Jaffee 2018-04-11 14:25:02 -05:00
parent 9daef2180c
commit 9257029da5
No known key found for this signature in database
GPG key ID: 51C676AF9FFCDB87
3 changed files with 6 additions and 18 deletions

4
api.go
View file

@ -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)

View file

@ -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)
}
}

View file

@ -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)
}
}