removing unused /api/origin/host/{id} route

This commit is contained in:
Paul Bellamy
2015-11-05 14:36:00 +00:00
parent 4d49aaccaa
commit 9877a2126a
3 changed files with 0 additions and 85 deletions

View File

@@ -1,50 +0,0 @@
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/scope/report"
)
// OriginHost represents a host that runs a probe, i.e. the origin host of
// some data in the system. The struct is returned by the /api/origin/{id}
// handler.
type OriginHost struct {
Hostname string `json:"hostname"`
OS string `json:"os"`
Networks []string `json:"networks"`
Load string `json:"load"`
}
func getOriginHost(t report.Topology, nodeID string) (OriginHost, bool) {
h, ok := t.Nodes[nodeID]
if !ok {
return OriginHost{}, false
}
return OriginHost{
Hostname: h.Metadata[host.HostName],
OS: h.Metadata[host.OS],
Networks: h.Sets[host.LocalNetworks],
Load: h.Metadata[host.Load],
}, true
}
// makeOriginHostHandler makes the /api/origin/* handler.
func makeOriginHostHandler(rep Reporter) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
vars = mux.Vars(r)
nodeID = vars["id"]
)
origin, ok := getOriginHost(rep.Report().Host, nodeID)
if !ok {
http.NotFound(w, r)
return
}
respondWith(w, http.StatusOK, origin)
}
}

View File

@@ -1,33 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"net/http/httptest"
"testing"
"github.com/weaveworks/scope/test/fixture"
)
func TestAPIOriginHost(t *testing.T) {
ts := httptest.NewServer(Router(StaticReport{}))
defer ts.Close()
is404(t, ts, "/api/origin/foobar")
is404(t, ts, "/api/origin/host/foobar")
{
// Origin
body := getRawJSON(t, ts, fmt.Sprintf("/api/origin/host/%s", fixture.ServerHostNodeID))
var o OriginHost
if err := json.Unmarshal(body, &o); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
if want, have := "Linux", o.OS; want != have {
t.Errorf("Origin error. Want %v, have %v", want, have)
}
if want, have := "0.01 0.01 0.01", o.Load; want != have {
t.Errorf("Origin error. Want %v, have %v", want, have)
}
}
}

View File

@@ -71,8 +71,6 @@ func Router(c collector) *mux.Router {
gzipHandler(topologyRegistry.captureRenderer(c, handleNode)))
get.MatcherFunc(URLMatcher("/api/topology/{topology}/{local}/{remote}")).HandlerFunc(
gzipHandler(topologyRegistry.captureRenderer(c, handleEdge)))
get.MatcherFunc(URLMatcher("/api/origin/host/{id}")).HandlerFunc(
gzipHandler(makeOriginHostHandler(c)))
get.HandleFunc("/api/report", gzipHandler(makeRawReportHandler(c)))
get.PathPrefix("/").Handler(http.FileServer(FS(false))) // everything else is static