state

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2017 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APP_STATE_NORMAL                 = "normal"
	APP_STATE_MARK_FOR_CREATING      = "creating"
	APP_STATE_MARK_FOR_DELETION      = "deleting"
	APP_STATE_MARK_FOR_UPDATING      = "updating"
	APP_STATE_MARK_FOR_CANCEL_UPDATE = "cancel_update"
	APP_STATE_MARK_FOR_SCALE_UP      = "scale_up"
	APP_STATE_MARK_FOR_SCALE_DOWN    = "scale_down"
)
View Source
const (
	SLOT_STATE_PENDING_OFFER = "slot_task_pending_offer"
	SLOT_STATE_PENDING_KILL  = "slot_task_pending_killed"
	SLOT_STATE_REAP          = "slot_task_reap"

	SLOT_STATE_TASK_STAGING          = "slot_task_staging"
	SLOT_STATE_TASK_STARTING         = "slot_task_starting"
	SLOT_STATE_TASK_RUNNING          = "slot_task_running"
	SLOT_STATE_TASK_KILLING          = "slot_task_killing"
	SLOT_STATE_TASK_FINISHED         = "slot_task_finished"
	SLOT_STATE_TASK_FAILED           = "slot_task_failed"
	SLOT_STATE_TASK_KILLED           = "slot_task_killed"
	SLOT_STATE_TASK_ERROR            = "slot_task_error"
	SLOT_STATE_TASK_LOST             = "slot_task_lost"
	SLOT_STATE_TASK_DROPPED          = "slot_task_dropped"
	SLOT_STATE_TASK_UNREACHABLE      = "slot_task_unreachable"
	SLOT_STATE_TASK_GONE             = "slot_task_gone"
	SLOT_STATE_TASK_GONE_BY_OPERATOR = "slot_task_gone_by_operator"
	SLOT_STATE_TASK_UNKNOWN          = "slot_task_unknown"
)
View Source
const AND = 57346
View Source
const CONTAINS = 57350
View Source
const EQUAL = 57352
View Source
const IDENTIFIER = 57353
View Source
const LIKE = 57349
View Source
const NOT = 57351
View Source
const OR = 57347
View Source
const (
	SWAN_RESERVED_NETWORK = "swan"
)
View Source
const UNIQUE = 57348

Variables

This section is empty.

Functions

func AppToRaft

func AppToRaft(app *App) *rafttypes.Application

func ContainerFromRaft

func ContainerFromRaft(raftContainer *rafttypes.Container) *types.Container

func ContainerToRaft

func ContainerToRaft(container *types.Container) *rafttypes.Container

func DockerFromRaft

func DockerFromRaft(raftDocker *rafttypes.Docker) *types.Docker

func DockerToRaft

func DockerToRaft(docker *types.Docker) *rafttypes.Docker

func HealthCheckFromRaft

func HealthCheckFromRaft(raftHealthCheck *rafttypes.HealthCheck) *types.HealthCheck

func HealthCheckToRaft

func HealthCheckToRaft(healthCheck *types.HealthCheck) *rafttypes.HealthCheck

func KillPolicyFromRaft

func KillPolicyFromRaft(raftKillPolicy *rafttypes.KillPolicy) *types.KillPolicy

func KillPolicyToRaft

func KillPolicyToRaft(killPolicy *types.KillPolicy) *rafttypes.KillPolicy

func LoadAppData

func LoadAppData(userEventChan chan *event.UserEvent) (map[string]*App, error)

load app data frm persistent data

func LoadOfferAllocatorMap

func LoadOfferAllocatorMap() (map[string]*OfferInfo, error)

func OfferAllocatorItemToRaft

func OfferAllocatorItemToRaft(slotID string, offerInfo *OfferInfo) *rafttypes.OfferAllocatorItem

func ParameterFromRaft

func ParameterFromRaft(raftParameter *rafttypes.Parameter) *types.Parameter

func ParameterToRaft

func ParameterToRaft(parameter *types.Parameter) *rafttypes.Parameter

func PortMappingFromRaft

func PortMappingFromRaft(raftPortMapping *rafttypes.PortMapping) *types.PortMapping

func PortMappingToRaft

func PortMappingToRaft(portMapping *types.PortMapping) *rafttypes.PortMapping

func SetStore

func SetStore(newStore store.Store)

func SlotToRaft

func SlotToRaft(slot *Slot) *rafttypes.Slot

func TaskToRaft

func TaskToRaft(task *Task) *rafttypes.Task

func UpdatePolicyFromRaft

func UpdatePolicyFromRaft(raftUpdatePolicy *rafttypes.UpdatePolicy) *types.UpdatePolicy

func UpdatePolicyToRaft

func UpdatePolicyToRaft(updatePolicy *types.UpdatePolicy) *rafttypes.UpdatePolicy

func VersionFromRaft

func VersionFromRaft(raftVersion *rafttypes.Version) *types.Version

func VersionToRaft

func VersionToRaft(version *types.Version, appID string) *rafttypes.Version

func VolumeFromFaft

func VolumeFromFaft(raftVolume *rafttypes.Volume) *types.Volume

func VolumeToRaft

func VolumeToRaft(volume *types.Volume) *rafttypes.Volume

func WithConvertApp

func WithConvertApp(ctx context.Context, app *App, cb func(), action func(ctx context.Context, app *rafttypes.Application, cb func()) error) error

func WithConvertSlot

func WithConvertSlot(ctx context.Context, slot *Slot, cb func(), action func(ctx context.Context, slot *rafttypes.Slot, cb func()) error) error

func WithConvertTask

func WithConvertTask(ctx context.Context, task *Task, cb func(), action func(ctx context.Context, task *rafttypes.Task, cb func()) error) error

Types

type AndStatement added in v0.1.3

type AndStatement struct {
	Op1 Statement
	Op2 Statement
}

and (unique hostname) (unique ip) and (not (unique hostname)) (unique ip)

func (*AndStatement) Eval added in v0.1.3

func (as *AndStatement) Eval() bool

func (*AndStatement) SetContext added in v0.1.3

func (as *AndStatement) SetContext(ctx *ConstraintParamHolder)

func (*AndStatement) Valid added in v0.1.3

func (as *AndStatement) Valid() error

type App

type App struct {
	ID       string           `json:"id"`
	Name     string           `json:"name"`
	Versions []*types.Version `json:"versions"`

	// app run with CurrentVersion config
	CurrentVersion *types.Version `json:"current_version"`
	// use when app updated, ProposedVersion can either be commit or revert
	ProposedVersion *types.Version `json:"proposed_version"`

	Mode AppMode `json:"mode"` // fixed or repliactes

	Created time.Time
	Updated time.Time

	State     string
	ClusterID string

	UserEventChan chan *event.UserEvent
	// contains filtered or unexported fields
}

func NewApp

func NewApp(version *types.Version,
	userEventChan chan *event.UserEvent) (*App, error)

func (*App) BeginTx

func (app *App) BeginTx()

func (*App) BuildAppEvent

func (app *App) BuildAppEvent(eventType string) *swanevent.Event

func (*App) CanBeCleanAfterDeletion

func (app *App) CanBeCleanAfterDeletion() bool

func (*App) CancelUpdate

func (app *App) CancelUpdate() error

func (*App) Commit

func (app *App) Commit()

here we persist the app anyway, no matter it touched or not

func (*App) Delete

func (app *App) Delete() error

delete a application and all related objects: versions, tasks, slots, proxies, dns record

func (*App) EmitAppEvent

func (app *App) EmitAppEvent(eventType string)

func (*App) EmitEvent

func (app *App) EmitEvent(swanEvent *swanevent.Event)

func (*App) GetSlot

func (app *App) GetSlot(index int) (*Slot, bool)

func (*App) GetSlots

func (app *App) GetSlots() []*Slot

func (*App) IsFixed

func (app *App) IsFixed() bool

func (*App) IsReplicates

func (app *App) IsReplicates() bool

func (*App) MarkForDeletionInstances

func (app *App) MarkForDeletionInstances() int

func (*App) ProceedingRollingUpdate

func (app *App) ProceedingRollingUpdate(instances int) error

func (*App) Reevaluate

func (app *App) Reevaluate()

func (*App) Remove

func (app *App) Remove()

1, remove app from persisted storage 2, other cleanup process

func (*App) RemoveSlot

func (app *App) RemoveSlot(index int)

func (*App) RollingUpdateInstances

func (app *App) RollingUpdateInstances() int

func (*App) RunningInstances

func (app *App) RunningInstances() int

func (*App) ScaleDown

func (app *App) ScaleDown(removeInstances int) error

func (*App) ScaleUp

func (app *App) ScaleUp(newInstances int, newIps []string) error

also need user pass ip here

func (*App) ServiceDiscoveryURL added in v0.1.3

func (app *App) ServiceDiscoveryURL() string

func (*App) SetSlot

func (app *App) SetSlot(index int, slot *Slot)

func (*App) SetState

func (app *App) SetState(state string)

func (*App) StateIs

func (app *App) StateIs(state string) bool

func (*App) Touch

func (app *App) Touch(force bool)

storage related

func (*App) Update

func (app *App) Update(version *types.Version, store store.Store) error

update application by follower steps

  1. check app state: if app state if not APP_STATE_NORMAL or app's propose version is not nil we can not update app, because that means target app maybe is in updateing.
  2. set the new version to the app's propose version.
  3. persist app data, and set the app's state to APP_STATE_MARK_FOR_UPDATING
  4. update slot version to propose version
  5. after all slot version update success. put the current version to version history and set the propose version as current version, set propose version to nil.
  6. set app's state to APP_STATE_NORMAL.

type AppMode

type AppMode string
var (
	APP_MODE_FIXED      AppMode = "fixed"
	APP_MODE_REPLICATES AppMode = "replicates"
)

type AppsByUpdated added in v0.1.3

type AppsByUpdated []*App

func (AppsByUpdated) Len added in v0.1.3

func (a AppsByUpdated) Len() int

func (AppsByUpdated) Less added in v0.1.3

func (a AppsByUpdated) Less(i, j int) bool

func (AppsByUpdated) Swap added in v0.1.3

func (a AppsByUpdated) Swap(i, j int)

type ConstraintParamHolder added in v0.1.3

type ConstraintParamHolder struct {
	Slot  *Slot
	Offer *mesos.Offer
}

type ConstraintParser added in v0.1.3

type ConstraintParser struct {
	scanner.Scanner
	// contains filtered or unexported fields
}

func (*ConstraintParser) Error added in v0.1.3

func (l *ConstraintParser) Error(e string)

func (*ConstraintParser) Lex added in v0.1.3

func (l *ConstraintParser) Lex(lval *yySymType) int

type ContainsStatement added in v0.1.3

type ContainsStatement struct {
	ConstraintParamHolder
	What  string
	Regex string
}

contains hostname barfoo

func (*ContainsStatement) Eval added in v0.1.3

func (cs *ContainsStatement) Eval() bool

func (*ContainsStatement) SetContext added in v0.1.3

func (cs *ContainsStatement) SetContext(ctx *ConstraintParamHolder)

func (*ContainsStatement) Valid added in v0.1.3

func (cs *ContainsStatement) Valid() error

type EqualStatement added in v0.1.5

type EqualStatement struct {
	ConstraintParamHolder
	What  string
	Regex string
}

equal hostname xxxx

func (*EqualStatement) Eval added in v0.1.5

func (ls *EqualStatement) Eval() bool

func (*EqualStatement) SetContext added in v0.1.5

func (ls *EqualStatement) SetContext(ctx *ConstraintParamHolder)

func (*EqualStatement) Valid added in v0.1.5

func (ls *EqualStatement) Valid() error

type LikeStatement added in v0.1.3

type LikeStatement struct {
	ConstraintParamHolder
	What  string
	Regex string
}

like hostname foobar*

func (*LikeStatement) Eval added in v0.1.3

func (ls *LikeStatement) Eval() bool

func (*LikeStatement) SetContext added in v0.1.3

func (ls *LikeStatement) SetContext(ctx *ConstraintParamHolder)

func (*LikeStatement) Valid added in v0.1.3

func (ls *LikeStatement) Valid() error

type NotStatement added in v0.1.3

type NotStatement struct {
	Op1 Statement
}

not (unique hostname)

func (*NotStatement) Eval added in v0.1.3

func (ns *NotStatement) Eval() bool

func (*NotStatement) SetContext added in v0.1.3

func (ns *NotStatement) SetContext(ctx *ConstraintParamHolder)

func (*NotStatement) Valid added in v0.1.3

func (ns *NotStatement) Valid() error

type OfferAllocator

type OfferAllocator struct {
	PendingOfferSlots []*Slot

	AllocatedOffer map[string]*OfferInfo // we store every offer that are occupied by running slot
	// contains filtered or unexported fields
}

func OfferAllocatorInstance

func OfferAllocatorInstance() *OfferAllocator

func (*OfferAllocator) PopNextPendingOffer

func (allocator *OfferAllocator) PopNextPendingOffer() *Slot

func (*OfferAllocator) PutSlotBackToPendingQueue

func (allocator *OfferAllocator) PutSlotBackToPendingQueue(slot *Slot)

func (*OfferAllocator) RemoveOfferSlotMapByOfferId

func (allocator *OfferAllocator) RemoveOfferSlotMapByOfferId(offerId string)

func (*OfferAllocator) RemoveOfferSlotMapBySlot

func (allocator *OfferAllocator) RemoveOfferSlotMapBySlot(slot *Slot)

func (*OfferAllocator) RemoveSlotFromAllocator added in v0.1.3

func (allocator *OfferAllocator) RemoveSlotFromAllocator(slot *Slot)

func (*OfferAllocator) RemoveSlotFromPendingOfferQueue

func (allocator *OfferAllocator) RemoveSlotFromPendingOfferQueue(slot *Slot)

func (*OfferAllocator) RetrieveSlotIdWithOfferId added in v0.1.3

func (allocator *OfferAllocator) RetrieveSlotIdWithOfferId(offerId string) (string, error)

func (*OfferAllocator) SetOfferSlotMap

func (allocator *OfferAllocator) SetOfferSlotMap(offer *mesos.Offer, slot *Slot)

func (*OfferAllocator) SlotsByAgentID added in v0.1.3

func (allocator *OfferAllocator) SlotsByAgentID(agentID string) []string

func (*OfferAllocator) SlotsByHostname added in v0.1.3

func (allocator *OfferAllocator) SlotsByHostname(hostname string) []string

type OfferInfo added in v0.1.3

type OfferInfo struct {
	OfferID  string
	AgentID  string
	Hostname string
	AgentIP  string
}

func OfferAllocatorItemFromRaft

func OfferAllocatorItemFromRaft(item *rafttypes.OfferAllocatorItem) (slotID string, offerInfo *OfferInfo)

type OfferWrapper

type OfferWrapper struct {
	Offer        *mesos.Offer
	CpusUsed     float64
	MemUsed      float64
	DiskUsed     float64
	PortUsedSize int
}

wrapper offer to record offer reserve history

func NewOfferWrapper

func NewOfferWrapper(offer *mesos.Offer) *OfferWrapper

func (*OfferWrapper) CpuRemain

func (ow *OfferWrapper) CpuRemain() float64

func (*OfferWrapper) DiskRemain

func (ow *OfferWrapper) DiskRemain() float64

func (*OfferWrapper) MemRemain

func (ow *OfferWrapper) MemRemain() float64

func (*OfferWrapper) PortsRemain

func (ow *OfferWrapper) PortsRemain() []uint64

type OrStatement added in v0.1.3

type OrStatement struct {
	ConstraintParamHolder
	Op1 Statement
	Op2 Statement
}

or (like ip foobar) (unique hostname)

func (*OrStatement) Eval added in v0.1.3

func (os *OrStatement) Eval() bool

func (*OrStatement) SetContext added in v0.1.3

func (os *OrStatement) SetContext(ctx *ConstraintParamHolder)

func (*OrStatement) Valid added in v0.1.3

func (os *OrStatement) Valid() error

type RestartPolicy

type RestartPolicy struct {
	BackoffSeconds        time.Duration
	BackoffFactor         float64
	MaxLaunchDelaySeconds time.Duration
	// contains filtered or unexported fields
}

func NewRestartPolicy

func NewRestartPolicy(slot *Slot, BackoffSeconds time.Duration, BackoffFactor float64,
	MaxLaunchDelaySeconds time.Duration, restartFunc TestAndRestartFunc) *RestartPolicy

func (*RestartPolicy) Stop

func (rs *RestartPolicy) Stop()

type Slot

type Slot struct {
	Index   int
	ID      string
	App     *App
	Version *types.Version
	State   string

	CurrentTask *Task
	TaskHistory []*Task

	OfferID       string
	AgentID       string
	Ip            string
	AgentHostName string
	// contains filtered or unexported fields
}

func LoadAppSlots

func LoadAppSlots(app *App) ([]*Slot, error)

func NewSlot

func NewSlot(app *App, version *types.Version, index int) *Slot

func SlotFromRaft

func SlotFromRaft(raftSlot *rafttypes.Slot) *Slot

func (*Slot) Abnormal

func (slot *Slot) Abnormal() bool

func (*Slot) Archive

func (slot *Slot) Archive()

func (*Slot) BeginTx

func (slot *Slot) BeginTx()

func (*Slot) BuildTaskEvent

func (slot *Slot) BuildTaskEvent(eventType string) *swanevent.Event

func (*Slot) Commit

func (slot *Slot) Commit()

here we persist the app anyway, no matter it touched or not

func (*Slot) DispatchNewTask

func (slot *Slot) DispatchNewTask(version *types.Version)

func (*Slot) Dispatched

func (slot *Slot) Dispatched() bool

func (*Slot) EmitTaskEvent

func (slot *Slot) EmitTaskEvent(eventType string)

func (*Slot) Healthy

func (slot *Slot) Healthy() bool

func (*Slot) Kill

func (slot *Slot) Kill()

kill task and make slot sweeped after successfully kill task

func (*Slot) KillTask

func (slot *Slot) KillTask()

kill task doesn't need cleanup slot from app.Slots

func (*Slot) MarkForDeletion

func (slot *Slot) MarkForDeletion() bool

func (*Slot) MarkForRollingUpdate

func (slot *Slot) MarkForRollingUpdate() bool

func (*Slot) Normal

func (slot *Slot) Normal() bool

func (*Slot) Remove

func (slot *Slot) Remove()

func (*Slot) ReserveOfferAndPrepareTaskInfo

func (slot *Slot) ReserveOfferAndPrepareTaskInfo(ow *OfferWrapper) (*OfferWrapper, *mesos.TaskInfo)

func (*Slot) ResourcesNeeded

func (slot *Slot) ResourcesNeeded() []*mesos.Resource

func (*Slot) ResourcesUsed

func (slot *Slot) ResourcesUsed() *SlotResource

func (*Slot) ServiceDiscoveryURL added in v0.1.3

func (slot *Slot) ServiceDiscoveryURL() string

func (*Slot) SetHealthy

func (slot *Slot) SetHealthy(healthy bool)

func (*Slot) SetMarkForDeletion

func (slot *Slot) SetMarkForDeletion(deletion bool)

func (*Slot) SetMarkForRollingUpdate

func (slot *Slot) SetMarkForRollingUpdate(rollingUpdate bool)

func (*Slot) SetState

func (slot *Slot) SetState(state string) error

func (*Slot) StateIs

func (slot *Slot) StateIs(state string) bool

func (*Slot) StopRestartPolicy

func (slot *Slot) StopRestartPolicy()

func (*Slot) TestOfferMatch

func (slot *Slot) TestOfferMatch(ow *OfferWrapper) bool

func (*Slot) Touch

func (slot *Slot) Touch(force bool)

func (*Slot) UpdateOfferInfo

func (slot *Slot) UpdateOfferInfo(offer *mesos.Offer) error

func (*Slot) UpdateTask

func (slot *Slot) UpdateTask(version *types.Version, isRollingUpdate bool)

type SlotResource

type SlotResource struct {
	CPU  float64
	Mem  float64
	Disk float64
}

type SlotsById

type SlotsById []*Slot

func (SlotsById) Len

func (a SlotsById) Len() int

func (SlotsById) Less

func (a SlotsById) Less(i, j int) bool

func (SlotsById) Swap

func (a SlotsById) Swap(i, j int)

type Statement added in v0.1.3

type Statement interface {
	Eval() bool
	Valid() error
	SetContext(ctx *ConstraintParamHolder)
}

func ParseConstraint added in v0.1.3

func ParseConstraint(c string) (Statement, error)

type Task

type Task struct {
	ID      string
	Version *types.Version
	Slot    *Slot

	State  string
	Stdout string
	Stderr string

	HostPorts     []uint64
	OfferID       string
	AgentID       string
	Ip            string
	AgentHostName string

	Reason  string // mesos updateStatus field
	Message string // mesos updateStatus field
	Source  string // mesos updateStatus field

	Created    time.Time
	ArchivedAt time.Time
	// contains filtered or unexported fields
}

func NewTask

func NewTask(version *types.Version, slot *Slot) *Task

func TaskFromRaft

func TaskFromRaft(raftTask *rafttypes.Task) *Task

func (*Task) Kill

func (task *Task) Kill()

func (*Task) PrepareTaskInfo

func (task *Task) PrepareTaskInfo(ow *OfferWrapper) *mesos.TaskInfo

type TaskBuilder

type TaskBuilder struct {
	HostPorts []uint64
	// contains filtered or unexported fields
}

func NewTaskBuilder

func NewTaskBuilder(task *Task) *TaskBuilder

func (*TaskBuilder) AppendContainerDockerEnvironments

func (builder *TaskBuilder) AppendContainerDockerEnvironments(envs map[string]string) *TaskBuilder

func (*TaskBuilder) AppendContainerDockerParameters

func (builder *TaskBuilder) AppendContainerDockerParameters(parameters []*types.Parameter) *TaskBuilder

func (*TaskBuilder) AppendContainerDockerVolumes

func (builder *TaskBuilder) AppendContainerDockerVolumes(volumes []*types.Volume) *TaskBuilder

func (*TaskBuilder) AppendTaskInfoLabels

func (builder *TaskBuilder) AppendTaskInfoLabels(labelMap map[string]string) *TaskBuilder

func (*TaskBuilder) GetTaskInfo

func (builder *TaskBuilder) GetTaskInfo() *mesos.TaskInfo

func (*TaskBuilder) SetAgentId

func (builder *TaskBuilder) SetAgentId(agentId string) *TaskBuilder

func (*TaskBuilder) SetCommand

func (builder *TaskBuilder) SetCommand(needShell bool, cmd string, args []string) *TaskBuilder

func (*TaskBuilder) SetContainerDockerForcePullImage

func (builder *TaskBuilder) SetContainerDockerForcePullImage(force bool) *TaskBuilder

func (*TaskBuilder) SetContainerDockerImage

func (builder *TaskBuilder) SetContainerDockerImage(image string) *TaskBuilder

func (*TaskBuilder) SetContainerDockerPrivileged

func (builder *TaskBuilder) SetContainerDockerPrivileged(privileged bool) *TaskBuilder

func (*TaskBuilder) SetContainerType

func (builder *TaskBuilder) SetContainerType(containerType string) *TaskBuilder

func (*TaskBuilder) SetHealthCheck

func (builder *TaskBuilder) SetHealthCheck(healthChecks []*types.HealthCheck) *TaskBuilder

func (*TaskBuilder) SetName

func (builder *TaskBuilder) SetName(name string) *TaskBuilder

func (*TaskBuilder) SetNetwork

func (builder *TaskBuilder) SetNetwork(network string, portsAvailable []uint64) *TaskBuilder

func (*TaskBuilder) SetResources

func (builder *TaskBuilder) SetResources(resources []*mesos.Resource) *TaskBuilder

func (*TaskBuilder) SetTaskId

func (builder *TaskBuilder) SetTaskId(taskId string) *TaskBuilder

func (*TaskBuilder) SetURIs

func (builder *TaskBuilder) SetURIs(uriList []string) *TaskBuilder

type TestAndRestartFunc

type TestAndRestartFunc func(slot *Slot) bool

type UniqueStatment added in v0.1.3

type UniqueStatment struct {
	ConstraintParamHolder
	What string
}

(unique hostname)

func (*UniqueStatment) Eval added in v0.1.3

func (us *UniqueStatment) Eval() bool

func (*UniqueStatment) SetContext added in v0.1.3

func (us *UniqueStatment) SetContext(ctx *ConstraintParamHolder)

func (*UniqueStatment) Valid added in v0.1.3

func (us *UniqueStatment) Valid() error

Jump to

Keyboard shortcuts

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