2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-09-07 01:39:03 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *HTTPServer) StatusLeaderRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2023-07-26 15:38:39 +00:00
|
|
|
if req.Method != http.MethodGet {
|
2015-09-07 01:39:03 +00:00
|
|
|
return nil, CodedError(405, ErrInvalidMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
var args structs.GenericRequest
|
|
|
|
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var leader string
|
|
|
|
if err := s.agent.RPC("Status.Leader", &args, &leader); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return leader, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *HTTPServer) StatusPeersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2023-07-26 15:38:39 +00:00
|
|
|
if req.Method != http.MethodGet {
|
2015-09-07 01:39:03 +00:00
|
|
|
return nil, CodedError(405, ErrInvalidMethod)
|
|
|
|
}
|
|
|
|
|
|
|
|
var args structs.GenericRequest
|
|
|
|
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var peers []string
|
|
|
|
if err := s.agent.RPC("Status.Peers", &args, &peers); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(peers) == 0 {
|
|
|
|
peers = make([]string, 0)
|
|
|
|
}
|
|
|
|
return peers, nil
|
|
|
|
}
|