Merge pull request #2192 from hashicorp/f-api-gc
Added the API for GC of allocations and nodes
This commit is contained in:
commit
d5dfa80c21
|
@ -67,6 +67,27 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (*AllocResourceU
|
|||
return &resp, err
|
||||
}
|
||||
|
||||
func (a *Allocations) GC(alloc *Allocation, q *QueryOptions) error {
|
||||
node, _, err := a.client.Nodes().Info(alloc.NodeID, q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if node.Status == "down" {
|
||||
return NodeDownErr
|
||||
}
|
||||
if node.HTTPAddr == "" {
|
||||
return fmt.Errorf("http addr of the node where alloc %q is running is not advertised", alloc.ID)
|
||||
}
|
||||
client, err := NewClient(a.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp struct{}
|
||||
_, err = client.query("/v1/client/allocation"+alloc.ID+"/gc", &resp, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// Allocation is used for serialization of allocations.
|
||||
type Allocation struct {
|
||||
ID string
|
||||
|
|
17
api/nodes.go
17
api/nodes.go
|
@ -91,6 +91,23 @@ func (n *Nodes) Stats(nodeID string, q *QueryOptions) (*HostStats, error) {
|
|||
return &resp, nil
|
||||
}
|
||||
|
||||
func (n *Nodes) GC(nodeID string, q *QueryOptions) error {
|
||||
node, _, err := n.client.Nodes().Info(nodeID, q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if node.HTTPAddr == "" {
|
||||
return fmt.Errorf("http addr of the node %q is running is not advertised", nodeID)
|
||||
}
|
||||
client, err := NewClient(n.client.config.CopyConfig(node.HTTPAddr, node.TLSEnabled))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var resp struct{}
|
||||
_, err = client.query("/v1/client/gc", &resp, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// Node is used to deserialize a node entry.
|
||||
type Node struct {
|
||||
ID string
|
||||
|
|
Loading…
Reference in a new issue