From 03dd54bc12851aabc094d81d739c6842a839ae1e Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 9 Feb 2017 17:40:13 -0800 Subject: [PATCH] Adding a task event for setup --- api/tasks.go | 1 + client/task_runner.go | 2 ++ command/alloc_status.go | 3 +++ nomad/structs/structs.go | 13 +++++++++++++ 4 files changed, 19 insertions(+) diff --git a/api/tasks.go b/api/tasks.go index b22938e1ea34..019ae006956f 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -243,6 +243,7 @@ type TaskState struct { } const ( + TaskSetup = "Task Setup" TaskSetupFailure = "Setup Failure" TaskDriverFailure = "Driver Failure" TaskDriverMessage = "Driver" diff --git a/client/task_runner.go b/client/task_runner.go index 6f183359cace..1cb261bb2857 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -424,6 +424,8 @@ func (r *TaskRunner) Run() { // Build base task directory structure regardless of FS isolation abilities. // This needs to happen before we start the Vault manager and call prestart // as both those can write to the task directories + r.setState(structs.TaskStatePending, structs.NewTaskEvent(structs.TaskSetup). + SetMessage(structs.TaskBuildingTaskDir)) if err := r.buildTaskDir(drv.FSIsolation()); err != nil { e := fmt.Errorf("failed to build task directory for %q: %v", r.task.Name, err) r.setState( diff --git a/command/alloc_status.go b/command/alloc_status.go index 45cc15b7ccda..9c9216d5db5d 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -280,6 +280,8 @@ func (c *AllocStatusCommand) outputTaskStatus(state *api.TaskState) { // Build up the description based on the event type. var desc string switch event.Type { + case api.TaskSetup: + desc = event.Message case api.TaskStarted: desc = "Task started by client" case api.TaskReceived: @@ -382,6 +384,7 @@ func (c *AllocStatusCommand) outputTaskStatus(state *api.TaskState) { } case api.TaskDriverMessage: desc = event.DriverMessage + } // Reverse order so we are sorted by time diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 3fe27853e2da..599398cab18a 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2769,6 +2769,13 @@ const ( // failed. TaskArtifactDownloadFailed = "Failed Artifact Download" + // TaskBuildingTaskDir indicates that the task direcotry/chroot is being + // built. + TaskBuildingTaskDir = "Building Task Directory" + + // TaskSetup indicates the task runner is setting up the task environment + TaskSetup = "Task Setup" + // TaskDiskExceeded indicates that one of the tasks in a taskgroup has // exceeded the requested disk resources. TaskDiskExceeded = "Disk Resources Exceeded" @@ -2848,6 +2855,12 @@ func (te *TaskEvent) GoString() string { return fmt.Sprintf("%v at %v", te.Type, te.Time) } +// SetMessage sets the message of TaskEvent +func (te *TaskEvent) SetMessage(msg string) *TaskEvent { + te.Message = msg + return te +} + func (te *TaskEvent) Copy() *TaskEvent { if te == nil { return nil