github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/api-docs/allocations.mdx (about)

     1  ---
     2  layout: api
     3  page_title: Allocations - HTTP API
     4  sidebar_title: Allocations
     5  description: The /allocation endpoints are used to query for and interact with allocations.
     6  ---
     7  
     8  # Allocations HTTP API
     9  
    10  The `/allocation` endpoints are used to query for and interact with allocations.
    11  
    12  ## List Allocations
    13  
    14  This endpoint lists all allocations.
    15  
    16  | Method | Path              | Produces           |
    17  | ------ | ----------------- | ------------------ |
    18  | `GET`  | `/v1/allocations` | `application/json` |
    19  
    20  The table below shows this endpoint's support for
    21  [blocking queries](/api-docs#blocking-queries) and
    22  [required ACLs](/api-docs#acls).
    23  
    24  | Blocking Queries | ACL Required         |
    25  | ---------------- | -------------------- |
    26  | `YES`            | `namespace:read-job` |
    27  
    28  ### Parameters
    29  
    30  - `prefix` `(string: "")`- Specifies a string to filter allocations based on an
    31    ID prefix. Because the value is decoded to bytes, the prefix must have an
    32    even number of hexadecimal characters (0-9a-f). This is specified as a query
    33    string parameter.
    34  
    35  ### Sample Request
    36  
    37  ```shell-session
    38  $ curl \
    39      https://localhost:4646/v1/allocations
    40  ```
    41  
    42  ```shell-session
    43  $ curl \
    44      https://localhost:4646/v1/allocations?prefix=a8198d79
    45  ```
    46  
    47  ### Sample Response
    48  
    49  ```json
    50  [
    51    {
    52      "ID": "a8198d79-cfdb-6593-a999-1e9adabcba2e",
    53      "EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577",
    54      "Name": "example.cache[0]",
    55      "NodeID": "fb2170a8-257d-3c64-b14d-bc06cc94e34c",
    56      "PreviousAllocation": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
    57      "NextAllocation": "cd13d9b9-4f97-7184-c88b-7b451981616b",
    58      "RescheduleTracker": {
    59        "Events": [
    60          {
    61            "PrevAllocID": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
    62            "PrevNodeID": "9230cd3b-3bda-9a3f-82f9-b2ea8dedb20e",
    63            "RescheduleTime": 1517434161192946200,
    64            "Delay": "5000000000"
    65          }
    66        ]
    67      },
    68      "JobID": "example",
    69      "TaskGroup": "cache",
    70      "DesiredStatus": "run",
    71      "DesiredDescription": "",
    72      "ClientStatus": "running",
    73      "ClientDescription": "",
    74      "TaskStates": {
    75        "redis": {
    76          "State": "running",
    77          "FinishedAt": "0001-01-01T00:00:00Z",
    78          "LastRestart": "0001-01-01T00:00:00Z",
    79          "Restarts": 0,
    80          "StartedAt": "2017-07-25T23:36:26.106431265Z",
    81          "Failed": false,
    82          "Events": [
    83            {
    84              "Type": "Received",
    85              "Time": 1495747371795703800,
    86              "FailsTask": false,
    87              "RestartReason": "",
    88              "SetupError": "",
    89              "DriverError": "",
    90              "ExitCode": 0,
    91              "Signal": 0,
    92              "Message": "",
    93              "KillTimeout": 0,
    94              "KillError": "",
    95              "KillReason": "",
    96              "StartDelay": 0,
    97              "DownloadError": "",
    98              "ValidationError": "",
    99              "DiskLimit": 0,
   100              "FailedSibling": "",
   101              "VaultError": "",
   102              "TaskSignalReason": "",
   103              "TaskSignal": "",
   104              "DriverMessage": ""
   105            },
   106            {
   107              "Type": "Driver",
   108              "Time": 1495747371798867200,
   109              "FailsTask": false,
   110              "RestartReason": "",
   111              "SetupError": "",
   112              "DriverError": "",
   113              "ExitCode": 0,
   114              "Signal": 0,
   115              "Message": "",
   116              "KillTimeout": 0,
   117              "KillError": "",
   118              "KillReason": "",
   119              "StartDelay": 0,
   120              "DownloadError": "",
   121              "ValidationError": "",
   122              "DiskLimit": 0,
   123              "FailedSibling": "",
   124              "VaultError": "",
   125              "TaskSignalReason": "",
   126              "TaskSignal": "",
   127              "DriverMessage": "Downloading image redis:3.2"
   128            },
   129            {
   130              "Type": "Started",
   131              "Time": 1495747379525667800,
   132              "FailsTask": false,
   133              "RestartReason": "",
   134              "SetupError": "",
   135              "DriverError": "",
   136              "ExitCode": 0,
   137              "Signal": 0,
   138              "Message": "",
   139              "KillTimeout": 0,
   140              "KillError": "",
   141              "KillReason": "",
   142              "StartDelay": 0,
   143              "DownloadError": "",
   144              "ValidationError": "",
   145              "DiskLimit": 0,
   146              "FailedSibling": "",
   147              "VaultError": "",
   148              "TaskSignalReason": "",
   149              "TaskSignal": "",
   150              "DriverMessage": ""
   151            }
   152          ]
   153        }
   154      },
   155      "CreateIndex": 54,
   156      "ModifyIndex": 57,
   157      "CreateTime": 1495747371794276400,
   158      "ModifyTime": 1495747371794276400
   159    }
   160  ]
   161  ```
   162  
   163  ## Read Allocation
   164  
   165  This endpoint reads information about a specific allocation.
   166  
   167  | Method | Path                       | Produces           |
   168  | ------ | -------------------------- | ------------------ |
   169  | `GET`  | `/v1/allocation/:alloc_id` | `application/json` |
   170  
   171  The table below shows this endpoint's support for
   172  [blocking queries](/api-docs#blocking-queries) and
   173  [required ACLs](/api-docs#acls).
   174  
   175  | Blocking Queries | ACL Required         |
   176  | ---------------- | -------------------- |
   177  | `YES`            | `namespace:read-job` |
   178  
   179  ### Parameters
   180  
   181  - `:alloc_id` `(string: <required>)`- Specifies the UUID of the allocation. This
   182    must be the full UUID, not the short 8-character one. This is specified as
   183    part of the path.
   184  
   185  ### Sample Request
   186  
   187  ```shell-session
   188  $ curl \
   189      https://localhost:4646/v1/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577
   190  ```
   191  
   192  ### Sample Response
   193  
   194  ```json
   195  {
   196    "ID": "a8198d79-cfdb-6593-a999-1e9adabcba2e",
   197    "EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577",
   198    "Name": "example.cache[0]",
   199    "NodeID": "fb2170a8-257d-3c64-b14d-bc06cc94e34c",
   200    "PreviousAllocation": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
   201    "NextAllocation": "cd13d9b9-4f97-7184-c88b-7b451981616b",
   202    "RescheduleTracker": {
   203      "Events": [
   204        {
   205          "PrevAllocID": "516d2753-0513-cfc7-57ac-2d6fac18b9dc",
   206          "PrevNodeID": "9230cd3b-3bda-9a3f-82f9-b2ea8dedb20e",
   207          "RescheduleTime": 1517434161192946200,
   208          "Delay": "5000000000"
   209        }
   210      ]
   211    },
   212    "JobID": "example",
   213    "Job": {
   214      "Region": "global",
   215      "ID": "example",
   216      "ParentID": "",
   217      "Name": "example",
   218      "Type": "service",
   219      "Priority": 50,
   220      "AllAtOnce": false,
   221      "Datacenters": ["dc1"],
   222      "Constraints": null,
   223      "Affinities": null,
   224      "TaskGroups": [
   225        {
   226          "Name": "cache",
   227          "Count": 1,
   228          "Constraints": null,
   229          "Affinities": null,
   230          "RestartPolicy": {
   231            "Attempts": 10,
   232            "Interval": 300000000000,
   233            "Delay": 25000000000,
   234            "Mode": "delay"
   235          },
   236          "Spreads": null,
   237          "Tasks": [
   238            {
   239              "Name": "redis",
   240              "Driver": "docker",
   241              "User": "",
   242              "Config": {
   243                "port_map": [
   244                  {
   245                    "db": 6379
   246                  }
   247                ],
   248                "image": "redis:3.2"
   249              },
   250              "Env": null,
   251              "Services": [
   252                {
   253                  "Name": "redis-cache",
   254                  "PortLabel": "db",
   255                  "Tags": ["global", "cache"],
   256                  "Checks": [
   257                    {
   258                      "Name": "alive",
   259                      "Type": "tcp",
   260                      "Command": "",
   261                      "Args": null,
   262                      "Path": "",
   263                      "Protocol": "",
   264                      "PortLabel": "",
   265                      "Interval": 10000000000,
   266                      "Timeout": 2000000000,
   267                      "InitialStatus": ""
   268                    }
   269                  ]
   270                }
   271              ],
   272              "Vault": null,
   273              "Templates": null,
   274              "Constraints": null,
   275              "Affinities": null,
   276              "Resources": {
   277                "CPU": 500,
   278                "MemoryMB": 10,
   279                "DiskMB": 0,
   280                "Networks": [
   281                  {
   282                    "Device": "",
   283                    "CIDR": "",
   284                    "IP": "",
   285                    "MBits": 10,
   286                    "ReservedPorts": null,
   287                    "DynamicPorts": [
   288                      {
   289                        "Label": "db",
   290                        "Value": 0
   291                      }
   292                    ]
   293                  }
   294                ]
   295              },
   296              "Spreads": null,
   297              "DispatchPayload": null,
   298              "Meta": null,
   299              "KillTimeout": 5000000000,
   300              "LogConfig": {
   301                "MaxFiles": 10,
   302                "MaxFileSizeMB": 10
   303              },
   304              "Artifacts": null,
   305              "Leader": false
   306            }
   307          ],
   308          "EphemeralDisk": {
   309            "Sticky": false,
   310            "SizeMB": 300,
   311            "Migrate": false
   312          },
   313          "Meta": null
   314        }
   315      ],
   316      "Update": {
   317        "Stagger": 10000000000,
   318        "MaxParallel": 0
   319      },
   320      "Periodic": null,
   321      "ParameterizedJob": null,
   322      "Payload": null,
   323      "Spreads": null,
   324      "Meta": null,
   325      "VaultToken": "",
   326      "Status": "pending",
   327      "StatusDescription": "",
   328      "CreateIndex": 52,
   329      "ModifyIndex": 52,
   330      "JobModifyIndex": 52
   331    },
   332    "TaskGroup": "cache",
   333    "Resources": {
   334      "CPU": 500,
   335      "MemoryMB": 10,
   336      "DiskMB": 300,
   337      "Networks": [
   338        {
   339          "Device": "lo0",
   340          "CIDR": "",
   341          "IP": "127.0.0.1",
   342          "MBits": 10,
   343          "ReservedPorts": null,
   344          "DynamicPorts": [
   345            {
   346              "Label": "db",
   347              "Value": 23116
   348            }
   349          ]
   350        }
   351      ]
   352    },
   353    "SharedResources": {
   354      "CPU": 0,
   355      "MemoryMB": 0,
   356      "DiskMB": 300,
   357      "Networks": null
   358    },
   359    "TaskResources": {
   360      "redis": {
   361        "CPU": 500,
   362        "MemoryMB": 10,
   363        "DiskMB": 0,
   364        "Networks": [
   365          {
   366            "Device": "lo0",
   367            "CIDR": "",
   368            "IP": "127.0.0.1",
   369            "MBits": 10,
   370            "ReservedPorts": null,
   371            "DynamicPorts": [
   372              {
   373                "Label": "db",
   374                "Value": 23116
   375              }
   376            ]
   377          }
   378        ]
   379      }
   380    },
   381    "Metrics": {
   382      "NodesEvaluated": 1,
   383      "NodesFiltered": 0,
   384      "NodesAvailable": {
   385        "dc1": 1
   386      },
   387      "ClassFiltered": null,
   388      "ConstraintFiltered": null,
   389      "NodesExhausted": 0,
   390      "ClassExhausted": null,
   391      "DimensionExhausted": null,
   392      "Scores": {
   393        "fb2170a8-257d-3c64-b14d-bc06cc94e34c.binpack": 0.6205732522109244
   394      },
   395      "AllocationTime": 31729,
   396      "CoalescedFailures": 0
   397    },
   398    "DesiredStatus": "run",
   399    "DesiredDescription": "",
   400    "ClientStatus": "running",
   401    "ClientDescription": "",
   402    "TaskStates": {
   403      "redis": {
   404        "State": "running",
   405        "Failed": false,
   406        "FinishedAt": "0001-01-01T00:00:00Z",
   407        "LastRestart": "0001-01-01T00:00:00Z",
   408        "Restarts": 0,
   409        "StartedAt": "2017-07-25T23:36:26.106431265Z",
   410        "Events": [
   411          {
   412            "Type": "Received",
   413            "Time": 1495747371795703800,
   414            "FailsTask": false,
   415            "RestartReason": "",
   416            "SetupError": "",
   417            "DriverError": "",
   418            "ExitCode": 0,
   419            "Signal": 0,
   420            "Message": "",
   421            "KillTimeout": 0,
   422            "KillError": "",
   423            "KillReason": "",
   424            "StartDelay": 0,
   425            "DownloadError": "",
   426            "ValidationError": "",
   427            "DiskLimit": 0,
   428            "FailedSibling": "",
   429            "VaultError": "",
   430            "TaskSignalReason": "",
   431            "TaskSignal": "",
   432            "DriverMessage": ""
   433          },
   434          {
   435            "Type": "Driver",
   436            "Time": 1495747371798867200,
   437            "FailsTask": false,
   438            "RestartReason": "",
   439            "SetupError": "",
   440            "DriverError": "",
   441            "ExitCode": 0,
   442            "Signal": 0,
   443            "Message": "",
   444            "KillTimeout": 0,
   445            "KillError": "",
   446            "KillReason": "",
   447            "StartDelay": 0,
   448            "DownloadError": "",
   449            "ValidationError": "",
   450            "DiskLimit": 0,
   451            "FailedSibling": "",
   452            "VaultError": "",
   453            "TaskSignalReason": "",
   454            "TaskSignal": "",
   455            "DriverMessage": "Downloading image redis:3.2"
   456          },
   457          {
   458            "Type": "Started",
   459            "Time": 1495747379525667800,
   460            "FailsTask": false,
   461            "RestartReason": "",
   462            "SetupError": "",
   463            "DriverError": "",
   464            "ExitCode": 0,
   465            "Signal": 0,
   466            "Message": "",
   467            "KillTimeout": 0,
   468            "KillError": "",
   469            "KillReason": "",
   470            "StartDelay": 0,
   471            "DownloadError": "",
   472            "ValidationError": "",
   473            "DiskLimit": 0,
   474            "FailedSibling": "",
   475            "VaultError": "",
   476            "TaskSignalReason": "",
   477            "TaskSignal": "",
   478            "DriverMessage": ""
   479          }
   480        ]
   481      }
   482    },
   483    "PreviousAllocation": "",
   484    "CreateIndex": 54,
   485    "ModifyIndex": 57,
   486    "AllocModifyIndex": 54,
   487    "CreateTime": 1495747371794276400,
   488    "ModifyTime": 1495747371794276400
   489  }
   490  ```
   491  
   492  #### Field Reference
   493  
   494  - `TaskStates` - A map of tasks to their current state and the latest events
   495    that have effected the state. `TaskState` objects contain the following
   496    fields:
   497  
   498    - `State`: The task's current state. It can have one of the following
   499      values:
   500  
   501      - `TaskStatePending` - The task is waiting to be run, either for the first
   502        time or due to a restart.
   503  
   504      - `TaskStateRunning` - The task is currently running.
   505  
   506      - `TaskStateDead` - The task is dead and will not run again.
   507  
   508    - `StartedAt`: The time the task was last started at. Can be updated through
   509      restarts.
   510  
   511    - `FinishedAt`: The time the task was finished at.
   512  
   513    - `LastRestart`: The last time the task was restarted.
   514  
   515    - `Restarts`: The number of times the task has restarted.
   516  
   517    - `Events` - An event contains metadata about the event. The latest 10 events
   518      are stored per task. Each event is timestamped (Unix nanoseconds) and has one
   519      of the following types:
   520  
   521      - `Setup Failure` - The task could not be started because there was a
   522        failure setting up the task prior to it running.
   523  
   524      - `Driver Failure` - The task could not be started due to a failure in the
   525        driver.
   526  
   527      - `Started` - The task was started; either for the first time or due to a
   528        restart.
   529  
   530      - `Terminated` - The task was started and exited.
   531  
   532      - `Killing` - The task has been sent the kill signal.
   533  
   534      - `Killed` - The task was killed by a user.
   535  
   536      - `Received` - The task has been pulled by the client at the given timestamp.
   537  
   538      - `Failed Validation` - The task was invalid and as such it didn't run.
   539  
   540      - `Restarting` - The task terminated and is being restarted.
   541  
   542      - `Not Restarting` - the task has failed and is not being restarted because
   543        it has exceeded its restart policy.
   544  
   545      - `Downloading Artifacts` - The task is downloading the artifact(s)
   546      - specified in the task.
   547  
   548      - `Failed Artifact Download` - Artifact(s) specified in the task failed to
   549        download.
   550  
   551      - `Restart Signaled` - The task was singled to be restarted.
   552  
   553      - `Signaling` - The task was is being sent a signal.
   554  
   555      - `Sibling Task Failed` - A task in the same task group failed.
   556  
   557      - `Leader Task Dead` - The group's leader task is dead.
   558  
   559      - `Driver` - A message from the driver.
   560  
   561      - `Task Setup` - Task setup messages.
   562  
   563      - `Building Task Directory` - Task is building its file system.
   564  
   565      Depending on the type the event will have applicable annotations.
   566  
   567  ## Stop Allocation
   568  
   569  This endpoint stops and reschedules a specific allocation.
   570  
   571  | Method         | Path                            | Produces           |
   572  | -------------- | ------------------------------- | ------------------ |
   573  | `POST` / `PUT` | `/v1/allocation/:alloc_id/stop` | `application/json` |
   574  
   575  The table below shows this endpoint's support for
   576  [blocking queries](/api-docs#blocking-queries) and
   577  [required ACLs](/api-docs#acls).
   578  
   579  | Blocking Queries | ACL Required                |
   580  | ---------------- | --------------------------- |
   581  | `NO`             | `namespace:alloc-lifecycle` |
   582  
   583  ### Parameters
   584  
   585  - `:alloc_id` `(string: <required>)`- Specifies the UUID of the allocation. This
   586    must be the full UUID, not the short 8-character one. This is specified as
   587    part of the path.
   588  
   589  ### Sample Request
   590  
   591  ```shell-session
   592  $ curl -X POST \
   593      https://localhost:4646/v1/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/stop
   594  ```
   595  
   596  ### Sample Response
   597  
   598  ```json
   599  {
   600    "EvalID": "5456bd7a-9fc0-c0dd-6131-cbee77f57577",
   601    "Index": 54
   602  }
   603  ```
   604  
   605  ## Signal Allocation
   606  
   607  This endpoint sends a signal to an allocation or task.
   608  
   609  | Method         | Path                                     | Produces           |
   610  | -------------- | ---------------------------------------- | ------------------ |
   611  | `POST` / `PUT` | `/v1/client/allocation/:alloc_id/signal` | `application/json` |
   612  
   613  The table below shows this endpoint's support for
   614  [blocking queries](/api-docs#blocking-queries) and
   615  [required ACLs](/api-docs#acls).
   616  
   617  | Blocking Queries | ACL Required                |
   618  | ---------------- | --------------------------- |
   619  | `NO`             | `namespace:alloc-lifecycle` |
   620  
   621  ### Parameters
   622  
   623  - `:alloc_id` `(string: <required>)`- Specifies the UUID of the allocation. This
   624    must be the full UUID, not the short 8-character one. This is specified as
   625    part of the path.
   626  
   627  ### Sample Payload
   628  
   629  ```json
   630  {
   631    "Signal": "SIGUSR1",
   632    "Task": "FOO"
   633  }
   634  ```
   635  
   636  ### Sample Request
   637  
   638  ```shell-session
   639  $ curl -X POST -d '{"Signal": "SIGUSR1" }' \
   640      https://localhost:4646/v1/client/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/signal
   641  ```
   642  
   643  ### Sample Response
   644  
   645  ```json
   646  {}
   647  ```
   648  
   649  ## Restart Allocation
   650  
   651  This endpoint restarts an allocation or task in-place.
   652  
   653  | Method         | Path                                      | Produces           |
   654  | -------------- | ----------------------------------------- | ------------------ |
   655  | `POST` / `PUT` | `/v1/client/allocation/:alloc_id/restart` | `application/json` |
   656  
   657  The table below shows this endpoint's support for
   658  [blocking queries](/api-docs#blocking-queries) and
   659  [required ACLs](/api-docs#acls).
   660  
   661  | Blocking Queries | ACL Required                |
   662  | ---------------- | --------------------------- |
   663  | `NO`             | `namespace:alloc-lifecycle` |
   664  
   665  ### Parameters
   666  
   667  - `:alloc_id` `(string: <required>)`- Specifies the UUID of the allocation. This
   668    must be the full UUID, not the short 8-character one. This is specified as
   669    part of the path.
   670  
   671  ### Sample Payload
   672  
   673  ```json
   674  {
   675    "Task": "FOO"
   676  }
   677  ```
   678  
   679  ### Sample Request
   680  
   681  ```shell-session
   682  $ curl -X POST -d '{"Task": "redis" }' \
   683      https://localhost:4646/v1/client/allocation/5456bd7a-9fc0-c0dd-6131-cbee77f57577/restart
   684  ```
   685  
   686  ### Sample Response
   687  
   688  ```json
   689  {}
   690  ```