Making the status command return the allocs of currently registered job

This commit is contained in:
Diptanu Choudhury
2016-11-24 13:20:52 +01:00
parent 3e6390839f
commit 5eb4e8adb3
12 changed files with 112 additions and 20 deletions

View File

@@ -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

View File

@@ -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)
}