Skip to content

Commit

Permalink
Merge pull request #12 from Comcast/feature/go-kit-service-discovery
Browse files Browse the repository at this point in the history
Feature/go kit service discovery
  • Loading branch information
johnabass committed Sep 4, 2017
2 parents d71319f + 2f572a8 commit 47ba3b9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
36 changes: 18 additions & 18 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/petasos
import:
- package: github.com/Comcast/webpa-common
version: 9f0810dec1058c339282960f3e34d9d94f8dd6be
version: cb246362b61aaf042a936fa615a48554d111f9b4
41 changes: 23 additions & 18 deletions src/petasos/petasos.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,42 @@ func petasos(arguments []string) int {
// Now, initialize the service discovery infrastructure
//

serviceOptions, registrar, _, err := service.Initialize(logger, nil, v.Sub(service.DiscoveryKey))
serviceOptions, err := service.FromViper(service.Sub(v))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to initialize service discovery: %s\n", err)
fmt.Fprintf(os.Stderr, "Unable to read service discovery options: %s\n", err)
return 2
}

logging.Info(logger).Log("configurationFile", v.ConfigFileUsed(), "serviceOptions", serviceOptions)
serviceOptions.Logger = logger
services, err := service.New(serviceOptions)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to initialize service discovery: %s\n", err)
return 2
}

instancer, err := services.NewInstancer()
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to obtain service discovery instancer: %s\n", err)
return 2
}

var (
accessor = service.NewUpdatableAccessor(serviceOptions, nil)
subscription = service.Subscription{
Logger: logger,
Registrar: registrar,
Listener: accessor.Update,
accessor = new(service.UpdatableAccessor)
subscription = service.Subscribe(serviceOptions, instancer)

redirectHandler = &service.RedirectHandler{
Logger: logger,
KeyFunc: device.IDHashParser,
Accessor: accessor,
RedirectCode: http.StatusTemporaryRedirect,
}

redirectHandler = service.NewRedirectHandler(
accessor,
http.StatusTemporaryRedirect,
device.IDHashParser,
logger,
)

_, runnable = webPA.Prepare(logger, nil, redirectHandler)
signals = make(chan os.Signal, 1)
)

if err := subscription.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Unable to run subscription: %s", err)
return 3
}
accessor.Consume(subscription)

//
// Execute the runnable, which runs all the servers, and wait for a signal
Expand Down
6 changes: 3 additions & 3 deletions src/petasos/petasos.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"address": ":9191"
},

"discovery": {
"service": {
"servers": ["localhost:2181"],
"serviceName": "talaria",
"environment": "dev"
"path": "/xmidt/local",
"serviceName": "talaria"
},

"log" : {
Expand Down

0 comments on commit 47ba3b9

Please sign in to comment.