mirror of
https://github.com/kemko/nomad.git
synced 2026-01-09 03:45:41 +03:00
search endpoint forwarding
This commit is contained in:
@@ -2,7 +2,9 @@ package nomad
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
metrics "github.com/armon/go-metrics"
|
||||
memdb "github.com/hashicorp/go-memdb"
|
||||
"github.com/hashicorp/nomad/acl"
|
||||
"github.com/hashicorp/nomad/nomad/state"
|
||||
@@ -114,6 +116,11 @@ func roundUUIDDownIfOdd(prefix string, context structs.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 *structs.SearchRequest, reply *structs.SearchResponse) error {
|
||||
if done, err := s.srv.forward("Search.PrefixSearch", args, args, reply); done {
|
||||
return err
|
||||
}
|
||||
defer metrics.MeasureSince([]string{"nomad", "search", "prefixsearch"}, time.Now())
|
||||
|
||||
aclObj, err := s.srv.ResolveToken(args.AuthToken)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -712,3 +712,47 @@ func TestSearch_PrefixSearch_RoundDownToEven(t *testing.T) {
|
||||
assert.Equal(1, len(resp.Matches[structs.Jobs]))
|
||||
assert.Equal(job.ID, resp.Matches[structs.Jobs][0])
|
||||
}
|
||||
|
||||
func TestSearch_PrefixSearch_MultiRegion(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
jobName := "exampleexample"
|
||||
|
||||
t.Parallel()
|
||||
s1 := testServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0
|
||||
c.Region = "foo"
|
||||
})
|
||||
defer s1.Shutdown()
|
||||
|
||||
s2 := testServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0
|
||||
c.Region = "bar"
|
||||
})
|
||||
defer s2.Shutdown()
|
||||
|
||||
testJoin(t, s1, s2)
|
||||
testutil.WaitForLeader(t, s1.RPC)
|
||||
|
||||
job := registerAndVerifyJob(s1, t, jobName, 0)
|
||||
|
||||
req := &structs.SearchRequest{
|
||||
Prefix: "",
|
||||
Context: structs.Jobs,
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Region: "foo",
|
||||
Namespace: job.Namespace,
|
||||
},
|
||||
}
|
||||
|
||||
codec := rpcClient(t, s2)
|
||||
|
||||
var resp structs.SearchResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(1, len(resp.Matches[structs.Jobs]))
|
||||
assert.Equal(job.ID, resp.Matches[structs.Jobs][0])
|
||||
assert.Equal(uint64(jobIndex), resp.Index)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user