Developing lightweight computation at the DSG edge

Commit 6a7fd3d4 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Update to new DeviceMonitorAssignation structure

This commit adapts monitor-assign.go to cnml.go's changes as per commit
6aa0b8a2

.
Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent 903a8c95
......@@ -231,7 +231,8 @@ func updateGlobalAssignationList() {
globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", dbHost, dbPort)
} else {
var newDev cnml.DeviceMonitorAssignation
newDev.DeviceID = v.ID
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)
}
......@@ -239,8 +240,8 @@ func updateGlobalAssignationList() {
newglobalAssign := globalAssign
for _, v := range globalAssign {
if !isDeviceInSliceByID(v.DeviceID, cnmlDevices) {
rmDeviceFromAssignationList(v.DeviceID, newglobalAssign)
if !isDeviceInSliceByID(v.Device.ID, cnmlDevices) {
rmDeviceFromAssignationList(v.Device.ID, newglobalAssign)
}
}
}
......@@ -360,12 +361,12 @@ func sanitizeAssignationsInDatabase() {
for _, x := range currentMonitors {
if w == x {
monitorFound = true
fmt.Println(fmt.Sprintf("Monitor %s found, keeping it for device %d", w, v.DeviceID))
fmt.Println(fmt.Sprintf("Monitor %s found, keeping it for device %d", w, v.Device.ID))
}
}
if monitorFound == false {
fmt.Println(fmt.Sprintf("Monitor %s not found, unassigning it from device %d", w, v.DeviceID))
unassignMonitorFromDevice(w, v.DeviceID)
fmt.Println(fmt.Sprintf("Monitor %s not found, unassigning it from device %d", w, v.Device.ID))
unassignMonitorFromDevice(w, v.Device.ID)
}
}
}
......@@ -431,7 +432,8 @@ func reassignDevs() {
j := randsource.Intn(len(unassignedDevices))
//Save it to the assigned devices list
var newAssignDev cnml.DeviceMonitorAssignation
newAssignDev.DeviceID = unassignedDevices[j].ID
newAssignDev.Device.ID = unassignedDevices[j].ID
newAssignDev.Device.Addresses = unassignedDevices[j].Addresses
newAssignDev.MonitorID = append(newAssignDev.MonitorID, ID)
localAssign = append(localAssign, newAssignDev)
assgnchanges = true
......@@ -450,7 +452,7 @@ func reassignDevs() {
if assgnchanges {
fmt.Println("Exporting the new assigned devices list")
for _, v := range localAssign {
goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", v.DeviceID), "monitors", ID, dbHost, dbPort)
goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", v.Device.ID), "monitors", ID, dbHost, dbPort)
}
}
}
......@@ -536,7 +538,7 @@ func isDeviceInSliceByID(deviceID int, slice []cnml.DeviceIpv4sGraphserver) bool
func posDeviceInAssignationSlice(device int, slice []cnml.DeviceMonitorAssignation) int {
for k, v := range slice {
if device == v.DeviceID {
if device == v.Device.ID {
return k
}
}
......
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