Merge pull request #2192 from hashicorp/f-api-gc

Added the API for GC of allocations and nodes
This commit is contained in:
Diptanu Choudhury 2017-01-17 12:32:14 -08:00 committed by GitHub
commit d5dfa80c21
2 changed files with 38 additions and 0 deletions

View file

@ -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

View file

@ -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