2015-11-14 06:07:13 +00:00
|
|
|
package structs
|
|
|
|
|
2016-02-19 22:01:07 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2016-03-24 07:13:30 +00:00
|
|
|
"time"
|
2016-02-29 00:56:05 +00:00
|
|
|
|
2016-02-19 22:01:07 +00:00
|
|
|
cgroupConfig "github.com/opencontainers/runc/libcontainer/configs"
|
|
|
|
)
|
2015-11-14 06:07:13 +00:00
|
|
|
|
2016-03-17 09:53:31 +00:00
|
|
|
const (
|
2016-03-18 22:04:15 +00:00
|
|
|
// The default user that the executor uses to run tasks
|
2016-03-17 09:53:31 +00:00
|
|
|
DefaultUnpriviledgedUser = "nobody"
|
2016-03-24 07:13:30 +00:00
|
|
|
|
|
|
|
// CheckBufSize is the size of the check output result
|
|
|
|
CheckBufSize = 4 * 1024
|
2016-03-17 09:53:31 +00:00
|
|
|
)
|
|
|
|
|
2015-11-14 06:07:13 +00:00
|
|
|
// WaitResult stores the result of a Wait operation.
|
|
|
|
type WaitResult struct {
|
|
|
|
ExitCode int
|
|
|
|
Signal int
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWaitResult(code, signal int, err error) *WaitResult {
|
|
|
|
return &WaitResult{
|
|
|
|
ExitCode: code,
|
|
|
|
Signal: signal,
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *WaitResult) Successful() bool {
|
|
|
|
return r.ExitCode == 0 && r.Signal == 0 && r.Err == nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *WaitResult) String() string {
|
|
|
|
return fmt.Sprintf("Wait returned exit code %v, signal %v, and error %v",
|
|
|
|
r.ExitCode, r.Signal, r.Err)
|
|
|
|
}
|
2016-02-19 22:01:07 +00:00
|
|
|
|
|
|
|
// IsolationConfig has information about the isolation mechanism the executor
|
|
|
|
// uses to put resource constraints and isolation on the user process
|
|
|
|
type IsolationConfig struct {
|
2016-04-02 08:06:41 +00:00
|
|
|
Cgroup *cgroupConfig.Cgroup
|
|
|
|
CgroupPaths map[string]string
|
2016-02-19 22:01:07 +00:00
|
|
|
}
|
2016-02-29 00:56:05 +00:00
|
|
|
|
|
|
|
// RecoverableError wraps an error and marks whether it is recoverable and could
|
|
|
|
// be retried or it is fatal.
|
|
|
|
type RecoverableError struct {
|
|
|
|
Err error
|
|
|
|
Recoverable bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewRecoverableError is used to wrap an error and mark it as recoverable or
|
|
|
|
// not.
|
|
|
|
func NewRecoverableError(e error, recoverable bool) *RecoverableError {
|
|
|
|
return &RecoverableError{
|
|
|
|
Err: e,
|
|
|
|
Recoverable: recoverable,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RecoverableError) Error() string {
|
|
|
|
return r.Err.Error()
|
|
|
|
}
|
2016-03-24 07:13:30 +00:00
|
|
|
|
|
|
|
// CheckResult encapsulates the result of a check
|
|
|
|
type CheckResult struct {
|
2016-05-05 17:45:02 +00:00
|
|
|
|
|
|
|
// ExitCode is the exit code of the check
|
|
|
|
ExitCode int
|
|
|
|
|
|
|
|
// Output is the output of the check script
|
|
|
|
Output string
|
|
|
|
|
|
|
|
// Timestamp is the time at which the check was executed
|
2016-03-24 07:13:30 +00:00
|
|
|
Timestamp time.Time
|
2016-05-05 17:45:02 +00:00
|
|
|
|
|
|
|
// Duration is the time it took the check to run
|
|
|
|
Duration time.Duration
|
|
|
|
|
|
|
|
// Err is the error that a check returned
|
|
|
|
Err error
|
2016-03-24 07:13:30 +00:00
|
|
|
}
|
2016-04-28 23:06:01 +00:00
|
|
|
|
2016-05-21 07:49:17 +00:00
|
|
|
// MemoryStats holds memory usage related stats
|
2016-04-28 23:06:01 +00:00
|
|
|
type MemoryStats struct {
|
2016-04-29 20:03:02 +00:00
|
|
|
RSS uint64
|
|
|
|
Cache uint64
|
|
|
|
Swap uint64
|
|
|
|
MaxUsage uint64
|
|
|
|
KernelUsage uint64
|
|
|
|
KernelMaxUsage uint64
|
2016-06-10 02:45:41 +00:00
|
|
|
|
|
|
|
// A list of fields whose values were actually sampled
|
|
|
|
Measured []string
|
2016-04-28 23:06:01 +00:00
|
|
|
}
|
|
|
|
|
2016-05-21 07:49:17 +00:00
|
|
|
// CpuStats holds cpu usage related stats
|
|
|
|
type CpuStats struct {
|
2016-05-11 19:56:47 +00:00
|
|
|
SystemMode float64
|
|
|
|
UserMode float64
|
2016-04-29 20:03:02 +00:00
|
|
|
ThrottledPeriods uint64
|
|
|
|
ThrottledTime uint64
|
2016-05-11 19:56:47 +00:00
|
|
|
Percent float64
|
2016-06-10 02:45:41 +00:00
|
|
|
|
|
|
|
// A list of fields whose values were actually sampled
|
|
|
|
Measured []string
|
2016-04-29 18:40:37 +00:00
|
|
|
}
|
|
|
|
|
2016-05-21 09:05:08 +00:00
|
|
|
// ResourceUsage holds information related to cpu and memory stats
|
|
|
|
type ResourceUsage struct {
|
2016-04-28 23:06:01 +00:00
|
|
|
MemoryStats *MemoryStats
|
2016-05-21 07:49:17 +00:00
|
|
|
CpuStats *CpuStats
|
2016-04-28 23:06:01 +00:00
|
|
|
}
|
2016-05-21 09:05:08 +00:00
|
|
|
|
|
|
|
// TaskResourceUsage holds aggregated resource usage of all processes in a Task
|
|
|
|
// and the resource usage of the individual pids
|
|
|
|
type TaskResourceUsage struct {
|
|
|
|
ResourceUsage *ResourceUsage
|
2016-05-27 21:15:51 +00:00
|
|
|
Timestamp int64
|
2016-05-21 09:05:08 +00:00
|
|
|
Pids map[string]*ResourceUsage
|
|
|
|
}
|