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