From bf548e7947e1f0d2a5dbc098e315277a6eece6cf Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Tue, 8 Sep 2015 15:37:07 -0700 Subject: [PATCH] api: starting on allocs --- api/allocs.go | 37 +++++++++++++++++++++++++++++++++++++ api/allocs_test.go | 20 ++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 api/allocs.go create mode 100644 api/allocs_test.go diff --git a/api/allocs.go b/api/allocs.go new file mode 100644 index 000000000..7928b92bd --- /dev/null +++ b/api/allocs.go @@ -0,0 +1,37 @@ +package api + +// Allocs is used to query the alloc-related endpoints. +type Allocs struct { + client *Client +} + +// Allocs returns a handle on the allocs endpoints. +func (c *Client) Allocs() *Allocs { + return &Allocs{client: c} +} + +// List returns a list of all of the allocations. +func (a *Allocs) List() ([]*Alloc, error) { + var resp []*Alloc + _, err := a.client.query("/v1/allocations", &resp, nil) + if err != nil { + return nil, err + } + return resp, nil +} + +// Alloc is used for serialization of allocations. +type Alloc struct { + ID string + EvalID string + Name string + NodeID string + JobID string + TaskGroup string + DesiredStatus string + DesiredDescription string + ClientStatus string + ClientDescription string + CreateIndex uint64 + ModifyIndex uint64 +} diff --git a/api/allocs_test.go b/api/allocs_test.go new file mode 100644 index 000000000..95561042f --- /dev/null +++ b/api/allocs_test.go @@ -0,0 +1,20 @@ +package api + +import ( + "testing" +) + +func TestAllocs_List(t *testing.T) { + c, s := makeClient(t, nil, nil) + defer s.Stop() + a := c.Allocs() + + // Querying when no allocs exist returns nothing + allocs, err := a.List() + if err != nil { + t.Fatalf("err: %s", err) + } + if n := len(allocs); n != 0 { + t.Fatalf("expected 0 allocs, got: %d", n) + } +}