Commit ce604b8b authored by Michael Schurter's avatar Michael Schurter
Browse files

rkt: standardize names/code

parent 4d707b5e
No related merge requests found
Showing with 31 additions and 32 deletions
+31 -32
......@@ -237,9 +237,9 @@ func (d *Driver) Capabilities() (*drivers.Capabilities, error) {
return capabilities, nil
}
func (r *Driver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, error) {
func (d *Driver) Fingerprint(ctx context.Context) (<-chan *drivers.Fingerprint, error) {
ch := make(chan *drivers.Fingerprint)
go r.handleFingerprint(ctx, ch)
go d.handleFingerprint(ctx, ch)
return ch, nil
}
......@@ -346,7 +346,7 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
filter := strings.Split(config.DefaultEnvBlacklist, ",")
rktEnv := eb.SetHostEnvvars(filter).Build()
h := &rktTaskHandle{
h := &taskHandle{
exec: execImpl,
env: rktEnv,
pid: taskState.Pid,
......@@ -653,7 +653,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
}
d.logger.Debug("started taskConfig", "aci", img, "uuid", uuid, "task_name", cfg.Name, "args", runArgs)
h := &rktTaskHandle{
h := &taskHandle{
exec: execImpl,
env: rktEnv,
pid: ps.Pid,
......@@ -764,22 +764,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
return nil, drivers.ErrTaskNotFound
}
handle.stateLock.RLock()
defer handle.stateLock.RUnlock()
status := &drivers.TaskStatus{
ID: handle.taskConfig.ID,
Name: handle.taskConfig.Name,
State: handle.procState,
StartedAt: handle.startedAt,
CompletedAt: handle.completedAt,
ExitResult: handle.exitResult,
DriverAttributes: map[string]string{
"pid": strconv.Itoa(handle.pid),
},
}
return status, nil
return handle.TaskStatus(), nil
}
func (d *Driver) TaskStats(taskID string) (*cstructs.TaskResourceUsage, error) {
......@@ -996,7 +981,7 @@ func elide(inBuf bytes.Buffer) string {
return tempBuf.String()
}
func (d *Driver) handleWait(ctx context.Context, handle *rktTaskHandle, ch chan *drivers.ExitResult) {
func (d *Driver) handleWait(ctx context.Context, handle *taskHandle, ch chan *drivers.ExitResult) {
defer close(ch)
var result *drivers.ExitResult
ps, err := handle.exec.Wait()
......
......@@ -3,6 +3,7 @@
package rkt
import (
"strconv"
"sync"
"time"
......@@ -13,7 +14,7 @@ import (
"github.com/hashicorp/nomad/plugins/drivers"
)
type rktTaskHandle struct {
type taskHandle struct {
exec executor.Executor
env *env.TaskEnv
uuid string
......@@ -31,17 +32,30 @@ type rktTaskHandle struct {
exitResult *drivers.ExitResult
}
func (h *rktTaskHandle) IsRunning() bool {
func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
h.stateLock.RLock()
defer h.stateLock.RUnlock()
return h.procState == drivers.TaskStateRunning
return &drivers.TaskStatus{
ID: h.taskConfig.ID,
Name: h.taskConfig.Name,
State: h.procState,
StartedAt: h.startedAt,
CompletedAt: h.completedAt,
ExitResult: h.exitResult,
DriverAttributes: map[string]string{
"pid": strconv.Itoa(h.pid),
},
}
}
func (h *rktTaskHandle) run() {
func (h *taskHandle) IsRunning() bool {
h.stateLock.RLock()
defer h.stateLock.RUnlock()
return h.procState == drivers.TaskStateRunning
}
// Since run is called immediately after the handle is created this
// ensures the exitResult is initialized so we avoid a nil pointer
// thus it does not need to be included in the lock
func (h *taskHandle) run() {
h.stateLock.Lock()
if h.exitResult == nil {
h.exitResult = &drivers.ExitResult{}
......
......@@ -7,21 +7,21 @@ import (
)
type taskStore struct {
store map[string]*rktTaskHandle
store map[string]*taskHandle
lock sync.RWMutex
}
func newTaskStore() *taskStore {
return &taskStore{store: map[string]*rktTaskHandle{}}
return &taskStore{store: map[string]*taskHandle{}}
}
func (ts *taskStore) Set(id string, handle *rktTaskHandle) {
func (ts *taskStore) Set(id string, handle *taskHandle) {
ts.lock.Lock()
defer ts.lock.Unlock()
ts.store[id] = handle
}
func (ts *taskStore) Get(id string) (*rktTaskHandle, bool) {
func (ts *taskStore) Get(id string) (*taskHandle, bool) {
ts.lock.RLock()
defer ts.lock.RUnlock()
t, ok := ts.store[id]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment