summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:07:43 +0200
committerMarkus Grüneis <gimpf@gimpf.org>2014-10-23 15:07:43 +0200
commit3fdd69ae1f2f02f0d54e73fb4bce7af81713fffd (patch)
treeaf9afc722430ff2e606082b5509e43ce39649169
parenthub: serve viz app under /viz (diff)
hub: Add per-DB UUID, optionally store in data-updates table
-rw-r--r--src/hub/Makefile1
-rwxr-xr-xsrc/hub/dump-test-db2
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store.go14
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5store_test.go2
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesApi.go2
-rw-r--r--src/hub/src/spreadspace.org/sfive/s5typesStore.go26
6 files changed, 37 insertions, 10 deletions
diff --git a/src/hub/Makefile b/src/hub/Makefile
index 205aa46..c62891c 100644
--- a/src/hub/Makefile
+++ b/src/hub/Makefile
@@ -38,6 +38,7 @@ getlibs:
$(GOCMD) get "github.com/coopernurse/gorp"
$(GOCMD) get "github.com/mattn/go-sqlite3"
$(GOCMD) get "github.com/zenazn/goji"
+ $(GOCMD) get "code.google.com/p/go-uuid/uuid"
build: export GOPATH=$(curdir)
build: getlibs
diff --git a/src/hub/dump-test-db b/src/hub/dump-test-db
index 89cc5af..9a7aae7 100755
--- a/src/hub/dump-test-db
+++ b/src/hub/dump-test-db
@@ -1,3 +1,3 @@
#!/bin/sh
-echo .dump | sqlite3 ~/test.sqlite
+echo .dump | sqlite3 /var/lib/sfive/db.sqlite
diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go
index 306cd1b..14d259f 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store.go
@@ -6,6 +6,7 @@ import (
_ "github.com/mattn/go-sqlite3"
+ "code.google.com/p/go-uuid/uuid"
"github.com/coopernurse/gorp"
)
@@ -46,6 +47,8 @@ func dataUpdateFromStatisticsData(value StatisticsData) dataUpdateDb {
return dataUpdateDb{
-1,
-1,
+ value.SourceHubUuid,
+ value.SourceHubDataUpdateId,
value.StartTime.Unix(),
int64(value.Duration.Seconds()),
value.Data.ClientCount,
@@ -77,6 +80,7 @@ func initDb(path string) (res *gorp.DbMap, err error) {
dbmap.AddTableWithName(sourceDb{}, sourcesTn).SetKeys(true, "Id").SetUniqueTogether("ContentId", "Format", "Quality", "Hostname")
dbmap.AddTableWithName(clientDataDb{}, clientdataUpdatesTn).SetKeys(true, "Id")
dbmap.AddTableWithName(dataUpdateDb{}, dataUpdatesTn).SetKeys(true, "Id")
+ dbmap.AddTableWithName(hubInfoDb{}, hubInfoTn).SetKeys(false, "Name")
// TODO use some real migration, yadda yadda
err = dbmap.CreateTablesIfNotExists()
@@ -84,6 +88,16 @@ func initDb(path string) (res *gorp.DbMap, err error) {
return
}
+ oldid, err := dbmap.SelectStr("select Value from " + hubInfoTn + " where Name = 'HubUuid'")
+ // TODO handle only not-found this way
+ if err != nil || oldid == "" {
+ newid := uuid.New()
+ _, err = db.Exec("insert into "+hubInfoTn+" values ('HubUuid', ?)", newid)
+ if err != nil {
+ return
+ }
+ }
+
res = dbmap
return
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go
index 022d662..c3d62f9 100644
--- a/src/hub/src/spreadspace.org/sfive/s5store_test.go
+++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go
@@ -28,7 +28,7 @@ func TestAppend(t *testing.T) {
update := DataUpdate{Data: SourceData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: startTime, Duration: 5 * time.Millisecond}
streamId := StreamId{ContentId: "content", Format: "7bitascii", Quality: QualityHigh}
source := SourceId{Hostname: "localhost", Tags: []string{"tag1", "master"}, StreamId: streamId, Version: 1}
- dat := StatisticsData{source, update}
+ dat := StatisticsData{nil, nil, source, update}
err = store.Append(dat)
if err != nil {
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesApi.go b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
index d9af20a..871a903 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesApi.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesApi.go
@@ -41,6 +41,8 @@ type DataUpdate struct {
}
type StatisticsData struct {
+ SourceHubUuid *string
+ SourceHubDataUpdateId *int
SourceId
DataUpdate
}
diff --git a/src/hub/src/spreadspace.org/sfive/s5typesStore.go b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
index 60dc6e7..cb73d2e 100644
--- a/src/hub/src/spreadspace.org/sfive/s5typesStore.go
+++ b/src/hub/src/spreadspace.org/sfive/s5typesStore.go
@@ -1,6 +1,8 @@
package sfive
-import "time"
+import (
+ "time"
+)
// compared to JSON DTOs, DB types are flattened, and use key-relations instead of collections
// this is very much not normalized at all, because I'm too lazy to type
@@ -12,8 +14,14 @@ const (
sourcesTn = "Sources"
clientdataUpdatesTn = "ClientDataUpdates"
dataUpdatesTn = "DataUpdates"
+ hubInfoTn = "HubInfo"
)
+type hubInfoDb struct {
+ Name string
+ Value string
+}
+
// stored in tagsTn
type tagDb struct {
Id int
@@ -45,13 +53,15 @@ type clientDataDb struct {
// stored in dataUpdatesTn
// in DB, StatisticsData/DataUpdate is flattened compared to JSON DTOs
type dataUpdateDb struct {
- Id int
- SourceId int // foreign key to sourcesTn
- StartTime int64 // time.Time
- Duration int64 // time.Duration
- ClientCount uint
- BytesReceived uint
- BytesSent uint
+ Id int
+ SourceId int // foreign key to sourcesTn
+ SourceHubUuid *string
+ SourceHubDataUpdateId *int
+ StartTime int64 // time.Time
+ Duration int64 // time.Duration
+ ClientCount uint
+ BytesReceived uint
+ BytesSent uint
}
func (self *SourceId) CopyFromSourceDb(value sourceDb) {