Skip to content

Commit

Permalink
Merge pull request #15 from Comcast/feature/integrate_device_health
Browse files Browse the repository at this point in the history
Integrated the devicehealth package
  • Loading branch information
johnabass authored Aug 17, 2017
2 parents 2a6005b + d35e2f9 commit 94a3ebc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 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,7 +2,7 @@ package: .
homepage: https://github.com/Comcast/talaria
import:
- package: github.com/Comcast/webpa-common
version: ae4ce7815a4dc6a3d982f6aee96619da71ffc358
version: 8c3337c32f98e4b38fea36b1d3c2dd03d7f95cd4
subpackages:
- device
- logging
Expand Down
31 changes: 21 additions & 10 deletions src/talaria/talaria.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ package main

import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"time"

"github.com/Comcast/webpa-common/concurrent"
"github.com/Comcast/webpa-common/device"
"github.com/Comcast/webpa-common/device/devicehealth"
"github.com/Comcast/webpa-common/health"
"github.com/Comcast/webpa-common/logging"
"github.com/Comcast/webpa-common/server"
"github.com/Comcast/webpa-common/service"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"time"
)

const (
Expand All @@ -25,7 +28,7 @@ const (
// startDeviceManagement handles the configuration and initialization of the device management subsystem
// for talaria. The returned HTTP handler can be used for device connections and messages, while the returned
// Manager can be used to route and administer the set of connected devices.
func startDeviceManagement(logger logging.Logger, v *viper.Viper) (http.Handler, device.Manager, error) {
func startDeviceManagement(logger logging.Logger, h *health.Health, v *viper.Viper) (http.Handler, device.Manager, error) {
deviceOptions, err := device.NewOptions(logger, v.Sub(device.DeviceManagerKey))
if err != nil {
return nil, nil, err
Expand All @@ -45,7 +48,14 @@ func startDeviceManagement(logger logging.Logger, v *viper.Viper) (http.Handler,
RefreshInterval: 10 * time.Second,
}).Listen()

deviceOptions.Listeners = []device.Listener{connectedDeviceListener, outboundListener}
deviceOptions.Listeners = []device.Listener{
connectedDeviceListener,
outboundListener,
(&devicehealth.Listener{
Dispatcher: h,
}).OnDeviceEvent,
}

manager := device.NewManager(deviceOptions, nil)
primaryHandler, err := NewPrimaryHandler(logger, connectedUpdates, manager, v)
return primaryHandler, manager, err
Expand Down Expand Up @@ -76,14 +86,15 @@ func talaria(arguments []string) int {
// Initialize the manager first, as if it fails we don't want to advertise this service
//

primaryHandler, manager, err := startDeviceManagement(logger, v)
health := webPA.Health.NewHealth(logger, devicehealth.Options...)
primaryHandler, manager, err := startDeviceManagement(logger, health, v)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to start device management: %s\n", err)
return 1
}

_, runnable := webPA.Prepare(logger, primaryHandler)
waitGroup, shutdown, err := concurrent.Execute(runnable)
_, talariaServer := webPA.Prepare(logger, health, primaryHandler)
waitGroup, shutdown, err := concurrent.Execute(talariaServer)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to start device manager: %s\n", err)
return 1
Expand Down

0 comments on commit 94a3ebc

Please sign in to comment.