mirror of https://github.com/status-im/consul.git
Use IndexedCoordinate instead
This commit is contained in:
parent
d8dd8d77d4
commit
bf5cb7522f
|
@ -576,10 +576,8 @@ func (a *Agent) SendCoordinates(shutdownCh chan struct{}) {
|
|||
c = a.client.GetCoordinate()
|
||||
}
|
||||
req := structs.CoordinateUpdateRequest{
|
||||
NodeSpecificRequest: structs.NodeSpecificRequest{
|
||||
Datacenter: a.config.Datacenter,
|
||||
Node: a.config.NodeName,
|
||||
},
|
||||
Datacenter: a.config.Datacenter,
|
||||
Node: a.config.NodeName,
|
||||
Op: structs.CoordinateSet,
|
||||
Coord: c,
|
||||
WriteRequest: structs.WriteRequest{Token: a.config.ACLToken},
|
||||
|
|
|
@ -13,19 +13,21 @@ type Coordinate struct {
|
|||
// If the node is in the same datacenter, then the LAN coordinate of the node is
|
||||
// returned. If the node is in a remote DC, then the WAN coordinate of the node
|
||||
// is returned.
|
||||
func (c *Coordinate) Get(args *structs.NodeSpecificRequest, reply *structs.Coordinate) error {
|
||||
func (c *Coordinate) Get(args *structs.CoordinateGetRequest, reply *structs.IndexedCoordinate) error {
|
||||
if done, err := c.srv.forward("Coordinate.Get", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
|
||||
state := c.srv.fsm.State()
|
||||
_, coord, err := state.CoordinateGet(args.Node)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = *coord
|
||||
|
||||
return nil
|
||||
return c.srv.blockingRPC(&args.QueryOptions,
|
||||
&reply.QueryMeta,
|
||||
state.QueryTables("Coordinates"),
|
||||
func() error {
|
||||
idx, coord, err := state.CoordinateGet(args.Node)
|
||||
reply.Index = idx
|
||||
reply.Coord = coord.Coord
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Coordinate) Update(args *structs.CoordinateUpdateRequest, reply *struct{}) error {
|
||||
|
|
|
@ -51,12 +51,10 @@ func TestCoordinate(t *testing.T) {
|
|||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
arg := structs.CoordinateUpdateRequest{
|
||||
NodeSpecificRequest: structs.NodeSpecificRequest{
|
||||
Datacenter: "dc1",
|
||||
Node: "node1",
|
||||
},
|
||||
Op: structs.CoordinateSet,
|
||||
Coord: getRandomCoordinate(),
|
||||
Datacenter: "dc1",
|
||||
Node: "node1",
|
||||
Op: structs.CoordinateSet,
|
||||
Coord: getRandomCoordinate(),
|
||||
}
|
||||
|
||||
var out struct{}
|
||||
|
@ -75,8 +73,8 @@ func TestCoordinate(t *testing.T) {
|
|||
}
|
||||
|
||||
// Get via RPC
|
||||
var out2 *structs.Coordinate
|
||||
arg2 := structs.NodeSpecificRequest{
|
||||
var out2 *structs.IndexedCoordinate
|
||||
arg2 := structs.CoordinateGetRequest{
|
||||
Datacenter: "dc1",
|
||||
Node: "node1",
|
||||
}
|
||||
|
|
|
@ -626,20 +626,40 @@ type Coordinate struct {
|
|||
Coord *coordinate.Coordinate
|
||||
}
|
||||
|
||||
type IndexedCoordinate struct {
|
||||
Coord *coordinate.Coordinate
|
||||
QueryMeta
|
||||
}
|
||||
|
||||
type CoordinateOp string
|
||||
|
||||
const (
|
||||
CoordinateSet CoordinateOp = "set"
|
||||
)
|
||||
|
||||
type CoordinateGetRequest struct {
|
||||
Datacenter string
|
||||
Node string
|
||||
QueryOptions
|
||||
}
|
||||
|
||||
func (c *CoordinateGetRequest) RequestDatacenter() string {
|
||||
return c.Datacenter
|
||||
}
|
||||
|
||||
// CoordinateUpdateRequest is used to update the network coordinate of a given node
|
||||
type CoordinateUpdateRequest struct {
|
||||
NodeSpecificRequest
|
||||
Op CoordinateOp
|
||||
Coord *coordinate.Coordinate
|
||||
Datacenter string
|
||||
Node string
|
||||
Op CoordinateOp
|
||||
Coord *coordinate.Coordinate
|
||||
WriteRequest
|
||||
}
|
||||
|
||||
func (c *CoordinateUpdateRequest) RequestDatacenter() string {
|
||||
return c.Datacenter
|
||||
}
|
||||
|
||||
// EventFireRequest is used to ask a server to fire
|
||||
// a Serf event. It is a bit odd, since it doesn't depend on
|
||||
// the catalog or leader. Any node can respond, so it's not quite
|
||||
|
|
Loading…
Reference in New Issue