2017-05-26 23:13:42 +00:00
---
layout: api
page_title: Allocations - HTTP API
2020-02-06 23:45:31 +00:00
description: The /allocation endpoints are used to query for and interact with allocations.
2017-05-26 23:13:42 +00:00
---
# Allocations HTTP API
The `/allocation` endpoints are used to query for and interact with allocations.
## List Allocations
This endpoint lists all allocations.
2020-02-06 23:45:31 +00:00
| Method | Path | Produces |
| ------ | ----------------- | ------------------ |
| `GET` | `/v1/allocations` | `application/json` |
2017-05-26 23:13:42 +00:00
The table below shows this endpoint's support for
2020-03-20 22:24:56 +00:00
[blocking queries](/api-docs#blocking-queries) and
[required ACLs](/api-docs#acls).
2017-05-26 23:13:42 +00:00
2017-09-15 00:24:51 +00:00
| Blocking Queries | ACL Required |
| ---------------- | -------------------- |
| `YES` | `namespace:read-job` |
2017-05-26 23:13:42 +00:00
### Parameters
2019-10-08 22:11:56 +00:00
- `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.
2017-05-26 23:13:42 +00:00
2022-03-14 14:58:42 +00:00
- `next_token` `(string: "")` - This endpoint supports paging. The `next_token`
parameter accepts a string which identifies the next expected allocation.
This value can be obtained from the `X-Nomad-NextToken` header from the
previous response.
- `per_page` `(int: 0)` - Specifies a maximum number of allocations to return
for this request. If omitted, the response is not paginated. The value of the
`X-Nomad-NextToken` header of the last response can be used as the
`next_token` of the next request to fetch additional pages.
- `filter` `(string: "")` - Specifies the [expression](/api-docs#filtering)
used to filter the results. Consider using pagination or a query parameter to
reduce resource used to serve the request.
2020-07-01 19:15:01 +00:00
- `namespace` `(string: "default")` - Specifies the namespace to search. Specifying
`*` would return all allocations across all the authorized namespaces.
2020-10-14 17:41:32 +00:00
- `resources` `(bool: false)` - Specifies whether or not to include the
`AllocatedResources` field in the response.
- `task_states` `(bool: true)` - Specifies whether or not to include the
`TaskStates` 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 set `task_states=false` to significantly
reduce the size of the response.
2022-03-12 00:44:52 +00:00
- `reverse` `(bool: false)` - Specifies the list of returned allocations should
be sorted in the reverse order. By default allocations are returned sorted in
chronological order (older evaluations first), or in lexicographical order by
their ID if the `prefix` query parameter is used.
2017-05-26 23:13:42 +00:00
### Sample Request
2020-05-01 20:02:21 +00:00
```shell-session
2017-05-26 23:13:42 +00:00
$ curl \
2018-01-29 16:27:52 +00:00
https://localhost:4646/v1/allocations
2017-05-26 23:13:42 +00:00
```
2020-05-01 20:02:21 +00:00
```shell-session
2017-05-26 23:13:42 +00:00
$ curl \
2018-01-29 16:27:52 +00:00
https://localhost:4646/v1/allocations?prefix=a8198d79
2017-05-26 23:13:42 +00:00
```
2020-07-01 19:15:01 +00:00
```shell-session
$ curl \
https://localhost:4646/v1/allocations?namespace=*&prefix=a8198d79
```
2017-05-26 23:13:42 +00:00
### Sample Response
```json
[
{
2021-11-04 09:22:21 +00:00
"ClientDescription": "Tasks are running",
"ClientStatus": "running",
"CreateIndex": 10,
"CreateTime": 1636017249798459000,
"DeploymentStatus": {
"Canary": false,
"Healthy": true,
"ModifyIndex": 15,
"Timestamp": "2021-11-04T10:14:22.054814+01:00"
},
"DesiredDescription": "",
"DesiredStatus": "run",
"DesiredTransition": {
"ForceReschedule": null,
"Migrate": null,
"Reschedule": null
2018-01-31 21:54:10 +00:00
},
2021-11-04 09:22:21 +00:00
"EvalID": "cb20d15d-861f-8d8d-8253-e93932beea2e",
"FollowupEvalID": "",
"ID": "5457f16d-0f87-8e6b-5e91-0c7da3a41eb7",
2017-05-26 23:13:42 +00:00
"JobID": "example",
2021-11-04 09:22:21 +00:00
"JobType": "service",
"JobVersion": 0,
"ModifyIndex": 15,
"ModifyTime": 1636017262190928000,
"Name": "example.cache[0]",
"Namespace": "default",
"NodeID": "f476d2b4-02dc-c216-d031-273396727347",
"NodeName": "linux",
"PreemptedAllocations": null,
"PreemptedByAllocation": "",
"RescheduleTracker": null,
2017-05-26 23:13:42 +00:00
"TaskGroup": "cache",
"TaskStates": {
"redis": {
"Events": [
{
2021-11-04 09:22:21 +00:00
"Details": {},
"DiskLimit": 0,
"DisplayMessage": "Task received by client",
"DownloadError": "",
2017-05-26 23:13:42 +00:00
"DriverError": "",
2021-11-04 09:22:21 +00:00
"DriverMessage": "",
2017-05-26 23:13:42 +00:00
"ExitCode": 0,
2021-11-04 09:22:21 +00:00
"FailedSibling": "",
"FailsTask": false,
"GenericSource": "",
2017-05-26 23:13:42 +00:00
"KillError": "",
"KillReason": "",
2021-11-04 09:22:21 +00:00
"KillTimeout": 0,
"Message": "",
"RestartReason": "",
"SetupError": "",
"Signal": 0,
2017-05-26 23:13:42 +00:00
"StartDelay": 0,
"TaskSignal": "",
2021-11-04 09:22:21 +00:00
"TaskSignalReason": "",
"Time": 1636017249803624000,
"Type": "Received",
"ValidationError": "",
"VaultError": ""
2017-05-26 23:13:42 +00:00
},
{
2021-11-04 09:22:21 +00:00
"Details": {
"message": "Building Task Directory"
},
"DiskLimit": 0,
"DisplayMessage": "Building Task Directory",
"DownloadError": "",
2017-05-26 23:13:42 +00:00
"DriverError": "",
2021-11-04 09:22:21 +00:00
"DriverMessage": "",
2017-05-26 23:13:42 +00:00
"ExitCode": 0,
2021-11-04 09:22:21 +00:00
"FailedSibling": "",
"FailsTask": false,
"GenericSource": "",
2017-05-26 23:13:42 +00:00
"KillError": "",
"KillReason": "",
2021-11-04 09:22:21 +00:00
"KillTimeout": 0,
"Message": "Building Task Directory",
"RestartReason": "",
"SetupError": "",
"Signal": 0,
2017-05-26 23:13:42 +00:00
"StartDelay": 0,
"TaskSignal": "",
2021-11-04 09:22:21 +00:00
"TaskSignalReason": "",
"Time": 1636017249805254000,
"Type": "Task Setup",
"ValidationError": "",
"VaultError": ""
2017-05-26 23:13:42 +00:00
},
{
2021-11-04 09:22:21 +00:00
"Details": {},
"DiskLimit": 0,
"DisplayMessage": "Task started by client",
"DownloadError": "",
2017-05-26 23:13:42 +00:00
"DriverError": "",
2021-11-04 09:22:21 +00:00
"DriverMessage": "",
2017-05-26 23:13:42 +00:00
"ExitCode": 0,
2021-11-04 09:22:21 +00:00
"FailedSibling": "",
"FailsTask": false,
"GenericSource": "",
2017-05-26 23:13:42 +00:00
"KillError": "",
"KillReason": "",
2021-11-04 09:22:21 +00:00
"KillTimeout": 0,
"Message": "",
"RestartReason": "",
"SetupError": "",
"Signal": 0,
2017-05-26 23:13:42 +00:00
"StartDelay": 0,
"TaskSignal": "",
2021-11-04 09:22:21 +00:00
"TaskSignalReason": "",
"Time": 1636017252049956000,
"Type": "Started",
"ValidationError": "",
"VaultError": ""
2017-05-26 23:13:42 +00:00
}
2021-11-04 09:22:21 +00:00
],
"Failed": false,
"FinishedAt": null,
"LastRestart": null,
"Restarts": 0,
"StartedAt": "2021-11-04T09:14:12.04996Z",
"State": "running",
"TaskHandle": null
2017-05-26 23:13:42 +00:00
}
2021-11-04 09:22:21 +00:00
}
2017-05-26 23:13:42 +00:00
}
]
```
## Read Allocation
This endpoint reads information about a specific allocation.
2020-02-06 23:45:31 +00:00
| Method | Path | Produces |
| ------ | -------------------------- | ------------------ |
| `GET` | `/v1/allocation/:alloc_id` | `application/json` |
2017-05-26 23:13:42 +00:00
The table below shows this endpoint's support for
2020-03-20 22:24:56 +00:00
[blocking queries](/api-docs#blocking-queries) and
[required ACLs](/api-docs#acls).
2017-05-26 23:13:42 +00:00
2017-09-15 00:43:27 +00:00
| Blocking Queries | ACL Required |
| ---------------- | -------------------- |
| `YES` | `namespace:read-job` |
2017-05-26 23:13:42 +00:00
### 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
2020-05-01 20:02:21 +00:00
```shell-session
2017-05-26 23:13:42 +00:00
$ curl \
2018-01-29 16:27:52 +00:00
https://localhost:4646/v1/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577
2017-05-26 23:13:42 +00:00
```
### Sample Response
```json
{
"ID": "a8198d79-cfdb-6593-a999-1e9adabcba2e",
"EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577",
"Name": "example.cache[0]",
"NodeID": "fb2170a8-257d-3c64-b14d-bc06cc94e34c",
2018-01-31 21:54:10 +00:00
"PreviousAllocation": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
"NextAllocation": "cd13d9b9-4f97-7184-c88b-7b451981616b",
"RescheduleTracker": {
2020-02-06 23:45:31 +00:00
"Events": [
{
"PrevAllocID": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
"PrevNodeID": "9230cd3b-3bda-9a3f-82f9-b2ea8dedb20e",
"RescheduleTime": 1517434161192946200,
"Delay": "5000000000"
}
]
2018-01-31 21:54:10 +00:00
},
2017-05-26 23:13:42 +00:00
"JobID": "example",
"Job": {
"Region": "global",
"ID": "example",
"ParentID": "",
"Name": "example",
"Type": "service",
"Priority": 50,
"AllAtOnce": false,
2020-02-06 23:45:31 +00:00
"Datacenters": ["dc1"],
2017-05-26 23:13:42 +00:00
"Constraints": null,
2018-11-05 22:41:20 +00:00
"Affinities": null,
2017-05-26 23:13:42 +00:00
"TaskGroups": [
{
"Name": "cache",
"Count": 1,
"Constraints": null,
2018-11-05 22:41:20 +00:00
"Affinities": null,
2017-05-26 23:13:42 +00:00
"RestartPolicy": {
"Attempts": 10,
"Interval": 300000000000,
"Delay": 25000000000,
"Mode": "delay"
},
2019-01-04 03:59:23 +00:00
"Spreads": null,
2017-05-26 23:13:42 +00:00
"Tasks": [
{
"Name": "redis",
"Driver": "docker",
"User": "",
"Config": {
"port_map": [
{
"db": 6379
}
],
"image": "redis:3.2"
},
"Env": null,
"Services": [
{
2018-01-17 20:10:41 +00:00
"Name": "redis-cache",
2017-05-26 23:13:42 +00:00
"PortLabel": "db",
2020-02-06 23:45:31 +00:00
"Tags": ["global", "cache"],
2017-05-26 23:13:42 +00:00
"Checks": [
{
"Name": "alive",
"Type": "tcp",
"Command": "",
"Args": null,
"Path": "",
"Protocol": "",
"PortLabel": "",
"Interval": 10000000000,
"Timeout": 2000000000,
"InitialStatus": ""
}
]
}
],
"Vault": null,
"Templates": null,
"Constraints": null,
2018-11-05 22:41:20 +00:00
"Affinities": null,
2017-05-26 23:13:42 +00:00
"Resources": {
"CPU": 500,
"MemoryMB": 10,
"DiskMB": 0,
"Networks": [
{
"Device": "",
"CIDR": "",
"IP": "",
"MBits": 10,
"ReservedPorts": null,
"DynamicPorts": [
{
"Label": "db",
"Value": 0
}
]
}
]
},
2019-01-04 03:59:23 +00:00
"Spreads": null,
2017-05-26 23:13:42 +00:00
"DispatchPayload": null,
"Meta": null,
"KillTimeout": 5000000000,
"LogConfig": {
"MaxFiles": 10,
"MaxFileSizeMB": 10
},
"Artifacts": null,
"Leader": false
}
],
"EphemeralDisk": {
"Sticky": false,
"SizeMB": 300,
"Migrate": false
},
"Meta": null
}
],
"Update": {
"Stagger": 10000000000,
"MaxParallel": 0
},
"Periodic": null,
"ParameterizedJob": null,
"Payload": null,
2019-01-04 03:59:23 +00:00
"Spreads": null,
2017-05-26 23:13:42 +00:00
"Meta": null,
"VaultToken": "",
"Status": "pending",
"StatusDescription": "",
"CreateIndex": 52,
"ModifyIndex": 52,
"JobModifyIndex": 52
},
"TaskGroup": "cache",
"Resources": {
"CPU": 500,
"MemoryMB": 10,
"DiskMB": 300,
"Networks": [
{
"Device": "lo0",
"CIDR": "",
"IP": "127.0.0.1",
"MBits": 10,
"ReservedPorts": null,
"DynamicPorts": [
{
"Label": "db",
"Value": 23116
}
]
}
]
},
"SharedResources": {
"CPU": 0,
"MemoryMB": 0,
"DiskMB": 300,
"Networks": null
},
"TaskResources": {
"redis": {
"CPU": 500,
"MemoryMB": 10,
"DiskMB": 0,
"Networks": [
{
"Device": "lo0",
"CIDR": "",
"IP": "127.0.0.1",
"MBits": 10,
"ReservedPorts": null,
"DynamicPorts": [
{
"Label": "db",
"Value": 23116
}
]
}
]
}
},
"Metrics": {
"NodesEvaluated": 1,
"NodesFiltered": 0,
"NodesAvailable": {
"dc1": 1
},
"ClassFiltered": null,
"ConstraintFiltered": null,
"NodesExhausted": 0,
"ClassExhausted": null,
"DimensionExhausted": null,
"Scores": {
"fb2170a8-257d-3c64-b14d-bc06cc94e34c.binpack": 0.6205732522109244
},
"AllocationTime": 31729,
"CoalescedFailures": 0
},
"DesiredStatus": "run",
"DesiredDescription": "",
"ClientStatus": "running",
"ClientDescription": "",
"TaskStates": {
"redis": {
"State": "running",
"Failed": false,
2017-07-26 00:18:15 +00:00
"FinishedAt": "0001-01-01T00:00:00Z",
"LastRestart": "0001-01-01T00:00:00Z",
"Restarts": 0,
"StartedAt": "2017-07-25T23:36:26.106431265Z",
2017-05-26 23:13:42 +00:00
"Events": [
{
"Type": "Received",
"Time": 1495747371795703800,
"FailsTask": false,
"RestartReason": "",
"SetupError": "",
"DriverError": "",
"ExitCode": 0,
"Signal": 0,
"Message": "",
"KillTimeout": 0,
"KillError": "",
"KillReason": "",
"StartDelay": 0,
"DownloadError": "",
"ValidationError": "",
"DiskLimit": 0,
"FailedSibling": "",
"VaultError": "",
"TaskSignalReason": "",
"TaskSignal": "",
"DriverMessage": ""
},
{
"Type": "Driver",
"Time": 1495747371798867200,
"FailsTask": false,
"RestartReason": "",
"SetupError": "",
"DriverError": "",
"ExitCode": 0,
"Signal": 0,
"Message": "",
"KillTimeout": 0,
"KillError": "",
"KillReason": "",
"StartDelay": 0,
"DownloadError": "",
"ValidationError": "",
"DiskLimit": 0,
"FailedSibling": "",
"VaultError": "",
"TaskSignalReason": "",
"TaskSignal": "",
"DriverMessage": "Downloading image redis:3.2"
},
{
"Type": "Started",
"Time": 1495747379525667800,
"FailsTask": false,
"RestartReason": "",
"SetupError": "",
"DriverError": "",
"ExitCode": 0,
"Signal": 0,
"Message": "",
"KillTimeout": 0,
"KillError": "",
"KillReason": "",
"StartDelay": 0,
"DownloadError": "",
"ValidationError": "",
"DiskLimit": 0,
"FailedSibling": "",
"VaultError": "",
"TaskSignalReason": "",
"TaskSignal": "",
"DriverMessage": ""
}
]
}
},
"PreviousAllocation": "",
"CreateIndex": 54,
"ModifyIndex": 57,
"AllocModifyIndex": 54,
2017-10-30 17:23:24 +00:00
"CreateTime": 1495747371794276400,
"ModifyTime": 1495747371794276400
2017-05-26 23:13:42 +00:00
}
```
#### Field Reference
2020-11-18 15:00:52 +00:00
- `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](/api-docs/jobs); take care to fetch the version of the job
associated with this allocation.
2017-05-26 23:13:42 +00:00
- `TaskStates` - A map of tasks to their current state and the latest events
2017-07-07 06:04:42 +00:00
that have effected the state. `TaskState` objects contain the following
fields:
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `State`: The task's current state. It can have one of the following
values:
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `TaskStatePending` - The task is waiting to be run, either for the first
time or due to a restart.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `TaskStateRunning` - The task is currently running.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `TaskStateDead` - The task is dead and will not run again.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `StartedAt`: The time the task was last started at. Can be updated through
restarts.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `FinishedAt`: The time the task was finished at.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `LastRestart`: The last time the task was restarted.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Restarts`: The number of times the task has restarted.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `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:
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Setup Failure` - The task could not be started because there was a
failure setting up the task prior to it running.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Driver Failure` - The task could not be started due to a failure in the
driver.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Started` - The task was started; either for the first time or due to a
restart.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Terminated` - The task was started and exited.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Killing` - The task has been sent the kill signal.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Killed` - The task was killed by a user.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Received` - The task has been pulled by the client at the given timestamp.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Failed Validation` - The task was invalid and as such it didn't run.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Restarting` - The task terminated and is being restarted.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Not Restarting` - the task has failed and is not being restarted because
it has exceeded its restart policy.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Downloading Artifacts` - The task is downloading the artifact(s)
- specified in the task.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Failed Artifact Download` - Artifact(s) specified in the task failed to
download.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Restart Signaled` - The task was singled to be restarted.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Signaling` - The task was is being sent a signal.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Sibling Task Failed` - A task in the same task group failed.
2017-05-26 23:13:42 +00:00
2020-02-06 23:45:31 +00:00
- `Leader Task Dead` - The group's leader task is dead.
2017-07-07 06:04:42 +00:00
2020-02-06 23:45:31 +00:00
- `Driver` - A message from the driver.
2017-07-07 06:04:42 +00:00
2020-02-06 23:45:31 +00:00
- `Task Setup` - Task setup messages.
2017-07-07 06:04:42 +00:00
2020-02-06 23:45:31 +00:00
- `Building Task Directory` - Task is building its file system.
2017-07-07 06:04:42 +00:00
2020-02-06 23:45:31 +00:00
Depending on the type the event will have applicable annotations.
2019-04-23 11:28:21 +00:00
2019-06-05 15:09:22 +00:00
## Stop Allocation
2019-04-23 11:28:21 +00:00
This endpoint stops and reschedules a specific allocation.
2020-02-06 23:45:31 +00:00
| Method | Path | Produces |
| -------------- | ------------------------------- | ------------------ |
| `POST` / `PUT` | `/v1/allocation/:alloc_id/stop` | `application/json` |
2019-04-23 11:28:21 +00:00
The table below shows this endpoint's support for
2020-03-20 22:24:56 +00:00
[blocking queries](/api-docs#blocking-queries) and
[required ACLs](/api-docs#acls).
2019-04-23 11:28:21 +00:00
2020-02-06 23:45:31 +00:00
| Blocking Queries | ACL Required |
| ---------------- | --------------------------- |
| `NO` | `namespace:alloc-lifecycle` |
2019-04-23 11:28:21 +00:00
### 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
2020-05-01 20:02:21 +00:00
```shell-session
2019-04-23 11:28:21 +00:00
$ curl -X POST \
https://localhost:4646/v1/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/stop
```
### Sample Response
```json
{
"EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577",
"Index": 54
}
2019-04-25 12:39:49 +00:00
```
2019-06-05 15:09:22 +00:00
## Signal Allocation
2019-04-25 12:39:49 +00:00
This endpoint sends a signal to an allocation or task.
2020-02-06 23:45:31 +00:00
| Method | Path | Produces |
| -------------- | ---------------------------------------- | ------------------ |
| `POST` / `PUT` | `/v1/client/allocation/:alloc_id/signal` | `application/json` |
2019-04-25 12:39:49 +00:00
The table below shows this endpoint's support for
2020-03-20 22:24:56 +00:00
[blocking queries](/api-docs#blocking-queries) and
[required ACLs](/api-docs#acls).
2019-04-25 12:39:49 +00:00
2020-02-06 23:45:31 +00:00
| Blocking Queries | ACL Required |
| ---------------- | --------------------------- |
| `NO` | `namespace:alloc-lifecycle` |
2019-04-25 12:39:49 +00:00
### 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
```json
{
"Signal": "SIGUSR1",
"Task": "FOO"
}
```
2021-04-09 19:57:19 +00:00
If `Task` is omitted, the signal will be sent to all tasks in the allocation.
2019-04-25 12:39:49 +00:00
### Sample Request
2020-05-01 20:02:21 +00:00
```shell-session
2019-04-25 12:39:49 +00:00
$ curl -X POST -d '{"Signal": "SIGUSR1" }' \
https://localhost:4646/v1/client/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/signal
```
### Sample Response
```json
{}
```
2019-06-12 13:09:52 +00:00
## Restart Allocation
This endpoint restarts an allocation or task in-place.
2020-02-06 23:45:31 +00:00
| Method | Path | Produces |
| -------------- | ----------------------------------------- | ------------------ |
| `POST` / `PUT` | `/v1/client/allocation/:alloc_id/restart` | `application/json` |
2019-06-12 13:09:52 +00:00
The table below shows this endpoint's support for
2020-03-20 22:24:56 +00:00
[blocking queries](/api-docs#blocking-queries) and
[required ACLs](/api-docs#acls).
2019-06-12 13:09:52 +00:00
2020-02-06 23:45:31 +00:00
| Blocking Queries | ACL Required |
| ---------------- | --------------------------- |
| `NO` | `namespace:alloc-lifecycle` |
2019-06-12 13:09:52 +00:00
### 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
```json
{
2021-07-30 14:45:21 +00:00
"TaskName": "FOO"
2019-06-12 13:09:52 +00:00
}
```
### Sample Request
2020-05-01 20:02:21 +00:00
```shell-session
2021-07-30 14:45:21 +00:00
$ curl -X POST -d '{"TaskName": "redis" }' \
2019-06-12 13:09:52 +00:00
https://localhost:4646/v1/client/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/restart
```
### Sample Response
```json
{}
```
2021-01-08 20:01:06 +00:00
## 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.
2021-03-31 13:43:17 +00:00
| Method | Path | Produces |
| ----------- | -------------------------------------- | ---------------------- |
2021-01-08 20:01:06 +00:00
| `WebSocket` | `/v1/client/allocation/:alloc_id/exec` | WebSocket JSON streams |
The table below shows this endpoint's support for
[blocking queries](/api/index.html#blocking-queries) and
[required ACLs](/api/index.html#acls).
2021-03-31 13:43:17 +00:00
| Blocking Queries | ACL Required |
| ---------------- | -------------------------------------------------------------------------------------------- |
| `NO` | `namespace:alloc-exec` (and `namespace:alloc-node-exec` if target task uses raw_exec driver) |
2021-01-08 20:01:06 +00:00
### 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.
2021-03-31 13:43:17 +00:00
- `command` `(string: <required>)` - Specifies the command to be executed. This
2021-01-08 20:01:06 +00:00
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:
```
# sending authentication token
{"version":1,"auth_token":"fc3c1968-8d31-5c50-9617-3db2e19ef32e"}
# sending stdin data
{"stdin": {"data": "...base64 encoded string of bytes ..."}}
# indicating stdin is closed
{"stdin": {"close": true}}
# indicating that TTY was resized
{"tty_size": {"height": <characters>, "width": <characters>}}
# basic application-level heartbeat
{}
```
### Response Frames
Response frames represent `stdout` and `stderr` output from the command as well as exit codes:
```
# transferring stdout data
{"stdout": {"data": "...base64 encoded string of bytes ..."}}
# signaling that host closed stdout
{"stdout": {"close": true}}
# transferring stderr data
{"stderr": {"data": "...base64 encoded string of bytes ..."}}
# signaling that host closed stderr
{"stderr": {"close": true}}
# signaling process exited
{"exited": true, "result": {"exit_code": <exit_code_int>}}
# basic application-level heartbeat
{}
```
### 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 `[`.
```
# \x12: form feed, to clear terminal
{"stdin":{"data":"DA=="}}
# "\x1b[H\x1b[2J$ ":
# CSI-H (move cursor to top left corner), CSI-2J (clear entire screen), print "$ "
{"stdout":{"data":"G1tIG1sySiQg"}}
2021-03-31 13:43:17 +00:00
```