Use IndexedCoordinate instead

This commit is contained in:
Derek Chiang 2015-04-18 17:05:29 -04:00 committed by James Phillips
parent d8dd8d77d4
commit bf5cb7522f
4 changed files with 41 additions and 23 deletions

View File

@ -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,
},
Op: structs.CoordinateSet,
Coord: c,
WriteRequest: structs.WriteRequest{Token: a.config.ACLToken},

View File

@ -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 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
}
*reply = *coord
return nil
})
}
func (c *Coordinate) Update(args *structs.CoordinateUpdateRequest, reply *struct{}) error {

View File

@ -51,10 +51,8 @@ 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(),
}
@ -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",
}

View File

@ -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
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