Update for new interfaces
This commit is contained in:
parent
0ca9b085a2
commit
a84fdd51e1
|
@ -82,13 +82,7 @@ func (c *Catalog) ListNodes(dc string, reply *structs.Nodes) error {
|
|||
|
||||
// Get the current nodes
|
||||
state := c.srv.fsm.State()
|
||||
rawNodes := state.Nodes()
|
||||
|
||||
// Format the response
|
||||
nodes := structs.Nodes(make([]structs.Node, len(rawNodes)/2))
|
||||
for i := 0; i < len(nodes); i++ {
|
||||
nodes[i] = structs.Node{rawNodes[i*2], rawNodes[i*2+1]}
|
||||
}
|
||||
nodes := state.Nodes()
|
||||
|
||||
*reply = nodes
|
||||
return nil
|
||||
|
|
|
@ -201,7 +201,7 @@ func TestCatalogListNodes(t *testing.T) {
|
|||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode("foo", "127.0.0.1")
|
||||
s1.fsm.State().EnsureNode(structs.Node{"foo", "127.0.0.1"})
|
||||
|
||||
if err := client.Call("Catalog.ListNodes", "dc1", &out); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -235,7 +235,7 @@ func TestCatalogListServices(t *testing.T) {
|
|||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode("foo", "127.0.0.1")
|
||||
s1.fsm.State().EnsureNode(structs.Node{"foo", "127.0.0.1"})
|
||||
s1.fsm.State().EnsureService("foo", "db", "db", "primary", 5000)
|
||||
|
||||
if err := client.Call("Catalog.ListServices", "dc1", &out); err != nil {
|
||||
|
@ -276,7 +276,7 @@ func TestCatalogListServiceNodes(t *testing.T) {
|
|||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode("foo", "127.0.0.1")
|
||||
s1.fsm.State().EnsureNode(structs.Node{"foo", "127.0.0.1"})
|
||||
s1.fsm.State().EnsureService("foo", "db", "db", "primary", 5000)
|
||||
|
||||
if err := client.Call("Catalog.ServiceNodes", &args, &out); err != nil {
|
||||
|
@ -289,6 +289,7 @@ func TestCatalogListServiceNodes(t *testing.T) {
|
|||
|
||||
// Try with a filter
|
||||
args.TagFilter = true
|
||||
out = nil
|
||||
|
||||
if err := client.Call("Catalog.ServiceNodes", &args, &out); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -319,7 +320,7 @@ func TestCatalogNodeServices(t *testing.T) {
|
|||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode("foo", "127.0.0.1")
|
||||
s1.fsm.State().EnsureNode(structs.Node{"foo", "127.0.0.1"})
|
||||
s1.fsm.State().EnsureService("foo", "db", "db", "primary", 5000)
|
||||
s1.fsm.State().EnsureService("foo", "web", "web", "", 80)
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ func (c *consulFSM) applyRegister(buf []byte) interface{} {
|
|||
}
|
||||
|
||||
// Ensure the node
|
||||
c.state.EnsureNode(req.Node, req.Address)
|
||||
node := structs.Node{req.Node, req.Address}
|
||||
c.state.EnsureNode(node)
|
||||
|
||||
// Ensure the service if provided
|
||||
if req.ServiceID != "" && req.ServiceName != "" {
|
||||
|
@ -136,7 +137,8 @@ func (c *consulFSM) Restore(old io.ReadCloser) error {
|
|||
state.EnsureService(req.Node, req.ServiceID, req.ServiceName,
|
||||
req.ServiceTag, req.ServicePort)
|
||||
} else {
|
||||
state.EnsureNode(req.Node, req.Address)
|
||||
node := structs.Node{req.Node, req.Address}
|
||||
state.EnsureNode(node)
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -159,10 +161,10 @@ func (s *consulSnapshot) Persist(sink raft.SnapshotSink) error {
|
|||
|
||||
// Register each node
|
||||
var req structs.RegisterRequest
|
||||
for i := 0; i < len(nodes); i += 2 {
|
||||
for i := 0; i < len(nodes); i++ {
|
||||
req = structs.RegisterRequest{
|
||||
Node: nodes[i],
|
||||
Address: nodes[i+1],
|
||||
Node: nodes[i].Node,
|
||||
Address: nodes[i].Address,
|
||||
}
|
||||
|
||||
// Register the node itself
|
||||
|
@ -173,7 +175,7 @@ func (s *consulSnapshot) Persist(sink raft.SnapshotSink) error {
|
|||
}
|
||||
|
||||
// Register each service this node has
|
||||
services := s.state.NodeServices(nodes[i])
|
||||
services := s.state.NodeServices(nodes[i].Node)
|
||||
for id, props := range services.Services {
|
||||
req.ServiceID = id
|
||||
req.ServiceName = props.Service
|
||||
|
|
|
@ -214,8 +214,8 @@ func TestFSM_SnapshotRestore(t *testing.T) {
|
|||
}
|
||||
|
||||
// Add some state
|
||||
fsm.state.EnsureNode("foo", "127.0.0.1")
|
||||
fsm.state.EnsureNode("baz", "127.0.0.2")
|
||||
fsm.state.EnsureNode(structs.Node{"foo", "127.0.0.1"})
|
||||
fsm.state.EnsureNode(structs.Node{"baz", "127.0.0.2"})
|
||||
fsm.state.EnsureService("foo", "web", "web", "", 80)
|
||||
fsm.state.EnsureService("foo", "db", "db", "primary", 5000)
|
||||
fsm.state.EnsureService("baz", "web", "web", "", 80)
|
||||
|
@ -248,7 +248,7 @@ func TestFSM_SnapshotRestore(t *testing.T) {
|
|||
|
||||
// Verify the contents
|
||||
nodes := fsm2.state.Nodes()
|
||||
if len(nodes) != 4 {
|
||||
if len(nodes) != 2 {
|
||||
t.Fatalf("Bad: %v", nodes)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue