Allocations HTTP API
The /allocation
endpoints are used to query for and interact with allocations.
List Allocations
This endpoint lists all allocations.
Method | Path | Produces |
---|---|---|
GET | /v1/allocations | application/json |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
YES | namespace:read-job |
Parameters
prefix
(string: "")
- Specifies a string to filter allocations based on an ID prefix. Because the value is decoded to bytes, the prefix must have an even number of hexadecimal characters (0-9a-f). This is specified as a query string parameter.namespace
(string: "default")
- Specifies the namespace to search. Specifying*
would return all allocations across all the authorized namespaces.resources
(bool: false)
- Specifies whether or not to include theAllocatedResources
field in the response.task_states
(bool: true)
- Specifies whether or not to include theTaskStates
field in the response. TaskStates are included by default but can represent a large percentage of the overall response size. Clusters with a large number of allocations may settask_states=false
to significantly reduce the size of the response.
Sample Request
Sample Response
Read Allocation
This endpoint reads information about a specific allocation.
Method | Path | Produces |
---|---|---|
GET | /v1/allocation/:alloc_id | application/json |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
YES | namespace:read-job |
Parameters
:alloc_id
(string: <required>)
- Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one. This is specified as part of the path.
Sample Request
Sample Response
Field Reference
Job
- A copy of the job at the time that the allocation is created or updated. This is primarily intended for use by the Nomad client when running the allocation, and it may include stale information on some job fields. Up-to-date information about the job status is available from the jobs API; take care to fetch the version of the job associated with this allocation.TaskStates
- A map of tasks to their current state and the latest events that have effected the state.TaskState
objects contain the following fields:State
: The task's current state. It can have one of the following values:TaskStatePending
- The task is waiting to be run, either for the first time or due to a restart.TaskStateRunning
- The task is currently running.TaskStateDead
- The task is dead and will not run again.
StartedAt
: The time the task was last started at. Can be updated through restarts.FinishedAt
: The time the task was finished at.LastRestart
: The last time the task was restarted.Restarts
: The number of times the task has restarted.Events
- An event contains metadata about the event. The latest 10 events are stored per task. Each event is timestamped (Unix nanoseconds) and has one of the following types:Setup Failure
- The task could not be started because there was a failure setting up the task prior to it running.Driver Failure
- The task could not be started due to a failure in the driver.Started
- The task was started; either for the first time or due to a restart.Terminated
- The task was started and exited.Killing
- The task has been sent the kill signal.Killed
- The task was killed by a user.Received
- The task has been pulled by the client at the given timestamp.Failed Validation
- The task was invalid and as such it didn't run.Restarting
- The task terminated and is being restarted.Not Restarting
- the task has failed and is not being restarted because it has exceeded its restart policy.Downloading Artifacts
- The task is downloading the artifact(s)specified in the task.
Failed Artifact Download
- Artifact(s) specified in the task failed to download.Restart Signaled
- The task was singled to be restarted.Signaling
- The task was is being sent a signal.Sibling Task Failed
- A task in the same task group failed.Leader Task Dead
- The group's leader task is dead.Driver
- A message from the driver.Task Setup
- Task setup messages.Building Task Directory
- Task is building its file system.
Depending on the type the event will have applicable annotations.
Stop Allocation
This endpoint stops and reschedules a specific allocation.
Method | Path | Produces |
---|---|---|
POST / PUT | /v1/allocation/:alloc_id/stop | application/json |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
NO | namespace:alloc-lifecycle |
Parameters
:alloc_id
(string: <required>)
- Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one. This is specified as part of the path.
Sample Request
Sample Response
Signal Allocation
This endpoint sends a signal to an allocation or task.
Method | Path | Produces |
---|---|---|
POST / PUT | /v1/client/allocation/:alloc_id/signal | application/json |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
NO | namespace:alloc-lifecycle |
Parameters
:alloc_id
(string: <required>)
- Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one. This is specified as part of the path.
Sample Payload
Sample Request
Sample Response
Restart Allocation
This endpoint restarts an allocation or task in-place.
Method | Path | Produces |
---|---|---|
POST / PUT | /v1/client/allocation/:alloc_id/restart | application/json |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
NO | namespace:alloc-lifecycle |
Parameters
:alloc_id
(string: <required>)
- Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one. This is specified as part of the path.
Sample Payload
Sample Request
Sample Response
Exec Allocation
This endpoint executes a command inside the isolation container where an allocation is running. It opens a WebSocket to transmit input to and output from the command.
Method | Path | Produces |
---|---|---|
WebSocket | /v1/client/allocation/:alloc_id/exec | WebSocket JSON streams |
The table below shows this endpoint's support for blocking queries and required ACLs.
Blocking Queries | ACL Required |
---|---|
NO | namespace:alloc-exec (and namespace:alloc-node-exec if target task uses raw_exec driver) |
Parameters
:alloc_id
(string: <required>)
- Specifies the UUID of the allocation. This must be the full UUID, not the short 8-character one. This is specified as part of the path.command
(string: <required>)
- Specifies the command to be executed. This must be a JSON-encoded array of the command to be executed, e.g.["echo", "hi"]
or["/bin/bash"]
. This is specified as a query parameter.task
(string: <required>)
- Specifies the task name, as a query parameter.tty
(bool: false)
- Specifies whether a TTY is allocated for this task, as a query parameter.ws_handshake
(bool: false)
- Specifies whether to expect the authentication token in the first frame, as a query parameter.
Request Frames
Request frames represent the stdin
stream from the command as well as TTY resize events.
When ?ws_handshake=true
, the first request frame must contain the authentication token.
The following are valid formats:
Response Frames
Response frames represent stdout
and stderr
output from the command as well as exit codes:
Sample Request and Response
Request and response frames encompass the full range of terminal emulator inputs and outputs, including the control characters necessary to render interactive applications. The example response includes instances of the ANSI “control sequence introducer” (CSI), which is ASCII code 27 followed by [
.