mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
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:
parent
9daef2180c
commit
9257029da5
3 changed files with 6 additions and 18 deletions
4
api.go
4
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)
|
||||
|
|
|
|||
17
handler.go
17
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue