github.com/hernad/nomad@v1.6.112/command/agent/status_endpoint.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package agent
     5  
     6  import (
     7  	"net/http"
     8  
     9  	"github.com/hernad/nomad/nomad/structs"
    10  )
    11  
    12  func (s *HTTPServer) StatusLeaderRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
    13  	if req.Method != "GET" {
    14  		return nil, CodedError(405, ErrInvalidMethod)
    15  	}
    16  
    17  	var args structs.GenericRequest
    18  	if s.parse(resp, req, &args.Region, &args.QueryOptions) {
    19  		return nil, nil
    20  	}
    21  
    22  	var leader string
    23  	if err := s.agent.RPC("Status.Leader", &args, &leader); err != nil {
    24  		return nil, err
    25  	}
    26  	return leader, nil
    27  }
    28  
    29  func (s *HTTPServer) StatusPeersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
    30  	if req.Method != "GET" {
    31  		return nil, CodedError(405, ErrInvalidMethod)
    32  	}
    33  
    34  	var args structs.GenericRequest
    35  	if s.parse(resp, req, &args.Region, &args.QueryOptions) {
    36  		return nil, nil
    37  	}
    38  
    39  	var peers []string
    40  	if err := s.agent.RPC("Status.Peers", &args, &peers); err != nil {
    41  		return nil, err
    42  	}
    43  	if len(peers) == 0 {
    44  		peers = make([]string, 0)
    45  	}
    46  	return peers, nil
    47  }