diff --git a/api/agent.go b/api/agent.go index 054d0c343a5..81c6e0e06d2 100644 --- a/api/agent.go +++ b/api/agent.go @@ -131,8 +131,8 @@ func (a *Agent) Join(addrs ...string) (int, error) { } // Members is used to query all of the known server members -func (a *Agent) Members() ([]*AgentMember, error) { - var resp []*AgentMember +func (a *Agent) Members() (*ServerMembers, error) { + var resp *ServerMembers // Query the known members _, err := a.client.query("/v1/agent/members", &resp, nil) @@ -217,6 +217,13 @@ type joinResponse struct { Error string `json:"error"` } +type ServerMembers struct { + ServerName string + Region string + DC string + Members []*AgentMember +} + // AgentMember represents a cluster member known to the agent type AgentMember struct { Name string diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 9e240956bd4..2ca5c43d967 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -94,7 +94,6 @@ func (s *HTTPServer) AgentMembersRequest(resp http.ResponseWriter, req *http.Req return nil, err } - s.logger.Printf("DIPTANU 111 %#v", out) return out, nil } diff --git a/command/server_members.go b/command/server_members.go index e8340920d77..378be3a6e00 100644 --- a/command/server_members.go +++ b/command/server_members.go @@ -64,17 +64,22 @@ func (c *ServerMembersCommand) Run(args []string) int { } // Query the members - mem, err := client.Agent().Members() + srvMembers, err := client.Agent().Members() if err != nil { c.Ui.Error(fmt.Sprintf("Error querying servers: %s", err)) return 1 } + if srvMembers == nil { + c.Ui.Error("Agent doesn't know about server members") + return 0 + } + // Sort the members - sort.Sort(api.AgentMembersNameSort(mem)) + sort.Sort(api.AgentMembersNameSort(srvMembers.Members)) // Determine the leaders per region. - leaders, err := regionLeaders(client, mem) + leaders, err := regionLeaders(client, srvMembers.Members) if err != nil { c.Ui.Error(fmt.Sprintf("Error determining leaders: %s", err)) return 1 @@ -83,9 +88,9 @@ func (c *ServerMembersCommand) Run(args []string) int { // Format the list var out []string if detailed { - out = detailedOutput(mem) + out = detailedOutput(srvMembers.Members) } else { - out = standardOutput(mem, leaders) + out = standardOutput(srvMembers.Members, leaders) } // Dump the list diff --git a/nomad/status_endpoint.go b/nomad/status_endpoint.go index a978332355c..cdd871841c3 100644 --- a/nomad/status_endpoint.go +++ b/nomad/status_endpoint.go @@ -82,12 +82,11 @@ func (s *Status) Members(args *structs.GenericRequest, reply *structs.ServerMemb DelegateCur: mem.DelegateCur, } } - reply = &structs.ServerMembersResponse{ + *reply = structs.ServerMembersResponse{ ServerName: s.srv.config.NodeName, ServerRegion: s.srv.config.Region, ServerDC: s.srv.config.Datacenter, Members: members, } - s.srv.logger.Printf("DIPTANU %#v", reply) return nil } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index c3ac670c101..a2da811b8c5 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -360,11 +360,6 @@ type PeriodicForceRequest struct { WriteRequest } -// ServerMembersRequest is used to query the list of peers for a given server -type ServerMembersRequest struct { - QueryOptions -} - // ServerMembersResponse has the list of servers in a cluster type ServerMembersResponse struct { ServerName string