bc42074f57
Fix spelling errors, API doc inconsistencies, and formatting issues. * Fix several spelling errors. * Prepend / to v1/event/list path in Watches. * Rename script handlers to match Watch type. * Remove /v1 path prefix on service health API endpoints. Makes request path consistent with the rest of the HTTP API documentation which does not include the /v1 prefix. * Fix bracket formatting issue on Telemetry page. The HTML codes used for brackets inside of the code block are not interpolated, and are shown as literal strings. Replace the numeric HTML codes with the intended character value to fix display formatting. Also placed variable reference on agent/options.html inside code block for consistency with the presentation of other options on the page. * Add missing word to Coordinate.Node docstring. Resolves #6014
107 lines
2.6 KiB
Go
107 lines
2.6 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/hashicorp/serf/coordinate"
|
|
)
|
|
|
|
// CoordinateEntry represents a node and its associated network coordinate.
|
|
type CoordinateEntry struct {
|
|
Node string
|
|
Segment string
|
|
Coord *coordinate.Coordinate
|
|
}
|
|
|
|
// CoordinateDatacenterMap has the coordinates for servers in a given datacenter
|
|
// and area. Network coordinates are only compatible within the same area.
|
|
type CoordinateDatacenterMap struct {
|
|
Datacenter string
|
|
AreaID string
|
|
Coordinates []CoordinateEntry
|
|
}
|
|
|
|
// Coordinate can be used to query the coordinate endpoints
|
|
type Coordinate struct {
|
|
c *Client
|
|
}
|
|
|
|
// Coordinate returns a handle to the coordinate endpoints
|
|
func (c *Client) Coordinate() *Coordinate {
|
|
return &Coordinate{c}
|
|
}
|
|
|
|
// Datacenters is used to return the coordinates of all the servers in the WAN
|
|
// pool.
|
|
func (c *Coordinate) Datacenters() ([]*CoordinateDatacenterMap, error) {
|
|
r := c.c.newRequest("GET", "/v1/coordinate/datacenters")
|
|
_, resp, err := requireOK(c.c.doRequest(r))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var out []*CoordinateDatacenterMap
|
|
if err := decodeBody(resp, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Nodes is used to return the coordinates of all the nodes in the LAN pool.
|
|
func (c *Coordinate) Nodes(q *QueryOptions) ([]*CoordinateEntry, *QueryMeta, error) {
|
|
r := c.c.newRequest("GET", "/v1/coordinate/nodes")
|
|
r.setQueryOptions(q)
|
|
rtt, resp, err := requireOK(c.c.doRequest(r))
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
qm := &QueryMeta{}
|
|
parseQueryMeta(resp, qm)
|
|
qm.RequestTime = rtt
|
|
|
|
var out []*CoordinateEntry
|
|
if err := decodeBody(resp, &out); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
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
|
|
}
|
|
|
|
// Node is used to return the coordinates of a single node in the LAN pool.
|
|
func (c *Coordinate) Node(node string, q *QueryOptions) ([]*CoordinateEntry, *QueryMeta, error) {
|
|
r := c.c.newRequest("GET", "/v1/coordinate/node/"+node)
|
|
r.setQueryOptions(q)
|
|
rtt, resp, err := requireOK(c.c.doRequest(r))
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
qm := &QueryMeta{}
|
|
parseQueryMeta(resp, qm)
|
|
qm.RequestTime = rtt
|
|
|
|
var out []*CoordinateEntry
|
|
if err := decodeBody(resp, &out); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return out, qm, nil
|
|
}
|