diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go new file mode 100644 index 0000000000..09966fcc84 --- /dev/null +++ b/command/agent/agent_endpoint.go @@ -0,0 +1,47 @@ +package agent + +import ( + "net/http" + "strings" +) + +func (s *HTTPServer) AgentServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + // TODO + return nil, nil +} + +func (s *HTTPServer) AgentMembers(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + // Check if the WAN is being queried + wan := false + if other := req.URL.Query().Get("wan"); other != "" { + wan = true + } + if wan { + return s.agent.WANMembers(), nil + } else { + return s.agent.LANMembers(), nil + } +} + +func (s *HTTPServer) AgentJoin(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + // Check if the WAN is being queried + wan := false + if other := req.URL.Query().Get("wan"); other != "" { + wan = true + } + + // Get the address + addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/join/") + if wan { + _, err := s.agent.JoinWAN([]string{addr}) + return err, nil + } else { + _, err := s.agent.JoinLAN([]string{addr}) + return err, nil + } +} + +func (s *HTTPServer) AgentForceLeave(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + addr := strings.TrimPrefix(req.URL.Path, "/v1/agent/force-leave/") + return s.agent.ForceLeave(addr), nil +} diff --git a/command/agent/http.go b/command/agent/http.go index 50f8df7aae..5e43a99fb7 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -64,6 +64,11 @@ func (s *HTTPServer) registerHandlers() { s.mux.HandleFunc("/v1/catalog/services", s.wrap(s.CatalogServices)) s.mux.HandleFunc("/v1/catalog/service/", s.wrap(s.CatalogServiceNodes)) s.mux.HandleFunc("/v1/catalog/node/", s.wrap(s.CatalogNodeServices)) + + s.mux.HandleFunc("/v1/agent/services", s.wrap(s.AgentServices)) + s.mux.HandleFunc("/v1/agent/members", s.wrap(s.AgentMembers)) + s.mux.HandleFunc("/v1/agent/join/", s.wrap(s.AgentJoin)) + s.mux.HandleFunc("/v1/agent/force-leave/", s.wrap(s.AgentForceLeave)) } // wrap is used to wrap functions to make them more convenient diff --git a/command/agent/http_api.md b/command/agent/http_api.md index 6fb830eac3..79486bb1ba 100644 --- a/command/agent/http_api.md +++ b/command/agent/http_api.md @@ -29,9 +29,9 @@ The current URLs supported are: * /v1/status/leader : Returns the current Raft leader * /v1/status/peers : Returns the current Raft peer set -* /v1/agent/services : Returns the services local agent is attempting to register * /v1/agent/health: Returns the health info from the local agent (future) +* /v1/agent/services : Returns the services local agent is attempting to register * /v1/agent/members : Returns the members as seen by the local serf agent -* /v1/agent/join : Instructs the local agent to join a node -* /v1/agent/force-leave: Instructs the agent to force a node into the left state +* /v1/agent/join/ : Instructs the local agent to join a node +* /v1/agent/force-leave/: Instructs the agent to force a node into the left state