Skip to content

Commit

Permalink
Show submit time
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Jul 7, 2017
1 parent 1c425de commit 3935656
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 33 deletions.
5 changes: 5 additions & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ type Job struct {
StatusDescription *string
Stable *bool
Version *uint64
SubmitTime *int64
CreateIndex *uint64
ModifyIndex *uint64
JobModifyIndex *uint64
Expand Down Expand Up @@ -513,6 +514,9 @@ func (j *Job) Canonicalize() {
if j.Version == nil {
j.Version = helper.Uint64ToPtr(0)
}
if j.SubmitTime == nil {
j.SubmitTime = helper.Int64ToPtr(0)
}
if j.CreateIndex == nil {
j.CreateIndex = helper.Uint64ToPtr(0)
}
Expand Down Expand Up @@ -588,6 +592,7 @@ type JobListStub struct {
CreateIndex uint64
ModifyIndex uint64
JobModifyIndex uint64
SubmitTime int64
}

// JobIDSort is used to sort jobs by their job ID's.
Expand Down
11 changes: 1 addition & 10 deletions command/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,7 @@ func (c *InspectCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
out := make([]string, len(jobs)+1)
out[0] = "ID|Type|Priority|Status"
for i, job := range jobs {
out[i+1] = fmt.Sprintf("%s|%s|%d|%s",
job.ID,
job.Type,
job.Priority,
job.Status)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", formatList(out)))
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
}

Expand Down
13 changes: 3 additions & 10 deletions command/job_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/dadgar/columnize"
"github.com/hashicorp/nomad/api"
Expand Down Expand Up @@ -86,16 +87,7 @@ func (c *JobHistoryCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
out := make([]string, len(jobs)+1)
out[0] = "ID|Type|Priority|Status"
for i, job := range jobs {
out[i+1] = fmt.Sprintf("%s|%s|%d|%s",
job.ID,
job.Type,
job.Priority,
job.Status)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", formatList(out)))
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
}

Expand Down Expand Up @@ -193,6 +185,7 @@ func (c *JobHistoryCommand) formatJobVersion(job *api.Job, diff *api.JobDiff, ne
basic := []string{
fmt.Sprintf("Version|%d", *job.Version),
fmt.Sprintf("Stable|%v", *job.Stable),
fmt.Sprintf("Submit Date|%v", formatTime(time.Unix(0, *job.SubmitTime))),
}

if diff != nil {
Expand Down
8 changes: 5 additions & 3 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (c *StatusCommand) Run(args []string) int {
basic := []string{
fmt.Sprintf("ID|%s", *job.ID),
fmt.Sprintf("Name|%s", *job.Name),
fmt.Sprintf("Submit Date|%s", formatTime(time.Unix(0, *job.SubmitTime))),
fmt.Sprintf("Type|%s", *job.Type),
fmt.Sprintf("Priority|%d", *job.Priority),
fmt.Sprintf("Datacenters|%s", strings.Join(job.Datacenters, ",")),
Expand Down Expand Up @@ -446,13 +447,14 @@ func (c *StatusCommand) outputFailedPlacements(failedEval *api.Evaluation) {
// list general information about a list of jobs
func createStatusListOutput(jobs []*api.JobListStub) string {
out := make([]string, len(jobs)+1)
out[0] = "ID|Type|Priority|Status"
out[0] = "ID|Type|Priority|Status|Submit Date"
for i, job := range jobs {
out[i+1] = fmt.Sprintf("%s|%s|%d|%s",
out[i+1] = fmt.Sprintf("%s|%s|%d|%s|%s",
job.ID,
getTypeString(job),
job.Priority,
getStatusString(job.Status, job.Stop))
getStatusString(job.Status, job.Stop),
formatTime(time.Unix(0, job.SubmitTime)))
}
return formatList(out)
}
Expand Down
11 changes: 1 addition & 10 deletions command/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,7 @@ func (c *StopCommand) Run(args []string) int {
return 1
}
if len(jobs) > 1 && strings.TrimSpace(jobID) != jobs[0].ID {
out := make([]string, len(jobs)+1)
out[0] = "ID|Type|Priority|Status"
for i, job := range jobs {
out[i+1] = fmt.Sprintf("%s|%s|%d|%s",
job.ID,
job.Type,
job.Priority,
job.Status)
}
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", formatList(out)))
c.Ui.Output(fmt.Sprintf("Prefix matched multiple jobs\n\n%s", createStatusListOutput(jobs)))
return 0
}
// Prefix lookup matched a single job
Expand Down
5 changes: 5 additions & 0 deletions helper/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func IntToPtr(i int) *int {
return &i
}

// Int64ToPtr returns the pointer to an int
func Int64ToPtr(i int64) *int64 {
return &i
}

// UintToPtr returns the pointer to an uint
func Uint64ToPtr(u uint64) *uint64 {
return &u
Expand Down
1 change: 1 addition & 0 deletions nomad/deployment_watcher_shims.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (d *deploymentWatcherRaftShim) UpsertEvals(evals []*structs.Evaluation) (ui
}

func (d *deploymentWatcherRaftShim) UpsertJob(job *structs.Job) (uint64, error) {
job.SetSubmitTime()
update := &structs.JobRegisterRequest{
Job: job,
}
Expand Down
4 changes: 4 additions & 0 deletions nomad/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func (j *Job) Register(args *structs.JobRegisterRequest, reply *structs.JobRegis

// Check if the job has changed at all
if existingJob == nil || existingJob.SpecChanged(args.Job) {
// Set the submit time
args.Job.SetSubmitTime()

// Commit this update via Raft
_, index, err := j.srv.raftApply(structs.JobRegisterRequestType, args)
if err != nil {
Expand Down Expand Up @@ -1070,6 +1073,7 @@ func (j *Job) Dispatch(args *structs.JobDispatchRequest, reply *structs.JobDispa
dispatchJob.ID = structs.DispatchedID(parameterizedJob.ID, time.Now())
dispatchJob.ParentID = parameterizedJob.ID
dispatchJob.Name = dispatchJob.ID
dispatchJob.SetSubmitTime()

// Merge in the meta data
for k, v := range args.Meta {
Expand Down
1 change: 1 addition & 0 deletions nomad/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type JobEvalDispatcher interface {
// evaluation and the job to the raft log. It returns the eval.
func (s *Server) DispatchJob(job *structs.Job) (*structs.Evaluation, error) {
// Commit this update via Raft
job.SetSubmitTime()
req := structs.JobRegisterRequest{Job: job}
_, index, err := s.raftApply(structs.JobRegisterRequestType, req)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,10 @@ type Job struct {
// on each job register.
Version uint64

// SubmitTime is the time at which the job was submitted as a UnixNano in
// UTC
SubmitTime int64

// Raft Indexes
CreateIndex uint64
ModifyIndex uint64
Expand Down Expand Up @@ -1679,6 +1683,7 @@ func (j *Job) Stub(summary *JobSummary) *JobListStub {
CreateIndex: j.CreateIndex,
ModifyIndex: j.ModifyIndex,
JobModifyIndex: j.JobModifyIndex,
SubmitTime: j.SubmitTime,
JobSummary: summary,
}
}
Expand Down Expand Up @@ -1783,11 +1788,16 @@ func (j *Job) SpecChanged(new *Job) bool {
c.CreateIndex = j.CreateIndex
c.ModifyIndex = j.ModifyIndex
c.JobModifyIndex = j.JobModifyIndex
c.SubmitTime = j.SubmitTime

// Deep equals the jobs
return !reflect.DeepEqual(j, c)
}

func (j *Job) SetSubmitTime() {
j.SubmitTime = time.Now().UTC().UnixNano()
}

// JobListStub is used to return a subset of job information
// for the job list
type JobListStub struct {
Expand All @@ -1805,6 +1815,7 @@ type JobListStub struct {
CreateIndex uint64
ModifyIndex uint64
JobModifyIndex uint64
SubmitTime int64
}

// JobSummary summarizes the state of the allocations of a job
Expand Down

0 comments on commit 3935656

Please sign in to comment.