fix join command

This commit is contained in:
Xiang Li 2013-08-10 17:00:25 -07:00
parent bbf78b076a
commit 84624f1ec0
2 changed files with 7 additions and 12 deletions

View File

@ -17,7 +17,6 @@ import (
"net/url"
"os"
"os/signal"
"path"
"runtime/pprof"
"strings"
"time"
@ -624,15 +623,10 @@ func joinCluster(s *raft.Server, serverName string) error {
address := resp.Header.Get("Location")
debugf("Send Join Request to %s", address)
u, err := url.Parse(address)
if err != nil {
return fmt.Errorf("Unable to join: %s", err.Error())
}
json.NewEncoder(&b).Encode(command)
resp, err = t.Post(path.Join(u.Host, u.Path), &b)
resp, err = t.Post(address, &b)
} else if resp.StatusCode == http.StatusBadRequest {
debug("Reach max number machines in the cluster")

View File

@ -106,7 +106,7 @@ func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
}
// Dispatch the command to leader
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool) {
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, etcd bool) {
if raftServer.State() == "leader" {
if body, err := raftServer.Do(c); err != nil {
if _, ok := err.(store.NotFoundError); ok {
@ -170,11 +170,12 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool)
var url string
if client {
clientAddr, _ := getEtcdURL(raftServer.Leader())
url = clientAddr + path
if etcd {
etcdAddr, _ := nameToEtcdURL(raftServer.Leader())
url = etcdAddr + path
} else {
url = raftServer.Leader() + path
raftAddr, _ := nameToRaftURL(raftServer.Leader())
url = raftAddr + path
}
debugf("Redirect to %s", url)