consul: Adding Misc RPC endpoint
This commit is contained in:
parent
75f9a126ae
commit
702fe3afda
|
@ -0,0 +1,48 @@
|
|||
package consul
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/consul/consul/structs"
|
||||
)
|
||||
|
||||
// Misc endpoint is used to query the miscellaneous info that
|
||||
// does not necessarily fit into the other systems. It is also
|
||||
// used to hold undocumented APIs that users should not rely on.
|
||||
type Misc struct {
|
||||
srv *Server
|
||||
}
|
||||
|
||||
// ChecksInState is used to get all the checks in a given state
|
||||
func (m *Misc) NodeInfo(args *structs.NodeSpecificRequest,
|
||||
reply *structs.IndexedNodeDump) error {
|
||||
if done, err := m.srv.forward("Misc.NodeInfo", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the state specific checks
|
||||
state := m.srv.fsm.State()
|
||||
return m.srv.blockingRPC(&args.QueryOptions,
|
||||
&reply.QueryMeta,
|
||||
state.QueryTables("NodeInfo"),
|
||||
func() error {
|
||||
reply.Index, reply.Dump = state.NodeInfo(args.Node)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// ChecksInState is used to get all the checks in a given state
|
||||
func (m *Misc) NodeDump(args *structs.DCSpecificRequest,
|
||||
reply *structs.IndexedNodeDump) error {
|
||||
if done, err := m.srv.forward("Misc.NodeDump", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the state specific checks
|
||||
state := m.srv.fsm.State()
|
||||
return m.srv.blockingRPC(&args.QueryOptions,
|
||||
&reply.QueryMeta,
|
||||
state.QueryTables("NodeDump"),
|
||||
func() error {
|
||||
reply.Index, reply.Dump = state.NodeDump()
|
||||
return nil
|
||||
})
|
||||
}
|
|
@ -112,6 +112,7 @@ type endpoints struct {
|
|||
Raft *Raft
|
||||
Status *Status
|
||||
KVS *KVS
|
||||
Misc *Misc
|
||||
}
|
||||
|
||||
// NewServer is used to construct a new Consul server from the
|
||||
|
@ -311,6 +312,7 @@ func (s *Server) setupRPC(tlsConfig *tls.Config) error {
|
|||
s.endpoints.Catalog = &Catalog{s}
|
||||
s.endpoints.Health = &Health{s}
|
||||
s.endpoints.KVS = &KVS{s}
|
||||
s.endpoints.Misc = &Misc{s}
|
||||
|
||||
// Register the handlers
|
||||
s.rpcServer.Register(s.endpoints.Status)
|
||||
|
@ -318,6 +320,7 @@ func (s *Server) setupRPC(tlsConfig *tls.Config) error {
|
|||
s.rpcServer.Register(s.endpoints.Catalog)
|
||||
s.rpcServer.Register(s.endpoints.Health)
|
||||
s.rpcServer.Register(s.endpoints.KVS)
|
||||
s.rpcServer.Register(s.endpoints.Misc)
|
||||
|
||||
list, err := net.ListenTCP("tcp", s.config.RPCAddr)
|
||||
if err != nil {
|
||||
|
|
|
@ -746,7 +746,7 @@ func (s *StateStore) parseCheckServiceNodes(tx *MDBTxn, res []interface{}, err e
|
|||
}
|
||||
|
||||
// NodeInfo is used to generate the full info about a node.
|
||||
func (s *StateStore) NodeInfo(node string) (uint64, *structs.NodeInfo) {
|
||||
func (s *StateStore) NodeInfo(node string) (uint64, structs.NodeDump) {
|
||||
tables := s.queryTables["NodeInfo"]
|
||||
tx, err := tables.StartTxn(true)
|
||||
if err != nil {
|
||||
|
@ -760,12 +760,7 @@ func (s *StateStore) NodeInfo(node string) (uint64, *structs.NodeInfo) {
|
|||
}
|
||||
|
||||
res, err := s.nodeTable.GetTxn(tx, "id", node)
|
||||
dump := s.parseNodeInfo(tx, res, err)
|
||||
var n *structs.NodeInfo
|
||||
if len(dump) > 0 {
|
||||
n = dump[0]
|
||||
}
|
||||
return idx, n
|
||||
return idx, s.parseNodeInfo(tx, res, err)
|
||||
}
|
||||
|
||||
// NodeDump is used to generate the NodeInfo for all nodes. This is very expensive,
|
||||
|
|
|
@ -1101,14 +1101,15 @@ func TestNodeInfo(t *testing.T) {
|
|||
t.Fatalf("err: %v")
|
||||
}
|
||||
|
||||
idx, info := store.NodeInfo("foo")
|
||||
idx, dump := store.NodeInfo("foo")
|
||||
if idx != 4 {
|
||||
t.Fatalf("bad: %v", idx)
|
||||
}
|
||||
if info == nil {
|
||||
t.Fatalf("Bad: %v", info)
|
||||
if len(dump) != 1 {
|
||||
t.Fatalf("Bad: %v", dump)
|
||||
}
|
||||
|
||||
info := dump[0]
|
||||
if info.Node != "foo" {
|
||||
t.Fatalf("Bad: %v", info)
|
||||
}
|
||||
|
|
|
@ -265,6 +265,11 @@ type IndexedCheckServiceNodes struct {
|
|||
QueryMeta
|
||||
}
|
||||
|
||||
type IndexedNodeDump struct {
|
||||
Dump NodeDump
|
||||
QueryMeta
|
||||
}
|
||||
|
||||
// DirEntry is used to represent a directory entry. This is
|
||||
// used for values in our Key-Value store.
|
||||
type DirEntry struct {
|
||||
|
|
Loading…
Reference in New Issue