2019-03-04 09:19:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2019-04-16 08:59:19 +00:00
|
|
|
)
|
2019-03-04 09:19:55 +00:00
|
|
|
|
|
|
|
type ResourcePool struct {
|
|
|
|
mu sync.Mutex
|
|
|
|
|
2019-04-16 08:59:19 +00:00
|
|
|
nodes map[int]NodeStatus
|
2019-03-04 09:19:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:59:19 +00:00
|
|
|
func (pool *ResourcePool) update(node NodeStatus) {
|
2019-03-04 09:19:55 +00:00
|
|
|
pool.mu.Lock()
|
|
|
|
defer pool.mu.Unlock()
|
|
|
|
|
2019-03-20 03:14:07 +00:00
|
|
|
status, ok := pool.nodes[node.ClientID]
|
|
|
|
if ok {
|
2019-04-16 08:59:19 +00:00
|
|
|
for i, GPU := range status.Status {
|
|
|
|
if GPU.UUID == node.Status[i].UUID {
|
|
|
|
node.Status[i].MemoryAllocated = GPU.MemoryAllocated
|
2019-03-20 03:14:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-16 08:59:19 +00:00
|
|
|
pool.nodes[node.ClientID] = node
|
2019-03-20 03:14:07 +00:00
|
|
|
|
|
|
|
//log.Println(pool.nodes)
|
2019-03-04 09:19:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:59:19 +00:00
|
|
|
func (pool *ResourcePool) getByID(id int) NodeStatus {
|
2019-03-04 09:19:55 +00:00
|
|
|
pool.mu.Lock()
|
|
|
|
defer pool.mu.Unlock()
|
|
|
|
|
|
|
|
status, ok := pool.nodes[id]
|
|
|
|
if ok {
|
|
|
|
return status
|
|
|
|
}
|
2019-04-16 08:59:19 +00:00
|
|
|
return NodeStatus{}
|
2019-03-04 09:19:55 +00:00
|
|
|
}
|