Developing lightweight computation at the DSG edge

Commit 55b9dc7b authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Improve sanitization of the assignation list



Properly detect devices assigned to crashed or disappeared monitors and
unassign them.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 6d8a6292
...@@ -323,15 +323,59 @@ func manageMonitorsList() { ...@@ -323,15 +323,59 @@ func manageMonitorsList() {
globalTimestamps = nextGlobalTimestamps globalTimestamps = nextGlobalTimestamps
} }
// The sanitizeAssignationsInDatabase function gets the current list of monitors
// from the database, the current nodes<->monitors assignations, and sanitizes
// it (unassigns crashed monitors, etc.)
func sanitizeAssignationsInDatabase() {
fmt.Println("")
fmt.Println("Sanitizing the assignation list...")
// Update the current monitors list
currentMonitors := getCurrentMonitorsList()
// Update the current devices list
cnmlDevices = getCnmlDevicesList()
// Update the local copy of the global assignations list
updateGlobalAssignationList()
for _, v := range globalAssign {
// fmt.Println("############")
// fmt.Println(k, ": device ID:", v.DeviceID)
// fmt.Println("Monitors:", v.MonitorID)
for _, w := range v.MonitorID {
var monitorFound = false
for _, x := range currentMonitors {
if w == x {
monitorFound = true
fmt.Println(fmt.Sprintf("Monitor %s found, keeping it for device %d", w, v.DeviceID))
}
}
if monitorFound == false {
fmt.Println(fmt.Sprintf("Monitor %s not found, unassigning it from device %d", w, v.DeviceID))
unassignMonitorFromDevice(w, v.DeviceID)
}
}
}
}
func getCurrentMonitorsList() []string {
return goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors")
}
func unassignMonitorFromDevice(monitorID string, deviceID int) bool {
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", deviceID), "monitors", monitorID)
}
func reassignDevs() { func reassignDevs() {
fmt.Println("") fmt.Println("")
fmt.Println("Reassignation of devices") fmt.Println("Reassignation of devices")
fmt.Println(cnmlDevices)
fmt.Println(globalAssign)
fmt.Println(localAssign)
fmt.Println(len(localAssign), "devices currently assigned (maximum:", maxDevs, "devices)") fmt.Println(len(localAssign), "devices currently assigned (maximum:", maxDevs, "devices)")
// fmt.Println(cnmlDevices)
// fmt.Println(globalAssign)
// fmt.Println(localAssign)
// Update the CNML devices list from AntidoteDB // Update the CNML devices list from AntidoteDB
cnmlDevices = getCnmlDevicesList() cnmlDevices = getCnmlDevicesList()
...@@ -555,7 +599,8 @@ func startLocalAssignTimer() { ...@@ -555,7 +599,8 @@ func startLocalAssignTimer() {
for range localAssignTicker.C { for range localAssignTicker.C {
registerMonitorInAntidote() registerMonitorInAntidote()
manageMonitorsList() manageMonitorsList()
//reassignDevs() sanitizeAssignationsInDatabase()
reassignDevs()
} }
}() }()
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment