forked from pfnet-research/k8s-cluster-simulator
/
types.go
60 lines (49 loc) · 984 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package jobparser
import (
"fmt"
"sort"
"time"
)
type PodMemory struct {
Name string
Records []Record
StartAt time.Time
EndAt time.Time
IsMigratingToNode string
isMigrating bool
}
func (p PodMemory) IsMigrating() bool {
return p.isMigrating
}
func (p *PodMemory) FinishedMigration() {
p.isMigrating = false
}
func (p *PodMemory) StartMigration() {
p.isMigrating = true
}
type Record struct {
Time time.Time
Usage int64
}
func GetJob(name string,jobs []PodMemory) *PodMemory {
for i, _ := range jobs {
if jobs[i].Name == name {
return &jobs[i]
}
}
return nil
}
func SortPodMemoriesByTime(podMemory []PodMemory) {
sort.Slice(podMemory, func(i, j int) bool {
return podMemory[i].StartAt.Before(podMemory[j].StartAt)
})
}
func SetStartTime(pod *PodMemory) error {
for _, record := range pod.Records {
if record.Usage != 0. {
pod.StartAt = record.Time
return nil
}
}
return fmt.Errorf("no start time found for pod %s", pod.Name)
}