API queries can request pagination using the `NextToken` and `PerPage`
fields of `QueryOptions`, when supported by the underlying API.
Add a `NextToken` field to the `structs.QueryMeta` so that we have a
common field across RPCs to tell the caller where to resume paging
from on their next API call. Include this field on the `api.QueryMeta`
as well so that it's available for future versions of List HTTP APIs
that wrap the response with `QueryMeta` rather than returning a simple
list of structs. In the meantime callers can get the `X-Nomad-NextToken`.
Add pagination to the `Eval.List` RPC by checking for pagination token
and page size in `QueryOptions`. This will allow resuming from the
last ID seen so long as the query parameters and the state store
itself are unchanged between requests.
Add filtering by job ID or evaluation status over the results we get
out of the state store.
Parse the query parameters of the `Eval.List` API into the arguments
expected for filtering in the RPC call.
* api: revert to defaulting to http/1
PR #10778 incidentally changed the api http client to connect with
HTTP/2 first. However, the websocket libraries used in `alloc exec`
features don't handle http/2 well, and don't downgrade to http/1
gracefully.
Given that the switch is incidental, and not requested by users.
Furthermore, api consumers can opt-in to forcing http/2 by setting
custom http clients.
Fixes#10922
Copy Consul API's format: QueryOptions.WithContext(context) will now return
a new QueryOption whose HTTP requests will be canceled with the context
provided (and similar for WriteOptions)
The API decodeBody function will now check the content length
before attempting to decode. If the length is zero, and the out
interface is nil then it is safe to assume the API call is not
returning any data to the user. This allows us to better handle
passing nil to API calls in a single place.
If a websocket connection errors we currently return the error with a
copy of the response body. The response body from the websocket can
often times be completely illegible so remove it from the error string.
make alloc id empty for more reliable failure
un-gzip if content encoding header present
Jobs can be created with user-provided IDs containing any character
except spaces. The jobId needs to be escaped when used in a request
path, otherwise jobs created with names such as "why?" can't be managed
after they are created.
`*Config.ConfigureTLS()` is invoked internally by `NewClient` and API
consumers should not invoke directly.
Now that http client is created in `api.NewClient`,
`*Config.ConfigureTLS` makes no sense. API consumers that call it
explicitly can remove the invocation and preserve the behavior.
Allow clients to configure httpClient, e.g. set a pooled/keep-alive
client.
When caller configures HttpClient explicitly, we aim to use as-is; e.g.
we assume it's configured with TLS already. Expose `ConfigureTLS` to
aid api consumers with configuring their http client.
Also, removes `SetTimeout` call that I believe is internal only and has
odd side-effects when called on already created config. Also deprecates
`config.ConfigureTLS` in preference to the new `ConfigureTLS`.
Adds nomad exec support in our API, by hitting the websocket endpoint.
We introduce API structs that correspond to the drivers streaming exec structs.
For creating the websocket connection, we reuse the transport setting from api
http client.
This PR enhances the API package by having client only RPCs route
through the server when they are low cost and for filesystem access to
first attempt a direct connection to the node and then falling back to
a server routed request.
This PR fixes the construction of the TLSServerName when connecting to a
node that has TLS enabled and adds tests for all possible permutations.
Fixes https://github.com/hashicorp/nomad/issues/3013
Fixes#3013
It's a little weird that Client now has a method for returning a
NewClient, but it's a convenient way to dedupe the logic to
connect-directly-to-a-node which is nontrivial and had sutble
differences between locations.
The format of the missing port error message changed from Go 1.7 to 1.8.
The fix is to just use strings.Contains instead of strings.HasPrefix
when looking for the "missing port" part.
Also add an error return to Client.newRequest as parsing the path
processes arbitrary user input and would panic if given an invalid URL.
See: https://groups.google.com/d/topic/nomad-tool/gi3-CTE7oXo/discussion