Add an RPC endpoint for server members

This commit is contained in:
Diptanu Choudhury 2016-11-03 14:14:52 -07:00
parent 15f085a4d7
commit 9e0507e878
3 changed files with 66 additions and 9 deletions

View file

@ -88,17 +88,14 @@ func (s *HTTPServer) AgentMembersRequest(resp http.ResponseWriter, req *http.Req
if req.Method != "GET" {
return nil, CodedError(405, ErrInvalidMethod)
}
srv := s.agent.Server()
if srv == nil {
return nil, CodedError(501, ErrInvalidMethod)
args := &structs.GenericRequest{}
var out structs.ServerMembersResponse
if err := s.agent.RPC("Status.Members", args, &out); err != nil {
return nil, err
}
serfMembers := srv.Members()
members := make([]Member, len(serfMembers))
for i, mem := range serfMembers {
members[i] = nomadMember(mem)
}
return members, nil
s.logger.Printf("DIPTANU 111 %#v", out)
return out, nil
}
func (s *HTTPServer) AgentForceLeaveRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {

View file

@ -61,3 +61,33 @@ func (s *Status) Peers(args *structs.GenericRequest, reply *[]string) error {
*reply = peers
return nil
}
// Members return the list of servers in a cluster that a particular server is
// aware of
func (s *Status) Members(args *structs.GenericRequest, reply *structs.ServerMembersResponse) error {
serfMembers := s.srv.Members()
members := make([]*structs.ServerMember, len(serfMembers))
for i, mem := range serfMembers {
members[i] = &structs.ServerMember{
Name: mem.Name,
Addr: mem.Addr,
Port: mem.Port,
Tags: mem.Tags,
Status: mem.Status.String(),
ProtocolMin: mem.ProtocolMin,
ProtocolMax: mem.ProtocolMax,
ProtocolCur: mem.ProtocolCur,
DelegateMin: mem.DelegateMin,
DelegateMax: mem.DelegateMax,
DelegateCur: mem.DelegateCur,
}
}
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
}

View file

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"net"
"os"
"path/filepath"
"reflect"
@ -359,6 +360,35 @@ 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
ServerRegion string
ServerDC string
Members []*ServerMember
QueryMeta
}
// ServerMember holds information about a Nomad server agent in a cluster
type ServerMember struct {
Name string
Addr net.IP
Port uint16
Tags map[string]string
Status string
ProtocolMin uint8
ProtocolMax uint8
ProtocolCur uint8
DelegateMin uint8
DelegateMax uint8
DelegateCur uint8
}
// DeriveVaultTokenRequest is used to request wrapped Vault tokens for the
// following tasks in the given allocation
type DeriveVaultTokenRequest struct {