From c80bdd9f5feefd8a011ac5cf43bd60beefe4bf21 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 | 2 ++ nomad/structs/structs.go | 13 +++++++++++++ 4 files changed, 18 insertions(+) diff --git a/api/tasks.go b/api/tasks.go index ff267dbe5..35d0fe973 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -409,6 +409,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 e6501429d..399a602d2 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -422,6 +422,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 27b7cd0c4..b2c98404e 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: diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 94eb20cad..4b46fdf5a 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2853,6 +2853,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" @@ -2935,6 +2942,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