Skip to content

Commit

Permalink
Merge pull request #82 from Comcast/feature/integrate-convey-and-trust
Browse files Browse the repository at this point in the history
Insert close reason and trust into the appropriate payloads
  • Loading branch information
johnabass authored Feb 17, 2019
2 parents 2b57463 + 447b801 commit bc16d08
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package: .
homepage: https://github.com/Comcast/talaria
import:
- package: github.com/Comcast/webpa-common
version: 0f087c5390cb60f4bdff2a27d1858c5e44755ce4
version: efad9ae77d96a45da1a3a1a38880745cbe958e90
10 changes: 5 additions & 5 deletions src/talaria/deviceStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func statusMetadata(d device.Interface) map[string]string {
wrpmeta.Field{From: "fw-name", To: "/fw-name"},
wrpmeta.Field{From: "last-reconnect-reason", To: "/last-reconnect-reason"},
wrpmeta.Field{From: "protocol", To: "/protocol"}).
Set("/trust", d.Trust().String()).
Set("/trust", d.Trust()).
Build()

if allFieldsPresent {
Expand Down Expand Up @@ -58,7 +58,7 @@ func newOnlineMessage(source string, d device.Interface) (string, *wrp.Message)
}
}

func offlinePayload(t time.Time, closeReason string, d device.Interface) []byte {
func offlinePayload(t time.Time, d device.Interface) []byte {
statistics := d.Statistics()

return []byte(fmt.Sprintf(`{
Expand All @@ -79,11 +79,11 @@ func offlinePayload(t time.Time, closeReason string, d device.Interface) []byte
statistics.MessagesReceived(),
statistics.ConnectedAt().Format(time.RFC3339Nano),
statistics.UpTime(),
closeReason,
d.CloseReason(),
))
}

func newOfflineMessage(source string, closeReason string, d device.Interface) (string, *wrp.Message) {
func newOfflineMessage(source string, d device.Interface) (string, *wrp.Message) {
eventType := statusEventType(d.ID(), "offline")

return eventType, &wrp.Message{
Expand All @@ -93,6 +93,6 @@ func newOfflineMessage(source string, closeReason string, d device.Interface) (s
ContentType: "json",
PartnerIDs: d.PartnerIDs(),
Metadata: statusMetadata(d),
Payload: offlinePayload(time.Now(), closeReason, d),
Payload: offlinePayload(time.Now(), d),
}
}
3 changes: 1 addition & 2 deletions src/talaria/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ func (d *dispatcher) OnDeviceEvent(event *device.Event) {
}

case device.Disconnect:
// TODO: FIgure out how to get the reason for closure
eventType, message := newOfflineMessage(d.source, "unknown", event.Device)
eventType, message := newOfflineMessage(d.source, event.Device)
if err := d.encodeAndDispatchEvent(eventType, wrp.Msgpack, message); err != nil {
d.errorLog.Log(logging.MessageKey(), "Error dispatching offline event", "eventType", eventType, "destination", message.Destination, logging.ErrorKey(), err)
}
Expand Down
3 changes: 2 additions & 1 deletion src/talaria/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/Comcast/webpa-common/convey"
"github.com/Comcast/webpa-common/device"
"github.com/Comcast/webpa-common/secure"
"github.com/Comcast/webpa-common/wrp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -44,7 +45,7 @@ func testDispatcherConnectEvent(t *testing.T) {
d.On("ID").Return(device.ID("mac:123412341234"))
d.On("PartnerIDs").Return([]string{"partner-1"})
d.On("Convey").Return(convey.C(nil))
d.On("Trust").Return(device.Untrusted)
d.On("Trust").Return(secure.Untrusted)
d.On("ConveyCompliance").Return(convey.Full)

dispatcher.OnDeviceEvent(&device.Event{Type: device.Connect, Device: d})
Expand Down

0 comments on commit bc16d08

Please sign in to comment.