github.com/marwan-at-work/consul@v1.4.5/api/operator_raft.go (about)

     1  package api
     2  
     3  // RaftServer has information about a server in the Raft configuration.
     4  type RaftServer struct {
     5  	// ID is the unique ID for the server. These are currently the same
     6  	// as the address, but they will be changed to a real GUID in a future
     7  	// release of Consul.
     8  	ID string
     9  
    10  	// Node is the node name of the server, as known by Consul, or this
    11  	// will be set to "(unknown)" otherwise.
    12  	Node string
    13  
    14  	// Address is the IP:port of the server, used for Raft communications.
    15  	Address string
    16  
    17  	// Leader is true if this server is the current cluster leader.
    18  	Leader bool
    19  
    20  	// Protocol version is the raft protocol version used by the server
    21  	ProtocolVersion string
    22  
    23  	// Voter is true if this server has a vote in the cluster. This might
    24  	// be false if the server is staging and still coming online, or if
    25  	// it's a non-voting server, which will be added in a future release of
    26  	// Consul.
    27  	Voter bool
    28  }
    29  
    30  // RaftConfiguration is returned when querying for the current Raft configuration.
    31  type RaftConfiguration struct {
    32  	// Servers has the list of servers in the Raft configuration.
    33  	Servers []*RaftServer
    34  
    35  	// Index has the Raft index of this configuration.
    36  	Index uint64
    37  }
    38  
    39  // RaftGetConfiguration is used to query the current Raft peer set.
    40  func (op *Operator) RaftGetConfiguration(q *QueryOptions) (*RaftConfiguration, error) {
    41  	r := op.c.newRequest("GET", "/v1/operator/raft/configuration")
    42  	r.setQueryOptions(q)
    43  	_, resp, err := requireOK(op.c.doRequest(r))
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	defer resp.Body.Close()
    48  
    49  	var out RaftConfiguration
    50  	if err := decodeBody(resp, &out); err != nil {
    51  		return nil, err
    52  	}
    53  	return &out, nil
    54  }
    55  
    56  // RaftRemovePeerByAddress is used to kick a stale peer (one that it in the Raft
    57  // quorum but no longer known to Serf or the catalog) by address in the form of
    58  // "IP:port".
    59  func (op *Operator) RaftRemovePeerByAddress(address string, q *WriteOptions) error {
    60  	r := op.c.newRequest("DELETE", "/v1/operator/raft/peer")
    61  	r.setWriteOptions(q)
    62  
    63  	r.params.Set("address", string(address))
    64  
    65  	_, resp, err := requireOK(op.c.doRequest(r))
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	resp.Body.Close()
    71  	return nil
    72  }
    73  
    74  // RaftRemovePeerByID is used to kick a stale peer (one that it in the Raft
    75  // quorum but no longer known to Serf or the catalog) by ID.
    76  func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error {
    77  	r := op.c.newRequest("DELETE", "/v1/operator/raft/peer")
    78  	r.setWriteOptions(q)
    79  
    80  	r.params.Set("id", string(id))
    81  
    82  	_, resp, err := requireOK(op.c.doRequest(r))
    83  	if err != nil {
    84  		return err
    85  	}
    86  
    87  	resp.Body.Close()
    88  	return nil
    89  }