CheckServiceNodes will return node checks that are not service associated

This commit is contained in:
Armon Dadgar 2014-01-15 11:14:28 -10:00
parent 15719e6d15
commit 7831f34606
2 changed files with 24 additions and 5 deletions

View File

@ -526,9 +526,13 @@ func (s *StateStore) parseCheckServiceNodes(tx *MDBTxn, res []interface{}, err e
panic(fmt.Errorf("Failed to join node: %v", err)) panic(fmt.Errorf("Failed to join node: %v", err))
} }
// Get any associated checks // Get any associated checks of the service
checks := parseHealthChecks(s.checkTable.GetTxn(tx, "node", srv.Node, srv.ServiceID)) checks := parseHealthChecks(s.checkTable.GetTxn(tx, "node", srv.Node, srv.ServiceID))
// Get any checks of the node, not assciated with any service
nodeChecks := parseHealthChecks(s.checkTable.GetTxn(tx, "node", srv.Node, ""))
checks = append(checks, nodeChecks...)
// Setup the node // Setup the node
nodes[i].Node = *nodeRes[0].(*structs.Node) nodes[i].Node = *nodeRes[0].(*structs.Node)
nodes[i].Service = structs.NodeService{ nodes[i].Service = structs.NodeService{

View File

@ -716,6 +716,15 @@ func TestCheckServiceNodes(t *testing.T) {
if err := store.EnsureCheck(check); err != nil { if err := store.EnsureCheck(check); err != nil {
t.Fatalf("err: %v") t.Fatalf("err: %v")
} }
check = &structs.HealthCheck{
Node: "foo",
CheckID: serfCheckID,
Name: serfCheckName,
Status: structs.HealthPassing,
}
if err := store.EnsureCheck(check); err != nil {
t.Fatalf("err: %v")
}
nodes := store.CheckServiceNodes("db") nodes := store.CheckServiceNodes("db")
if len(nodes) != 1 { if len(nodes) != 1 {
@ -728,10 +737,13 @@ func TestCheckServiceNodes(t *testing.T) {
if nodes[0].Service.ID != "db1" { if nodes[0].Service.ID != "db1" {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
if len(nodes[0].Checks) != 1 { if len(nodes[0].Checks) != 2 {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
if nodes[0].Checks[0].Status != structs.HealthPassing { if nodes[0].Checks[0].CheckID != "db" {
t.Fatalf("Bad: %v", nodes[0])
}
if nodes[0].Checks[1].CheckID != serfCheckID {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
@ -746,10 +758,13 @@ func TestCheckServiceNodes(t *testing.T) {
if nodes[0].Service.ID != "db1" { if nodes[0].Service.ID != "db1" {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
if len(nodes[0].Checks) != 1 { if len(nodes[0].Checks) != 2 {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
if nodes[0].Checks[0].Status != structs.HealthPassing { if nodes[0].Checks[0].CheckID != "db" {
t.Fatalf("Bad: %v", nodes[0])
}
if nodes[0].Checks[1].CheckID != serfCheckID {
t.Fatalf("Bad: %v", nodes[0]) t.Fatalf("Bad: %v", nodes[0])
} }
} }