From fca8c2eb9a7ace659efec6b58c4826b1d21d4b7b Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 12 Jan 2017 16:18:29 -0800 Subject: [PATCH] Added the API for GC of allocations and nodes --- api/allocations.go | 21 +++++++++++++++++++++ api/nodes.go | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) 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