Merge pull request #45 from hashicorp/f-api-updates

API has ListStub's
This commit is contained in:
Ryan Uber 2015-09-13 20:11:13 -07:00
commit 3c855b8c2b
6 changed files with 89 additions and 16 deletions

View File

@ -1,5 +1,9 @@
package api
import (
"time"
)
// Allocations is used to query the alloc-related endpoints.
type Allocations struct {
client *Client
@ -11,8 +15,8 @@ func (c *Client) Allocations() *Allocations {
}
// List returns a list of all of the allocations.
func (a *Allocations) List(q *QueryOptions) ([]*Allocation, *QueryMeta, error) {
var resp []*Allocation
func (a *Allocations) List(q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) {
var resp []*AllocationListStub
qm, err := a.client.query("/v1/allocations", &resp, q)
if err != nil {
return nil, nil, err
@ -32,6 +36,41 @@ func (a *Allocations) Info(allocID string, q *QueryOptions) (*Allocation, *Query
// Allocation is used for serialization of allocations.
type Allocation struct {
ID string
EvalID string
Name string
NodeID string
JobID string
Job *Job
TaskGroup string
Resources *Resources
TaskResources map[string]*Resources
Metrics *AllocationMetric
DesiredStatus string
DesiredDescription string
ClientStatus string
ClientDescription string
CreateIndex uint64
ModifyIndex uint64
}
// AllocationMetric is used to deserialize allocation metrics.
type AllocationMetric struct {
NodesEvaluated int
NodesFiltered int
ClassFiltered map[string]int
ConstraintFiltered map[string]int
NodesExhausted int
ClassExhausted map[string]int
DimensionExhaused map[string]int
Scores map[string]float64
AllocationTime time.Duration
CoalescedFailures int
}
// AllocationListStub is used to return a subset of an allocation
// during list operations.
type AllocationListStub struct {
ID string
EvalID string
Name string
@ -42,4 +81,6 @@ type Allocation struct {
DesiredDescription string
ClientStatus string
ClientDescription string
CreateIndex uint64
ModifyIndex uint64
}

View File

@ -36,8 +36,8 @@ func (e *Evaluations) Info(evalID string, q *QueryOptions) (*Evaluation, *QueryM
// Allocations is used to retrieve a set of allocations given
// an evaluation ID.
func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*Allocation, *QueryMeta, error) {
var resp []*Allocation
func (e *Evaluations) Allocations(evalID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) {
var resp []*AllocationListStub
qm, err := e.client.query("/v1/evaluation/"+evalID+"/allocations", &resp, q)
if err != nil {
return nil, nil, err

View File

@ -32,8 +32,8 @@ func (j *Jobs) Register(job *Job, q *WriteOptions) (string, *WriteMeta, error) {
}
// List is used to list all of the existing jobs.
func (j *Jobs) List(q *QueryOptions) ([]*Job, *QueryMeta, error) {
var resp []*Job
func (j *Jobs) List(q *QueryOptions) ([]*JobListStub, *QueryMeta, error) {
var resp []*JobListStub
qm, err := j.client.query("/v1/jobs", &resp, q)
if err != nil {
return nil, qm, err
@ -53,8 +53,8 @@ func (j *Jobs) Info(jobID string, q *QueryOptions) (*Job, *QueryMeta, error) {
}
// Allocations is used to return the allocs for a given job ID.
func (j *Jobs) Allocations(jobID string, q *QueryOptions) ([]*Allocation, *QueryMeta, error) {
var resp []*Allocation
func (j *Jobs) Allocations(jobID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) {
var resp []*AllocationListStub
qm, err := j.client.query("/v1/job/"+jobID+"/allocations", &resp, q)
if err != nil {
return nil, nil, err
@ -105,6 +105,21 @@ type Job struct {
Meta map[string]string
Status string
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
}
// JobListStub is used to return a subset of information about
// jobs during list operations.
type JobListStub struct {
ID string
Name string
Type string
Priority int
Status string
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
}
// NewServiceJob creates and returns a new service-style job

View File

@ -42,8 +42,7 @@ func TestJobs_Register(t *testing.T) {
assertQueryMeta(t, qm)
// Check that we got the expected response
expect := []*Job{job}
if !reflect.DeepEqual(resp, expect) {
if len(resp) != 1 || resp[0].ID != job.ID {
t.Fatalf("bad: %#v", resp[0])
}
}
@ -76,7 +75,7 @@ func TestJobs_Info(t *testing.T) {
assertQueryMeta(t, qm)
// Check that the result is what we expect
if !reflect.DeepEqual(result, job) {
if result == nil || result.ID != job.ID {
t.Fatalf("expect: %#v, got: %#v", job, result)
}
}

View File

@ -15,8 +15,8 @@ func (c *Client) Nodes() *Nodes {
}
// List is used to list out all of the nodes
func (n *Nodes) List(q *QueryOptions) ([]*Node, *QueryMeta, error) {
var resp []*Node
func (n *Nodes) List(q *QueryOptions) ([]*NodeListStub, *QueryMeta, error) {
var resp []*NodeListStub
qm, err := n.client.query("/v1/nodes", &resp, q)
if err != nil {
return nil, nil, err
@ -45,8 +45,8 @@ func (n *Nodes) ToggleDrain(nodeID string, drain bool, q *WriteOptions) (*WriteM
}
// Allocations is used to return the allocations associated with a node.
func (n *Nodes) Allocations(nodeID string, q *QueryOptions) ([]*Allocation, *QueryMeta, error) {
var resp []*Allocation
func (n *Nodes) Allocations(nodeID string, q *QueryOptions) ([]*AllocationListStub, *QueryMeta, error) {
var resp []*AllocationListStub
qm, err := n.client.query("/v1/node/"+nodeID+"/allocations", &resp, q)
if err != nil {
return nil, nil, err
@ -66,6 +66,24 @@ func (n *Nodes) ForceEvaluate(nodeID string, q *WriteOptions) (string, *WriteMet
// Node is used to deserialize a node entry.
type Node struct {
ID string
Datacenter string
Name string
Attributes map[string]string
Resources *Resources
Reserved *Resources
Links map[string]string
NodeClass string
Drain bool
Status string
StatusDescription string
CreateIndex uint64
ModifyIndex uint64
}
// NodeListStub is a subset of information returned during
// node list operations.
type NodeListStub struct {
ID string
Datacenter string
Name string

View File

@ -16,7 +16,7 @@ func TestNodes_List(t *testing.T) {
nodes := c.Nodes()
var qm *QueryMeta
var out []*Node
var out []*NodeListStub
var err error
testutil.WaitForResult(func() (bool, error) {