mirror of https://github.com/status-im/consul.git
Factor out registerNodes function
This commit is contained in:
parent
5589eadcf5
commit
1e3b0d441b
|
@ -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
|
||||
// coordinates are available for a node it won't appear in this list).
|
||||
// Node returns the raw coordinates for a single node.
|
||||
func (c *Coordinate) Node(args *structs.NodeSpecificRequest, reply *structs.IndexedCoordinates) error {
|
||||
if done, err := c.srv.forward("Coordinate.Node", args, args, reply); done {
|
||||
return err
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -50,16 +51,8 @@ func TestCoordinate_Update(t *testing.T) {
|
|||
|
||||
// Register some nodes.
|
||||
nodes := []string{"node1", "node2"}
|
||||
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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := registerNodes(nodes, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Send an update for the first node.
|
||||
|
@ -201,16 +194,8 @@ func TestCoordinate_Update_ACLDeny(t *testing.T) {
|
|||
|
||||
// Register some nodes.
|
||||
nodes := []string{"node1", "node2"}
|
||||
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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := registerNodes(nodes, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 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.
|
||||
nodes := []string{"foo", "bar", "baz"}
|
||||
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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := registerNodes(nodes, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Send coordinate updates for a few nodes.
|
||||
|
@ -515,16 +492,8 @@ func TestCoordinate_Node(t *testing.T) {
|
|||
|
||||
// Register some nodes.
|
||||
nodes := []string{"foo", "bar"}
|
||||
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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := registerNodes(nodes, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Send coordinate updates for each node.
|
||||
|
@ -582,16 +551,8 @@ func TestCoordinate_Node_ACLDeny(t *testing.T) {
|
|||
|
||||
// Register some nodes.
|
||||
nodes := []string{"node1", "node2"}
|
||||
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 {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if err := registerNodes(nodes, codec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Send an update for the first node. This should go through since we
|
||||
|
@ -646,3 +607,19 @@ node "node1" {
|
|||
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)
|
||||
defer tx.Abort()
|
||||
|
||||
// Get the table index.
|
||||
idx := maxIndexTxn(tx, "coordinates")
|
||||
tableIdx := maxIndexTxn(tx, "coordinates")
|
||||
|
||||
iter, err := tx.Get("coordinates", "node", node)
|
||||
if err != nil {
|
||||
|
@ -60,7 +59,7 @@ func (s *Store) Coordinate(node string, ws memdb.WatchSet) (uint64, lib.Coordina
|
|||
coord := raw.(*structs.Coordinate)
|
||||
results[coord.Segment] = coord.Coord
|
||||
}
|
||||
return idx, results, nil
|
||||
return tableIdx, results, nil
|
||||
}
|
||||
|
||||
// Coordinates queries for all nodes with coordinates.
|
||||
|
|
Loading…
Reference in New Issue