core

package
v0.0.0-...-467849e Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

//定义了集群内发生事件的各种事件类型

EventDB 的作用是存储模拟器模拟区间内所有的事件.

同时在使用外部调度器时,发生时间线变动时,方便修 改某个instance 在时间线中的所有的事件

Index

Constants

View Source
const (
	MinHourToSimulate = 1  // 最小模拟开始的时间
	MaxHourToSimulate = 10 // 最大模拟开始的时间

)
View Source
const (
	INSTANCESubmit        int64 = 0
	INSTANCEQueue         int64 = 1
	INSTANCEEnable        int64 = 2
	INSTANCESchdule       int64 = 3
	INSTANCEEvict         int64 = 4
	INSTANCEFail          int64 = 5
	INSTANCEFinish        int64 = 6
	INSTANCEKill          int64 = 7
	INSTANCELost          int64 = 8
	INSTANCEUpdatePending int64 = 9
	INSTANCEUpdateRunning int64 = 10
)
View Source
const (
	MACHINEAdd    int64 = 1
	MACHINEDelete int64 = 2
	MACHINEUpdate int64 = 3
)
View Source
const (
	SECOND int64 = 1000 * 1000
	MINUTE int64 = 60 * SECOND
	HOUR   int64 = 60 * MINUTE
)

Variables

View Source
var (
	ErrAlreadyExisted = errors.New("already existed")
	ErrNoInstance     = errors.New("the instance can not find")
	ErrNoMachine      = errors.New("the machine can not find")
)

Functions

func CsvToList

func CsvToList(path string) (table [][]string, tabletop []string)

func EventHandle

func EventHandle(c ClusterState, e IEvent)

func ListToCsv

func ListToCsv(table [][]string, tabletop []string, outpath string)

func SortByQueueTime

func SortByQueueTime(i []Instance)

Types

type ByQueueTime

type ByQueueTime []Instance

func (ByQueueTime) Len

func (a ByQueueTime) Len() int

func (ByQueueTime) Less

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

func (ByQueueTime) Swap

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

type CRClusterState

type CRClusterState struct {
	Time  int64
	Queue *CRQueue
	Nodes *CRNodeState
}

C for center ,R for ram.

func (*CRClusterState) GetNodes

func (c *CRClusterState) GetNodes() NodeState

func (*CRClusterState) GetQueue

func (c *CRClusterState) GetQueue() QueueState

func (*CRClusterState) GetTime

func (c *CRClusterState) GetTime() int64

func (*CRClusterState) SetTime

func (c *CRClusterState) SetTime(t int64)

func (*CRClusterState) SnapShot

func (c *CRClusterState) SnapShot() CRClusterStateSnapShot

type CRClusterStateSnapShot

type CRClusterStateSnapShot struct {
	Time           int64
	Queue          []Instance
	NodesInstances []Instance
	NodesMachines  []MachineBasicInfo
}

------------------ SnapShot define----------------

func (*CRClusterStateSnapShot) Recover

func (snap *CRClusterStateSnapShot) Recover() *CRClusterState

type CRNodeState

type CRNodeState struct {
	Instances map[InstanceKey]*Instance
	Machines  map[MachineID]*Machine
}

集群状态的实现 存储在内存的集中式数据库。 C for center ,R for ram.

func NewCRClusterState

func NewCRClusterState() *CRNodeState

func (*CRNodeState) AddMachine

func (state *CRNodeState) AddMachine(newMachine *Machine) error

func (*CRNodeState) GetAllocs

func (state *CRNodeState) GetAllocs() (machines []MachineBasicInfo)

func (*CRNodeState) GetUsage

func (state *CRNodeState) GetUsage()

func (*CRNodeState) IsInstanceExisted

func (state *CRNodeState) IsInstanceExisted(targetId InstanceKey) bool

func (*CRNodeState) IsMachineExisted

func (state *CRNodeState) IsMachineExisted(machineId MachineID) bool

func (*CRNodeState) RemoveInstance

func (state *CRNodeState) RemoveInstance(targetId InstanceKey) error

func (*CRNodeState) RemoveMachine

func (state *CRNodeState) RemoveMachine(machineId MachineID) error

func (*CRNodeState) ScduleInstance

func (state *CRNodeState) ScduleInstance(machineId MachineID, newInstance *Instance) error

func (*CRNodeState) UpdateInstanceRequest

func (state *CRNodeState) UpdateInstanceRequest(targetId InstanceKey, cpuReq, ramReq float64) error

func (*CRNodeState) UpdateMachineCapacity

func (state *CRNodeState) UpdateMachineCapacity(machineId MachineID, cpuCapacity, ramCapacity float64) error

type CRQueue

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

func InitCRQueue

func InitCRQueue(i []Instance) *CRQueue

func (*CRQueue) Add

func (q *CRQueue) Add(i Instance) error

func (*CRQueue) All

func (q *CRQueue) All() (instances []Instance)

func (*CRQueue) Get

func (q *CRQueue) Get(k InstanceKey) (Instance, error)

func (*CRQueue) IsExisted

func (q *CRQueue) IsExisted(k InstanceKey) bool

func (*CRQueue) Remove

func (q *CRQueue) Remove(k InstanceKey) error

type ClusterState

type ClusterState interface {
	SetTime(int64)
	GetTime() int64
	GetQueue() QueueState
	GetNodes() NodeState
}

func InitCRClusterState

func InitCRClusterState() ClusterState

type DataLoader

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

DataLoader is preprocessor of data and the provider of data it deal the csv data to the binary data and store the data as cache (powered by boltdb) it also provide the state and events of the cluster data

func NewDataLoader

func NewDataLoader(dataDir string, cacheDir string) *DataLoader

func (*DataLoader) AllMachineEvent

func (dl *DataLoader) AllMachineEvent() (res []MachineEvent, err error)

func (*DataLoader) GetInstanceEventBetween

func (dl *DataLoader) GetInstanceEventBetween(startHour, endHour int) (res []InstanceEvent, err error)

return the InstanceEvent between startHour to endHour ,for example startHour=8,endHour=10, then the function will return the event of 8 and 9 hour( not including 10)

func (*DataLoader) GetMachineEvent

func (dl *DataLoader) GetMachineEvent(startHour, endHour int) (res []MachineEvent, err error)

func (*DataLoader) InitialState

func (dl *DataLoader) InitialState(targetHour int) ClusterState

type Event

type Event struct {
	Time   int64
	Object EventObjectType
}

func (*Event) HappenTime

func (e *Event) HappenTime() int64

func (*Event) ObjectType

func (e *Event) ObjectType() EventObjectType

type EventObjectType

type EventObjectType uint8
const (
	E_MACHINE EventObjectType = iota
	E_INSTANCE
)

type EventTable

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

func NewEventTable

func NewEventTable(i []InstanceEvent, m []MachineEvent) (table *EventTable)

type IEvent

type IEvent interface {
	HappenTime() int64
	ObjectType() EventObjectType
}

type Instance

type Instance struct {
	InstanceId      InstanceKey
	QueueTime       int64 //进入队列的时间
	CpuRequest      float64
	RamRequest      float64
	AllocCollection int64
	MachineId       MachineID
}

type InstanceEvent

type InstanceEvent struct {
	Event
	Type          int64
	InstanceId    InstanceKey
	CpuRequest    float64
	RamRequest    float64
	MachineID     MachineID
	AllocID       int64
	ScheduleClass int64
	Priority      int64
}

func FileToInstanceEventList

func FileToInstanceEventList(fileName string) []InstanceEvent

type InstanceKey

type InstanceKey struct {
	CollectionId  int64
	InstanceIndex int64
}

type Machine

type Machine struct {
	MachineBasicInfo
	Instances map[InstanceKey]*Instance
}

func NewMachine

func NewMachine(id MachineID, cpuCap, ramCap float64) *Machine

func (*Machine) CalAlloc

func (m *Machine) CalAlloc() MachineBasicInfo

type MachineBasicInfo

type MachineBasicInfo struct {
	MachineId   MachineID
	CpuCapacity float64
	RamCapacity float64
	CpuAlloc    float64
	RamAlloc    float64
}

func (MachineBasicInfo) ToMachine

func (m_info MachineBasicInfo) ToMachine() *Machine

type MachineEvent

type MachineEvent struct {
	Event
	MachineId   MachineID
	Type        int64
	CpuCapacity float64
	RamCapacity float64
}

type MachineID

type MachineID int64

type NodeState

type NodeState interface {
	IsInstanceExisted(InstanceKey) bool
	IsMachineExisted(MachineID) bool

	AddMachine(*Machine) error
	RemoveMachine(MachineID) error
	ScduleInstance(MachineID, *Instance) error
	RemoveInstance(InstanceKey) error
	UpdateInstanceRequest(targetId InstanceKey, cpuReq, ramReq float64) error
	UpdateMachineCapacity(machineId MachineID, cpuCapacity, ramCapacity float64) error
	GetAllocs() []MachineBasicInfo
	GetUsage()
}

type QueueState

type QueueState interface {
	Add(i Instance) error
	Remove(i InstanceKey) error
	Get(i InstanceKey) (Instance, error)
	IsExisted(i InstanceKey) bool
	All() []Instance
}

-------------------- queue define-------------------

type SimState

type SimState string
const (
	STATE_notInit      SimState = "not initialized"
	STATE_initializing SimState = "initializing"
	STATE_ready        SimState = "ready"
	STATE_running      SimState = "running"
)

type Simulator

type Simulator struct {
	Flag      SimState
	DataPath  string
	CachePath string
	// contains filtered or unexported fields
}

func NewSimulator

func NewSimulator(dataPath string, cachePath string) *Simulator

func (*Simulator) GetMachineInfo

func (s *Simulator) GetMachineInfo() (res []MachineBasicInfo, err error)

func (*Simulator) GetQueueInfo

func (s *Simulator) GetQueueInfo() (res []Instance, err error)

func (*Simulator) GetTimeNow

func (s *Simulator) GetTimeNow() (time int64, err error)

func (*Simulator) Goto

func (s *Simulator) Goto(end int64) error

启动模拟器,使之运行到目标时间点

func (*Simulator) Init

func (s *Simulator) Init(startHour, endHour int) error

初始化模拟器状态, 向模拟器的主线程发送初始化命令,

func (*Simulator) Schdule

func (s *Simulator) Schdule(iID InstanceKey, mID MachineID) (err error)

type Timeline

type Timeline interface {
	IsEmpty() bool
	Insert(e IEvent) error
	OutFirst() (IEvent, error)
}

func InitTimeline

func InitTimeline(i []IEvent) Timeline

初始化一个Timeline,根据三种类型的事件

type UsageEvent

type UsageEvent struct {
	Event
	InstanceId InstanceKey
	CpuUsage   float64
	RamUsage   float64
	MachineID  int64
}

Jump to

Keyboard shortcuts

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