mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
client: standardize naming
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user