mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Add /machines and /machines/:name endpoints.
This commit is contained in:
parent
c3247755ea
commit
3fff1a8dcd
@ -300,6 +300,8 @@ func (s *PeerServer) HTTPHandler() http.Handler {
|
|||||||
router.HandleFunc("/remove/{name:.+}", s.RemoveHttpHandler)
|
router.HandleFunc("/remove/{name:.+}", s.RemoveHttpHandler)
|
||||||
router.HandleFunc("/config", s.getClusterConfigHttpHandler).Methods("GET")
|
router.HandleFunc("/config", s.getClusterConfigHttpHandler).Methods("GET")
|
||||||
router.HandleFunc("/config", s.setClusterConfigHttpHandler).Methods("PUT")
|
router.HandleFunc("/config", s.setClusterConfigHttpHandler).Methods("PUT")
|
||||||
|
router.HandleFunc("/machines", s.getMachinesHttpHandler).Methods("GET")
|
||||||
|
router.HandleFunc("/machines/{name}", s.getMachineHttpHandler).Methods("GET")
|
||||||
router.HandleFunc("/vote", s.VoteHttpHandler)
|
router.HandleFunc("/vote", s.VoteHttpHandler)
|
||||||
router.HandleFunc("/log", s.GetLogHttpHandler)
|
router.HandleFunc("/log", s.GetLogHttpHandler)
|
||||||
router.HandleFunc("/log/append", s.AppendEntriesHttpHandler)
|
router.HandleFunc("/log/append", s.AppendEntriesHttpHandler)
|
||||||
|
@ -227,6 +227,50 @@ func (ps *PeerServer) setClusterConfigHttpHandler(w http.ResponseWriter, req *ht
|
|||||||
json.NewEncoder(w).Encode(&ps.clusterConfig)
|
json.NewEncoder(w).Encode(&ps.clusterConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieves a list of peers and proxies.
|
||||||
|
func (ps *PeerServer) getMachinesHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
machines := make([]*machineMessage, 0)
|
||||||
|
for _, name := range ps.registry.Peers() {
|
||||||
|
machines = append(machines, ps.getMachineMessage(name))
|
||||||
|
}
|
||||||
|
for _, name := range ps.registry.Proxies() {
|
||||||
|
machines = append(machines, ps.getMachineMessage(name))
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(&machines)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve single peer or proxy.
|
||||||
|
func (ps *PeerServer) getMachineHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
vars := mux.Vars(req)
|
||||||
|
json.NewEncoder(w).Encode(ps.getMachineMessage(vars["name"]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *PeerServer) getMachineMessage(name string) *machineMessage {
|
||||||
|
if ps.registry.PeerExists(name) {
|
||||||
|
clientURL, _ := ps.registry.ClientURL(name)
|
||||||
|
peerURL, _ := ps.registry.PeerURL(name)
|
||||||
|
return &machineMessage{
|
||||||
|
Name: name,
|
||||||
|
Mode: PeerMode,
|
||||||
|
ClientURL: clientURL,
|
||||||
|
PeerURL: peerURL,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ps.registry.ProxyExists(name) {
|
||||||
|
clientURL, _ := ps.registry.ProxyClientURL(name)
|
||||||
|
peerURL, _ := ps.registry.ProxyPeerURL(name)
|
||||||
|
return &machineMessage{
|
||||||
|
Name: name,
|
||||||
|
Mode: ProxyMode,
|
||||||
|
ClientURL: clientURL,
|
||||||
|
PeerURL: peerURL,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Response to the name request
|
// Response to the name request
|
||||||
func (ps *PeerServer) NameHttpHandler(w http.ResponseWriter, req *http.Request) {
|
func (ps *PeerServer) NameHttpHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
log.Debugf("[recv] Get %s/name/ ", ps.Config.URL)
|
log.Debugf("[recv] Get %s/name/ ", ps.Config.URL)
|
||||||
@ -272,3 +316,11 @@ func (ps *PeerServer) UpgradeHttpHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// machineMessage represents information about a peer or proxy in the registry.
|
||||||
|
type machineMessage struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Mode Mode `json:"mode"`
|
||||||
|
ClientURL string `json:"clientURL"`
|
||||||
|
PeerURL string `json:"peerURL"`
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ func TestProxy(t *testing.T) {
|
|||||||
|
|
||||||
// Check that all peers and proxies have the value.
|
// Check that all peers and proxies have the value.
|
||||||
for i, _ := range etcds {
|
for i, _ := range etcds {
|
||||||
resp, err := tests.Get(fmt.Sprintf("http://localhost:%d/v2/keys/foo", 4000 + (i+1)))
|
resp, err := tests.Get(fmt.Sprintf("http://localhost:%d/v2/keys/foo", 4000+(i+1)))
|
||||||
if assert.NoError(t, err) {
|
if assert.NoError(t, err) {
|
||||||
body := tests.ReadBodyJSON(resp)
|
body := tests.ReadBodyJSON(resp)
|
||||||
if node, _ := body["node"].(map[string]interface{}); assert.NotNil(t, node) {
|
if node, _ := body["node"].(map[string]interface{}); assert.NotNil(t, node) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user