From dc0d244dd82f03fc3d90ecbd30a38453af165144 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 2 Nov 2018 08:29:39 -0400 Subject: [PATCH] Reconcile with latest master patterns --- drivers/java/driver.go | 24 +++--------------------- drivers/java/handle.go | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/drivers/java/driver.go b/drivers/java/driver.go index 6860fd716..f94a55c67 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -9,8 +9,6 @@ import ( "syscall" "time" - "strconv" - "github.com/hashicorp/consul-template/signals" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-plugin" @@ -134,8 +132,7 @@ type Driver struct { // ctx passed to any subsystems signalShutdown context.CancelFunc - // logger will log to the plugin output which is usually an 'executor.out' - // file located in the root of the TaskDir + // logger will log to the Nomad agent logger hclog.Logger } @@ -206,7 +203,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint { // Only enable if w are root and cgroups are mounted when running on linux system if syscall.Geteuid() != 0 { fp.Health = drivers.HealthStateUnhealthy - fp.HealthDescription = "java driver must run as root" + fp.HealthDescription = "run as root" return fp } @@ -485,22 +482,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) { diff --git a/drivers/java/handle.go b/drivers/java/handle.go index fa991d00d..979c8f1c4 100644 --- a/drivers/java/handle.go +++ b/drivers/java/handle.go @@ -1,6 +1,7 @@ package java import ( + "strconv" "sync" "time" @@ -27,15 +28,30 @@ type taskHandle struct { exitResult *drivers.ExitResult } -func (h *taskHandle) IsRunning() bool { +func (h *taskHandle) TaskStatus() *drivers.TaskStatus { h.stateLock.RLock() defer h.stateLock.RUnlock() + 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 *taskHandle) IsRunning() bool { + h.stateLock.RLock() + defer h.stateLock.RUnlock() return h.procState == drivers.TaskStateRunning } func (h *taskHandle) run() { - h.stateLock.Lock() if h.exitResult == nil { h.exitResult = &drivers.ExitResult{} @@ -43,6 +59,7 @@ func (h *taskHandle) run() { h.stateLock.Unlock() ps, err := h.exec.Wait() + h.stateLock.Lock() defer h.stateLock.Unlock()