Skip to content

Commit

Permalink
Merge pull request #601 from mreiferson/nsqd_config_endpoint_601
Browse files Browse the repository at this point in the history
nsqd: ability to dynamically reconfigure nsqlookupd addresses
  • Loading branch information
jehiah committed Jul 18, 2015
2 parents 917a6c8 + f387012 commit 9376ebc
Show file tree
Hide file tree
Showing 36 changed files with 849 additions and 944 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: go
go:
- 1.3.3
- 1.4.1
- 1.4.2
env:
- GOARCH=amd64
- GOARCH=386
sudo: false
script:
- curl -s https://raw.githubusercontent.com/pote/gpm/v1.2.3/bin/gpm > gpm
- chmod +x gpm
Expand Down
1 change: 1 addition & 0 deletions Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ github.com/mreiferson/go-options 2cf7eb1fdd83e2bb3375fef6fdadb04c3ad564da
github.com/mreiferson/go-snappystream 028eae7ab5c4c9e2d1cb4c4ca1e53259bbe7e504 # v0.2.3
github.com/bitly/timer_metrics afad1794bb13e2a094720aeb27c088aa64564895
github.com/blang/semver 9bf7bff48b0388cb75991e58c6df7d13e982f1f2
github.com/julienschmidt/httprouter 6aacfd5ab513e34f7e64ea9627ab9670371b34e7
4 changes: 2 additions & 2 deletions apps/nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ func main() {
}
cfg.Validate()

opts := nsqd.NewNSQDOptions()
opts := nsqd.NewOptions()
options.Resolve(opts, flagSet, cfg)
nsqd := nsqd.NewNSQD(opts)
nsqd := nsqd.New(opts)

nsqd.LoadMetadata()
err := nsqd.PersistMetadata()
Expand Down
4 changes: 2 additions & 2 deletions apps/nsqd/nsqd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func TestConfigFlagParsing(t *testing.T) {
toml.DecodeReader(f, &cfg)
cfg.Validate()

opts := nsqd.NewNSQDOptions()
opts := nsqd.NewOptions()
options.Resolve(opts, flagSet, cfg)
nsqd.NewNSQD(opts)
nsqd.New(opts)

if opts.TLSMinVersion != tls.VersionTLS10 {
t.Errorf("min %#v not expected %#v", opts.TLSMinVersion, tls.VersionTLS10)
Expand Down
4 changes: 2 additions & 2 deletions apps/nsqlookupd/nsqlookupd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func main() {
}
}

opts := nsqlookupd.NewNSQLookupdOptions()
opts := nsqlookupd.NewOptions()
options.Resolve(opts, flagSet, cfg)
daemon := nsqlookupd.NewNSQLookupd(opts)
daemon := nsqlookupd.New(opts)

daemon.Main()
<-signalChan
Expand Down
51 changes: 25 additions & 26 deletions internal/http_api/api_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"fmt"
"net/http"
"strconv"

"github.com/julienschmidt/httprouter"
)

type APIHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (interface{}, error)

type Err struct {
Code int
Text string
Expand All @@ -24,40 +28,35 @@ func acceptVersion(req *http.Request) int {
return 0
}

func RequirePOST(req *http.Request, f func() (interface{}, error)) func() (interface{}, error) {
if req.Method != "POST" {
return func() (interface{}, error) {
return nil, Err{405, "INVALID_REQUEST"}
func NegotiateVersion(f APIHandler) httprouter.Handle {
return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
data, err := f(w, req, ps)
if err != nil {
if acceptVersion(req) == 1 {
RespondV1(w, err.(Err).Code, err)
} else {
// this handler always returns 500 for backwards compatibility
Respond(w, 500, err.Error(), nil)
}
return
}
}
return f
}

func NegotiateVersionWrapper(w http.ResponseWriter, req *http.Request, f func() (interface{}, error)) {
data, err := f()
if err != nil {
if acceptVersion(req) == 1 {
RespondV1(w, err.(Err).Code, err)
RespondV1(w, 200, data)
} else {
// this handler always returns 500 for backwards compatibility
Respond(w, 500, err.Error(), nil)
Respond(w, 200, "OK", data)
}
return
}
if acceptVersion(req) == 1 {
RespondV1(w, 200, data)
} else {
Respond(w, 200, "OK", data)
}
}

func V1Wrapper(w http.ResponseWriter, req *http.Request, f func() (interface{}, error)) {
data, err := f()
if err != nil {
RespondV1(w, err.(Err).Code, err)
return
func V1(f APIHandler) httprouter.Handle {
return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
data, err := f(w, req, ps)
if err != nil {
RespondV1(w, err.(Err).Code, err)
return
}
RespondV1(w, 200, data)
}
RespondV1(w, 200, data)
}

func Respond(w http.ResponseWriter, statusCode int, statusTxt string, data interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion internal/http_api/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/bitly/nsq/internal/app"
)

func Serve(listener net.Listener, handler http.Handler, l app.Logger, proto string) {
func Serve(listener net.Listener, handler http.Handler, proto string, l app.Logger) {
l.Output(2, fmt.Sprintf("%s: listening on %s", proto, listener.Addr()))

server := &http.Server{
Expand Down
Loading

0 comments on commit 9376ebc

Please sign in to comment.