mirror of https://github.com/status-im/consul.git
Add `/v1/agent/self` and return local agent config
This commit is contained in:
parent
39c9011ade
commit
d0e447d29b
|
@ -311,6 +311,11 @@ func (a *Agent) ForceLeave(node string) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// LocalMember is used to return the local node
|
||||
func (a *Agent) LocalMember() serf.Member {
|
||||
return a.server.LocalMember()
|
||||
}
|
||||
|
||||
// LANMembers is used to retrieve the LAN members
|
||||
func (a *Agent) LANMembers() []serf.Member {
|
||||
if a.server != nil {
|
||||
|
|
|
@ -7,6 +7,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func (s *HTTPServer) AgentSelf(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
return s.agent.LocalMember(), nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) AgentServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
services := s.agent.state.Services()
|
||||
return services, nil
|
||||
|
|
|
@ -66,6 +66,28 @@ func TestHTTPAgentChecks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHTTPAgentSelf(t *testing.T) {
|
||||
dir, srv := makeHTTPServer(t)
|
||||
defer os.RemoveAll(dir)
|
||||
defer srv.Shutdown()
|
||||
defer srv.agent.Shutdown()
|
||||
|
||||
req, err := http.NewRequest("GET", "/v1/agent/self", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
obj, err := srv.AgentSelf(nil, req)
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
|
||||
val := obj.(serf.Member)
|
||||
if int(val.Port) != srv.agent.config.Ports.SerfLan {
|
||||
t.Fatalf("incorrect port: %v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPAgentMembers(t *testing.T) {
|
||||
dir, srv := makeHTTPServer(t)
|
||||
defer os.RemoveAll(dir)
|
||||
|
|
|
@ -76,6 +76,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
|
|||
s.mux.HandleFunc("/v1/health/state/", s.wrap(s.HealthChecksInState))
|
||||
s.mux.HandleFunc("/v1/health/service/", s.wrap(s.HealthServiceNodes))
|
||||
|
||||
s.mux.HandleFunc("/v1/agent/self", s.wrap(s.AgentSelf))
|
||||
s.mux.HandleFunc("/v1/agent/services", s.wrap(s.AgentServices))
|
||||
s.mux.HandleFunc("/v1/agent/checks", s.wrap(s.AgentChecks))
|
||||
s.mux.HandleFunc("/v1/agent/members", s.wrap(s.AgentMembers))
|
||||
|
|
|
@ -28,7 +28,8 @@ Status:
|
|||
* /v1/status/peers : Returns the current Raft peer set
|
||||
|
||||
Agent:
|
||||
* /v1/agent/checks: Returns the checks the local agent is managing
|
||||
* /v1/agent/self : Returns the local configuration
|
||||
* /v1/agent/checks : Returns the checks the local agent is managing
|
||||
* /v1/agent/services : Returns the services local agent is managing
|
||||
* /v1/agent/members : Returns the members as seen by the local serf agent
|
||||
* /v1/agent/join/<node> : Instructs the local agent to join a node
|
||||
|
|
|
@ -484,6 +484,11 @@ func (s *Server) JoinWAN(addrs []string) (int, error) {
|
|||
return s.serfWAN.Join(addrs, true)
|
||||
}
|
||||
|
||||
// LocalMember is used to return the local node
|
||||
func (c *Server) LocalMember() serf.Member {
|
||||
return c.serfLAN.LocalMember()
|
||||
}
|
||||
|
||||
// LANMembers is used to return the members of the LAN cluster
|
||||
func (s *Server) LANMembers() []serf.Member {
|
||||
return s.serfLAN.Members()
|
||||
|
|
|
@ -200,7 +200,8 @@ msgpack RPC protocol.
|
|||
|
||||
The following endpoints are supported:
|
||||
|
||||
* /v1/agent/checks: Returns the checks the local agent is managing
|
||||
* /v1/agent/self : Returns the local node configuration
|
||||
* /v1/agent/checks : Returns the checks the local agent is managing
|
||||
* /v1/agent/services : Returns the services local agent is managing
|
||||
* /v1/agent/members : Returns the members as seen by the local serf agent
|
||||
* /v1/agent/join/\<address\> : Trigger local agent to join a node
|
||||
|
@ -213,6 +214,34 @@ The following endpoints are supported:
|
|||
* /v1/agent/service/register : Registers a new local service
|
||||
* /v1/agent/service/deregister/\<serviceID\> : Deregister a local service
|
||||
|
||||
### /v1/agent/self
|
||||
|
||||
This endpoint is used to return configuration of the local agent.
|
||||
|
||||
It returns a JSON body like this:
|
||||
|
||||
{
|
||||
"Name": "foobar",
|
||||
"Addr": "10.1.10.12",
|
||||
"Port": 8301,
|
||||
"Tags": {
|
||||
"bootstrap": "1",
|
||||
"dc": "dc1",
|
||||
"port": "8300",
|
||||
"role": "consul",
|
||||
"vsn": "1",
|
||||
"vsn_max": "1",
|
||||
"vsn_min":"1"
|
||||
},
|
||||
"Status": 1,
|
||||
"ProtocolMin": 1,
|
||||
"ProtocolMax": 2,
|
||||
"ProtocolCur": 2,
|
||||
"DelegateMin": 2,
|
||||
"DelegateMax": 4,
|
||||
"DelegateCur": 4
|
||||
}
|
||||
|
||||
### /v1/agent/checks
|
||||
|
||||
This endpoint is used to return the all the checks that are registered with
|
||||
|
|
Loading…
Reference in New Issue