forked from ehazlett/stellar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health.go
44 lines (37 loc) · 964 Bytes
/
health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cluster
import (
"context"
api "github.com/ehazlett/stellar/api/services/cluster/v1"
healthapi "github.com/ehazlett/stellar/api/services/health/v1"
"github.com/ehazlett/stellar/client"
ptypes "github.com/gogo/protobuf/types"
)
func (s *service) Health(ctx context.Context, req *api.HealthRequest) (*api.HealthResponse, error) {
nodes, err := s.nodes()
if err != nil {
return nil, err
}
status := map[*api.Node]*healthapi.HealthResponse{}
for _, node := range nodes {
nc, err := client.NewClient(node.Addr)
if err != nil {
return nil, err
}
resp, err := nc.HealthService().Health(context.Background(), &ptypes.Empty{})
if err != nil {
return nil, err
}
status[node] = resp
nc.Close()
}
nodeHealth := []*api.NodeHealth{}
for node, resp := range status {
nodeHealth = append(nodeHealth, &api.NodeHealth{
Node: node,
Health: resp.Health,
})
}
return &api.HealthResponse{
Nodes: nodeHealth,
}, nil
}