-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
85 lines (64 loc) · 1.33 KB
/
cache.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package scheduler
type Cache struct {
nodes map[string]*nodeInfo
tasks map[string]*taskInfo
headNode *nodeInfo
}
type nodeInfo struct {
name string
tasks []*taskInfo
next *nodeInfo
prev *nodeInfo
allocatable *Resource
requested *Resource
}
type TaskStatus int
const (
Pending TaskStatus = iota
Running
Completed
Failed
)
type taskInfo struct {
name string
Requested *Resource
status TaskStatus
node *nodeInfo
}
func cacheCleaner() {
// todo: periodically clean up completed tasks
for {
}
}
func (c *Cache) AddNode(node *WorkerConfig) {
if _, ok := c.nodes[node.name]; ok {
c.DeleteNode(node.name)
}
nodeInfo := &nodeInfo{name: node.name, allocatable: node.resources, requested: &Resource{0, 0}, prev: c.headNode, next: c.headNode.next}
c.headNode.next = nodeInfo
nodeInfo.next.prev = nodeInfo
c.nodes[node.name] = nodeInfo
}
func (c *Cache) DeleteNode(node string) {
n, ok := c.nodes[node]
if !ok {
return
}
n.prev.next = n.next
n.next.prev = n.prev
delete(c.nodes, node)
}
func (c *Cache) AddTask(node string, task Task) {
name := task.Name()
n := c.nodes[node]
t := &taskInfo{
name: name,
Requested: task.Resource(),
node: n,
}
c.tasks[name] = t
n.tasks = append(n.tasks, t)
}
func (c *Cache) UpdateTaskStatus(task string, status TaskStatus) {
c.tasks[task].status = status
}