2015-06-03 10:26:50 +00:00
|
|
|
package nomad
|
|
|
|
|
2015-08-15 19:59:10 +00:00
|
|
|
import "github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
|
2015-06-03 10:26:50 +00:00
|
|
|
// Status endpoint is used to check on server status
|
|
|
|
type Status struct {
|
2015-08-15 19:59:10 +00:00
|
|
|
srv *Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version is used to allow clients to determine the capabilities
|
|
|
|
// of the server
|
|
|
|
func (s *Status) Version(args *structs.GenericRequest, reply *structs.VersionResponse) error {
|
|
|
|
if done, err := s.srv.forward("Status.Version", args, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
conf := s.srv.config
|
|
|
|
reply.Build = conf.Build
|
|
|
|
reply.Versions = map[string]int{
|
|
|
|
structs.ProtocolVersion: int(conf.ProtocolVersion),
|
2016-05-28 01:14:34 +00:00
|
|
|
structs.APIMajorVersion: structs.ApiMajorVersion,
|
|
|
|
structs.APIMinorVersion: structs.ApiMinorVersion,
|
2015-08-15 19:59:10 +00:00
|
|
|
}
|
|
|
|
return nil
|
2015-06-03 10:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ping is used to just check for connectivity
|
|
|
|
func (s *Status) Ping(args struct{}, reply *struct{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leader is used to get the address of the leader
|
2015-09-07 01:07:05 +00:00
|
|
|
func (s *Status) Leader(args *structs.GenericRequest, reply *string) error {
|
|
|
|
if args.Region == "" {
|
|
|
|
args.Region = s.srv.config.Region
|
|
|
|
}
|
|
|
|
if done, err := s.srv.forward("Status.Leader", args, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-15 19:59:10 +00:00
|
|
|
leader := s.srv.raft.Leader()
|
2015-06-03 10:26:50 +00:00
|
|
|
if leader != "" {
|
|
|
|
*reply = leader
|
|
|
|
} else {
|
|
|
|
*reply = ""
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peers is used to get all the Raft peers
|
2015-09-07 01:07:05 +00:00
|
|
|
func (s *Status) Peers(args *structs.GenericRequest, reply *[]string) error {
|
|
|
|
if done, err := s.srv.forward("Status.Peers", args, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-15 19:59:10 +00:00
|
|
|
peers, err := s.srv.raftPeers.Peers()
|
2015-06-03 10:26:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*reply = peers
|
|
|
|
return nil
|
|
|
|
}
|
2016-11-03 21:14:52 +00:00
|
|
|
|
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
2016-11-06 18:29:09 +00:00
|
|
|
*reply = structs.ServerMembersResponse{
|
2016-11-03 21:14:52 +00:00
|
|
|
ServerName: s.srv.config.NodeName,
|
|
|
|
ServerRegion: s.srv.config.Region,
|
|
|
|
ServerDC: s.srv.config.Datacenter,
|
|
|
|
Members: members,
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|