Skip to content

Commit

Permalink
Changing the API to use the new servermember datastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Nov 6, 2016
1 parent b57a750 commit f766f71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
11 changes: 9 additions & 2 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion command/agent/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 10 additions & 5 deletions command/server_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nomad/status_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 0 additions & 5 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f766f71

Please sign in to comment.