rename to cluster search

comment updates
This commit is contained in:
Chelsea Holland Komlo
2017-08-10 14:13:35 +00:00
parent a45bf60c22
commit 787f7bc0c4
12 changed files with 162 additions and 161 deletions

28
api/cluster_search.go Normal file
View File

@@ -0,0 +1,28 @@
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 all resources for a particular context. 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
}

View File

@@ -18,7 +18,7 @@ func TestJobResource_PrefixList(t *testing.T) {
id := *job.ID
prefix := id[:len(id)-2]
resp, err := c.JobResources().List(prefix, "jobs")
resp, err := c.ClusterSearch().List(prefix, "jobs")
assert.Nil(err)
assert.NotEqual(0, resp.Index)

View File

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

View File

@@ -0,0 +1,31 @@
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

@@ -10,7 +10,7 @@ import (
a "github.com/stretchr/testify/assert"
)
func TestHTTP_ResourcesWithIllegalMethod(t *testing.T) {
func TestHTTP_ClusterSearchWithIllegalMethod(t *testing.T) {
assert := a.New(t)
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
@@ -18,7 +18,7 @@ func TestHTTP_ResourcesWithIllegalMethod(t *testing.T) {
assert.Nil(err)
respW := httptest.NewRecorder()
_, err = s.Server.ResourceListRequest(respW, req)
_, err = s.Server.ClusterSearchRequest(respW, req)
assert.NotNil(err, "HTTP DELETE should not be accepted for this endpoint")
})
}
@@ -44,16 +44,16 @@ func TestHTTP_Resources_POST(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
createJobForTest(testJob, s, t)
data := structs.ResourceListRequest{Prefix: testJobPrefix, Context: "jobs"}
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -76,16 +76,16 @@ func TestHTTP_Resources_PUT(t *testing.T) {
httpTest(t, nil, func(s *TestAgent) {
createJobForTest(testJob, s, t)
data := structs.ResourceListRequest{Prefix: testJobPrefix, Context: "jobs"}
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("PUT", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -114,16 +114,16 @@ func TestHTTP_Resources_MultipleJobs(t *testing.T) {
createJobForTest(testJobB, s, t)
createJobForTest(testJobC, s, t)
data := structs.ResourceListRequest{Prefix: testJobPrefix, Context: "jobs"}
data := structs.ClusterSearchRequest{Prefix: testJobPrefix, Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -152,16 +152,16 @@ func TestHTTP_ResoucesList_Evaluation(t *testing.T) {
assert.Nil(err)
prefix := eval1.ID[:len(eval1.ID)-2]
data := structs.ResourceListRequest{Prefix: prefix, Context: "evals"}
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "evals"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -186,16 +186,16 @@ func TestHTTP_ResoucesList_Allocations(t *testing.T) {
assert.Nil(err)
prefix := alloc.ID[:len(alloc.ID)-2]
data := structs.ResourceListRequest{Prefix: prefix, Context: "allocs"}
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "allocs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -219,16 +219,16 @@ func TestHTTP_ResoucesList_Nodes(t *testing.T) {
assert.Nil(err)
prefix := node.ID[:len(node.ID)-2]
data := structs.ResourceListRequest{Prefix: prefix, Context: "nodes"}
data := structs.ClusterSearchRequest{Prefix: prefix, Context: "nodes"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
@@ -246,16 +246,16 @@ func TestHTTP_Resources_NoJob(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
data := structs.ResourceListRequest{Prefix: "12345", Context: "jobs"}
data := structs.ClusterSearchRequest{Prefix: "12345", Context: "jobs"}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
assert.Equal(1, len(res.Matches))
assert.Equal(0, len(res.Matches["jobs"]))
@@ -279,16 +279,16 @@ func TestHTTP_Resources_NoContext(t *testing.T) {
err := state.UpsertEvals(8000, []*structs.Evaluation{eval1})
assert.Nil(err)
data := structs.ResourceListRequest{Prefix: testJobPrefix}
data := structs.ClusterSearchRequest{Prefix: testJobPrefix}
req, err := http.NewRequest("POST", "/v1/resources", encodeReq(data))
assert.Nil(err)
respW := httptest.NewRecorder()
resp, err := s.Server.ResourceListRequest(respW, req)
resp, err := s.Server.ClusterSearchRequest(respW, req)
assert.Nil(err)
res := resp.(structs.ResourceListResponse)
res := resp.(structs.ClusterSearchResponse)
matchedJobs := res.Matches["jobs"]
matchedEvals := res.Matches["evals"]

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/resources/", s.wrap(s.ResourceListRequest))
s.mux.HandleFunc("/v1/cluster/search", s.wrap(s.ClusterSearchRequest))
s.mux.HandleFunc("/v1/deployments", s.wrap(s.DeploymentsRequest))
s.mux.HandleFunc("/v1/deployment/", s.wrap(s.DeploymentSpecificRequest))

View File

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

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.JobResources().List(a.Last, "allocs")
resp, err := client.ClusterSearch().List(a.Last, "allocs")
if err != nil {
return []string{}
}

View File

@@ -20,14 +20,14 @@ var (
allContexts = []string{"allocs", "nodes", "jobs", "evals"}
)
// Resource endpoint is used to lookup matches for a given prefix and context
type Resources struct {
// ClusterSearch endpoint is used to lookup matches for a given prefix and context
type ClusterSearch struct {
srv *Server
}
// getMatches extracts matches for an iterator, and returns a list of ids for
// these matches.
func (r *Resources) getMatches(iter memdb.ResultIterator) ([]string, bool) {
func (c *ClusterSearch) getMatches(iter memdb.ResultIterator) ([]string, bool) {
var matches []string
for i := 0; i < truncateLimit; i++ {
@@ -47,7 +47,7 @@ func (r *Resources) getMatches(iter memdb.ResultIterator) ([]string, bool) {
case *structs.Node:
id = raw.(*structs.Node).ID
default:
r.srv.logger.Printf("[ERR] nomad.resources: unexpected type for resources context: %T", t)
c.srv.logger.Printf("[ERR] nomad.resources: unexpected type for resources context: %T", t)
continue
}
@@ -84,9 +84,10 @@ func roundDownIfOdd(s string) string {
}
// List is used to list the resouces registered in the system that matches the
// given prefix. Resources are jobs, evaluations, allocations, and/or nodes.
func (r *Resources) List(args *structs.ResourceListRequest,
reply *structs.ResourceListResponse) error {
// given prefix. ClusterSearch returns jobs, evaluations, allocations, and/or
// nodes.
func (c *ClusterSearch) List(args *structs.ClusterSearchRequest,
reply *structs.ClusterSearchResponse) error {
reply.Matches = make(map[string][]string)
reply.Truncations = make(map[string]bool)
@@ -113,7 +114,7 @@ func (r *Resources) List(args *structs.ResourceListRequest,
// Return matches for the given prefix
for k, v := range iters {
res, isTrunc := r.getMatches(v)
res, isTrunc := c.getMatches(v)
reply.Matches[k] = res
reply.Truncations[k] = isTrunc
}
@@ -131,8 +132,8 @@ func (r *Resources) List(args *structs.ResourceListRequest,
}
}
r.srv.setQueryMeta(&reply.QueryMeta)
c.srv.setQueryMeta(&reply.QueryMeta)
return nil
}}
return r.srv.blockingRPC(&opts)
return c.srv.blockingRPC(&opts)
}

View File

@@ -25,7 +25,7 @@ func registerAndVerifyJob(s *Server, t *testing.T, prefix string, counter int) s
return job.ID
}
func TestResourcesEndpoint_List(t *testing.T) {
func TestClusterEndpoint_List(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@@ -40,13 +40,13 @@ func TestResourcesEndpoint_List(t *testing.T) {
jobID := registerAndVerifyJob(s, t, prefix, 0)
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -56,7 +56,7 @@ func TestResourcesEndpoint_List(t *testing.T) {
}
// truncate should limit results to 20
func TestResourcesEndpoint_List_Truncate(t *testing.T) {
func TestClusterEndpoint_List_Truncate(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@@ -73,13 +73,13 @@ func TestResourcesEndpoint_List_Truncate(t *testing.T) {
registerAndVerifyJob(s, t, prefix, counter)
}
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -88,7 +88,7 @@ func TestResourcesEndpoint_List_Truncate(t *testing.T) {
assert.Equal(uint64(jobIndex), resp.Index)
}
func TestResourcesEndpoint_List_Evals(t *testing.T) {
func TestClusterEndpoint_List_Evals(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@@ -104,13 +104,13 @@ func TestResourcesEndpoint_List_Evals(t *testing.T) {
prefix := eval1.ID[:len(eval1.ID)-2]
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "evals",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -121,7 +121,7 @@ func TestResourcesEndpoint_List_Evals(t *testing.T) {
assert.Equal(uint64(2000), resp.Index)
}
func TestResourcesEndpoint_List_Allocation(t *testing.T) {
func TestClusterEndpoint_List_Allocation(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@@ -145,13 +145,13 @@ func TestResourcesEndpoint_List_Allocation(t *testing.T) {
prefix := alloc.ID[:len(alloc.ID)-2]
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "allocs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -162,7 +162,7 @@ func TestResourcesEndpoint_List_Allocation(t *testing.T) {
assert.Equal(uint64(90), resp.Index)
}
func TestResourcesEndpoint_List_Node(t *testing.T) {
func TestClusterEndpoint_List_Node(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@@ -182,13 +182,13 @@ func TestResourcesEndpoint_List_Node(t *testing.T) {
prefix := node.ID[:len(node.ID)-2]
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "nodes",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -199,7 +199,7 @@ func TestResourcesEndpoint_List_Node(t *testing.T) {
assert.Equal(uint64(100), resp.Index)
}
func TestResourcesEndpoint_List_InvalidContext(t *testing.T) {
func TestClusterEndpoint_List_InvalidContext(t *testing.T) {
assert := assert.New(t)
t.Parallel()
@@ -211,19 +211,19 @@ func TestResourcesEndpoint_List_InvalidContext(t *testing.T) {
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: "anyPrefix",
Context: "invalid",
}
var resp structs.ResourceListResponse
err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp)
var resp structs.ClusterSearchResponse
err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.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 TestResourcesEndpoint_List_NoContext(t *testing.T) {
func TestClusterEndpoint_List_NoContext(t *testing.T) {
assert := assert.New(t)
t.Parallel()
s := testServer(t, func(c *Config) {
@@ -249,13 +249,13 @@ func TestResourcesEndpoint_List_NoContext(t *testing.T) {
prefix := node.ID[:len(node.ID)-2]
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -269,7 +269,7 @@ func TestResourcesEndpoint_List_NoContext(t *testing.T) {
}
// Tests that the top 20 matches are returned when no prefix is set
func TestResourcesEndpoint_List_NoPrefix(t *testing.T) {
func TestClusterEndpoint_List_NoPrefix(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@@ -285,13 +285,13 @@ func TestResourcesEndpoint_List_NoPrefix(t *testing.T) {
jobID := registerAndVerifyJob(s, t, prefix, 0)
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: "",
Context: "jobs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -302,7 +302,7 @@ func TestResourcesEndpoint_List_NoPrefix(t *testing.T) {
// Tests that the zero matches are returned when a prefix has no matching
// results
func TestResourcesEndpoint_List_NoMatches(t *testing.T) {
func TestClusterEndpoint_List_NoMatches(t *testing.T) {
assert := assert.New(t)
prefix := "aaaaaaaa-e8f7-fd38-c855-ab94ceb8970"
@@ -316,13 +316,13 @@ func TestResourcesEndpoint_List_NoMatches(t *testing.T) {
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
@@ -332,9 +332,10 @@ func TestResourcesEndpoint_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 TestResourcesEndpoint_List_RoundDownToEven(t *testing.T) {
func TestClusterEndpoint_List_RoundDownToEven(t *testing.T) {
assert := assert.New(t)
id := "aaafaaaa-e8f7-fd38-c855-ab94ceb89"
id1 := "aaafaaaa-e8f7-fd38-c855-ab94ceb89"
id2 := "aaaeeaaa-e8f7-fd38-c855-ab94ceb89"
prefix := "aaafe"
t.Parallel()
@@ -346,19 +347,19 @@ func TestResourcesEndpoint_List_RoundDownToEven(t *testing.T) {
codec := rpcClient(t, s)
testutil.WaitForLeader(t, s.RPC)
jobID := registerAndVerifyJob(s, t, id, 0)
registerAndVerifyJob(s, t, "bbafaaaa-e8f7-fd38-c855-ab94ceb89", 50)
jobID1 := registerAndVerifyJob(s, t, id1, 0)
registerAndVerifyJob(s, t, id2, 50)
req := &structs.ResourceListRequest{
req := &structs.ClusterSearchRequest{
Prefix: prefix,
Context: "jobs",
}
var resp structs.ResourceListResponse
if err := msgpackrpc.CallWithCodec(codec, "Resources.List", req, &resp); err != nil {
var resp structs.ClusterSearchResponse
if err := msgpackrpc.CallWithCodec(codec, "ClusterSearch.List", req, &resp); err != nil {
t.Fatalf("err: %v", err)
}
assert.Equal(1, len(resp.Matches["jobs"]))
assert.Equal(jobID, resp.Matches["jobs"][0])
assert.Equal(jobID1, resp.Matches["jobs"][0])
}

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
Resources *Resources
Periodic *Periodic
System *System
Operator *Operator
Status *Status
Node *Node
Job *Job
Eval *Eval
Plan *Plan
Alloc *Alloc
Deployment *Deployment
Region *Region
ClusterSearch *ClusterSearch
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.Resources = &Resources{s}
s.endpoints.ClusterSearch = &ClusterSearch{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.Resources)
s.rpcServer.Register(s.endpoints.ClusterSearch)
list, err := net.ListenTCP("tcp", s.config.RPCAddr)
if err != nil {

View File

@@ -231,9 +231,9 @@ type NodeSpecificRequest struct {
QueryOptions
}
// ResourceListResponse is used to return matches and information about whether
// ClusterSearchResponse is used to return matches and information about whether
// the match list is truncated specific to each type of context.
type ResourceListResponse struct {
type ClusterSearchResponse struct {
// Map of context types to resource ids which match a specified prefix
Matches map[string][]string
@@ -244,10 +244,10 @@ type ResourceListResponse struct {
QueryMeta
}
// ResourceListRequest is used to parameterize a resources request, and returns a
// ClusterSearchRequest is used to parameterize a resources request, and returns a
// subset of information for jobs, allocations, evaluations, and nodes, along
// with whether or not the information returned is truncated.
type ResourceListRequest struct {
type ClusterSearchRequest 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