Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
26c8aeaf
Commit
26c8aeaf
authored
7 years ago
by
Chelsea Holland Komlo
Browse files
Options
Download
Email Patches
Plain Diff
fixups from code review
parent
e59e21ad
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
api/contexts/contexts.go
+1
-1
api/contexts/contexts.go
api/search.go
+5
-5
api/search.go
command/alloc_status.go
+1
-1
command/alloc_status.go
nomad/search_endpoint.go
+37
-40
nomad/search_endpoint.go
nomad/structs/structs.go
+1
-1
nomad/structs/structs.go
with
45 additions
and
48 deletions
+45
-48
api/contexts/contexts.go
+
1
-
1
View file @
26c8aeaf
package
contexts
// Context
is a type
which
is
search
able via a unique identifier.
// Context
defines the scope in
which
a
search
for Nomad object operates
type
Context
string
const
(
...
...
This diff is collapsed.
Click to expand it.
api/search.go
+
5
-
5
View file @
26c8aeaf
package
api
import
(
c
"github.com/hashicorp/nomad/api/contexts"
"github.com/hashicorp/nomad/api/contexts"
)
type
Search
struct
{
...
...
@@ -15,7 +15,7 @@ func (c *Client) Search() *Search {
// PrefixSearch returns a list of matches for a particular context and prefix. If a
// context is not specified, matches for all contexts are returned.
func
(
s
*
Search
)
PrefixSearch
(
prefix
string
,
context
c
.
Context
)
(
*
SearchResponse
,
error
)
{
func
(
s
*
Search
)
PrefixSearch
(
prefix
string
,
context
c
ontexts
.
Context
)
(
*
SearchResponse
,
error
)
{
var
resp
SearchResponse
req
:=
&
SearchRequest
{
Prefix
:
prefix
,
Context
:
context
}
...
...
@@ -29,11 +29,11 @@ func (s *Search) PrefixSearch(prefix string, context c.Context) (*SearchResponse
type
SearchRequest
struct
{
Prefix
string
Context
c
.
Context
Context
c
ontexts
.
Context
}
type
SearchResponse
struct
{
Matches
map
[
c
.
Context
][]
string
Truncations
map
[
c
.
Context
]
bool
Matches
map
[
c
ontexts
.
Context
][]
string
Truncations
map
[
c
ontexts
.
Context
]
bool
QueryMeta
}
This diff is collapsed.
Click to expand it.
command/alloc_status.go
+
1
-
1
View file @
26c8aeaf
...
...
@@ -8,7 +8,7 @@ import (
"strings"
"time"
humanize
"github.com/dustin/go-humanize"
"github.com/dustin/go-humanize"
"github.com/mitchellh/colorstring"
"github.com/hashicorp/nomad/api"
...
...
This diff is collapsed.
Click to expand it.
nomad/search_endpoint.go
+
37
-
40
View file @
26c8aeaf
...
...
@@ -2,22 +2,23 @@ package nomad
import
(
"fmt"
"strings"
memdb
"github.com/hashicorp/go-memdb"
"github.com/hashicorp/go-memdb"
"github.com/hashicorp/nomad/nomad/state"
st
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs"
)
// truncateLimit is the maximum number of matches that will be returned for a
// prefix for a specific context
const
(
// truncateLimit is the maximum number of matches that will be returned for a
// prefix for a specific context
truncateLimit
=
20
)
// allContexts are the available contexts which are searched to find matches
// for a given prefix
var
(
allContexts
=
[]
st
.
Context
{
st
.
Allocs
,
st
.
Jobs
,
st
.
Nodes
,
st
.
Evals
}
// allContexts are the available contexts which are searched to find matches
// for a given prefix
allContexts
=
[]
structs
.
Context
{
structs
.
Allocs
,
structs
.
Jobs
,
structs
.
Nodes
,
structs
.
Evals
}
)
// Search endpoint is used to look up matches for a given prefix and context
...
...
@@ -25,10 +26,6 @@ type Search struct {
srv
*
Server
}
func
isSubset
(
prefix
,
id
string
)
bool
{
return
id
[
0
:
len
(
prefix
)]
==
prefix
}
// getMatches extracts matches for an iterator, and returns a list of ids for
// these matches.
func
(
s
*
Search
)
getMatches
(
iter
memdb
.
ResultIterator
,
prefix
string
)
([]
string
,
bool
)
{
...
...
@@ -42,20 +39,20 @@ func (s *Search) getMatches(iter memdb.ResultIterator, prefix string) ([]string,
var
id
string
switch
t
:=
raw
.
(
type
)
{
case
*
st
.
Job
:
id
=
raw
.
(
*
st
.
Job
)
.
ID
case
*
st
.
Evaluation
:
id
=
raw
.
(
*
st
.
Evaluation
)
.
ID
case
*
st
.
Allocation
:
id
=
raw
.
(
*
st
.
Allocation
)
.
ID
case
*
st
.
Node
:
id
=
raw
.
(
*
st
.
Node
)
.
ID
case
*
st
ructs
.
Job
:
id
=
raw
.
(
*
st
ructs
.
Job
)
.
ID
case
*
st
ructs
.
Evaluation
:
id
=
raw
.
(
*
st
ructs
.
Evaluation
)
.
ID
case
*
st
ructs
.
Allocation
:
id
=
raw
.
(
*
st
ructs
.
Allocation
)
.
ID
case
*
st
ructs
.
Node
:
id
=
raw
.
(
*
st
ructs
.
Node
)
.
ID
default
:
s
.
srv
.
logger
.
Printf
(
"[ERR] nomad.resources: unexpected type for resources context: %T"
,
t
)
continue
}
if
!
isSubset
(
prefix
,
id
)
{
if
!
strings
.
HasPrefix
(
id
,
prefix
)
{
continue
}
...
...
@@ -67,15 +64,15 @@ func (s *Search) getMatches(iter memdb.ResultIterator, prefix string) ([]string,
// getResourceIter takes a context and returns a memdb iterator specific to
// that context
func
getResourceIter
(
context
st
.
Context
,
prefix
string
,
ws
memdb
.
WatchSet
,
state
*
state
.
StateStore
)
(
memdb
.
ResultIterator
,
error
)
{
func
getResourceIter
(
context
st
ructs
.
Context
,
prefix
string
,
ws
memdb
.
WatchSet
,
state
*
state
.
StateStore
)
(
memdb
.
ResultIterator
,
error
)
{
switch
context
{
case
st
.
Jobs
:
case
st
ructs
.
Jobs
:
return
state
.
JobsByIDPrefix
(
ws
,
prefix
)
case
st
.
Evals
:
case
st
ructs
.
Evals
:
return
state
.
EvalsByIDPrefix
(
ws
,
prefix
)
case
st
.
Allocs
:
case
st
ructs
.
Allocs
:
return
state
.
AllocsByIDPrefix
(
ws
,
prefix
)
case
st
.
Nodes
:
case
st
ructs
.
Nodes
:
return
state
.
NodesByIDPrefix
(
ws
,
prefix
)
default
:
return
nil
,
fmt
.
Errorf
(
"context must be one of %v; got %q"
,
allContexts
,
context
)
...
...
@@ -84,8 +81,8 @@ func getResourceIter(context st.Context, prefix string, ws memdb.WatchSet, state
// If the length of a prefix is odd, return a subset to the last even character
// This only applies to UUIDs, jobs are excluded
func
roundUUIDDownIfOdd
(
prefix
string
,
context
st
.
Context
)
string
{
if
context
==
st
.
Jobs
{
func
roundUUIDDownIfOdd
(
prefix
string
,
context
st
ructs
.
Context
)
string
{
if
context
==
st
ructs
.
Jobs
{
return
prefix
}
...
...
@@ -98,30 +95,30 @@ func roundUUIDDownIfOdd(prefix string, context st.Context) string {
// PrefixSearch is used to list matches for a given prefix, and returns
// matching jobs, evaluations, allocations, and/or nodes.
func
(
s
*
Search
)
PrefixSearch
(
args
*
st
.
SearchRequest
,
reply
*
st
.
SearchResponse
)
error
{
reply
.
Matches
=
make
(
map
[
st
.
Context
][]
string
)
reply
.
Truncations
=
make
(
map
[
st
.
Context
]
bool
)
func
(
s
*
Search
)
PrefixSearch
(
args
*
st
ructs
.
SearchRequest
,
reply
*
st
ructs
.
SearchResponse
)
error
{
reply
.
Matches
=
make
(
map
[
st
ructs
.
Context
][]
string
)
reply
.
Truncations
=
make
(
map
[
st
ructs
.
Context
]
bool
)
// Setup the blocking query
opts
:=
blockingOptions
{
queryMeta
:
&
reply
.
QueryMeta
,
queryOpts
:
&
st
.
QueryOptions
{},
queryOpts
:
&
st
ructs
.
QueryOptions
{},
run
:
func
(
ws
memdb
.
WatchSet
,
state
*
state
.
StateStore
)
error
{
iters
:=
make
(
map
[
st
.
Context
]
memdb
.
ResultIterator
)
iters
:=
make
(
map
[
st
ructs
.
Context
]
memdb
.
ResultIterator
)
contexts
:=
allContexts
if
args
.
Context
!=
st
.
All
{
contexts
=
[]
st
.
Context
{
args
.
Context
}
if
args
.
Context
!=
st
ructs
.
All
{
contexts
=
[]
st
ructs
.
Context
{
args
.
Context
}
}
for
_
,
e
:=
range
contexts
{
iter
,
err
:=
getResourceIter
(
e
,
roundUUIDDownIfOdd
(
args
.
Prefix
,
args
.
Context
),
ws
,
state
)
for
_
,
ctx
:=
range
contexts
{
iter
,
err
:=
getResourceIter
(
ctx
,
roundUUIDDownIfOdd
(
args
.
Prefix
,
args
.
Context
),
ws
,
state
)
if
err
!=
nil
{
return
err
}
iters
[
e
]
=
iter
iters
[
ctx
]
=
iter
}
// Return matches for the given prefix
...
...
@@ -134,8 +131,8 @@ func (s *Search) PrefixSearch(args *st.SearchRequest,
// Set the index for the context. If the context has been specified, it
// will be used as the index of the response. Otherwise, the
// maximum index from all resources will be used.
for
_
,
e
:=
range
contexts
{
index
,
err
:=
state
.
Index
(
string
(
e
))
for
_
,
ctx
:=
range
contexts
{
index
,
err
:=
state
.
Index
(
string
(
ctx
))
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
1
-
1
View file @
26c8aeaf
...
...
@@ -89,7 +89,7 @@ const (
GetterModeDir
=
"dir"
)
// Context
is a type
which
is
search
able via a unique identifier.
// Context
defines the scope in
which
a
search
for Nomad object operates
type
Context
string
const
(
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment