mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
Add additional API endpoint for requesting client specific node allocations.
This commit is contained in:
12
api/nodes.go
12
api/nodes.go
@@ -61,6 +61,18 @@ func (n *Nodes) Allocations(nodeID string, q *QueryOptions) ([]*Allocation, *Que
|
||||
return resp, qm, nil
|
||||
}
|
||||
|
||||
// ClientAllocations is used to return a lightweight list of allocations associated with a node.
|
||||
// It is primarily used by the client in order to determine which allocations actually need
|
||||
// an update.
|
||||
func (n *Nodes) ClientAllocations(nodeID string, q *QueryOptions) (map[string]uint64, *QueryMeta, error) {
|
||||
var resp map[string]uint64
|
||||
qm, err := n.client.query("/v1/node/"+nodeID+"/clientallocations", &resp, q)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return resp, qm, nil
|
||||
}
|
||||
|
||||
// ForceEvaluate is used to force-evaluate an existing node.
|
||||
func (n *Nodes) ForceEvaluate(nodeID string, q *WriteOptions) (string, *WriteMeta, error) {
|
||||
var resp nodeEvalResponse
|
||||
|
||||
@@ -207,6 +207,24 @@ func TestNodes_Allocations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodes_ClientAllocations(t *testing.T) {
|
||||
c, s := makeClient(t, nil, nil)
|
||||
defer s.Stop()
|
||||
nodes := c.Nodes()
|
||||
|
||||
// Looking up by a non-existent node returns nothing. We
|
||||
// don't check the index here because it's possible the node
|
||||
// has already registered, in which case we will get a non-
|
||||
// zero result anyways.
|
||||
allocs, _, err := nodes.ClientAllocations("nope", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
if n := len(allocs); n != 0 {
|
||||
t.Fatalf("expected 0 allocs, got: %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodes_ForceEvaluate(t *testing.T) {
|
||||
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
|
||||
c.DevMode = true
|
||||
|
||||
Reference in New Issue
Block a user