Developing lightweight computation at the DSG edge

Commit 29a98e83 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Merge functions



The manageMonitorsList() and sanitizeAssignationsInDatabase() functions are
now merged into sanitizeMonitorsAndDatabase().

To avoid some weird corner cases, first the devices are unassigned and then
the crashed monitor is removed from the list.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent c65d3b2f
......@@ -359,7 +359,11 @@ func mergeGlobalAssignIntoLocalAssign() {
}
}
func manageMonitorsList() {
// The sanitizeMonitorsAndDatabase function gets the current list of monitors
// from the database, the current nodes<->monitors assignations, and sanitizes
// it (unassigns crashed monitors, etc.)
func sanitizeMonitorsAndDatabase() {
fmt.Println("")
fmt.Println("Managing the monitors list...")
......@@ -393,6 +397,7 @@ func manageMonitorsList() {
}
var nextGlobalTimestamps []MonitorTimestamp
var monitorsToRemove []string
// Iterate the fetched timestamps list and process it
for _, v := range currentTimestamps {
......@@ -411,8 +416,7 @@ func manageMonitorsList() {
// The monitor is not updating its info to the database, check local timestamps
if v.timestamps.local-w.timestamps.local > monitorTimeout {
// Deregister the monitor
fmt.Println("Deregistering crashed monitor", v.id)
deregisterMonitorInAntidote(v.id)
monitorsToRemove = append(monitorsToRemove, v.id)
} else {
nextGlobalTimestamps = append(nextGlobalTimestamps, w)
}
......@@ -430,36 +434,25 @@ func manageMonitorsList() {
}
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...")
// TODO: This list of monitors should be the same as the one just asked for
// in the manageMonitors function. Try to minimize calls by doing it only once
// Update the current monitors list
fmt.Println("Getting the current monitors list...")
currentMonitors := getCurrentMonitorsList()
// Update the current devices list
fmt.Println("Updating the current cnml...")
cnmlDevices = getCnmlDevicesList()
for _, v := range globalAssign {
// fmt.Println("############")
// fmt.Println(k, ": device ID:", v.Device.ID)
// 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.Device.ID))
}
}
for _, x := range monitorsToRemove {
if w == x {
monitorFound = false
}
}
if monitorFound == false {
......@@ -469,6 +462,11 @@ func sanitizeAssignationsInDatabase() {
}
}
fmt.Println("Ended assignation list sanitization...")
for _, v := range monitorsToRemove {
fmt.Println("Deregistering crashed monitor", v)
deregisterMonitorInAntidote(v)
}
}
func getCurrentMonitorsList() []string {
......@@ -758,11 +756,8 @@ func startAssignTimer() {
// Do the actual reassignation of devices to this monitor
reassignDevs()
// Manage the monitors list
manageMonitorsList()
// Sanitize the global assignations in the shared database
sanitizeAssignationsInDatabase()
// Sanitize the monitors and their global assignations in the database
sanitizeMonitorsAndDatabase()
}
}()
}
......@@ -801,16 +796,18 @@ func updateMonitorMaxDevsInAntidote() {
func deregisterMonitorInAntidote(monitorID string) {
// Try up to 3 times
for i := 0; i < 3; i++ {
var retry = 3
for i := 0; i < retry; i++ {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", monitorID, dbHost, dbPort) {
fmt.Println("Deregistration successful")
break
} else {
fmt.Println("Deregistration unsuccessful")
fmt.Println("The monitor has been successfully deregistered.")
return
}
if i < retry-1 {
fmt.Println("Retrying...")
}
}
goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID), dbHost, dbPort)
fmt.Println("An error occurred while deregistering the monitor.")
}
func calculateGlobalAverageLoad() float64 {
......
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