mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
non-purge deregisters
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -312,8 +313,20 @@ func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
|
||||
|
||||
func (s *HTTPServer) jobDelete(resp http.ResponseWriter, req *http.Request,
|
||||
jobName string) (interface{}, error) {
|
||||
|
||||
purgeStr := req.URL.Query().Get("purge")
|
||||
var purgeBool bool
|
||||
if purgeStr != "" {
|
||||
var err error
|
||||
purgeBool, err = strconv.ParseBool(purgeStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse value of %q (%v) as a bool: %v", "purge", purgeStr, err)
|
||||
}
|
||||
}
|
||||
|
||||
args := structs.JobDeregisterRequest{
|
||||
JobID: jobName,
|
||||
Purge: purgeBool,
|
||||
}
|
||||
s.parseRegion(req, &args.Region)
|
||||
|
||||
@@ -397,6 +410,7 @@ func ApiJobToStructJob(job *api.Job) *structs.Job {
|
||||
job.Canonicalize()
|
||||
|
||||
j := &structs.Job{
|
||||
Stop: *job.Stop,
|
||||
Region: *job.Region,
|
||||
ID: *job.ID,
|
||||
ParentID: *job.ParentID,
|
||||
|
||||
@@ -383,7 +383,7 @@ func TestHTTP_JobDelete(t *testing.T) {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Make the HTTP request
|
||||
// Make the HTTP request to do a soft delete
|
||||
req, err := http.NewRequest("DELETE", "/v1/job/"+job.ID, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
@@ -407,16 +407,56 @@ func TestHTTP_JobDelete(t *testing.T) {
|
||||
t.Fatalf("missing index")
|
||||
}
|
||||
|
||||
// Check the job is gone
|
||||
getReq := structs.JobSpecificRequest{
|
||||
// Check the job is still queryable
|
||||
getReq1 := structs.JobSpecificRequest{
|
||||
JobID: job.ID,
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
var getResp structs.SingleJobResponse
|
||||
if err := s.Agent.RPC("Job.GetJob", &getReq, &getResp); err != nil {
|
||||
var getResp1 structs.SingleJobResponse
|
||||
if err := s.Agent.RPC("Job.GetJob", &getReq1, &getResp1); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if getResp.Job != nil {
|
||||
if getResp1.Job == nil {
|
||||
t.Fatalf("job doesn't exists")
|
||||
}
|
||||
if !getResp1.Job.Stop {
|
||||
t.Fatalf("job should be marked as stop")
|
||||
}
|
||||
|
||||
// Make the HTTP request to do a purge delete
|
||||
req2, err := http.NewRequest("DELETE", "/v1/job/"+job.ID+"?purge=true", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
respW.Flush()
|
||||
|
||||
// Make the request
|
||||
obj, err = s.Server.JobSpecificRequest(respW, req2)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Check the response
|
||||
dereg = obj.(structs.JobDeregisterResponse)
|
||||
if dereg.EvalID == "" {
|
||||
t.Fatalf("bad: %v", dereg)
|
||||
}
|
||||
|
||||
// Check for the index
|
||||
if respW.HeaderMap.Get("X-Nomad-Index") == "" {
|
||||
t.Fatalf("missing index")
|
||||
}
|
||||
|
||||
// Check the job is gone
|
||||
getReq2 := structs.JobSpecificRequest{
|
||||
JobID: job.ID,
|
||||
QueryOptions: structs.QueryOptions{Region: "global"},
|
||||
}
|
||||
var getResp2 structs.SingleJobResponse
|
||||
if err := s.Agent.RPC("Job.GetJob", &getReq2, &getResp2); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if getResp2.Job != nil {
|
||||
t.Fatalf("job still exists")
|
||||
}
|
||||
})
|
||||
@@ -751,6 +791,7 @@ func TestHTTP_JobDispatch(t *testing.T) {
|
||||
|
||||
func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
apiJob := &api.Job{
|
||||
Stop: helper.BoolToPtr(true),
|
||||
Region: helper.StringToPtr("global"),
|
||||
ID: helper.StringToPtr("foo"),
|
||||
ParentID: helper.StringToPtr("lol"),
|
||||
@@ -922,12 +963,14 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
VaultToken: helper.StringToPtr("token"),
|
||||
Status: helper.StringToPtr("status"),
|
||||
StatusDescription: helper.StringToPtr("status_desc"),
|
||||
Version: helper.Uint64ToPtr(10),
|
||||
CreateIndex: helper.Uint64ToPtr(1),
|
||||
ModifyIndex: helper.Uint64ToPtr(3),
|
||||
JobModifyIndex: helper.Uint64ToPtr(5),
|
||||
}
|
||||
|
||||
expected := &structs.Job{
|
||||
Stop: true,
|
||||
Region: "global",
|
||||
ID: "foo",
|
||||
ParentID: "lol",
|
||||
@@ -1094,12 +1137,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
VaultToken: "token",
|
||||
Status: "status",
|
||||
StatusDescription: "status_desc",
|
||||
CreateIndex: 1,
|
||||
ModifyIndex: 3,
|
||||
JobModifyIndex: 5,
|
||||
VaultToken: "token",
|
||||
}
|
||||
|
||||
structsJob := ApiJobToStructJob(apiJob)
|
||||
|
||||
Reference in New Issue
Block a user