Skip to content

Commit

Permalink
Merge pull request #2192 from hashicorp/f-api-gc
Browse files Browse the repository at this point in the history
Added the API for GC of allocations and nodes
  • Loading branch information
diptanu authored Jan 17, 2017
2 parents 3b1ea4e + fca8c2e commit 38fd66f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions api/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38fd66f

Please sign in to comment.