-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
autocomplete api #2964
Changes from 2 commits
1b24ae5
cb1e898
c3e0bd8
0bd9742
5435773
4945b98
1ec5010
9e06777
dfd8c1d
e14b279
a9ed750
ed8e707
a9728c3
a3234b2
760f429
c9c7b19
9947939
01640d8
ca4ed64
96a1723
971183d
74f35dd
b2df34c
753b157
e5e4fc4
a1b5925
440fea7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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: | ||
|
@@ -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) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log an error here |
||
} | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
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.