mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Merge pull request #4274 from hashicorp/f-force-rescheduling
Add CLI and API support for forcing rescheduling of failed allocs
This commit is contained in:
@@ -90,8 +90,25 @@ func (s *HTTPServer) jobForceEvaluate(resp http.ResponseWriter, req *http.Reques
|
||||
if req.Method != "PUT" && req.Method != "POST" {
|
||||
return nil, CodedError(405, ErrInvalidMethod)
|
||||
}
|
||||
args := structs.JobEvaluateRequest{
|
||||
JobID: jobName,
|
||||
var args structs.JobEvaluateRequest
|
||||
|
||||
// TODO(preetha): remove in 0.9
|
||||
// COMPAT: For backwards compatibility allow using this endpoint without a payload
|
||||
if req.ContentLength == 0 {
|
||||
args = structs.JobEvaluateRequest{
|
||||
JobID: jobName,
|
||||
}
|
||||
} else {
|
||||
if err := decodeBody(req, &args); err != nil {
|
||||
return nil, CodedError(400, err.Error())
|
||||
}
|
||||
if args.JobID == "" {
|
||||
return nil, CodedError(400, "Job ID must be specified")
|
||||
}
|
||||
|
||||
if jobName != "" && args.JobID != jobName {
|
||||
return nil, CodedError(400, "JobID not same as job name")
|
||||
}
|
||||
}
|
||||
s.parseWriteRequest(req, &args.WriteRequest)
|
||||
|
||||
|
||||
@@ -609,6 +609,57 @@ func TestHTTP_JobForceEvaluate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_JobEvaluate_ForceReschedule(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
// Create the job
|
||||
job := mock.Job()
|
||||
args := structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
WriteRequest: structs.WriteRequest{
|
||||
Region: "global",
|
||||
Namespace: structs.DefaultNamespace,
|
||||
},
|
||||
}
|
||||
var resp structs.JobRegisterResponse
|
||||
if err := s.Agent.RPC("Job.Register", &args, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
jobEvalReq := api.JobEvaluateRequest{
|
||||
JobID: job.ID,
|
||||
EvalOptions: api.EvalOptions{
|
||||
ForceReschedule: true,
|
||||
},
|
||||
}
|
||||
|
||||
buf := encodeReq(jobEvalReq)
|
||||
|
||||
// Make the HTTP request
|
||||
req, err := http.NewRequest("POST", "/v1/job/"+job.ID+"/evaluate", buf)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
respW := httptest.NewRecorder()
|
||||
|
||||
// Make the request
|
||||
obj, err := s.Server.JobSpecificRequest(respW, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Check the response
|
||||
reg := obj.(structs.JobRegisterResponse)
|
||||
if reg.EvalID == "" {
|
||||
t.Fatalf("bad: %v", reg)
|
||||
}
|
||||
|
||||
// Check for the index
|
||||
if respW.HeaderMap.Get("X-Nomad-Index") == "" {
|
||||
t.Fatalf("missing index")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_JobEvaluations(t *testing.T) {
|
||||
t.Parallel()
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
|
||||
Reference in New Issue
Block a user