1
0
Fork 0

Sart integration of disco service

master
Philip O'Toole 8 years ago
parent d02b7e93bf
commit b0abb64d62

@ -30,6 +30,7 @@ import (
"github.com/rqlite/rqlite/auth"
"github.com/rqlite/rqlite/cluster"
"github.com/rqlite/rqlite/disco"
httpd "github.com/rqlite/rqlite/http"
"github.com/rqlite/rqlite/store"
"github.com/rqlite/rqlite/tcp"
@ -75,6 +76,8 @@ var raftAddr string
var raftAdv string
var joinAddr string
var noVerify bool
var discoURL string
var discoID string
var expvar bool
var pprofEnabled bool
var dsn string
@ -99,6 +102,8 @@ func init() {
flag.StringVar(&raftAdv, "raftadv", "", "Raft advertise address. If not set, same as bind")
flag.StringVar(&joinAddr, "join", "", "Join a cluster via node at protocol://host:port")
flag.BoolVar(&noVerify, "noverify", false, "Skip verification of remote HTTPS cert when joining cluster")
flag.StringVar(&discoURL, "disco", "http://discovery.rqlite.com", "Set Discovery Service URL")
flag.StringVar(&discoID, "discoid", "", "Set Discovery ID. If not set, Discovery Service not used")
flag.BoolVar(&expvar, "expvar", true, "Serve expvar data on HTTP server")
flag.BoolVar(&pprofEnabled, "pprof", true, "Serve pprof data on HTTP server")
flag.StringVar(&dsn, "dsn", "", `SQLite DSN parameters. E.g. "cache=shared&mode=memory"`)
@ -204,6 +209,11 @@ func main() {
log.Fatalf("failed to open cluster service: %s", err.Error())
}
// It doesn't make sense to specify both a disco ID and join URL.
if joinAddr != "" && discoID != "" {
log.Fatalf("specifiying both join addrress and diso ID is not valid")
}
// If join was specified, make the join request.
if joinAddr != "" {
if !store.JoinRequired() {
@ -269,6 +279,10 @@ func main() {
log.Println("rqlite server stopped")
}
func determineJoinAddr(d *disco.Response) string {
return ""
}
func join(joinAddr string, skipVerify bool, raftAddr, raftAdv string) error {
addr := raftAddr
if raftAdv != "" {

@ -10,8 +10,8 @@ import (
"net/http"
)
// DiscoResponse represents the response returned by a Discovery Service.
type DiscoResponse struct {
// Response represents the response returned by a Discovery Service.
type Response struct {
CreatedAt string `json:"created_at"`
DiscoID string `json:"disco_id"`
Nodes []string `json:"nodes"`
@ -36,7 +36,7 @@ func (c *Client) URL() string {
// Register attempts to register with the Discovery Service, using the given
// address.
func (c *Client) Register(id, addr string) (*DiscoResponse, error) {
func (c *Client) Register(id, addr string) (*Response, error) {
m := map[string]string{
"addr": addr,
}
@ -45,7 +45,7 @@ func (c *Client) Register(id, addr string) (*DiscoResponse, error) {
return nil, err
}
url := fmt.Sprintf("%s/%s", c.url, id)
url := c.registrationURL(id)
resp, err := http.Post(url, "application-type/json", bytes.NewReader(b))
if err != nil {
return nil, err
@ -61,10 +61,14 @@ func (c *Client) Register(id, addr string) (*DiscoResponse, error) {
return nil, errors.New(resp.Status)
}
disco := &DiscoResponse{}
if err := json.Unmarshal(b, disco); err != nil {
r := &Response{}
if err := json.Unmarshal(b, r); err != nil {
return nil, err
}
return disco, nil
return r, nil
}
func (c *Client) registrationURL(id string) string {
return fmt.Sprintf("%s/%s", c.url, id)
}

Loading…
Cancel
Save