mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Making the status command return the allocs of currently registered job
This commit is contained in:
@@ -2,6 +2,7 @@ package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -130,8 +131,11 @@ func (s *HTTPServer) jobAllocations(resp http.ResponseWriter, req *http.Request,
|
||||
if req.Method != "GET" {
|
||||
return nil, CodedError(405, ErrInvalidMethod)
|
||||
}
|
||||
allAllocs, _ := strconv.ParseBool(req.URL.Query().Get("all"))
|
||||
|
||||
args := structs.JobSpecificRequest{
|
||||
JobID: jobName,
|
||||
JobID: jobName,
|
||||
AllAllocs: allAllocs,
|
||||
}
|
||||
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
||||
return nil, nil
|
||||
|
||||
@@ -396,9 +396,9 @@ func TestHTTP_JobEvaluations(t *testing.T) {
|
||||
func TestHTTP_JobAllocations(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Create the job
|
||||
job := mock.Job()
|
||||
alloc1 := mock.Alloc()
|
||||
args := structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
Job: alloc1.Job,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
var resp structs.JobRegisterResponse
|
||||
@@ -408,15 +408,13 @@ func TestHTTP_JobAllocations(t *testing.T) {
|
||||
|
||||
// Directly manipulate the state
|
||||
state := s.Agent.server.State()
|
||||
alloc1 := mock.Alloc()
|
||||
alloc1.JobID = job.ID
|
||||
err := state.UpsertAllocs(1000, []*structs.Allocation{alloc1})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Make the HTTP request
|
||||
req, err := http.NewRequest("GET", "/v1/job/"+job.ID+"/allocations", nil)
|
||||
req, err := http.NewRequest("GET", "/v1/job/"+alloc1.Job.ID+"/allocations?all=true", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user