github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/nomad/status_endpoint.go (about)

     1  package nomad
     2  
     3  import "github.com/hashicorp/nomad/nomad/structs"
     4  
     5  // Status endpoint is used to check on server status
     6  type Status struct {
     7  	srv *Server
     8  }
     9  
    10  // Version is used to allow clients to determine the capabilities
    11  // of the server
    12  func (s *Status) Version(args *structs.GenericRequest, reply *structs.VersionResponse) error {
    13  	if done, err := s.srv.forward("Status.Version", args, args, reply); done {
    14  		return err
    15  	}
    16  
    17  	conf := s.srv.config
    18  	reply.Build = conf.Build
    19  	reply.Versions = map[string]int{
    20  		structs.ProtocolVersion: int(conf.ProtocolVersion),
    21  		structs.APIMajorVersion: apiMajorVersion,
    22  		structs.APIMinorVersion: apiMinorVersion,
    23  	}
    24  	return nil
    25  }
    26  
    27  // Ping is used to just check for connectivity
    28  func (s *Status) Ping(args struct{}, reply *struct{}) error {
    29  	return nil
    30  }
    31  
    32  // Leader is used to get the address of the leader
    33  func (s *Status) Leader(args *structs.GenericRequest, reply *string) error {
    34  	if args.Region == "" {
    35  		args.Region = s.srv.config.Region
    36  	}
    37  	if done, err := s.srv.forward("Status.Leader", args, args, reply); done {
    38  		return err
    39  	}
    40  
    41  	leader := s.srv.raft.Leader()
    42  	if leader != "" {
    43  		*reply = leader
    44  	} else {
    45  		*reply = ""
    46  	}
    47  	return nil
    48  }
    49  
    50  // Peers is used to get all the Raft peers
    51  func (s *Status) Peers(args *structs.GenericRequest, reply *[]string) error {
    52  	if done, err := s.srv.forward("Status.Peers", args, args, reply); done {
    53  		return err
    54  	}
    55  
    56  	peers, err := s.srv.raftPeers.Peers()
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	*reply = peers
    62  	return nil
    63  }