Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,14 @@ func (s *HTTPServer) jobAllocations(resp http.ResponseWriter, req *http.Request,
return nil, CodedError(405, ErrInvalidMethod)
}
allAllocs, _ := strconv.ParseBool(req.URL.Query().Get("all"))
reverse, _ := strconv.ParseBool(req.URL.Query().Get("reverse"))

args := structs.JobSpecificRequest{
JobID: jobID,
All: allAllocs,
QueryOptions: structs.QueryOptions {
Reverse: reverse,
},
}
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
return nil, nil
Expand Down
7 changes: 7 additions & 0 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,13 @@ func (j *Job) Allocations(args *structs.JobSpecificRequest,
return err
}

sort.Slice(allocs, func(i,j int) bool {
if (args.QueryOptions.Reverse) {
return allocs[i].ID > allocs[j].ID
}
return allocs[i].ID < allocs[j].ID
})

// Convert to stubs
if len(allocs) > 0 {
reply.Allocations = make([]*structs.AllocListStub, 0, len(allocs))
Expand Down
2 changes: 2 additions & 0 deletions website/content/api-docs/jobs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ The table below shows this endpoint's support for
enabled, this value must match a namespace that the token is allowed to
access. This is specified as a query string parameter.

- `reverse` `(bool: false)` - Specifies the list of returned allocations to be sorted in the reverse lexicographical order. By default, they are lexicographically sorted.
Copy link
Member

@tgross tgross Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added "by ID", and also we hard-wrap markdown text:

Suggested change
- `reverse` `(bool: false)` - Specifies the list of returned allocations to be sorted in the reverse lexicographical order. By default, they are lexicographically sorted.
- `reverse` `(bool: false)` - Specifies the list of returned allocations to be
sorted in the reverse lexicographical order. By default, they are
lexicographically sorted by ID.


### Sample Request

```shell-session
Expand Down