mirror of https://github.com/status-im/consul.git
Added coordinate update http endpoint
This commit is contained in:
parent
d56936e27a
commit
291455f475
|
@ -104,3 +104,25 @@ func (s *HTTPServer) CoordinateNodes(resp http.ResponseWriter, req *http.Request
|
||||||
|
|
||||||
return out.Coordinates, nil
|
return out.Coordinates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CoordinateUpdate inserts or updates the LAN coordinate of a node.
|
||||||
|
func (s *HTTPServer) CoordinateUpdate(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
if req.Method != "PUT" {
|
||||||
|
return nil, MethodNotAllowedError{req.Method, []string{"PUT"}}
|
||||||
|
}
|
||||||
|
|
||||||
|
args := structs.CoordinateUpdateRequest{}
|
||||||
|
if err := decodeBody(req, &args, nil); err != nil {
|
||||||
|
resp.WriteHeader(http.StatusBadRequest)
|
||||||
|
fmt.Fprintf(resp, "Request decode failed: %v", err)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
s.parseDC(req, &args.Datacenter)
|
||||||
|
|
||||||
|
var reply struct{}
|
||||||
|
if err := s.agent.RPC("Coordinate.Update", &args, &reply); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
|
@ -139,9 +139,11 @@ func (s *HTTPServer) handler(enableDebug bool) http.Handler {
|
||||||
if !s.agent.config.DisableCoordinates {
|
if !s.agent.config.DisableCoordinates {
|
||||||
handleFuncMetrics("/v1/coordinate/datacenters", s.wrap(s.CoordinateDatacenters))
|
handleFuncMetrics("/v1/coordinate/datacenters", s.wrap(s.CoordinateDatacenters))
|
||||||
handleFuncMetrics("/v1/coordinate/nodes", s.wrap(s.CoordinateNodes))
|
handleFuncMetrics("/v1/coordinate/nodes", s.wrap(s.CoordinateNodes))
|
||||||
|
handleFuncMetrics("/v1/coordinate/update", s.wrap(s.CoordinateUpdate))
|
||||||
} else {
|
} else {
|
||||||
handleFuncMetrics("/v1/coordinate/datacenters", s.wrap(coordinateDisabled))
|
handleFuncMetrics("/v1/coordinate/datacenters", s.wrap(coordinateDisabled))
|
||||||
handleFuncMetrics("/v1/coordinate/nodes", s.wrap(coordinateDisabled))
|
handleFuncMetrics("/v1/coordinate/nodes", s.wrap(coordinateDisabled))
|
||||||
|
handleFuncMetrics("/v1/coordinate/update", s.wrap(coordinateDisabled))
|
||||||
}
|
}
|
||||||
handleFuncMetrics("/v1/event/fire/", s.wrap(s.EventFire))
|
handleFuncMetrics("/v1/event/fire/", s.wrap(s.EventFire))
|
||||||
handleFuncMetrics("/v1/event/list", s.wrap(s.EventList))
|
handleFuncMetrics("/v1/event/list", s.wrap(s.EventList))
|
||||||
|
|
|
@ -66,3 +66,20 @@ func (c *Coordinate) Nodes(q *QueryOptions) ([]*CoordinateEntry, *QueryMeta, err
|
||||||
}
|
}
|
||||||
return out, qm, nil
|
return out, qm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update inserts or updates the LAN coordinate of a node.
|
||||||
|
func (c *Coordinate) Update(coord *CoordinateEntry, q *WriteOptions) (*WriteMeta, error) {
|
||||||
|
r := c.c.newRequest("PUT", "/v1/coordinate/update")
|
||||||
|
r.setWriteOptions(q)
|
||||||
|
r.obj = coord
|
||||||
|
rtt, resp, err := requireOK(c.c.doRequest(r))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
wm := &WriteMeta{}
|
||||||
|
wm.RequestTime = rtt
|
||||||
|
|
||||||
|
return wm, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue