Skip to content

Commit

Permalink
remove get-paths tracker endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Feb 8, 2018
1 parent 1446fdb commit ced7d9a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 51 deletions.
40 changes: 0 additions & 40 deletions tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func NewTracker(c *Config) (*Tracker, error) {
m := http.NewServeMux()
m.HandleFunc("/ping", t.ping)
m.HandleFunc("/get-path", t.getPath)
m.HandleFunc("/get-paths", t.getPaths)
m.HandleFunc("/get-devices", t.getDevices)
m.HandleFunc("/get-hosts", t.getHosts)
m.HandleFunc("/create-open", t.createOpen)
Expand Down Expand Up @@ -166,45 +165,6 @@ func (t *Tracker) getPath(w http.ResponseWriter, r *http.Request) {
encoder.Encode(response) // nolint: errcheck
}

func (t *Tracker) getPaths(w http.ResponseWriter, r *http.Request) {
var response GetPaths
response.Paths = make([]string, 0)
key := r.FormValue("key")
rows, err := t.db.Query("select h.hostip, d.read_port, d.devid, f.fid "+
"from file f "+
"join file_on fo on f.fid=fo.fid "+
"join device d on d.devid=fo.devid "+
"join host h on h.hostid=d.hostid "+
"where h.status='alive' "+
"and d.status in ('alive', 'drain') "+
"and f.dkey=?", key)
if err != nil {
t.internalServerError("cannot select rows", err, r, w)
return
}
defer rows.Close() // nolint: errcheck
for rows.Next() {
var hostip string
var httpPort int64
var devid int64
var fid int64
err = rows.Scan(&hostip, &httpPort, &devid, &fid)
if err != nil {
t.internalServerError("cannot scan rows", err, r, w)
return
}
path := fmt.Sprintf("http://%s:%d/dev%d/%s", hostip, httpPort, devid, vivify(fid))
response.Paths = append(response.Paths, path)
}
err = rows.Err()
if err != nil {
t.internalServerError("error while fetching rows", err, r, w)
return
}
encoder := json.NewEncoder(w)
encoder.Encode(response) // nolint: errcheck
}

func (t *Tracker) createOpen(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
Expand Down
18 changes: 12 additions & 6 deletions tracker_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -29,7 +30,7 @@ func TestPing(t *testing.T) {
}
}

func TestGetPaths(t *testing.T) {
func TestGetPath(t *testing.T) {
tr, err := NewTracker(testConfig)
if err != nil {
t.Fatal(err)
Expand All @@ -51,7 +52,7 @@ func TestGetPaths(t *testing.T) {
if err != nil {
t.Fatal(err)
}
req, err := http.NewRequest("GET", "/get-paths?key=foo", nil)
req, err := http.NewRequest("GET", "/get-path?key=foo", nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -62,10 +63,15 @@ func TestGetPaths(t *testing.T) {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
expected := "{\"paths\":[\"http://1.2.3.4:1234/dev2/0/000/000/0000000042.fid\"]}\n"
if rr.Body.String() != expected {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expected)
var resp GetPath
err = json.Unmarshal(rr.Body.Bytes(), &resp)
if err != nil {
t.Fatal(err)
}
expected := "http://1.2.3.4:1234/dev2/0/000/000/0000000042.fid"
if resp.Path != expected {
t.Errorf("handler returned unexpected path: got %v want %v",
resp.Path, expected)
}
}

Expand Down
5 changes: 0 additions & 5 deletions trackerapi.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package main

// TODO remove
type GetPaths struct {
Paths []string `json:"paths"`
}

type GetPath struct {
Path string `json:"path"`
CreatedAt string `json:"created_at"`
Expand Down

0 comments on commit ced7d9a

Please sign in to comment.