Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the API for GC of allocations and nodes #2192

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message doesn't sound like real english to me?

http addr of the node %q is not advertised ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jippi Good catch, fixing on master.

}
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