diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-04-30 03:50:13 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-04-30 03:50:13 +0200 |
commit | ea7b72b4544770cc7f26297c7fd6f1b7f4bb64ab (patch) | |
tree | e2c630c802f49209bdd7361c35bd5963103eba5a /src/hub | |
parent | readded basic append/fetch test and benchmark (diff) |
new web api endpoint hubs
use -read-only for forwarding tests
Diffstat (limited to 'src/hub')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvWeb.go | 16 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store.go | 12 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store_test.go | 9 | ||||
-rwxr-xr-x | src/hub/test-fwd | 2 | ||||
-rwxr-xr-x | src/hub/test-fwd-es | 2 | ||||
-rwxr-xr-x | src/hub/test-fwd-piwik | 2 |
6 files changed, 40 insertions, 3 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go index 8ecb673..fd7e214 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go @@ -48,6 +48,21 @@ func (srv Server) webHealthz(c web.C, w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s\n", srv.GetHubId()) } +func (srv Server) webGetHubsList(c web.C, w http.ResponseWriter, r *http.Request) { + const resourceName = "hubs" + values, err := srv.store.GetHubs() + if err != nil { + http.Error(w, fmt.Sprintf("failed to retrieve %s: %v", resourceName, err), http.StatusInternalServerError) + return + } + jsonString, err := json.Marshal(GenericDataContainer{values}) + if err != nil { + http.Error(w, fmt.Sprintf("failed to marshal %s: %v", resourceName, err), http.StatusInternalServerError) + return + } + fmt.Fprintf(w, "%s", jsonString) +} + func (srv Server) webGetSourcesList(c web.C, w http.ResponseWriter, r *http.Request) { const resourceName = "sources" values, err := srv.store.GetSources() @@ -187,6 +202,7 @@ func (srv Server) webGetLastUpdateIdForUuid(c web.C, w http.ResponseWriter, r *h func (srv Server) ServeWeb() { goji.Get("/healthz", srv.webHealthz) + goji.Get("/hubs", srv.webGetHubsList) goji.Get("/sources", srv.webGetSourcesList) goji.Get("/sources/:id", srv.webGetSource) goji.Get("/updates", srv.webGetUpdateList) diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 568b448..8b9cae6 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -505,6 +505,18 @@ func (st Store) GetLastUpdateForUuid(uuid string) (updateId int, err error) { return } +func (st Store) GetHubs() (res []string, err error) { + res = []string{st.hubUuid} + err = st.db.View(func(tx *bolt.Tx) error { + c := tx.Bucket([]byte(hubUuidsRevBn)).Cursor() + for k, v := c.First(); k != nil; k, v = c.Next() { + res = append(res, string(v)) + } + return nil + }) + return +} + func (st Store) GetSource(id int) (res SourceId, err error) { err = st.db.View(func(tx *bolt.Tx) error { src, err := st.getSource(tx, id) diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index 67557d4..b9aa36c 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -253,6 +253,15 @@ func TestReadOnly(t *testing.T) { // } +// +// TODO: add tests for +// * store.GetUpdatesAfter +// * store.GetHubs +// * store.GetSource(s) +// * GetLastUpdateId +// * GetLastUpdateForUuid +// + func generateDataUpdateFull(n int) (data []DataUpdateFull) { hostnames := []string{"streamer1", "streamer2"} contents := []string{"av", "audio"} diff --git a/src/hub/test-fwd b/src/hub/test-fwd index 35dd324..371aa55 100755 --- a/src/hub/test-fwd +++ b/src/hub/test-fwd @@ -8,4 +8,4 @@ fi TEST_D="./test" TEST_DB="$TEST_D/$1.bolt" -exec ./bin/sfive-hub -db "$TEST_DB" -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-url="http://localhost:8000" +exec ./bin/sfive-hub -db "$TEST_DB" -read-only -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-url="http://localhost:8000" diff --git a/src/hub/test-fwd-es b/src/hub/test-fwd-es index 2d74db6..61bbcf7 100755 --- a/src/hub/test-fwd-es +++ b/src/hub/test-fwd-es @@ -8,4 +8,4 @@ fi TEST_D="./test" TEST_DB="$TEST_D/$1.bolt" -exec ./bin/sfive-hub -db "$TEST_DB" -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-es-url="http://stream.elevate.at:9200/testing" +exec ./bin/sfive-hub -db "$TEST_DB" -read-only -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-es-url="http://stream.elevate.at:9200/testing" diff --git a/src/hub/test-fwd-piwik b/src/hub/test-fwd-piwik index c7df4ae..8a2ae33 100755 --- a/src/hub/test-fwd-piwik +++ b/src/hub/test-fwd-piwik @@ -8,4 +8,4 @@ fi TEST_D="./test" TEST_DB="$TEST_D/$1.bolt" -exec ./bin/sfive-hub -db "$TEST_DB" -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-piwik-url="http://localhost/piwik.php" -piwik-token "asdfjlkasjdflk" -piwik-site-id 4 -piwik-site-url "https://stream.elevate.at" +exec ./bin/sfive-hub -db "$TEST_DB" -read-only -start-pipe-server=false -start-pipegram-server=false -start-web-server=false -forward-piwik-url="http://localhost/piwik.php" -piwik-token "asdfjlkasjdflk" -piwik-site-id 4 -piwik-site-url "https://stream.elevate.at" |