github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/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 37 // RaftConfigration is returned when querying for the current Raft configuration. 38 type RaftConfiguration struct { 39 // Servers has the list of servers in the Raft configuration. 40 Servers []*RaftServer 41 42 // Index has the Raft index of this configuration. 43 Index uint64 44 } 45 46 // RaftGetConfiguration is used to query the current Raft peer set. 47 func (op *Operator) RaftGetConfiguration(q *QueryOptions) (*RaftConfiguration, error) { 48 r, err := op.c.newRequest("GET", "/v1/operator/raft/configuration") 49 if err != nil { 50 return nil, err 51 } 52 r.setQueryOptions(q) 53 _, resp, err := requireOK(op.c.doRequest(r)) 54 if err != nil { 55 return nil, err 56 } 57 defer resp.Body.Close() 58 59 var out RaftConfiguration 60 if err := decodeBody(resp, &out); err != nil { 61 return nil, err 62 } 63 return &out, nil 64 } 65 66 // RaftRemovePeerByAddress is used to kick a stale peer (one that it in the Raft 67 // quorum but no longer known to Serf or the catalog) by address in the form of 68 // "IP:port". 69 func (op *Operator) RaftRemovePeerByAddress(address string, q *WriteOptions) error { 70 r, err := op.c.newRequest("DELETE", "/v1/operator/raft/peer") 71 if err != nil { 72 return err 73 } 74 r.setWriteOptions(q) 75 76 // TODO (alexdadgar) Currently we made address a query parameter. Once 77 // IDs are in place this will be DELETE /v1/operator/raft/peer/<id>. 78 r.params.Set("address", string(address)) 79 80 _, resp, err := requireOK(op.c.doRequest(r)) 81 if err != nil { 82 return err 83 } 84 85 resp.Body.Close() 86 return nil 87 }