2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-10-01 13:59:55 +00:00
|
|
|
//go:build !ent
|
2020-02-10 20:56:14 +00:00
|
|
|
// +build !ent
|
2017-09-07 23:56:15 +00:00
|
|
|
|
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
2017-10-12 01:05:27 +00:00
|
|
|
"github.com/hashicorp/nomad/acl"
|
2017-09-07 23:56:15 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/state"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
2017-09-08 00:13:18 +00:00
|
|
|
var (
|
|
|
|
// allContexts are the available contexts which are searched to find matches
|
|
|
|
// for a given prefix
|
|
|
|
allContexts = ossContexts
|
|
|
|
)
|
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
// contextToIndex returns the index name to lookup in the state store.
|
|
|
|
func contextToIndex(ctx structs.Context) string {
|
2022-06-20 03:39:00 +00:00
|
|
|
switch ctx {
|
|
|
|
// Handle cases where context name and state store table name do not match
|
2022-08-26 18:03:56 +00:00
|
|
|
case structs.Variables:
|
|
|
|
return state.TableVariables
|
2022-06-20 03:39:00 +00:00
|
|
|
default:
|
|
|
|
return string(ctx)
|
|
|
|
}
|
2017-10-13 21:36:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-07 23:56:15 +00:00
|
|
|
// getEnterpriseMatch is a no-op in oss since there are no enterprise objects.
|
|
|
|
func getEnterpriseMatch(match interface{}) (id string, ok bool) {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
// getEnterpriseResourceIter is used to retrieve an iterator over an enterprise
|
|
|
|
// only table.
|
2017-10-13 21:36:02 +00:00
|
|
|
func getEnterpriseResourceIter(context structs.Context, _ *acl.ACL, namespace, prefix string, ws memdb.WatchSet, state *state.StateStore) (memdb.ResultIterator, error) {
|
2017-09-07 23:56:15 +00:00
|
|
|
// If we have made it here then it is an error since we have exhausted all
|
|
|
|
// open source contexts.
|
2017-09-08 00:13:18 +00:00
|
|
|
return nil, fmt.Errorf("context must be one of %v or 'all' for all contexts; got %q", allContexts, context)
|
2017-09-07 23:56:15 +00:00
|
|
|
}
|
2017-10-12 01:05:27 +00:00
|
|
|
|
api: implement fuzzy search API
This PR introduces the /v1/search/fuzzy API endpoint, used for fuzzy
searching objects in Nomad. The fuzzy search endpoint routes requests
to the Nomad Server leader, which implements the Search.FuzzySearch RPC
method.
Requests to the fuzzy search API are based on the api.FuzzySearchRequest
object, e.g.
{
"Text": "ed",
"Context": "all"
}
Responses from the fuzzy search API are based on the api.FuzzySearchResponse
object, e.g.
{
"Index": 27,
"KnownLeader": true,
"LastContact": 0,
"Matches": {
"tasks": [
{
"ID": "redis",
"Scope": [
"default",
"example",
"cache"
]
}
],
"evals": [],
"deployment": [],
"volumes": [],
"scaling_policy": [],
"images": [
{
"ID": "redis:3.2",
"Scope": [
"default",
"example",
"cache",
"redis"
]
}
]
},
"Truncations": {
"volumes": false,
"scaling_policy": false,
"evals": false,
"deployment": false
}
}
The API is tunable using the new server.search stanza, e.g.
server {
search {
fuzzy_enabled = true
limit_query = 200
limit_results = 1000
min_term_length = 5
}
}
These values can be increased or decreased, so as to provide more
search results or to reduce load on the Nomad Server. The fuzzy search
API can be disabled entirely by setting `fuzzy_enabled` to `false`.
2021-02-23 20:24:52 +00:00
|
|
|
// getEnterpriseFuzzyResourceIter is used to retrieve an iterator over an enterprise
|
|
|
|
// only table.
|
|
|
|
func getEnterpriseFuzzyResourceIter(context structs.Context, _ *acl.ACL, _ string, _ memdb.WatchSet, _ *state.StateStore) (memdb.ResultIterator, error) {
|
|
|
|
return nil, fmt.Errorf("context must be one of %v or 'all' for all contexts; got %q", allContexts, context)
|
|
|
|
}
|
|
|
|
|
2022-07-14 15:31:08 +00:00
|
|
|
func filteredSearchContextsEnt(aclObj *acl.ACL, namespace string, context structs.Context) bool {
|
|
|
|
return true
|
2017-10-12 01:05:27 +00:00
|
|
|
}
|