|
|
@@ -14,8 +14,10 @@ import (
|
|
|
"io/ioutil"
|
|
|
"net"
|
|
|
"net/http"
|
|
|
+ "net/url"
|
|
|
"os"
|
|
|
"os/signal"
|
|
|
+ "path"
|
|
|
"runtime/pprof"
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -267,9 +269,6 @@ func startRaft(securityType int) {
|
|
|
|
|
|
raftServer.Start()
|
|
|
|
|
|
- // start to response to raft requests
|
|
|
- go startRaftTransport(info.RaftPort, securityType)
|
|
|
-
|
|
|
if raftServer.IsLogEmpty() {
|
|
|
|
|
|
// start as a leader in a new cluster
|
|
|
@@ -339,6 +338,9 @@ func startRaft(securityType int) {
|
|
|
go raftServer.Snapshot()
|
|
|
}
|
|
|
|
|
|
+ // start to response to raft requests
|
|
|
+ go startRaftTransport(info.RaftPort, securityType)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// Create transporter using by raft server
|
|
|
@@ -436,6 +438,7 @@ func startClientTransport(port int, st int) {
|
|
|
http.HandleFunc("/machines", MachinesHttpHandler)
|
|
|
http.HandleFunc("/", VersionHttpHandler)
|
|
|
http.HandleFunc("/stats", StatsHttpHandler)
|
|
|
+ http.HandleFunc("/test/", TestHttpHandler)
|
|
|
|
|
|
switch st {
|
|
|
|
|
|
@@ -624,15 +627,19 @@ func joinCluster(s *raft.Server, serverName string) error {
|
|
|
return nil
|
|
|
}
|
|
|
if resp.StatusCode == http.StatusTemporaryRedirect {
|
|
|
+
|
|
|
address := resp.Header.Get("Location")
|
|
|
debugf("Send Join Request to %s", address)
|
|
|
- json.NewEncoder(&b).Encode(command)
|
|
|
- segs := strings.Split(address, "://")
|
|
|
- if len(segs) != 2 {
|
|
|
- return fmt.Errorf("Unable to join: wrong redirection info")
|
|
|
+ u, err := url.Parse(address)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("Unable to join: %s", err.Error())
|
|
|
}
|
|
|
- path := segs[1]
|
|
|
- resp, err = t.Post(path, &b)
|
|
|
+
|
|
|
+ json.NewEncoder(&b).Encode(command)
|
|
|
+
|
|
|
+ resp, err = t.Post(path.Join(u.Host, u.Path), &b)
|
|
|
+
|
|
|
} else if resp.StatusCode == http.StatusBadRequest {
|
|
|
debug("Reach max number machines in the cluster")
|
|
|
return fmt.Errorf(errors[103])
|