change endpoint to /v1/search

This commit is contained in:
Chelsea Holland Komlo 2017-08-10 19:24:11 +00:00
parent b7736c8b4a
commit 465c4d7082
12 changed files with 178 additions and 176 deletions

View File

@ -1,28 +0,0 @@
package api
import (
"github.com/hashicorp/nomad/nomad/structs"
)
type ClusterSearch struct {
client *Client
}
// ClusterSearch returns a handle on the ClusterSearch endpoints
func (c *Client) ClusterSearch() *ClusterSearch {
return &ClusterSearch{client: c}
}
// List returns a list of matches for a particular context and prefix. If a
// context is not specified, matches for all contexts are returned.
func (cs *ClusterSearch) List(prefix, context string) (*structs.ClusterSearchResponse, error) {
var resp structs.ClusterSearchResponse
req := &structs.ClusterSearchRequest{Prefix: prefix, Context: context}
_, err := cs.client.write("/v1/cluster/search", req, &resp, nil)
if err != nil {
return nil, err
}
return &resp, nil
}

28
api/search.go Normal file
View File

@ -0,0 +1,28 @@
package api
import (
"github.com/hashicorp/nomad/nomad/structs"
)
type Search struct {
client *Client
}
// Search returns a handle on the Search endpoints
func (c *Client) Search() *Search {
return &Search{client: c}
}
// List 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) List(prefix, context string) (*structs.SearchResponse, error) {
var resp structs.SearchResponse
req := &structs.SearchRequest{Prefix: prefix, Context: context}
_, err := s.client.write("/v1/search", req, &resp, nil)
if err != nil {
return nil, err
}
return &resp, nil
}

View File

@ -1,11 +1,12 @@
package api
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJobResource_PrefixList(t *testing.T) {
func TestSearch_List(t *testing.T) {
assert := assert.New(t)
t.Parallel()
@ -18,7 +19,7 @@ func TestJobResource_PrefixList(t *testing.T) {
id := *job.ID
prefix := id[:len(id)-2]
resp, err := c.ClusterSearch().List(prefix, "jobs")
resp, err := c.Search().List(prefix, "jobs")
assert.Nil(err)
assert.NotEqual(0, resp.Index)

View File

@ -1,31 +0,0 @@
package agent
import (
"github.com/hashicorp/nomad/nomad/structs"
"net/http"
)
// ClusterSearchRequest accepts a prefix and context and returns a list of matching
// IDs for that context.
func (s *HTTPServer) ClusterSearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method == "POST" || req.Method == "PUT" {
return s.newClusterSearchRequest(resp, req)
}
return nil, CodedError(405, ErrInvalidMethod)
}
func (s *HTTPServer) newClusterSearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
args := structs.ClusterSearchRequest{}
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(400, err.Error())
}
var out structs.ClusterSearchResponse
if err := s.agent.RPC("ClusterSearch.List", &args, &out); err != nil {
return nil, err
}
setMeta(resp, &out.QueryMeta)
return out, nil
}

View File

@ -145,7 +145,7 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) {
s.mux.HandleFunc("/v1/evaluations", s.wrap(s.EvalsRequest))
s.mux.HandleFunc("/v1/evaluation/", s.wrap(s.EvalSpecificRequest))
s.mux.HandleFunc("/v1/cluster/search", s.wrap(s.ClusterSearchRequest))
s.mux.HandleFunc("/v1/search", s.wrap(s.SearchRequest))
s.mux.HandleFunc("/v1/deployments", s.wrap(s.DeploymentsRequest))
s.mux.HandleFunc("/v1/deployment/", s.wrap(s.DeploymentSpecificRequest))

View File

@ -0,0 +1,32 @@
package agent
import (
"net/http"
"github.com/hashicorp/nomad/nomad/structs"
)
// SearchRequest accepts a prefix and context and returns a list of matching
// IDs for that context.
func (s *HTTPServer) SearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method == "POST" || req.Method == "PUT" {
return s.newSearchRequest(resp, req)
}
return nil, CodedError(405, ErrInvalidMethod)
}
func (s *HTTPServer) newSearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
args := structs.SearchRequest{}
if err := decodeBody(req, &args); err != nil {
return nil, CodedError(400, err.Error())
}
var out structs.SearchResponse
if err := s.agent.RPC("Search.List", &args, &out); err != nil {
return nil, err
}
setMeta(resp, &out.QueryMeta)
return out, nil
}

View File

@ -10,7 +10,7 @@ import (
a "github.com/stretchr/testify/assert"
)
func TestHTTP_ClusterSearchWithIllegalMethod(t *testing.T) {
func TestHTTP_SearchWithIllegalMethod(t *testing.T) {
assert := a.New(t)
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
@ -18,7 +18,7 @@ func TestHTTP_ClusterSearchWithIllegalMethod(t *testing.T) {
assert.Nil(err)
respW := httptest.NewRecorder()
_, err = s.Server.ClusterSearchRequest(respW, req)
_, err = s.Server.SearchRequest(respW, req)
assert.NotNil(err, "HTTP DELETE should not be accepted for this endpoint")
})
}
@ -35,7 +35,7 @@ func createJobForTest(jobID string, s *TestAgent, t *testing.T) {
assert.Nil(err)
}
func TestHTTP_Resources_POST(t *testing.T) {
func TestHTTP_Search_POST(t *testing.T) {
assert := a.New(t)
testJob := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706"
@ -44,16 +44,16 @@ func TestHTTP_Resources_POST(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
createJobForTest(testJob, s, t)
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -67,7 +67,7 @@ func TestHTTP_Resources_POST(t *testing.T) {
})
}
func TestHTTP_Resources_PUT(t *testing.T) {
func TestHTTP_Search_PUT(t *testing.T) {
assert := a.New(t)
testJob := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706"
@ -76,16 +76,16 @@ func TestHTTP_Resources_PUT(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
createJobForTest(testJob, s, t)
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("PUT", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("PUT", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -99,7 +99,7 @@ func TestHTTP_Resources_PUT(t *testing.T) {
})
}
func TestHTTP_Resources_MultipleJobs(t *testing.T) {
func TestHTTP_Search_MultipleJobs(t *testing.T) {
assert := a.New(t)
testJobA := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706"
@ -114,16 +114,16 @@ func TestHTTP_Resources_MultipleJobs(t *testing.T) {
createJobForTest(testJobB, s, t)
createJobForTest(testJobC, s, t)
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -139,7 +139,7 @@ func TestHTTP_Resources_MultipleJobs(t *testing.T) {
})
}
func TestHTTP_ResoucesList_Evaluation(t *testing.T) {
func TestHTTP_Search_Evaluation(t *testing.T) {
assert := a.New(t)
t.Parallel()
@ -152,16 +152,16 @@ func TestHTTP_ResoucesList_Evaluation(t *testing.T) {
assert.Nil(err)
prefix := eval1.ID[:len(eval1.ID)-2]
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "evals"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: prefix, Context: "evals"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -175,7 +175,7 @@ func TestHTTP_ResoucesList_Evaluation(t *testing.T) {
})
}
func TestHTTP_ResoucesList_Allocations(t *testing.T) {
func TestHTTP_Search_Allocations(t *testing.T) {
assert := a.New(t)
t.Parallel()
@ -186,16 +186,16 @@ func TestHTTP_ResoucesList_Allocations(t *testing.T) {
assert.Nil(err)
prefix := alloc.ID[:len(alloc.ID)-2]
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "allocs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: prefix, Context: "allocs"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -208,7 +208,7 @@ func TestHTTP_ResoucesList_Allocations(t *testing.T) {
})
}
func TestHTTP_ResoucesList_Nodes(t *testing.T) {
func TestHTTP_Search_Nodes(t *testing.T) {
assert := a.New(t)
t.Parallel()
@ -219,16 +219,16 @@ func TestHTTP_ResoucesList_Nodes(t *testing.T) {
assert.Nil(err)
prefix := node.ID[:len(node.ID)-2]
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "nodes"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: prefix, Context: "nodes"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
@ -241,21 +241,21 @@ func TestHTTP_ResoucesList_Nodes(t *testing.T) {
})
}
func TestHTTP_Resources_NoJob(t *testing.T) {
func TestHTTP_Search_NoJob(t *testing.T) {
assert := a.New(t)
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
data := structs.ClusterSearchRequest{Prefix: "12345", Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: "12345", Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
assert.Equal(1, len(res.Matches))
assert.Equal(0, len(res.Matches["jobs"]))
@ -264,7 +264,7 @@ func TestHTTP_Resources_NoJob(t *testing.T) {
})
}
func TestHTTP_Resources_NoContext(t *testing.T) {
func TestHTTP_Search_NoContext(t *testing.T) {
assert := a.New(t)
testJobID := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706"
@ -279,16 +279,16 @@ func TestHTTP_Resources_NoContext(t *testing.T) {
err := state.UpsertEvals(8000, []*structs.Evaluation{eval1})
assert.Nil(err)
data := structs.ClusterSearchRequest{Prefix: testJobPrefix}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
data := structs.SearchRequest{Prefix: testJobPrefix}
req, err := http.NewRequest("POST", "/v1/search", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ClusterSearchRequest(respW, req)
resp, err := s.Server.SearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ClusterSearchResponse)
res := resp.(structs.SearchResponse)
matchedJobs := res.Matches["jobs"]
matchedEvals := res.Matches["evals"]

View File

@ -200,7 +200,7 @@ func (c *AllocStatusCommand) AutocompleteFlags() complete.Flags {
func (c *AllocStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
resp, err := client.ClusterSearch().List(a.Last, "allocs")
resp, err := client.Search().List(a.Last, "allocs")
if err != nil {
return []string{}
}

View File

@ -3,7 +3,7 @@ package nomad
import (
"fmt"
"github.com/hashicorp/go-memdb"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/nomad/nomad/state"
"github.com/hashicorp/nomad/nomad/structs"
)
@ -20,8 +20,8 @@ var (
allContexts = []string{"allocs", "nodes", "jobs", "evals"}
)
// ClusterSearch endpoint is used to lookup matches for a given prefix and context
type ClusterSearch struct {
// Search endpoint is used to lookup matches for a given prefix and context
type Search struct {
srv *Server
}
@ -31,7 +31,7 @@ func isSubset(prefix, id string) bool {
// getMatches extracts matches for an iterator, and returns a list of ids for
// these matches.
func (c *ClusterSearch) getMatches(iter memdb.ResultIterator, prefix string) ([]string, bool) {
func (s *Search) getMatches(iter memdb.ResultIterator, prefix string) ([]string, bool) {
var matches []string
for i := 0; i < truncateLimit; i++ {
@ -51,7 +51,7 @@ func (c *ClusterSearch) getMatches(iter memdb.ResultIterator, prefix string) ([]
case *structs.Node:
id = raw.(*structs.Node).ID
default:
c.srv.logger.Printf("[ERR] nomad.resources: unexpected type for resources context: %T", t)
s.srv.logger.Printf("[ERR] nomad.resources: unexpected type for resources context: %T", t)
continue
}
@ -95,10 +95,10 @@ func roundUUIDDownIfOdd(prefix, context string) string {
return prefix[:len(prefix)-1]
}
// List is used to list matches for a given prefix. ClusterSearch returns jobs,
// List is used to list matches for a given prefix. Search returns jobs,
// evaluations, allocations, and/or nodes.
func (c *ClusterSearch) List(args *structs.ClusterSearchRequest,
reply *structs.ClusterSearchResponse) error {
func (s *Search) List(args *structs.SearchRequest,
reply *structs.SearchResponse) error {
reply.Matches = make(map[string][]string)
reply.Truncations = make(map[string]bool)
@ -125,7 +125,7 @@ func (c *ClusterSearch) List(args *structs.ClusterSearchRequest,
// Return matches for the given prefix
for k, v := range iters {
res, isTrunc := c.getMatches(v, args.Prefix)
res, isTrunc := s.getMatches(v, args.Prefix)
reply.Matches[k] = res
reply.Truncations[k] = isTrunc
}
@ -143,8 +143,8 @@ func (c *ClusterSearch) List(args *structs.ClusterSearchRequest,
}
}
c.srv.setQueryMeta(&reply.QueryMeta)
s.srv.setQueryMeta(&reply.QueryMeta)
return nil
}}
return c.srv.blockingRPC(&opts)
return s.srv.blockingRPC(&opts)
}

View File

@ -4,7 +4,7 @@ import (
"strconv"
"testing"
"github.com/hashicorp/net-rpc-msgpackrpc"
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
@ -25,7 +25,7 @@ func registerAndVerifyJob(s *Server, t *testing.T, prefix string, counter int) s
return job.ID
}
func TestClusterEndpoint_List(t *testing.T) {
func TestSearch_List(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@ -40,13 +40,13 @@ func TestClusterEndpoint_List(t *testing.T) {
jobID := registerAndVerifyJob(s, t, prefix, 0)
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -56,7 +56,7 @@ func TestClusterEndpoint_List(t *testing.T) {
}
// truncate should limit results to 20
func TestClusterEndpoint_List_Truncate(t *testing.T) {
func TestSearch_List_Truncate(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@ -73,13 +73,13 @@ func TestClusterEndpoint_List_Truncate(t *testing.T) {
registerAndVerifyJob(s, t, prefix, counter)
}
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -88,7 +88,7 @@ func TestClusterEndpoint_List_Truncate(t *testing.T) {
assert.Equal(uint64(jobIndex), resp.Index)
}
func TestClusterEndpoint_List_Evals(t *testing.T) {
func TestSearch_List_Evals(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@ -104,13 +104,13 @@ func TestClusterEndpoint_List_Evals(t *testing.T) {
prefix := eval1.ID[:len(eval1.ID)-2]
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "evals",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -121,7 +121,7 @@ func TestClusterEndpoint_List_Evals(t *testing.T) {
assert.Equal(uint64(2000), resp.Index)
}
func TestClusterEndpoint_List_Allocation(t *testing.T) {
func TestSearch_List_Allocation(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@ -145,13 +145,13 @@ func TestClusterEndpoint_List_Allocation(t *testing.T) {
prefix := alloc.ID[:len(alloc.ID)-2]
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "allocs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -162,7 +162,7 @@ func TestClusterEndpoint_List_Allocation(t *testing.T) {
assert.Equal(uint64(90), resp.Index)
}
func TestClusterEndpoint_List_Node(t *testing.T) {
func TestSearch_List_Node(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@ -182,13 +182,13 @@ func TestClusterEndpoint_List_Node(t *testing.T) {
prefix := node.ID[:len(node.ID)-2]
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "nodes",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -199,7 +199,7 @@ func TestClusterEndpoint_List_Node(t *testing.T) {
assert.Equal(uint64(100), resp.Index)
}
func TestClusterEndpoint_List_InvalidContext(t *testing.T) {
func TestSearch_List_InvalidContext(t *testing.T) {
assert := assert.New(t)
t.Parallel()
@ -211,19 +211,19 @@ func TestClusterEndpoint_List_InvalidContext(t *testing.T) {
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: "anyPrefix",
Context: "invalid",
}
var resp structs.ClusterSearchResponse
err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp)
var resp structs.SearchResponse
err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp)
assert.Equal(err.Error(), "context must be one of [allocs nodes jobs evals]; got \"invalid\"")
assert.Equal(uint64(0), resp.Index)
}
func TestClusterEndpoint_List_NoContext(t *testing.T) {
func TestSearch_List_NoContext(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@ -249,13 +249,13 @@ func TestClusterEndpoint_List_NoContext(t *testing.T) {
prefix := node.ID[:len(node.ID)-2]
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -269,7 +269,7 @@ func TestClusterEndpoint_List_NoContext(t *testing.T) {
}
// Tests that the top 20 matches are returned when no prefix is set
func TestClusterEndpoint_List_NoPrefix(t *testing.T) {
func TestSearch_List_NoPrefix(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@ -285,13 +285,13 @@ func TestClusterEndpoint_List_NoPrefix(t *testing.T) {
jobID := registerAndVerifyJob(s, t, prefix, 0)
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: "",
Context: "jobs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -302,7 +302,7 @@ func TestClusterEndpoint_List_NoPrefix(t *testing.T) {
// Tests that the zero matches are returned when a prefix has no matching
// results
func TestClusterEndpoint_List_NoMatches(t *testing.T) {
func TestSearch_List_NoMatches(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@ -316,13 +316,13 @@ func TestClusterEndpoint_List_NoMatches(t *testing.T) {
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@ -332,7 +332,7 @@ func TestClusterEndpoint_List_NoMatches(t *testing.T) {
// Prefixes can only be looked up if their length is a power of two. For
// prefixes which are an odd length, use the length-1 characters.
func TestClusterEndpoint_List_RoundDownToEven(t *testing.T) {
func TestSearch_List_RoundDownToEven(t *testing.T) {
assert := assert.New(t)
id1 := "aaafaaaa-e8f7-fd38-c855-ab94ceb89"
id2 := "aaafeaaa-e8f7-fd38-c855-ab94ceb89"
@ -350,13 +350,13 @@ func TestClusterEndpoint_List_RoundDownToEven(t *testing.T) {
jobID1 := registerAndVerifyJob(s, t, id1, 0)
registerAndVerifyJob(s, t, id2, 50)
req := &structs.ClusterSearchRequest{
req := &structs.SearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
var resp structs.SearchResponse
if err := msgpackrpc.CallWithCodec(codec, "Search.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -166,18 +166,18 @@ type Server struct {
// Holds the RPC endpoints
type endpoints struct {
Status *Status
Node *Node
Job *Job
Eval *Eval
Plan *Plan
Alloc *Alloc
Deployment *Deployment
Region *Region
ClusterSearch *ClusterSearch
Periodic *Periodic
System *System
Operator *Operator
Status *Status
Node *Node
Job *Job
Eval *Eval
Plan *Plan
Alloc *Alloc
Deployment *Deployment
Region *Region
Search *Search
Periodic *Periodic
System *System
Operator *Operator
}
// NewServer is used to construct a new Nomad server from the
@ -726,7 +726,7 @@ func (s *Server) setupRPC(tlsWrap tlsutil.RegionWrapper) error {
s.endpoints.Region = &Region{s}
s.endpoints.Status = &Status{s}
s.endpoints.System = &System{s}
s.endpoints.ClusterSearch = &ClusterSearch{s}
s.endpoints.Search = &Search{s}
// Register the handlers
s.rpcServer.Register(s.endpoints.Alloc)
@ -740,7 +740,7 @@ func (s *Server) setupRPC(tlsWrap tlsutil.RegionWrapper) error {
s.rpcServer.Register(s.endpoints.Region)
s.rpcServer.Register(s.endpoints.Status)
s.rpcServer.Register(s.endpoints.System)
s.rpcServer.Register(s.endpoints.ClusterSearch)
s.rpcServer.Register(s.endpoints.Search)
list, err := net.ListenTCP("tcp", s.config.RPCAddr)
if err != nil {

View File

@ -231,9 +231,9 @@ type NodeSpecificRequest struct {
QueryOptions
}
// ClusterSearchResponse is used to return matches and information about whether
// SearchResponse is used to return matches and information about whether
// the match list is truncated specific to each type of context.
type ClusterSearchResponse struct {
type SearchResponse struct {
// Map of context types to ids which match a specified prefix
Matches map[string][]string
@ -244,10 +244,10 @@ type ClusterSearchResponse struct {
QueryMeta
}
// ClusterSearchRequest is used to parameterize a request, and returns a
// SearchRequest is used to parameterize a request, and returns a
// list of matches made up of jobs, allocations, evaluations, and/or nodes,
// along with whether or not the information returned is truncated.
type ClusterSearchRequest struct {
type SearchRequest struct {
// Prefix is what ids are matched to. I.e, if the given prefix were
// "a", potential matches might be "abcd" or "aabb"
Prefix string