change getMachines
parent
64e6d54758
commit
49c160b50c
|
@ -212,7 +212,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) {
|
||||||
if c.Name == raftServer.Name() {
|
if c.Name == raftServer.Name() {
|
||||||
// the removed node is this node
|
// the removed node is this node
|
||||||
|
|
||||||
// if the node is not replying the previous logs
|
// if the node is not replaying the previous logs
|
||||||
// and the node has sent out a join request in this
|
// and the node has sent out a join request in this
|
||||||
// start. It is sure that this node received a new remove
|
// start. It is sure that this node received a new remove
|
||||||
// command and need to be removed
|
// command and need to be removed
|
||||||
|
@ -220,7 +220,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) {
|
||||||
debugf("server [%s] is removed", raftServer.Name())
|
debugf("server [%s] is removed", raftServer.Name())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
// the node is replying previous logs and there is a join command
|
// the node is replaying previous logs and there is a join command
|
||||||
// afterwards, we should not exit
|
// afterwards, we should not exit
|
||||||
|
|
||||||
if r.joinIndex == 0 {
|
if r.joinIndex == 0 {
|
||||||
|
|
|
@ -189,7 +189,7 @@ func LeaderHttpHandler(w http.ResponseWriter, req *http.Request) error {
|
||||||
|
|
||||||
// Handler to return all the known machines in the current cluster
|
// Handler to return all the known machines in the current cluster
|
||||||
func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) error {
|
func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) error {
|
||||||
machines := getMachines(true)
|
machines := getMachines(nameToEtcdURL)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write([]byte(strings.Join(machines, ", ")))
|
w.Write([]byte(strings.Join(machines, ", ")))
|
||||||
|
|
12
machines.go
12
machines.go
|
@ -8,22 +8,14 @@ func machineNum() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMachines gets the current machines in the cluster
|
// getMachines gets the current machines in the cluster
|
||||||
func getMachines(etcd bool) []string {
|
func getMachines(toURL func(string) (string, bool)) []string {
|
||||||
|
|
||||||
peers := r.Peers()
|
peers := r.Peers()
|
||||||
|
|
||||||
machines := make([]string, len(peers)+1)
|
machines := make([]string, len(peers)+1)
|
||||||
|
|
||||||
var toURL func(string) (string, bool)
|
|
||||||
|
|
||||||
if etcd {
|
|
||||||
toURL = nameToEtcdURL
|
|
||||||
} else {
|
|
||||||
toURL = nameToRaftURL
|
|
||||||
}
|
|
||||||
|
|
||||||
leader, ok := toURL(r.Leader())
|
leader, ok := toURL(r.Leader())
|
||||||
self := e.url
|
self, _ := toURL(r.Name())
|
||||||
i := 1
|
i := 1
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (r *raftServer) ListenAndServe() {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if r.pendingJoin {
|
if r.pendingJoin {
|
||||||
cluster = getMachines(false)
|
cluster = getMachines(nameToRaftURL)
|
||||||
for i := 0; i < len(cluster); i++ {
|
for i := 0; i < len(cluster); i++ {
|
||||||
u, err := url.Parse(cluster[i])
|
u, err := url.Parse(cluster[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue