diff --git a/api/allocations.go b/api/allocations.go index c2d50450064..540fcf5f790 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -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 diff --git a/api/nodes.go b/api/nodes.go index 3c8db40608f..18cc68cfe36 100644 --- a/api/nodes.go +++ b/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