Use IndexedCoordinate instead

This commit is contained in:
Derek Chiang 2015-04-18 17:05:29 -04:00 committed by James Phillips
parent 979c0c6c9e
commit 23c08aeeb4
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() c = a.client.GetCoordinate()
} }
req := structs.CoordinateUpdateRequest{ req := structs.CoordinateUpdateRequest{
NodeSpecificRequest: structs.NodeSpecificRequest{ Datacenter: a.config.Datacenter,
Datacenter: a.config.Datacenter, Node: a.config.NodeName,
Node: a.config.NodeName,
},
Op: structs.CoordinateSet, Op: structs.CoordinateSet,
Coord: c, Coord: c,
WriteRequest: structs.WriteRequest{Token: a.config.ACLToken}, 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 // 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 // returned. If the node is in a remote DC, then the WAN coordinate of the node
// is returned. // 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 { if done, err := c.srv.forward("Coordinate.Get", args, args, reply); done {
return err return err
} }
state := c.srv.fsm.State() state := c.srv.fsm.State()
_, coord, err := state.CoordinateGet(args.Node) return c.srv.blockingRPC(&args.QueryOptions,
if err != nil { &reply.QueryMeta,
return err state.QueryTables("Coordinates"),
} func() error {
*reply = *coord idx, coord, err := state.CoordinateGet(args.Node)
reply.Index = idx
return nil reply.Coord = coord.Coord
return err
})
} }
func (c *Coordinate) Update(args *structs.CoordinateUpdateRequest, reply *struct{}) error { func (c *Coordinate) Update(args *structs.CoordinateUpdateRequest, reply *struct{}) error {

View file

@ -51,12 +51,10 @@ func TestCoordinate(t *testing.T) {
testutil.WaitForLeader(t, client.Call, "dc1") testutil.WaitForLeader(t, client.Call, "dc1")
arg := structs.CoordinateUpdateRequest{ arg := structs.CoordinateUpdateRequest{
NodeSpecificRequest: structs.NodeSpecificRequest{ Datacenter: "dc1",
Datacenter: "dc1", Node: "node1",
Node: "node1", Op: structs.CoordinateSet,
}, Coord: getRandomCoordinate(),
Op: structs.CoordinateSet,
Coord: getRandomCoordinate(),
} }
var out struct{} var out struct{}
@ -75,8 +73,8 @@ func TestCoordinate(t *testing.T) {
} }
// Get via RPC // Get via RPC
var out2 *structs.Coordinate var out2 *structs.IndexedCoordinate
arg2 := structs.NodeSpecificRequest{ arg2 := structs.CoordinateGetRequest{
Datacenter: "dc1", Datacenter: "dc1",
Node: "node1", Node: "node1",
} }

View file

@ -626,20 +626,40 @@ type Coordinate struct {
Coord *coordinate.Coordinate Coord *coordinate.Coordinate
} }
type IndexedCoordinate struct {
Coord *coordinate.Coordinate
QueryMeta
}
type CoordinateOp string type CoordinateOp string
const ( const (
CoordinateSet CoordinateOp = "set" 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 // CoordinateUpdateRequest is used to update the network coordinate of a given node
type CoordinateUpdateRequest struct { type CoordinateUpdateRequest struct {
NodeSpecificRequest Datacenter string
Op CoordinateOp Node string
Coord *coordinate.Coordinate Op CoordinateOp
Coord *coordinate.Coordinate
WriteRequest WriteRequest
} }
func (c *CoordinateUpdateRequest) RequestDatacenter() string {
return c.Datacenter
}
// EventFireRequest is used to ask a server to fire // EventFireRequest is used to ask a server to fire
// a Serf event. It is a bit odd, since it doesn't depend on // 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 // the catalog or leader. Any node can respond, so it's not quite