2015-09-09 20:02:39 +00:00
|
|
|
package api
|
|
|
|
|
2015-10-30 23:32:05 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2016-05-27 22:24:22 +00:00
|
|
|
// MemoryStats holds memory usage related stats
|
2016-04-29 20:03:02 +00:00
|
|
|
type MemoryStats struct {
|
|
|
|
RSS uint64
|
|
|
|
Cache uint64
|
|
|
|
Swap uint64
|
|
|
|
MaxUsage uint64
|
|
|
|
KernelUsage uint64
|
|
|
|
KernelMaxUsage uint64
|
2016-06-10 02:45:41 +00:00
|
|
|
Measured []string
|
2016-04-29 20:03:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 22:24:22 +00:00
|
|
|
// CpuStats holds cpu usage related stats
|
2016-05-21 07:49:17 +00:00
|
|
|
type CpuStats struct {
|
2016-05-19 21:06:19 +00:00
|
|
|
SystemMode float64
|
|
|
|
UserMode float64
|
2016-06-10 21:32:45 +00:00
|
|
|
TotalTicks float64
|
2016-04-29 20:03:02 +00:00
|
|
|
ThrottledPeriods uint64
|
|
|
|
ThrottledTime uint64
|
2016-05-19 21:06:19 +00:00
|
|
|
Percent float64
|
2016-06-10 02:45:41 +00:00
|
|
|
Measured []string
|
2016-04-29 20:03:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 22:24:22 +00:00
|
|
|
// ResourceUsage holds information related to cpu and memory stats
|
2016-05-21 09:05:08 +00:00
|
|
|
type ResourceUsage struct {
|
2016-04-29 20:03:02 +00:00
|
|
|
MemoryStats *MemoryStats
|
2016-05-21 07:49:17 +00:00
|
|
|
CpuStats *CpuStats
|
2016-05-21 09:05:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 22:24:22 +00:00
|
|
|
// TaskResourceUsage holds aggregated resource usage of all processes in a Task
|
|
|
|
// and the resource usage of the individual pids
|
2016-05-21 09:05:08 +00:00
|
|
|
type TaskResourceUsage struct {
|
|
|
|
ResourceUsage *ResourceUsage
|
2016-05-27 22:24:22 +00:00
|
|
|
Timestamp int64
|
2016-05-21 09:05:08 +00:00
|
|
|
Pids map[string]*ResourceUsage
|
2016-04-29 20:03:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 03:15:50 +00:00
|
|
|
// AllocResourceUsage holds the aggregated task resource usage of the
|
|
|
|
// allocation.
|
|
|
|
type AllocResourceUsage struct {
|
|
|
|
ResourceUsage *ResourceUsage
|
|
|
|
Tasks map[string]*TaskResourceUsage
|
|
|
|
Timestamp int64
|
|
|
|
}
|
|
|
|
|
2015-11-02 21:24:59 +00:00
|
|
|
// RestartPolicy defines how the Nomad client restarts
|
|
|
|
// tasks in a taskgroup when they fail
|
2015-10-30 23:32:05 +00:00
|
|
|
type RestartPolicy struct {
|
2016-02-02 23:08:07 +00:00
|
|
|
Interval time.Duration
|
|
|
|
Attempts int
|
|
|
|
Delay time.Duration
|
|
|
|
Mode string
|
2015-10-31 04:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 07:20:35 +00:00
|
|
|
// The ServiceCheck data model represents the consul health check that
|
|
|
|
// Nomad registers for a Task
|
|
|
|
type ServiceCheck struct {
|
2016-08-23 20:49:37 +00:00
|
|
|
Id string
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Command string
|
|
|
|
Args []string
|
|
|
|
Path string
|
|
|
|
Protocol string `mapstructure:"port"`
|
|
|
|
PortLabel string `mapstructure:"port"`
|
|
|
|
Interval time.Duration
|
|
|
|
Timeout time.Duration
|
|
|
|
InitialStatus string `mapstructure:"initial_status"`
|
2015-11-17 07:20:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-15 16:41:34 +00:00
|
|
|
// The Service model represents a Consul service definition
|
2015-11-17 07:20:35 +00:00
|
|
|
type Service struct {
|
|
|
|
Id string
|
|
|
|
Name string
|
|
|
|
Tags []string
|
|
|
|
PortLabel string `mapstructure:"port"`
|
|
|
|
Checks []ServiceCheck
|
|
|
|
}
|
|
|
|
|
2016-09-14 22:43:42 +00:00
|
|
|
// EphemeralDisk is an ephemeral disk object
|
|
|
|
type EphemeralDisk struct {
|
2016-10-03 16:59:57 +00:00
|
|
|
Sticky bool
|
|
|
|
Migrate bool
|
|
|
|
SizeMB int `mapstructure:"size"`
|
2016-08-24 18:51:15 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
// TaskGroup is the unit of scheduling.
|
|
|
|
type TaskGroup struct {
|
2015-10-30 23:32:05 +00:00
|
|
|
Name string
|
|
|
|
Count int
|
|
|
|
Constraints []*Constraint
|
|
|
|
Tasks []*Task
|
|
|
|
RestartPolicy *RestartPolicy
|
2016-09-14 22:43:42 +00:00
|
|
|
EphemeralDisk *EphemeralDisk
|
2015-10-30 23:32:05 +00:00
|
|
|
Meta map[string]string
|
2015-09-09 20:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTaskGroup creates a new TaskGroup.
|
2015-09-10 00:59:18 +00:00
|
|
|
func NewTaskGroup(name string, count int) *TaskGroup {
|
2015-09-09 20:02:39 +00:00
|
|
|
return &TaskGroup{
|
2015-12-18 20:17:13 +00:00
|
|
|
Name: name,
|
|
|
|
Count: count,
|
2015-09-09 20:02:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constrain is used to add a constraint to a task group.
|
|
|
|
func (g *TaskGroup) Constrain(c *Constraint) *TaskGroup {
|
|
|
|
g.Constraints = append(g.Constraints, c)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddMeta is used to add a meta k/v pair to a task group
|
|
|
|
func (g *TaskGroup) SetMeta(key, val string) *TaskGroup {
|
|
|
|
if g.Meta == nil {
|
|
|
|
g.Meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
g.Meta[key] = val
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddTask is used to add a new task to a task group.
|
|
|
|
func (g *TaskGroup) AddTask(t *Task) *TaskGroup {
|
|
|
|
g.Tasks = append(g.Tasks, t)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
2016-09-14 22:43:42 +00:00
|
|
|
// RequireDisk adds a ephemeral disk to the task group
|
|
|
|
func (g *TaskGroup) RequireDisk(disk *EphemeralDisk) *TaskGroup {
|
|
|
|
g.EphemeralDisk = disk
|
2016-08-26 03:10:25 +00:00
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
2016-02-05 07:54:15 +00:00
|
|
|
// LogConfig provides configuration for log rotation
|
|
|
|
type LogConfig struct {
|
2016-02-11 00:40:36 +00:00
|
|
|
MaxFiles int
|
|
|
|
MaxFileSizeMB int
|
2016-02-05 07:54:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 22:56:50 +00:00
|
|
|
// DispatchInputConfig configures how a task gets its input from a job dispatch
|
|
|
|
type DispatchInputConfig struct {
|
2016-12-14 20:50:08 +00:00
|
|
|
File string
|
2016-11-23 22:56:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
// Task is a single process in a task group.
|
|
|
|
type Task struct {
|
2016-11-23 22:56:50 +00:00
|
|
|
Name string
|
|
|
|
Driver string
|
|
|
|
User string
|
|
|
|
Config map[string]interface{}
|
|
|
|
Constraints []*Constraint
|
|
|
|
Env map[string]string
|
|
|
|
Services []Service
|
|
|
|
Resources *Resources
|
|
|
|
Meta map[string]string
|
|
|
|
KillTimeout time.Duration
|
|
|
|
LogConfig *LogConfig
|
|
|
|
Artifacts []*TaskArtifact
|
|
|
|
Vault *Vault
|
|
|
|
Templates []*Template
|
|
|
|
DispatchInput *DispatchInputConfig
|
2016-03-14 22:46:06 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 03:21:52 +00:00
|
|
|
// TaskArtifact is used to download artifacts before running a task.
|
2016-03-14 22:46:06 +00:00
|
|
|
type TaskArtifact struct {
|
|
|
|
GetterSource string
|
|
|
|
GetterOptions map[string]string
|
2016-03-18 19:01:46 +00:00
|
|
|
RelativeDest string
|
2015-09-09 20:02:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 22:39:52 +00:00
|
|
|
type Template struct {
|
2016-10-05 20:41:29 +00:00
|
|
|
SourcePath string
|
|
|
|
DestPath string
|
|
|
|
EmbeddedTmpl string
|
|
|
|
ChangeMode string
|
|
|
|
ChangeSignal string
|
|
|
|
Splay time.Duration
|
2016-09-23 22:39:52 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 04:32:25 +00:00
|
|
|
type Vault struct {
|
2016-10-17 18:41:22 +00:00
|
|
|
Policies []string
|
|
|
|
Env bool
|
|
|
|
ChangeMode string
|
|
|
|
ChangeSignal string
|
2016-08-17 04:32:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 20:02:39 +00:00
|
|
|
// NewTask creates and initializes a new Task.
|
|
|
|
func NewTask(name, driver string) *Task {
|
|
|
|
return &Task{
|
|
|
|
Name: name,
|
|
|
|
Driver: driver,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure is used to configure a single k/v pair on
|
|
|
|
// the task.
|
2016-08-22 16:35:25 +00:00
|
|
|
func (t *Task) SetConfig(key string, val interface{}) *Task {
|
2015-09-09 20:02:39 +00:00
|
|
|
if t.Config == nil {
|
2015-11-14 04:51:30 +00:00
|
|
|
t.Config = make(map[string]interface{})
|
2015-09-09 20:02:39 +00:00
|
|
|
}
|
|
|
|
t.Config[key] = val
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMeta is used to add metadata k/v pairs to the task.
|
|
|
|
func (t *Task) SetMeta(key, val string) *Task {
|
|
|
|
if t.Meta == nil {
|
|
|
|
t.Meta = make(map[string]string)
|
|
|
|
}
|
|
|
|
t.Meta[key] = val
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
// Require is used to add resource requirements to a task.
|
|
|
|
func (t *Task) Require(r *Resources) *Task {
|
|
|
|
t.Resources = r
|
|
|
|
return t
|
|
|
|
}
|
2015-09-10 00:29:43 +00:00
|
|
|
|
|
|
|
// Constraint adds a new constraints to a single task.
|
|
|
|
func (t *Task) Constrain(c *Constraint) *Task {
|
|
|
|
t.Constraints = append(t.Constraints, c)
|
|
|
|
return t
|
|
|
|
}
|
2015-11-12 23:28:22 +00:00
|
|
|
|
2016-02-10 21:36:47 +00:00
|
|
|
// SetLogConfig sets a log config to a task
|
|
|
|
func (t *Task) SetLogConfig(l *LogConfig) *Task {
|
|
|
|
t.LogConfig = l
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2015-11-12 23:28:22 +00:00
|
|
|
// TaskState tracks the current state of a task and events that caused state
|
2016-05-15 16:41:34 +00:00
|
|
|
// transitions.
|
2015-11-12 23:28:22 +00:00
|
|
|
type TaskState struct {
|
|
|
|
State string
|
2016-10-21 00:27:16 +00:00
|
|
|
Failed bool
|
2015-11-12 23:28:22 +00:00
|
|
|
Events []*TaskEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2016-10-10 21:49:37 +00:00
|
|
|
TaskSetupFailure = "Setup Failure"
|
2016-03-15 17:53:20 +00:00
|
|
|
TaskDriverFailure = "Driver Failure"
|
2016-12-20 19:51:09 +00:00
|
|
|
TaskDriverMessage = "Driver"
|
2016-03-15 17:53:20 +00:00
|
|
|
TaskReceived = "Received"
|
2016-03-24 17:55:14 +00:00
|
|
|
TaskFailedValidation = "Failed Validation"
|
2016-03-15 17:53:20 +00:00
|
|
|
TaskStarted = "Started"
|
|
|
|
TaskTerminated = "Terminated"
|
2016-07-21 22:49:54 +00:00
|
|
|
TaskKilling = "Killing"
|
2016-03-15 17:53:20 +00:00
|
|
|
TaskKilled = "Killed"
|
|
|
|
TaskRestarting = "Restarting"
|
2016-03-24 22:43:55 +00:00
|
|
|
TaskNotRestarting = "Not Restarting"
|
2016-03-15 17:53:20 +00:00
|
|
|
TaskDownloadingArtifacts = "Downloading Artifacts"
|
|
|
|
TaskArtifactDownloadFailed = "Failed Artifact Download"
|
2016-09-15 01:27:13 +00:00
|
|
|
TaskVaultRenewalFailed = "Vault token renewal failed"
|
|
|
|
TaskSiblingFailed = "Sibling task failed"
|
2016-10-05 20:41:29 +00:00
|
|
|
TaskSignaling = "Signaling"
|
2016-10-05 22:11:09 +00:00
|
|
|
TaskRestartSignal = "Restart Signaled"
|
2015-11-12 23:28:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TaskEvent is an event that effects the state of a task and contains meta-data
|
|
|
|
// appropriate to the events type.
|
|
|
|
type TaskEvent struct {
|
2016-12-20 19:51:09 +00:00
|
|
|
Type string
|
|
|
|
Time int64
|
|
|
|
FailsTask bool
|
|
|
|
RestartReason string
|
|
|
|
SetupError string
|
|
|
|
DriverError string
|
|
|
|
DriverMessage string
|
|
|
|
ExitCode int
|
|
|
|
Signal int
|
|
|
|
Message string
|
|
|
|
KillReason string
|
|
|
|
KillTimeout time.Duration
|
|
|
|
KillError string
|
|
|
|
StartDelay int64
|
|
|
|
DownloadError string
|
|
|
|
ValidationError string
|
|
|
|
DiskLimit int64
|
|
|
|
DiskSize int64
|
|
|
|
FailedSibling string
|
|
|
|
VaultError string
|
|
|
|
TaskSignalReason string
|
|
|
|
TaskSignal string
|
2015-11-12 23:28:22 +00:00
|
|
|
}
|