From 213490c98fa28bb481a8f0db62e5e3ece8580ec5 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Sat, 18 Oct 2014 18:32:35 +0200 Subject: hub: add kind of a Makefile --- src/hub/Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/hub/Makefile diff --git a/src/hub/Makefile b/src/hub/Makefile new file mode 100644 index 0000000..317615a --- /dev/null +++ b/src/hub/Makefile @@ -0,0 +1,21 @@ +curdir:= $(shell pwd) +GOCMD := go + +getlibs: export GOPATH=$(curdir) +getlibs: + $(GOCMD) get "github.com/coopernurse/gorp" + $(GOCMD) get "github.com/mattn/go-sqlite3" + +build: export GOPATH=$(curdir) +build: getlibs + $(GOCMD) install spreadspace.org/sfive-hub + +test: export GOPATH=$(curdir) +test: getlibs + $(GOCMD) test spreadspace.org/sfive + +all: build test + +.PHONY: getlibs build test _setenv +.DEFAULT_GOAL = all + -- cgit v1.2.3 From 6c3079981325a0b61606198850ac4431da346ee3 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Sat, 18 Oct 2014 19:06:10 +0200 Subject: hub: fix unique-constraint violation --- src/hub/src/spreadspace.org/sfive/s5store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hub/src/spreadspace.org/sfive/s5store.go b/src/hub/src/spreadspace.org/sfive/s5store.go index 6fcb6a2..09ba684 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store.go +++ b/src/hub/src/spreadspace.org/sfive/s5store.go @@ -222,7 +222,11 @@ func (s sqliteStore) insertSourceTagLinks(src sourceDb, tags []tagDb) (err error st[i].SourceId = src.Id } for i := range st { - err = s.db.Insert(&st[i]) + _, err = s.db.Exec( + "insert or ignore into "+SourceTagsTn+" values (?,?)", + st[i].SourceId, + st[i].TagId) + // err = s.db.Insert(&st[i]) if err != nil { //fmt.Printf("st\n") return -- cgit v1.2.3 From f970098d24547e3209cc1d9b4b49795a9e806fe0 Mon Sep 17 00:00:00 2001 From: Markus Grüneis Date: Sat, 18 Oct 2014 19:35:34 +0200 Subject: hub: parse version and require version 1 --- src/hub/src/spreadspace.org/sfive/s5cvt.go | 6 +++++- src/hub/src/spreadspace.org/sfive/s5cvt_test.go | 4 ++-- src/hub/src/spreadspace.org/sfive/s5store_test.go | 2 +- src/hub/src/spreadspace.org/sfive/s5types.go | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt.go b/src/hub/src/spreadspace.org/sfive/s5cvt.go index d828af7..24b458a 100644 --- a/src/hub/src/spreadspace.org/sfive/s5cvt.go +++ b/src/hub/src/spreadspace.org/sfive/s5cvt.go @@ -2,6 +2,7 @@ package sfive import ( "encoding/json" + "fmt" ) type StatsDecoder interface { @@ -26,6 +27,9 @@ func NewStatefulDecoder(jsonString []byte) (decoder StatsDecoder, err error) { if err != nil { return } + if res.sourceId.Version != 1 { + err = fmt.Errorf("unsupported version, expected 1, actual %v", res.sourceId.Version) + } decoder = res return } @@ -35,8 +39,8 @@ func NewPlainDecoder() (decoder StatsDecoder) { } func (self *StatefulDecoder) Decode(jsonString []byte) (dat StatisticsData, err error) { - err = json.Unmarshal(jsonString, &dat) dat.CopyFrom(&self.sourceId) + err = json.Unmarshal(jsonString, &dat) // like in PlainDecoder, let the client decide how to use partial results // (Unmarshal returns partial results in case of errors) return diff --git a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go index 418d154..2326911 100644 --- a/src/hub/src/spreadspace.org/sfive/s5cvt_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5cvt_test.go @@ -7,9 +7,9 @@ import ( ) var ( - sourceIdFields = `"hostname": "localhost", "streamer-id": {"quality": "low", "content-id": "av", "format": "webm"}, "tags": ["elevate", "2014"]` + sourceIdFields = `"hostname": "localhost", "streamer-id": {"quality": "low", "content-id": "av", "format": "webm"}, "tags": ["elevate", "2014"], "version": 1` sourceIdData = `{` + sourceIdFields + `}` - sourceIdDataStruct = SourceId{Hostname: "localhost", StreamId: StreamId{Quality: "low", ContentId: "av", Format: "webm"}, Tags: []string{"elevate", "2014"}} + sourceIdDataStruct = SourceId{Hostname: "localhost", StreamId: StreamId{Quality: "low", ContentId: "av", Format: "webm"}, Tags: []string{"elevate", "2014"}, Version: 1} updateFields = `"data": {"bytes-sent": 1, "client-count": 3, "bytes-received": 1}, "start-time": "2014-08-24T14:35:33.847282Z", "duration-ms": 5000` updateData = "{" + updateFields + "}" updateDataStruct = DataUpdate{Data: SourceData{BytesSent: 1, ClientCount: 3, BytesReceived: 1}, StartTime: time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC), Duration: 5000} diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index 3ff437e..356b42f 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -15,7 +15,7 @@ func TestAppend(t *testing.T) { startTime := time.Date(2014, time.August, 24, 14, 35, 33, 847282000, time.UTC) 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} + source := SourceId{Hostname: "localhost", Tags: []string{"tag1", "master"}, StreamId: streamId, Version: 1} dat := StatisticsData{source, update} err = store.Append(dat) diff --git a/src/hub/src/spreadspace.org/sfive/s5types.go b/src/hub/src/spreadspace.org/sfive/s5types.go index 64b3f48..74c7f1c 100644 --- a/src/hub/src/spreadspace.org/sfive/s5types.go +++ b/src/hub/src/spreadspace.org/sfive/s5types.go @@ -15,6 +15,7 @@ type StreamId struct { } type SourceId struct { + Version uint `json:"version" db:"-"` Hostname string `json:"hostname"` StreamId StreamId `json:"streamer-id" db:"-"` Tags []string `json:"tags" db:"-"` @@ -48,6 +49,7 @@ func (self *StatisticsData) CopyFrom(id *SourceId) { self.Hostname = id.Hostname self.StreamId = id.StreamId self.Tags = id.Tags + self.Version = id.Version } func (self *StatisticsData) CopyFromUpdate(id *DataUpdate) { -- cgit v1.2.3