Factor out registerNodes function
This commit is contained in:
parent
f80e70271d
commit
fd4d9f1c16
|
@ -201,8 +201,7 @@ func (c *Coordinate) ListNodes(args *structs.DCSpecificRequest, reply *structs.I
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListNodes returns the list of nodes with their raw network coordinates (if no
|
// Node returns the raw coordinates for a single node.
|
||||||
// coordinates are available for a node it won't appear in this list).
|
|
||||||
func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.IndexedCoordinates) error {
|
func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.IndexedCoordinates) error {
|
||||||
if done, err := c.srv.forward("Coordinate.Node", args, args, reply); done {
|
if done, err := c.srv.forward("Coordinate.Node", args, args, reply); done {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -50,16 +51,8 @@ func TestCoordinate_Update(t *testing.T) {
|
||||||
|
|
||||||
// Register some nodes.
|
// Register some nodes.
|
||||||
nodes := []string{"node1", "node2"}
|
nodes := []string{"node1", "node2"}
|
||||||
for _, node := range nodes {
|
if err := registerNodes(nodes, codec); err != nil {
|
||||||
req := structs.RegisterRequest{
|
t.Fatal(err)
|
||||||
Datacenter: "dc1",
|
|
||||||
Node: node,
|
|
||||||
Address: "127.0.0.1",
|
|
||||||
}
|
|
||||||
var reply struct{}
|
|
||||||
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an update for the first node.
|
// Send an update for the first node.
|
||||||
|
@ -201,16 +194,8 @@ func TestCoordinate_Update_ACLDeny(t *testing.T) {
|
||||||
|
|
||||||
// Register some nodes.
|
// Register some nodes.
|
||||||
nodes := []string{"node1", "node2"}
|
nodes := []string{"node1", "node2"}
|
||||||
for _, node := range nodes {
|
if err := registerNodes(nodes, codec); err != nil {
|
||||||
req := structs.RegisterRequest{
|
t.Fatal(err)
|
||||||
Datacenter: "dc1",
|
|
||||||
Node: node,
|
|
||||||
Address: "127.0.0.1",
|
|
||||||
}
|
|
||||||
var reply struct{}
|
|
||||||
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an update for the first node. This should go through since we
|
// Send an update for the first node. This should go through since we
|
||||||
|
@ -309,16 +294,8 @@ func TestCoordinate_ListNodes(t *testing.T) {
|
||||||
|
|
||||||
// Register some nodes.
|
// Register some nodes.
|
||||||
nodes := []string{"foo", "bar", "baz"}
|
nodes := []string{"foo", "bar", "baz"}
|
||||||
for _, node := range nodes {
|
if err := registerNodes(nodes, codec); err != nil {
|
||||||
req := structs.RegisterRequest{
|
t.Fatal(err)
|
||||||
Datacenter: "dc1",
|
|
||||||
Node: node,
|
|
||||||
Address: "127.0.0.1",
|
|
||||||
}
|
|
||||||
var reply struct{}
|
|
||||||
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send coordinate updates for a few nodes.
|
// Send coordinate updates for a few nodes.
|
||||||
|
@ -515,16 +492,8 @@ func TestCoordinate_Node(t *testing.T) {
|
||||||
|
|
||||||
// Register some nodes.
|
// Register some nodes.
|
||||||
nodes := []string{"foo", "bar"}
|
nodes := []string{"foo", "bar"}
|
||||||
for _, node := range nodes {
|
if err := registerNodes(nodes, codec); err != nil {
|
||||||
req := structs.RegisterRequest{
|
t.Fatal(err)
|
||||||
Datacenter: "dc1",
|
|
||||||
Node: node,
|
|
||||||
Address: "127.0.0.1",
|
|
||||||
}
|
|
||||||
var reply struct{}
|
|
||||||
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send coordinate updates for each node.
|
// Send coordinate updates for each node.
|
||||||
|
@ -582,16 +551,8 @@ func TestCoordinate_Node_ACLDeny(t *testing.T) {
|
||||||
|
|
||||||
// Register some nodes.
|
// Register some nodes.
|
||||||
nodes := []string{"node1", "node2"}
|
nodes := []string{"node1", "node2"}
|
||||||
for _, node := range nodes {
|
if err := registerNodes(nodes, codec); err != nil {
|
||||||
req := structs.RegisterRequest{
|
t.Fatal(err)
|
||||||
Datacenter: "dc1",
|
|
||||||
Node: node,
|
|
||||||
Address: "127.0.0.1",
|
|
||||||
}
|
|
||||||
var reply struct{}
|
|
||||||
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
|
||||||
t.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an update for the first node. This should go through since we
|
// Send an update for the first node. This should go through since we
|
||||||
|
@ -646,3 +607,19 @@ node "node1" {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func registerNodes(nodes []string, codec rpc.ClientCodec) error {
|
||||||
|
for _, node := range nodes {
|
||||||
|
req := structs.RegisterRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
Node: node,
|
||||||
|
Address: "127.0.0.1",
|
||||||
|
}
|
||||||
|
var reply struct{}
|
||||||
|
if err := msgpackrpc.CallWithCodec(codec, "Catalog.Register", &req, &reply); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -46,8 +46,7 @@ func (s *Store) Coordinate(node string, ws memdb.WatchSet) (uint64, lib.Coordina
|
||||||
tx := s.db.Txn(false)
|
tx := s.db.Txn(false)
|
||||||
defer tx.Abort()
|
defer tx.Abort()
|
||||||
|
|
||||||
// Get the table index.
|
tableIdx := maxIndexTxn(tx, "coordinates")
|
||||||
idx := maxIndexTxn(tx, "coordinates")
|
|
||||||
|
|
||||||
iter, err := tx.Get("coordinates", "node", node)
|
iter, err := tx.Get("coordinates", "node", node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,7 +59,7 @@ func (s *Store) Coordinate(node string, ws memdb.WatchSet) (uint64, lib.Coordina
|
||||||
coord := raw.(*structs.Coordinate)
|
coord := raw.(*structs.Coordinate)
|
||||||
results[coord.Segment] = coord.Coord
|
results[coord.Segment] = coord.Coord
|
||||||
}
|
}
|
||||||
return idx, results, nil
|
return tableIdx, results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coordinates queries for all nodes with coordinates.
|
// Coordinates queries for all nodes with coordinates.
|
||||||
|
|
Loading…
Reference in New Issue