2013-07-14 22:45:35 +04:00
|
|
|
package main
|
|
|
|
|
2013-07-31 22:05:12 +04:00
|
|
|
// machineNum returns the number of machines in the cluster
|
|
|
|
func machineNum() int {
|
2013-08-03 07:21:11 +04:00
|
|
|
response, _ := etcdStore.RawGet("_etcd/machines")
|
|
|
|
|
|
|
|
return len(response)
|
2013-07-31 22:05:12 +04:00
|
|
|
}
|
2013-08-14 08:35:23 +04:00
|
|
|
|
|
|
|
// getMachines gets the current machines in the cluster
|
|
|
|
func getMachines() []string {
|
|
|
|
|
|
|
|
peers := raftServer.Peers()
|
|
|
|
|
|
|
|
machines := make([]string, len(peers)+1)
|
|
|
|
|
|
|
|
leader, _ := nameToEtcdURL(raftServer.Leader())
|
|
|
|
|
2013-08-14 08:42:26 +04:00
|
|
|
i := 0
|
2013-08-14 08:35:23 +04:00
|
|
|
|
|
|
|
if leader != "" {
|
|
|
|
|
|
|
|
// Add leader at the first of the machines list
|
|
|
|
// Add server itself to the machine list
|
|
|
|
// Since peer map does not contain the server itself
|
|
|
|
if leader == info.EtcdURL {
|
|
|
|
machines[i] = info.EtcdURL
|
|
|
|
i++
|
|
|
|
} else {
|
|
|
|
machines[i] = leader
|
|
|
|
i++
|
|
|
|
machines[i] = info.EtcdURL
|
2013-08-14 08:42:26 +04:00
|
|
|
i++
|
2013-08-14 08:35:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all peers to the slice
|
|
|
|
for peerName, _ := range peers {
|
|
|
|
if machine, ok := nameToEtcdURL(peerName); ok {
|
|
|
|
// do not add leader twice
|
|
|
|
if machine != leader {
|
|
|
|
machines[i] = machine
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return machines
|
|
|
|
}
|