2015-11-07 00:59:32 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
// QueryDatacenterOptions sets options about how we fail over if there are no
|
|
|
|
// healthy nodes in the local datacenter.
|
|
|
|
type QueryDatacenterOptions struct {
|
|
|
|
// NearestN is set to the number of remote datacenters to try, based on
|
|
|
|
// network coordinates.
|
|
|
|
NearestN int
|
|
|
|
|
|
|
|
// Datacenters is a fixed list of datacenters to try after NearestN. We
|
|
|
|
// never try a datacenter multiple times, so those are subtracted from
|
|
|
|
// this list before proceeding.
|
|
|
|
Datacenters []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryDNSOptions controls settings when query results are served over DNS.
|
|
|
|
type QueryDNSOptions struct {
|
|
|
|
// TTL is the time to live for the served DNS results.
|
|
|
|
TTL string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceQuery is used to query for a set of healthy nodes offering a specific
|
|
|
|
// service.
|
|
|
|
type ServiceQuery struct {
|
|
|
|
// Service is the service to query.
|
|
|
|
Service string
|
|
|
|
|
|
|
|
// Failover controls what we do if there are no healthy nodes in the
|
|
|
|
// local datacenter.
|
|
|
|
Failover QueryDatacenterOptions
|
|
|
|
|
|
|
|
// If OnlyPassing is true then we will only include nodes with passing
|
|
|
|
// health checks (critical AND warning checks will cause a node to be
|
|
|
|
// discarded)
|
|
|
|
OnlyPassing bool
|
|
|
|
|
|
|
|
// Tags are a set of required and/or disallowed tags. If a tag is in
|
2015-11-17 16:29:20 +00:00
|
|
|
// this list it must be present. If the tag is preceded with "!" then
|
2015-11-07 00:59:32 +00:00
|
|
|
// it is disallowed.
|
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PreparedQuery defines a complete prepared query, and is the structure we
|
|
|
|
// maintain in the state store.
|
|
|
|
type PreparedQuery struct {
|
|
|
|
// ID is this UUID-based ID for the query, always generated by Consul.
|
|
|
|
ID string
|
|
|
|
|
|
|
|
// Name is an optional friendly name for the query supplied by the
|
|
|
|
// user. NOTE - if this feature is used then it will reduce the security
|
|
|
|
// of any read ACL associated with this query/service since this name
|
|
|
|
// can be used to locate nodes with supplying any ACL.
|
|
|
|
Name string
|
|
|
|
|
|
|
|
// Session is an optional session to tie this query's lifetime to. If
|
2015-11-07 06:18:11 +00:00
|
|
|
// this is omitted then the query will not expire.
|
2015-11-07 00:59:32 +00:00
|
|
|
Session string
|
|
|
|
|
|
|
|
// Token is the ACL token used when the query was created, and it is
|
|
|
|
// used when a query is subsequently executed. This token, or a token
|
|
|
|
// with management privileges, must be used to change the query later.
|
|
|
|
Token string
|
|
|
|
|
|
|
|
// Service defines a service query (leaving things open for other types
|
|
|
|
// later).
|
|
|
|
Service ServiceQuery
|
|
|
|
|
|
|
|
// DNS has options that control how the results of this query are
|
|
|
|
// served over DNS.
|
|
|
|
DNS QueryDNSOptions
|
|
|
|
|
|
|
|
RaftIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
type PreparedQueries []*PreparedQuery
|
|
|
|
|
2015-11-10 07:03:20 +00:00
|
|
|
type IndexedPreparedQueries struct {
|
|
|
|
Queries PreparedQueries
|
|
|
|
QueryMeta
|
|
|
|
}
|
|
|
|
|
2015-11-10 04:37:41 +00:00
|
|
|
type PreparedQueryOp string
|
2015-11-07 00:59:32 +00:00
|
|
|
|
|
|
|
const (
|
2015-11-10 04:37:41 +00:00
|
|
|
PreparedQueryCreate PreparedQueryOp = "create"
|
2015-11-17 17:27:10 +00:00
|
|
|
PreparedQueryUpdate PreparedQueryOp = "update"
|
|
|
|
PreparedQueryDelete PreparedQueryOp = "delete"
|
2015-11-07 00:59:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// QueryRequest is used to create or change prepared queries.
|
2015-11-10 04:37:41 +00:00
|
|
|
type PreparedQueryRequest struct {
|
2015-11-12 01:27:51 +00:00
|
|
|
// Datacenter is the target this request is intended for.
|
2015-11-07 00:59:32 +00:00
|
|
|
Datacenter string
|
2015-11-12 01:27:51 +00:00
|
|
|
|
|
|
|
// Op is the operation to apply.
|
|
|
|
Op PreparedQueryOp
|
|
|
|
|
|
|
|
// Query is the query itself.
|
|
|
|
Query *PreparedQuery
|
|
|
|
|
|
|
|
// WriteRequest holds the ACL token to go along with this request.
|
2015-11-07 00:59:32 +00:00
|
|
|
WriteRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestDatacenter returns the datacenter for a given request.
|
2015-11-10 04:37:41 +00:00
|
|
|
func (q *PreparedQueryRequest) RequestDatacenter() string {
|
2015-11-07 00:59:32 +00:00
|
|
|
return q.Datacenter
|
|
|
|
}
|
|
|
|
|
2015-11-10 07:03:20 +00:00
|
|
|
// PreparedQuerySpecificRequest is used to get information about a prepared
|
|
|
|
// query.
|
|
|
|
type PreparedQuerySpecificRequest struct {
|
|
|
|
// Datacenter is the target this request is intended for.
|
|
|
|
Datacenter string
|
|
|
|
|
2015-11-11 20:20:40 +00:00
|
|
|
// QueryID is the ID of a query.
|
|
|
|
QueryID string
|
2015-11-10 07:03:20 +00:00
|
|
|
|
|
|
|
// QueryOptions (unfortunately named here) controls the consistency
|
|
|
|
// settings for the query lookup itself, as well as the service lookups.
|
|
|
|
QueryOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestDatacenter returns the datacenter for a given request.
|
|
|
|
func (q *PreparedQuerySpecificRequest) RequestDatacenter() string {
|
|
|
|
return q.Datacenter
|
|
|
|
}
|
|
|
|
|
2015-11-10 04:37:41 +00:00
|
|
|
// PreparedQueryExecuteRequest is used to execute a prepared query.
|
|
|
|
type PreparedQueryExecuteRequest struct {
|
2015-11-10 04:59:16 +00:00
|
|
|
// Datacenter is the target this request is intended for.
|
|
|
|
Datacenter string
|
|
|
|
|
|
|
|
// QueryIDOrName is the ID of a query _or_ the name of one, either can
|
|
|
|
// be provided.
|
2015-11-07 00:59:32 +00:00
|
|
|
QueryIDOrName string
|
2015-11-10 04:59:16 +00:00
|
|
|
|
|
|
|
// Limit will trim the resulting list down to the given limit.
|
|
|
|
Limit int
|
|
|
|
|
|
|
|
// Source is used to sort the results relative to a given node using
|
|
|
|
// network coordinates.
|
|
|
|
Source QuerySource
|
|
|
|
|
|
|
|
// QueryOptions (unfortunately named here) controls the consistency
|
|
|
|
// settings for the query lookup itself, as well as the service lookups.
|
2015-11-07 00:59:32 +00:00
|
|
|
QueryOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestDatacenter returns the datacenter for a given request.
|
2015-11-10 04:37:41 +00:00
|
|
|
func (q *PreparedQueryExecuteRequest) RequestDatacenter() string {
|
2015-11-07 00:59:32 +00:00
|
|
|
return q.Datacenter
|
|
|
|
}
|
|
|
|
|
2015-11-10 04:37:41 +00:00
|
|
|
// PreparedQueryExecuteRemoteRequest is used when running a local query in a
|
2015-11-10 04:59:16 +00:00
|
|
|
// remote datacenter.
|
2015-11-10 04:37:41 +00:00
|
|
|
type PreparedQueryExecuteRemoteRequest struct {
|
2015-11-10 04:59:16 +00:00
|
|
|
// Datacenter is the target this request is intended for.
|
2015-11-07 00:59:32 +00:00
|
|
|
Datacenter string
|
2015-11-10 04:59:16 +00:00
|
|
|
|
|
|
|
// Query is a copy of the query to execute. We have to ship the entire
|
|
|
|
// query over since it won't be present in the remote state store.
|
|
|
|
Query PreparedQuery
|
|
|
|
|
|
|
|
// Limit will trim the resulting list down to the given limit.
|
|
|
|
Limit int
|
|
|
|
|
|
|
|
// QueryOptions (unfortunately named here) controls the consistency
|
|
|
|
// settings for the the service lookups.
|
2015-11-07 00:59:32 +00:00
|
|
|
QueryOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestDatacenter returns the datacenter for a given request.
|
2015-11-10 04:37:41 +00:00
|
|
|
func (q *PreparedQueryExecuteRemoteRequest) RequestDatacenter() string {
|
2015-11-07 00:59:32 +00:00
|
|
|
return q.Datacenter
|
|
|
|
}
|
|
|
|
|
2015-11-10 04:37:41 +00:00
|
|
|
// PreparedQueryExecuteResponse has the results of executing a query.
|
|
|
|
type PreparedQueryExecuteResponse struct {
|
2015-11-13 18:38:44 +00:00
|
|
|
// Service is the service that was queried.
|
|
|
|
Service string
|
|
|
|
|
2015-11-11 01:42:41 +00:00
|
|
|
// Nodes has the nodes that were output by the query.
|
2015-11-07 00:59:32 +00:00
|
|
|
Nodes CheckServiceNodes
|
2015-11-11 01:42:41 +00:00
|
|
|
|
|
|
|
// DNS has the options for serving these results over DNS.
|
|
|
|
DNS QueryDNSOptions
|
|
|
|
|
|
|
|
// Datacenter is the datacenter that these results came from.
|
|
|
|
Datacenter string
|
|
|
|
|
|
|
|
// Failovers is a count of how many times we had to query a remote
|
|
|
|
// datacenter.
|
|
|
|
Failovers int
|
2015-11-12 06:34:46 +00:00
|
|
|
|
|
|
|
// QueryMeta has freshness information about the query.
|
|
|
|
QueryMeta
|
2015-11-07 00:59:32 +00:00
|
|
|
}
|