From 5f11b99caa47e8b9fdc2dc158a810c24becbbd88 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Sun, 23 Aug 2015 15:36:06 -0700 Subject: [PATCH] client: standardize naming --- client/alloc_runner.go | 32 ++++++++++++++++---------------- client/driver/driver.go | 12 ++++++++++++ client/task_runner.go | 28 ++++++++++++++-------------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/client/alloc_runner.go b/client/alloc_runner.go index 12b071826..3b4e09873 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -34,21 +34,21 @@ func NewAllocRunner(client *Client, alloc *structs.Allocation) *AllocRunner { } // Alloc returns the associated allocation -func (c *AllocRunner) Alloc() *structs.Allocation { - return c.alloc +func (r *AllocRunner) Alloc() *structs.Allocation { + return r.alloc } // Run is a long running goroutine used to manage an allocation -func (c *AllocRunner) Run() { - c.logger.Printf("[DEBUG] client: starting context for alloc '%s'", c.alloc.ID) +func (r *AllocRunner) Run() { + r.logger.Printf("[DEBUG] client: starting context for alloc '%s'", r.alloc.ID) // TODO: Start for { select { - case update := <-c.updateCh: + case update := <-r.updateCh: // TODO: Update - c.alloc = update - case <-c.destroyCh: + r.alloc = update + case <-r.destroyCh: // TODO: Destroy return } @@ -56,22 +56,22 @@ func (c *AllocRunner) Run() { } // Update is used to update the allocation of the context -func (c *AllocRunner) Update(update *structs.Allocation) { +func (r *AllocRunner) Update(update *structs.Allocation) { select { - case c.updateCh <- update: + case r.updateCh <- update: default: - c.logger.Printf("[ERR] client: dropping update to alloc '%s'", update.ID) + r.logger.Printf("[ERR] client: dropping update to alloc '%s'", update.ID) } } // Destroy is used to indicate that the allocation context should be destroyed -func (c *AllocRunner) Destroy() { - c.destroyLock.Lock() - defer c.destroyLock.Unlock() +func (r *AllocRunner) Destroy() { + r.destroyLock.Lock() + defer r.destroyLock.Unlock() - if c.destroy { + if r.destroy { return } - c.destroy = true - close(c.destroyCh) + r.destroy = true + close(r.destroyCh) } diff --git a/client/driver/driver.go b/client/driver/driver.go index 9eae26607..4131d10fb 100644 --- a/client/driver/driver.go +++ b/client/driver/driver.go @@ -3,6 +3,7 @@ package driver import ( "fmt" "log" + "sync" "github.com/hashicorp/nomad/client/fingerprint" ) @@ -37,3 +38,14 @@ type Driver interface { // Drivers must support the fingerprint interface for detection fingerprint.Fingerprint } + +// ExecContext is shared between drivers within an allocation +type ExecContext struct { + sync.Mutex +} + +// NewExecContext is used to create a new execution context +func NewExecContext() *ExecContext { + ctx := &ExecContext{} + return ctx +} diff --git a/client/task_runner.go b/client/task_runner.go index c7062ef04..e72319c14 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -34,16 +34,16 @@ func NewTaskRunner(ctx *AllocRunner, task *structs.Task) *TaskRunner { } // Run is a long running routine used to manage the task -func (t *TaskRunner) Run() { - t.logger.Printf("[DEBUG] client: starting task context for '%s' (alloc '%s')", t.task.Name, t.ctx.Alloc().ID) +func (r *TaskRunner) Run() { + r.logger.Printf("[DEBUG] client: starting task context for '%s' (alloc '%s')", r.task.Name, r.ctx.Alloc().ID) // TODO: Start for { select { - case update := <-t.updateCh: + case update := <-r.updateCh: // TODO: Update - t.task = update - case <-t.destroyCh: + r.task = update + case <-r.destroyCh: // TODO: Destroy return } @@ -51,22 +51,22 @@ func (t *TaskRunner) Run() { } // Update is used to update the task of the context -func (t *TaskRunner) Update(update *structs.Task) { +func (r *TaskRunner) Update(update *structs.Task) { select { - case t.updateCh <- update: + case r.updateCh <- update: default: - t.logger.Printf("[ERR] client: dropping task update '%s' (alloc '%s')", update.Name, t.ctx.Alloc().ID) + r.logger.Printf("[ERR] client: dropping task update '%s' (alloc '%s')", update.Name, r.ctx.Alloc().ID) } } // Destroy is used to indicate that the task context should be destroyed -func (t *TaskRunner) Destroy() { - t.destroyLock.Lock() - defer t.destroyLock.Unlock() +func (r *TaskRunner) Destroy() { + r.destroyLock.Lock() + defer r.destroyLock.Unlock() - if t.destroy { + if r.destroy { return } - t.destroy = true - close(t.destroyCh) + r.destroy = true + close(r.destroyCh) }