diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 19e2f67ed..591ca9d7e 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -5,6 +5,7 @@ import ( "net/http" "strings" + "github.com/golang/snappy" "github.com/hashicorp/nomad/nomad/structs" ) @@ -57,7 +58,19 @@ func (s *HTTPServer) AllocSpecificRequest(resp http.ResponseWriter, req *http.Re if out.Alloc == nil { return nil, CodedError(404, "alloc not found") } - return out.Alloc, nil + + // Decode the input data if there is any + alloc := out.Alloc + if alloc.Job != nil && len(alloc.Job.InputData) != 0 { + decoded, err := snappy.Decode(nil, alloc.Job.InputData) + if err != nil { + return nil, err + } + alloc = alloc.Copy() + alloc.Job.InputData = decoded + } + + return alloc, nil } func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 460a91c1d..30504436d 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -4,6 +4,7 @@ import ( "net/http" "strings" + "github.com/golang/snappy" "github.com/hashicorp/nomad/nomad/structs" ) @@ -208,7 +209,19 @@ func (s *HTTPServer) jobQuery(resp http.ResponseWriter, req *http.Request, if out.Job == nil { return nil, CodedError(404, "job not found") } - return out.Job, nil + + // Decode the input data if there is any + job := out.Job + if len(job.InputData) != 0 { + decoded, err := snappy.Decode(nil, out.Job.InputData) + if err != nil { + return nil, err + } + job = job.Copy() + job.InputData = decoded + } + + return job, nil } func (s *HTTPServer) jobUpdate(resp http.ResponseWriter, req *http.Request, diff --git a/nomad/job_endpoint.go b/nomad/job_endpoint.go index 5490526ac..53d3d6a87 100644 --- a/nomad/job_endpoint.go +++ b/nomad/job_endpoint.go @@ -316,6 +316,8 @@ func (j *Job) Evaluate(args *structs.JobEvaluateRequest, reply *structs.JobRegis if job.IsPeriodic() { return fmt.Errorf("can't evaluate periodic job") + } else if job.IsDispatchTemplate() { + return fmt.Errorf("can't evaluate dispatch template job") } // Create a new evaluation @@ -807,19 +809,19 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa return err } - // XXX disable job/evaluate on periodic jobs - - // XXX merge in the meta data - // Derive the child job and commit it via Raft dispatchJob := tmpl.Copy() dispatchJob.Dispatch = nil dispatchJob.ID = structs.DispatchedID(tmpl.ID, time.Now()) dispatchJob.Name = dispatchJob.ID + // Merge in the meta data + for k, v := range args.Meta { + dispatchJob.Meta[k] = v + } + // Compress the input - // XXX Decompress on the HTTP endpoint - dispatchJob.InputData = snappy.Encode(dispatchJob.InputData, args.InputData) + dispatchJob.InputData = snappy.Encode(nil, args.InputData) regReq := &structs.JobRegisterRequest{ Job: dispatchJob,