Reconcile with latest master patterns

This commit is contained in:
Mahmood Ali
2018-11-02 08:29:39 -04:00
parent efe9a60556
commit dc0d244dd8
2 changed files with 22 additions and 23 deletions

View File

@@ -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) {

View File

@@ -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()