mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
http/job: adding job query endpoint
This commit is contained in:
@@ -83,7 +83,23 @@ func (s *HTTPServer) jobCRUD(resp http.ResponseWriter, req *http.Request,
|
||||
|
||||
func (s *HTTPServer) jobQuery(resp http.ResponseWriter, req *http.Request,
|
||||
jobName string) (interface{}, error) {
|
||||
return nil, nil
|
||||
args := structs.JobSpecificRequest{
|
||||
JobID: jobName,
|
||||
}
|
||||
if s.parse(resp, req, &args.Region, &args.QueryOptions) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var out structs.SingleJobResponse
|
||||
if err := s.agent.RPC("Job.GetJob", &args, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
setMeta(resp, &out.QueryMeta)
|
||||
if out.Job == nil {
|
||||
return nil, CodedError(404, "job not found")
|
||||
}
|
||||
return out.Job, nil
|
||||
}
|
||||
|
||||
func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request,
|
||||
@@ -102,5 +118,6 @@ func (s *HTTPServer) jobDelete(resp http.ResponseWriter, req *http.Request,
|
||||
if err := s.agent.RPC("Job.Deregister", &args, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
setIndex(resp, out.Index)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,51 @@ import (
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
func TestHTTP_JobQuery(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Create the job
|
||||
job := mock.Job()
|
||||
args := structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
WriteRequest: structs.WriteRequest{Region: "region1"},
|
||||
}
|
||||
var resp structs.JobRegisterResponse
|
||||
if err := s.Agent.RPC("Job.Register", &args, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Make the HTTP request
|
||||
req, err := http.NewRequest("GET", "/v1/job/"+job.ID, nil)
|
||||
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 for the index
|
||||
if respW.HeaderMap.Get("X-Nomad-Index") == "" {
|
||||
t.Fatalf("missing index")
|
||||
}
|
||||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" {
|
||||
t.Fatalf("missing known leader")
|
||||
}
|
||||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" {
|
||||
t.Fatalf("missing last contact")
|
||||
}
|
||||
|
||||
// Check the job
|
||||
j := obj.(*structs.Job)
|
||||
if j.ID != job.ID {
|
||||
t.Fatalf("bad: %#v", j)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_JobDelete(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
// Create the job
|
||||
@@ -41,6 +86,11 @@ func TestHTTP_JobDelete(t *testing.T) {
|
||||
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
|
||||
getReq := structs.JobSpecificRequest{
|
||||
JobID: job.ID,
|
||||
|
||||
Reference in New Issue
Block a user