engine

package
v2.3.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2017 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EtcdResourcesKey = "/lain/config/resources"

	EtcdGuardSwitchKey = "/lain/config/guardswitch"
)
View Source
const (
	DefaultHealthInterval = 10
	DefaultHealthTimeout  = 5
	DefaultHealthRetries  = 3

	CPUQuota        = int64(1000000)
	CPUMaxPctg      = 50 // max percentage of total cpu
	CPUMaxLevel     = 8
	CPUDeafultLevel = 2

	CURL_TMPLT = `echo $(curl -s -o /dev/null -w '%%{http_code}\n' %s) | grep -Eq "^[2-3]..$"`
)
View Source
const (
	RunStatePending = iota
	RunStateDrift
	RunStateSuccess
	RunStateExit
	RunStateFail
	RunStateInconsistent
	RunStateMissing
	RunStateRemoved
)
View Source
const (
	HealthStateNone = iota
	HealthStateStarting
	HealthStateHealthy
	HealthStateUnHealthy
)
View Source
const (
	MinPodSetupTime = 0
	MaxPodSetupTime = 300

	MinPodKillTimeout = 10
	MaxPodKillTimeout = 120
)
View Source
const (
	CloudVolumeSingleMode = "single"
	CloudVolumeMultiMode  = "multi"
)
View Source
const (
	DependencyNamespaceLevel = iota
	DependencyNodeLevel
)
View Source
const (
	RestartPolicyNever = iota
	RestartPolicyAlways
	RestartPolicyOnFail
)
View Source
const (
	ClusterFailedThreadSold = 20
)
View Source
const (
	KeyPrefixStreamPorts = "/lain/deployd/stream/ports"
)

Variables

View Source
var (
	ErrPodGroupExists         = errors.New("PodGroup has already existed")
	ErrPodGroupNotExists      = errors.New("PodGroup not existed")
	ErrPodGroupCleaning       = errors.New("PodGroup is removing, need to wait for that")
	ErrNotEnoughResources     = errors.New("Not enough CPUs and Memory to use")
	ErrDependencyPodExists    = errors.New("DependencyPod has already existed")
	ErrDependencyPodNotExists = errors.New("DependencyPod not existed")
	ErrConstraintNotExists    = errors.New("Constraint not existed")
	ErrNotifyNotExists        = errors.New("Notify uri not existed")
)
View Source
var (
	NotifyPodMissing   = "LAIN found pod missing, ready to redeployd it"
	NotifyPodDown      = "LAIN found pod down, ready to restart it"
	NotifyPodDownOOM   = "LAIN found pod down with OOM, ready to restart it"
	NotifyLetPodGo     = "LAIN found pod restart too many times in a short period, will let it go"
	NotifyPodIPLost    = "LAIN found pod lost IP, please inform the SA team"
	NotifyPodUnHealthy = "LAIN found pod Unhealthy, please check your service"

	NotifyClusterUnHealthy = "LAIN found Cluster Manager Unhealthy, please check your cluster"
)
View Source
var DependsGarbageCollectTimeout time.Duration

set GarbageCollectTimeout long enough. sometimes, podgroup refresh goroutine may having some problem(such as swarm exception), and do not verify it's portal for a long time

View Source
var RefreshInterval int
View Source
var RestartInfoClearInterval time.Duration

some instances written with JAVA like language may suffer from OOM, if they are restarted before (now - RestartInfoClearInterval), clear the restart info

View Source
var RestartMaxCount int

Functions

func CancelPorts

func CancelPorts(sps ...*StreamProc)

func ConfigPortsManager

func ConfigPortsManager(endpoint string)

func GuardGotoSleep

func GuardGotoSleep(store storage.Store) bool

func GuardGotoWork

func GuardGotoWork(store storage.Store) bool

func NewConstraintController

func NewConstraintController() *constraintController

func NewNotifyController

func NewNotifyController(stop chan struct{}) *notifyController

func OccupiedPorts

func OccupiedPorts(ports ...int) []int

func RefreshPorts

func RefreshPorts(pgCtrls map[string]*podGroupController)

func RegisterPorts

func RegisterPorts(sps ...*StreamProc) (bool, []int)

func UpdatePorts

func UpdatePorts(sps ...*StreamProc)

Types

type BaseRuntime

type BaseRuntime struct {
	Healthst  HealthState
	State     RunState
	OOMkilled bool
	LastError string
	UpdatedAt time.Time
}

type CloudVolumeSpec

type CloudVolumeSpec struct {
	Type string
	Dirs []string
}

func (CloudVolumeSpec) Clone

func (s CloudVolumeSpec) Clone() CloudVolumeSpec

func (CloudVolumeSpec) Equals

func (s CloudVolumeSpec) Equals(o CloudVolumeSpec) bool

func (CloudVolumeSpec) VerifyParams

func (s CloudVolumeSpec) VerifyParams() bool

type ConstraintSpec

type ConstraintSpec struct {
	Type  string
	Equal bool
	Value string
	Soft  bool
}

type Container

type Container struct {
	// FIXME(mijia): multiple ports supporing, will have multiple entries of <NodePort, ContainerPort, Protocol>
	Id            string
	Runtime       adoc.ContainerDetail
	NodeName      string
	NodeIp        string
	ContainerIp   string
	NodePort      int
	ContainerPort int
	Protocol      string
}

func (Container) Clone

func (c Container) Clone() Container

func (Container) Equals

func (c Container) Equals(o Container) bool

type ContainerLabel

type ContainerLabel struct {
	Name           string
	Namespace      string
	InstanceNo     int
	Version        int
	DriftCount     int
	ContainerIndex int
	Annotation     string
}

func (*ContainerLabel) FromMaps

func (label *ContainerLabel) FromMaps(m map[string]string) bool

func (ContainerLabel) Label2Maps

func (label ContainerLabel) Label2Maps() map[string]string

func (ContainerLabel) NameAffinity

func (label ContainerLabel) NameAffinity() string

type ContainerSpec

type ContainerSpec struct {
	ImSpec
	Image         string
	Env           []string
	User          string
	WorkingDir    string
	DnsSearch     []string
	Volumes       []string // a stateful flag
	SystemVolumes []string // not a stateful flag, every node has system volumes
	CloudVolumes  []CloudVolumeSpec
	Command       []string
	Entrypoint    []string
	CpuLimit      int
	MemoryLimit   int64
	Expose        int
	LogConfig     adoc.LogConfig
}

func NewContainerSpec

func NewContainerSpec(image string) ContainerSpec

func (ContainerSpec) Clone

func (s ContainerSpec) Clone() ContainerSpec

func (ContainerSpec) Equals

func (s ContainerSpec) Equals(o ContainerSpec) bool

func (ContainerSpec) VerifyParams

func (s ContainerSpec) VerifyParams() bool

type Dependency

type Dependency struct {
	PodName string
	Policy  DependencyPolicy
}

func (Dependency) Clone

func (d Dependency) Clone() Dependency

type DependencyEvent

type DependencyEvent struct {
	Type      string // add, remove, verify
	Name      string
	NodeName  string
	Namespace string
}

type DependencyPolicy

type DependencyPolicy int

type Guard

type Guard struct {
	Working bool `json:"Working"`
}

func FetchGuard

func FetchGuard() *Guard

type HealthCnfOptions

type HealthCnfOptions struct {
	Interval int `json:"interval"`
	Timeout  int `json:"timeout"`
	Retries  int `json:"retries"`
}

func (HealthCnfOptions) Equals

func (hco HealthCnfOptions) Equals(cp HealthCnfOptions) bool

type HealthConfig

type HealthConfig struct {
	Cmd     string           `json:"cmd"`
	Options HealthCnfOptions `json:"options"`
}

func (HealthConfig) Equals

func (hc HealthConfig) Equals(cp HealthConfig) bool

type HealthState

type HealthState int

func (HealthState) String

func (hs HealthState) String() string

type ImRuntime

type ImRuntime struct {
	BaseRuntime
	DriftCount   int
	RestartCount int
	RestartAt    time.Time
}

type ImSpec

type ImSpec struct {
	Name      string
	Namespace string
	Version   int
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Listener

type Listener interface {
	ListenerId() string
	HandleEvent(payload interface{})
}

type NamespacePodsWithSpec

type NamespacePodsWithSpec struct {
	Spec PodSpec
	Pods map[string][]Pod
}

type NotifySpec

type NotifySpec struct {
	Level      string
	Namespace  string
	PodName    string
	InstanceNo int
	Timestamp  time.Time
	Message    string
}

func NewNotifySpec

func NewNotifySpec(namespace string, podName string, instanceNo int, timestamp time.Time, message string) NotifySpec

type OrcEngine

type OrcEngine struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(cluster cluster.Cluster, store storage.Store) (*OrcEngine, error)

func (*OrcEngine) AddNotify

func (engine *OrcEngine) AddNotify(callback string) error

func (*OrcEngine) DeleteConstraints

func (engine *OrcEngine) DeleteConstraints(cstType string) error

func (*OrcEngine) DeleteNotify

func (engine *OrcEngine) DeleteNotify(callback string) error

func (*OrcEngine) DriftNode

func (engine *OrcEngine) DriftNode(fromNode, toNode string, pgName string, pgInstance int, force bool)

func (*OrcEngine) GetConstraints

func (engine *OrcEngine) GetConstraints(cstType string) (ConstraintSpec, bool)

func (*OrcEngine) GetDependencyPod

func (engine *OrcEngine) GetDependencyPod(name string) (NamespacePodsWithSpec, error)

func (*OrcEngine) GetNodes

func (engine *OrcEngine) GetNodes() ([]cluster.Node, error)

func (*OrcEngine) GetNotifies

func (engine *OrcEngine) GetNotifies() []string

func (*OrcEngine) GuardGotoSleep

func (engine *OrcEngine) GuardGotoSleep() bool

func (*OrcEngine) GuardGotoWork

func (engine *OrcEngine) GuardGotoWork() bool

func (*OrcEngine) HandleEvent

func (engine *OrcEngine) HandleEvent(payload interface{})

func (*OrcEngine) InspectPodGroup

func (engine *OrcEngine) InspectPodGroup(name string) (PodGroupWithSpec, bool)

func (*OrcEngine) ListenerId

func (engine *OrcEngine) ListenerId() string

func (*OrcEngine) LoadDependsPods

func (engine *OrcEngine) LoadDependsPods() error

func (*OrcEngine) LoadPodGroups

func (engine *OrcEngine) LoadPodGroups() error

func (*OrcEngine) NewDependencyPod

func (engine *OrcEngine) NewDependencyPod(spec PodSpec) error

func (*OrcEngine) NewPodGroup

func (engine *OrcEngine) NewPodGroup(spec PodGroupSpec) error

func (*OrcEngine) RefreshPodGroup

func (engine *OrcEngine) RefreshPodGroup(name string, forceUpdate bool) error

func (*OrcEngine) RemoveDependencyPod

func (engine *OrcEngine) RemoveDependencyPod(name string, force bool) error

func (*OrcEngine) RemovePodGroup

func (engine *OrcEngine) RemovePodGroup(name string) error

func (*OrcEngine) RescheduleInstance

func (engine *OrcEngine) RescheduleInstance(name string, numInstances int, restartPolicy ...RestartPolicy) error

func (*OrcEngine) RescheduleSpec

func (engine *OrcEngine) RescheduleSpec(name string, podSpec PodSpec) error

func (*OrcEngine) Start

func (engine *OrcEngine) Start()

func (*OrcEngine) Started

func (engine *OrcEngine) Started() bool

func (*OrcEngine) Stop

func (engine *OrcEngine) Stop()

func (*OrcEngine) UpdateConstraints

func (engine *OrcEngine) UpdateConstraints(spec ConstraintSpec) error

func (*OrcEngine) UpdateDependencyPod

func (engine *OrcEngine) UpdateDependencyPod(spec PodSpec) error

type Pod

type Pod struct {
	InstanceNo int
	Containers []Container
	ImRuntime
}

func (Pod) Clone

func (p Pod) Clone() Pod

func (Pod) ContainerIds

func (pod Pod) ContainerIds() []string

func (Pod) Equals

func (p Pod) Equals(o Pod) bool

func (Pod) NeedRestart

func (pod Pod) NeedRestart(policy RestartPolicy) bool

func (Pod) NodeIp

func (pod Pod) NodeIp() string

func (Pod) NodeName

func (pod Pod) NodeName() string

func (Pod) PodIp

func (pod Pod) PodIp() string

func (Pod) RestartEnoughTimes

func (pod Pod) RestartEnoughTimes() bool

type PodGroup

type PodGroup struct {
	Pods []Pod
	BaseRuntime
}

func (PodGroup) Clone

func (pg PodGroup) Clone() PodGroup

func (PodGroup) Equals

func (pg PodGroup) Equals(o PodGroup) bool

type PodGroupPrevState

type PodGroupPrevState struct {
	Nodes []string
	// we think a instance only have one ip, as now a instance only have one container.
	IPs []string
}

func (PodGroupPrevState) Clone

func (pgps PodGroupPrevState) Clone() PodGroupPrevState

func (PodGroupPrevState) Length

func (pgps PodGroupPrevState) Length() int

func (PodGroupPrevState) Reset

func (pgps PodGroupPrevState) Reset(instanceNo int) PodGroupPrevState

type PodGroupSpec

type PodGroupSpec struct {
	ImSpec
	Pod           PodSpec
	NumInstances  int
	RestartPolicy RestartPolicy
}

func NewPodGroupSpec

func NewPodGroupSpec(name string, namespace string, podSpec PodSpec, numInstances int) PodGroupSpec

func (PodGroupSpec) Clone

func (spec PodGroupSpec) Clone() PodGroupSpec

func (PodGroupSpec) Equals

func (spec PodGroupSpec) Equals(o PodGroupSpec) bool

func (PodGroupSpec) String

func (spec PodGroupSpec) String() string

func (PodGroupSpec) VerifyParams

func (spec PodGroupSpec) VerifyParams() bool

type PodGroupWithSpec

type PodGroupWithSpec struct {
	Spec      PodGroupSpec
	PrevState []PodPrevState
	PodGroup
}

type PodPrevState

type PodPrevState struct {
	NodeName string
	IPs      []string
}

func NewPodPrevState

func NewPodPrevState(length int) PodPrevState

func (PodPrevState) Clone

func (pps PodPrevState) Clone() PodPrevState

type PodSpec

type PodSpec struct {
	ImSpec
	Network      string
	Containers   []ContainerSpec
	Filters      []string // for cluster scheduling
	Labels       map[string]string
	Dependencies []Dependency
	Annotation   string
	Stateful     bool
	SetupTime    int
	KillTimeout  int
	PrevState    PodPrevState
	HealthConfig HealthConfig
}

func NewPodSpec

func NewPodSpec(containerSpec ContainerSpec, otherSpecs ...ContainerSpec) PodSpec

func (PodSpec) Clone

func (s PodSpec) Clone() PodSpec

func (PodSpec) Equals

func (s PodSpec) Equals(o PodSpec) bool

func (PodSpec) GetKillTimeout

func (s PodSpec) GetKillTimeout() int

func (PodSpec) GetSetupTime

func (s PodSpec) GetSetupTime() int

func (PodSpec) HasVolumes

func (s PodSpec) HasVolumes() bool

func (PodSpec) IsHardStateful

func (s PodSpec) IsHardStateful() bool

func (PodSpec) IsStateful

func (s PodSpec) IsStateful() bool

func (PodSpec) Merge

func (s PodSpec) Merge(o PodSpec) PodSpec

func (PodSpec) String

func (s PodSpec) String() string

func (PodSpec) VerifyParams

func (s PodSpec) VerifyParams() bool

type PortsManager

type PortsManager struct {
	// contains filtered or unexported fields
}

func NewPortsManager

func NewPortsManager(endpoint string) *PortsManager

func (*PortsManager) CancelStreamPort

func (pm *PortsManager) CancelStreamPort(sp *StreamProc) bool

func (PortsManager) CancelStreamPorts

func (pm PortsManager) CancelStreamPorts(spArr ...*StreamProc)

func (PortsManager) FetchAllStreamPortsInfo

func (pm PortsManager) FetchAllStreamPortsInfo() []StreamProc

func (PortsManager) Refresh

func (pm PortsManager) Refresh(pgCtrls map[string]*podGroupController)

func (PortsManager) RegisterStreamPort

func (pm PortsManager) RegisterStreamPort(sp *StreamProc) bool

func (PortsManager) RegisterStreamPorts

func (pm PortsManager) RegisterStreamPorts(spArr ...*StreamProc) (bool, []int)

func (*PortsManager) UpdateStreamPort

func (pm *PortsManager) UpdateStreamPort(sp *StreamProc) bool

func (PortsManager) UpdateStreamPorts

func (pm PortsManager) UpdateStreamPorts(spArr ...*StreamProc)

type Publisher

type Publisher interface {
	EmitEvent(payload interface{})
	AddListener(subscriber Listener)
	RemoveListener(subscriber Listener)
}

func NewPublisher

func NewPublisher(goRoutine bool) Publisher

type Resource

type Resource struct {
	Cpu    int    `json:"cpu"`
	Memory string `json:"memory"`
}

func FetchResource

func FetchResource() *Resource

type RestartPolicy

type RestartPolicy int

func (RestartPolicy) String

func (rp RestartPolicy) String() string

type RunState

type RunState int

func (RunState) String

func (rs RunState) String() string

type RuntimeEaglePod

type RuntimeEaglePod struct {
	ContainerLabel
	Container   adoc.Container
	ParseSource string
}

func (RuntimeEaglePod) String

func (pod RuntimeEaglePod) String() string

type RuntimeEagleView

type RuntimeEagleView struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRuntimeEagleView

func NewRuntimeEagleView() *RuntimeEagleView

func (*RuntimeEagleView) Activate

func (ev *RuntimeEagleView) Activate(c cluster.Cluster)

func (*RuntimeEagleView) GetRuntimeEaglePods

func (ev *RuntimeEagleView) GetRuntimeEaglePods(name string) ([]RuntimeEaglePod, bool)

func (*RuntimeEagleView) Refresh

func (ev *RuntimeEagleView) Refresh(c cluster.Cluster) error

func (*RuntimeEagleView) RefreshPodGroup

func (ev *RuntimeEagleView) RefreshPodGroup(c cluster.Cluster, pgName string) ([]RuntimeEaglePod, error)

func (*RuntimeEagleView) RefreshPodsByNamespace

func (ev *RuntimeEagleView) RefreshPodsByNamespace(c cluster.Cluster, namespace string) ([]RuntimeEaglePod, error)

type SharedPodWithSpec

type SharedPodWithSpec struct {
	RefCount   int
	VerifyTime time.Time
	Spec       PodSpec
	Pod        Pod
}

type StreamPort

type StreamPort struct {
	SrcPort int    `json:"srcport"`
	DstPort int    `json:"dstport"`
	Proto   string `json:"proto"`
}

func (StreamPort) Equals

func (sp StreamPort) Equals(osp StreamPort) bool

type StreamPorts

type StreamPorts struct {
	Ports []StreamPort `json:"ports"`
}

func (StreamPorts) Equals

func (sp StreamPorts) Equals(osp StreamPorts) bool

type StreamProc

type StreamProc struct {
	StreamPort
	NameSpace string
	ProcName  string
}

func FetchAllPortsInfo

func FetchAllPortsInfo() []StreamProc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL