Developing lightweight computation at the DSG edge

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

[monitor-assign] Update function updateGlobalAssignationList()



There is no concurrent operation in globalAssign anymore.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent b4b6cabb
......@@ -201,25 +201,39 @@ func getCnmlDevicesList() []cnml.DeviceIpv4sGraphserver {
//Import all the monitor=>device assignations
func updateGlobalAssignationList() {
fmt.Println("Updating globalAssign...")
var newDevices []cnml.DeviceMonitorAssignation
for _, v := range cnmlDevices {
if isDeviceInAssignationSlice(v.ID, globalAssign) {
// We already know this device; update its monitors assignation from AntidoteDB
globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", dbHost, dbPort)
} else {
// A new device from the cnmlDevices list; let's add it to our global assignation list
fmt.Printf("Adding device %d from cnmlDevices into globalAssign\n", v.ID)
var newDev cnml.DeviceMonitorAssignation
newDev.Device.ID = v.ID
newDev.Device.Addresses = v.Addresses
newDev.MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", dbHost, dbPort)
globalAssign = append(globalAssign, newDev)
newDevices = append(newDevices, newDev)
}
}
newglobalAssign := globalAssign
// Append the new devices to the globalAssign list
for _, v := range newDevices {
globalAssign = append(globalAssign, v)
}
// The globalAssign list may contain old devices, not in the CNML anymore; discard them
newDevices = nil
for _, v := range globalAssign {
if !isDeviceInSliceByID(v.Device.ID, cnmlDevices) {
rmDeviceFromAssignationList(v.Device.ID, newglobalAssign)
if isDeviceInSliceByID(v.Device.ID, cnmlDevices) {
newDevices = append(newDevices, v)
}
}
globalAssign = newDevices
fmt.Println("globalAssign updated!")
}
func updateLocalAssignationList() {
......
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