Developing lightweight computation at the DSG edge

Commit bec044df authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Deregister crashed monitors from the DB



Now monitors check for other [crashed] and remove them from the DB after a timeout
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent f9c66144
......@@ -18,6 +18,18 @@ import (
"github.com/golang/glog"
)
// The Timestamp struct contains a monitor's timestamp and a local timestamp
type Timestamps struct {
monitor int64
local int64
}
// The MonitorTimestamp struct contains a monitor's id and timestamps
type MonitorTimestamp struct {
id string
timestamps Timestamps
}
// Error levels
// FATAL output code
......@@ -63,6 +75,7 @@ var cnmlDevices []cnml.DeviceIpv4sGraphserver //The global list with all the
var cnmlDevicesChecksum string //The checksum of the last global devices list and IPv4 addresses fetched
var localAssign []cnml.DeviceMonitorAssignation //The list of locally assigned devices and their IPv4 addresses
var globalAssign []cnml.DeviceMonitorAssignation //The global assignation list of devices<=>monitors
var globalTimestamps []MonitorTimestamp
func main() {
//Initialize the service (read the configuration flags, etc.)
......@@ -234,8 +247,74 @@ func updateLocalAssignationList() {
localAssign = newlocalAssign
}
func manageMonitorsList() {
fmt.Println("Managing the monitors list...")
// Move the current monitors list to a temporary variable
// var oldTimestamps []MonitorTimestamp
// oldTimestamps = globalTimestamps
// Fetch the current monitors list
currentMonitors := goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors")
fmt.Println(len(currentMonitors), "monitors registered in the database")
// Create an array and store the timestamps fetched from the database
var currentTimestamps []MonitorTimestamp
for _, v := range currentMonitors {
var thisMonitor MonitorTimestamp
mts, err := strconv.ParseInt(goclidote.AntidoteReadRegisterInBucket("guifi", fmt.Sprintf("%s_ts", v)), 10, 64)
errCheck(err, WARNING, fmt.Sprintf("Unable to read the timestamp from Antidote for monitor %s", v))
thisMonitor.id = v
thisMonitor.timestamps.monitor = mts
thisMonitor.timestamps.local = time.Now().Unix()
currentTimestamps = append(currentTimestamps, thisMonitor)
}
var nextGlobalTimestamps []MonitorTimestamp
// Iterate the fetched timestamps list and process it
for k, v := range currentTimestamps {
var knownMonitor = false
// Look for the matching monitor
for l, w := range globalTimestamps {
fmt.Println("##################################")
fmt.Println(k, l, v, w)
if v.id == w.id {
knownMonitor = true
// Check if the timestamps are the same
if v.timestamps.monitor == w.timestamps.monitor {
// The monitor is not updating its info to the database, check local timestamps
if v.timestamps.local-w.timestamps.local > 15 {
// Deregister the monitor
goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", v.id)
} else {
nextGlobalTimestamps = append(nextGlobalTimestamps, w)
}
// The monitor is updating its info to the database, keep the latest info
} else {
nextGlobalTimestamps = append(nextGlobalTimestamps, v)
}
}
}
// This monitor is new, save it for the next iteration
if knownMonitor == false {
nextGlobalTimestamps = append(nextGlobalTimestamps, v)
}
}
globalTimestamps = nextGlobalTimestamps
}
func reassignDevs() {
fmt.Println("\nReassignation of devices")
fmt.Println("")
fmt.Println("Reassignation of devices")
fmt.Println(cnmlDevices)
fmt.Println(globalAssign)
fmt.Println(localAssign)
......@@ -464,7 +543,8 @@ func startLocalAssignTimer() {
go func() {
for range localAssignTicker.C {
updateMonitorTimestampInAntidote()
reassignDevs()
manageMonitorsList()
//reassignDevs()
}
}()
}
......@@ -481,7 +561,17 @@ func updateMonitorTimestampInAntidote() {
}
func deregisterMonitorInAntidote() {
goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID)
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) {
fmt.Println("Deregistration successful")
} else {
fmt.Println("Deregistration unsuccessful")
}
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", ID) {
fmt.Println("Deregistration successful")
} else {
fmt.Println("Deregistration unsuccessful")
}
goclidote.AntidoteRemoveRegisterInBucket("guifi", IDts)
}
......
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