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

autocomplete api #2964

Merged
merged 27 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b24ae5
Retrieve job information for resources endpoint
chelseakomlo Jul 28, 2017
cb1e898
adding test validation that received resources matches requested
chelseakomlo Aug 1, 2017
c3e0bd8
test resources endpoint will return matching prefixes
chelseakomlo Aug 1, 2017
0bd9742
remove unnecessary validations; these are tested elsewhere
chelseakomlo Aug 1, 2017
5435773
refactor test helper
chelseakomlo Aug 1, 2017
4945b98
limit resources results to 20
chelseakomlo Aug 1, 2017
1ec5010
remove resourceliststub, no need for another layer of abstraction
chelseakomlo Aug 1, 2017
9e06777
change resources endpoint from http get to post
chelseakomlo Aug 2, 2017
dfd8c1d
adds evaluations
chelseakomlo Aug 2, 2017
e14b279
add truncation boolean to response
chelseakomlo Aug 2, 2017
a9ed750
use upsert as a test helper
chelseakomlo Aug 2, 2017
ed8e707
refactor to remove duplication for types of resources
chelseakomlo Aug 2, 2017
a9728c3
adding allocations to resouces list endpoint
chelseakomlo Aug 3, 2017
a3234b2
refactor and add error handling for invalid context type
chelseakomlo Aug 3, 2017
760f429
resources list endpoint accepts http POST and PUT
chelseakomlo Aug 3, 2017
c9c7b19
refactor rpc endpoint and tests
chelseakomlo Aug 3, 2017
9947939
add documentation
chelseakomlo Aug 3, 2017
01640d8
set response index and meta information
chelseakomlo Aug 3, 2017
ca4ed64
resources are expected by state store to be plural
chelseakomlo Aug 4, 2017
96a1723
further refactoring
chelseakomlo Aug 4, 2017
971183d
fix up tests to intantiate assertion test helper
chelseakomlo Aug 4, 2017
74f35dd
if no context is specified, set maximum index for available contexts
chelseakomlo Aug 4, 2017
b2df34c
further refactoring
chelseakomlo Aug 4, 2017
753b157
syntax fixups and logging
chelseakomlo Aug 7, 2017
e5e4fc4
max index for any resource, if context is unspecified
chelseakomlo Aug 7, 2017
a1b5925
code simplifications and logging
chelseakomlo Aug 7, 2017
440fea7
update changelog
chelseakomlo Aug 7, 2017
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
30 changes: 13 additions & 17 deletions nomad/resources_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Resources struct {

// getMatches extracts matches for an iterator, and returns a list of ids for
// these matches.
func getMatches(iter memdb.ResultIterator) ([]string, bool) {
func (r *Resources) getMatches(iter memdb.ResultIterator) ([]string, bool) {
var matches []string
isTruncated := false

Expand All @@ -37,7 +37,7 @@ func getMatches(iter memdb.ResultIterator) ([]string, bool) {
}

var id string
switch raw.(type) {
switch t := raw.(type) {
case *structs.Job:
id = raw.(*structs.Job).ID
case *structs.Evaluation:
Expand All @@ -47,8 +47,7 @@ func getMatches(iter memdb.ResultIterator) ([]string, bool) {
case *structs.Node:
id = raw.(*structs.Node).ID
default:
//s.logger.Printf("[ERR] nomad: unexpected type for resources context; not a job, allocation, node, or evaluation")
// TODO
r.srv.logger.Printf("[ERR] nomad.resources: unexpected type for resources context; %T \n", t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change ; to : just for consistency and you also don't need the \n. The logger adds it automatically.

continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Log an error here

}

Expand Down Expand Up @@ -109,25 +108,22 @@ func (r *Resources) List(args *structs.ResourceListRequest,

// Return matches for the given prefix
for k, v := range iters {
res, isTrunc := getMatches(v)
res, isTrunc := r.getMatches(v)
reply.Matches[k] = res
reply.Truncations[k] = isTrunc
}

// Set the index for the context. If the context has been specified, it
// is the only non-empty match set, and the index is set for it.
// If the context was not specified, we set the index to be the max index
// from available contexts
// will be used as the index of the response. Otherwise, the
// maximum index from all resources will be used.
reply.Index = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

It is already initialized at zero

for k, v := range reply.Matches {
if len(v) != 0 { // make sure matches exist for this context
index, err := state.Index(k)
if err != nil {
return err
}
if index > reply.Index {
reply.Index = index
}
for _, e := range contexts {
index, err := state.Index(e)
if err != nil {
return err
}
if index > reply.Index {
reply.Index = index
}
}

Expand Down
2 changes: 1 addition & 1 deletion nomad/resources_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestResourcesEndpoint_List_NoContext(t *testing.T) {
assert.Equal(uint64(1000), resp.Index)
}

//// Tests that the top 20 matches are returned when no prefix is set
// Tests that the top 20 matches are returned when no prefix is set
func TestResourcesEndpoint_List_NoPrefix(t *testing.T) {
assert := assert.New(t)

Expand Down
7 changes: 6 additions & 1 deletion nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ type NodeSpecificRequest struct {
// the match list is truncated specific to each type of context.
type ResourceListResponse struct {
// Map of context types to resource ids which match a specified prefix
Matches map[string][]string
Matches map[string][]string

// Truncations indicates whether the matches for a particular context have
// been truncated
Truncations map[string]bool

QueryMeta
}

Expand All @@ -247,6 +251,7 @@ type ResourceListRequest struct {
// Prefix is what resources are matched to. I.e, if the given prefix were
// "a", potential matches might be "abcd" or "aabb"
Prefix string

// Context is the resource that can be matched. A context can be a job, node,
Copy link
Contributor

Choose a reason for hiding this comment

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

White space above

// evaluation, allocation, or empty (indicated every context should be
// matched)
Expand Down