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 {
|
|
|
|
|
2013-08-15 01:45:47 +04:00
|
|
|
peers := r.server.Peers()
|
2013-08-14 08:35:23 +04:00
|
|
|
|
|
|
|
machines := make([]string, len(peers)+1)
|
|
|
|
|
2013-08-15 01:45:47 +04:00
|
|
|
leader, ok := nameToEtcdURL(r.server.Leader())
|
|
|
|
self := e.url
|
2013-08-14 22:27:54 +04:00
|
|
|
i := 1
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
machines[0] = leader
|
|
|
|
if leader != self {
|
|
|
|
machines[1] = self
|
|
|
|
i = 2
|
2013-08-14 08:35:23 +04:00
|
|
|
}
|
2013-08-14 22:27:54 +04:00
|
|
|
} else {
|
|
|
|
machines[0] = self
|
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
|
|
|
|
}
|