state

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2017 License: Apache-2.0 Imports: 22 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 (
	SWAN_RESERVED_NETWORK = "swan"
)

Variables

This section is empty.

Functions

func AppToRaft

func AppToRaft(app *App) *rafttypes.Application

func CommandFromRaft

func CommandFromRaft(raftCommand *rafttypes.Command) *types.Command

func CommandToRaft

func CommandToRaft(command *types.Command) *rafttypes.Command

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]*mesos.OfferID, error)

func OfferAllocatorItemFromRaft

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

func OfferAllocatorItemToRaft

func OfferAllocatorItemToRaft(slotID, offerID string) *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 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) 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 OfferAllocator

type OfferAllocator struct {
	PendingOfferSlots []*Slot
	BySlotId          map[string]*mesos.OfferID // record allocated offers that map 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 *mesos.OfferID)

func (*OfferAllocator) RemoveOfferSlotMapBySlot

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

func (*OfferAllocator) RemoveSlot

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

func (*OfferAllocator) RemoveSlotFromPendingOfferQueue

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

func (*OfferAllocator) RetriveSlotIdWithOfferId

func (allocator *OfferAllocator) RetriveSlotIdWithOfferId(offerId *mesos.OfferID) (string, error)

func (*OfferAllocator) SetOfferSlotMap

func (allocator *OfferAllocator) SetOfferSlotMap(offerID *mesos.OfferID, slot *Slot)

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 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) 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 Task

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

	State  string
	Stdout string
	Stderr string

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

	Reason  string
	Message string
	Source  string

	Created 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

Jump to

Keyboard shortcuts

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