From fb8f922f2e65417d5ee1f216c3b04610156449ab Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Thu, 5 Nov 2015 18:31:39 -0800 Subject: [PATCH] Passing in the AllocID to exec context so that it can be used in the drivers --- client/alloc_runner.go | 2 +- client/driver/driver.go | 7 +++++-- client/driver/driver_test.go | 2 +- client/task_runner_test.go | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index c434ef65f51..1504900c115 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -295,7 +295,7 @@ func (r *AllocRunner) Run() { r.setStatus(structs.AllocClientStatusFailed, fmt.Sprintf("failed to build task dirs for '%s'", alloc.TaskGroup)) return } - r.ctx = driver.NewExecContext(allocDir) + r.ctx = driver.NewExecContext(allocDir, r.alloc.ID) } // Start the task runners diff --git a/client/driver/driver.go b/client/driver/driver.go index dd4fcf43c97..e2739e2b8a2 100644 --- a/client/driver/driver.go +++ b/client/driver/driver.go @@ -100,11 +100,14 @@ type ExecContext struct { // AllocDir contains information about the alloc directory structure. AllocDir *allocdir.AllocDir + + // Alloc ID + AllocID string } // NewExecContext is used to create a new execution context -func NewExecContext(alloc *allocdir.AllocDir) *ExecContext { - return &ExecContext{AllocDir: alloc} +func NewExecContext(alloc *allocdir.AllocDir, allocID string) *ExecContext { + return &ExecContext{AllocDir: alloc, AllocID: allocID} } // TaskEnvironmentVariables converts exec context and task configuration into a diff --git a/client/driver/driver_test.go b/client/driver/driver_test.go index a6f62145519..106eeb96b03 100644 --- a/client/driver/driver_test.go +++ b/client/driver/driver_test.go @@ -43,7 +43,7 @@ func testDriverContext(task string) *DriverContext { func testDriverExecContext(task *structs.Task, driverCtx *DriverContext) *ExecContext { allocDir := allocdir.NewAllocDir(filepath.Join(driverCtx.config.AllocDir, structs.GenerateUUID())) allocDir.Build([]*structs.Task{task}) - ctx := NewExecContext(allocDir) + ctx := NewExecContext(allocDir, "dummyAllocId") return ctx } diff --git a/client/task_runner_test.go b/client/task_runner_test.go index 7a7242e7b14..17709316ff5 100644 --- a/client/task_runner_test.go +++ b/client/task_runner_test.go @@ -51,7 +51,7 @@ func testTaskRunner() (*MockTaskStateUpdater, *TaskRunner) { allocDir := allocdir.NewAllocDir(filepath.Join(conf.AllocDir, alloc.ID)) allocDir.Build([]*structs.Task{task}) - ctx := driver.NewExecContext(allocDir) + ctx := driver.NewExecContext(allocDir, alloc.ID) rp := structs.NewRestartPolicy(structs.JobTypeService) restartTracker := newRestartTracker(structs.JobTypeService, rp) tr := NewTaskRunner(logger, conf, upd.Update, ctx, alloc.ID, task, restartTracker)