Developing lightweight computation at the DSG edge

Commit 74917e3f authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[assign] AntidoteDB interaction (WiP)



 - Get global assignation list from AntidoteDB
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 0ce77862
......@@ -122,7 +122,7 @@ func initialize() {
setCurrentAllDevsChecksum()
//Import the global devices assignation lists
updateGlobalImportAllAssignFiles()
updateGlobalAssignationList()
initializeTimers()
......@@ -394,6 +394,30 @@ func updateGlobalImportAllAssignFiles() {
}
}
//Import all the monitor=>device assignations
func updateGlobalAssignationList() {
// Update alldevs
allDevs = apidote.ReadDevicesFromAntidote()
for _, v := range allDevs {
if isDeviceInAssignationSlice(v.ID, globalAssign) {
globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID = apidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "mo")
} else {
var newDev cnml.DeviceMonitorAssignation
newDev.DeviceID = v.ID
globalAssign = append(globalAssign, newDev)
}
}
newglobalAssign := globalAssign
for _, v := range globalAssign {
if !isDeviceInSliceByID(v.DeviceID, allDevs) {
rmDeviceFromAssignationList(v.DeviceID, newglobalAssign)
}
}
}
func assignDeviceMonitor(assgnlist []cnml.DeviceMonitorAssignation, deviceID int, monitorID string) []cnml.DeviceMonitorAssignation {
if !isDeviceInAssignationSlice(deviceID, assgnlist) {
var nassgn cnml.DeviceMonitorAssignation
......@@ -526,6 +550,15 @@ func posDeviceInSlice(device cnml.DeviceIpv4sGraphserver, slice []cnml.DeviceIpv
return -1
}
func posDeviceInSliceByID(deviceID int, slice []cnml.DeviceIpv4sGraphserver) int {
for k, v := range slice {
if deviceID == v.ID {
return k
}
}
return -1
}
func isDeviceInSlice(device cnml.DeviceIpv4sGraphserver, slice []cnml.DeviceIpv4sGraphserver) bool {
if posDeviceInSlice(device, slice) >= 0 {
return true
......@@ -534,6 +567,14 @@ func isDeviceInSlice(device cnml.DeviceIpv4sGraphserver, slice []cnml.DeviceIpv4
return false
}
func isDeviceInSliceByID(deviceID int, slice []cnml.DeviceIpv4sGraphserver) bool {
if posDeviceInSliceByID(deviceID, slice) >= 0 {
return true
}
return false
}
func posDeviceInAssignationSlice(device int, slice []cnml.DeviceMonitorAssignation) int {
for k, v := range slice {
if device == v.DeviceID {
......@@ -576,6 +617,16 @@ func rmDeviceFromSlice(device cnml.DeviceIpv4sGraphserver, slice []cnml.DeviceIp
return slice
}
func rmDeviceFromAssignationList(DeviceID int, slice []cnml.DeviceMonitorAssignation) []cnml.DeviceMonitorAssignation {
if isDeviceInAssignationSlice(DeviceID, slice) {
pos := posDeviceInAssignationSlice(DeviceID, slice)
return append(slice[:pos], slice[pos+1:]...)
}
return slice
}
func startAllDevsChecksumTimer() {
allDevsChecksumTicker := time.NewTicker(time.Duration(devsCheckInterval) * time.Second)
go func() {
......@@ -589,7 +640,7 @@ func startGlobalAssignTimer() {
globalAssignTicker := time.NewTicker(time.Duration(globalAssignCheckInterval) * time.Second)
go func() {
for range globalAssignTicker.C {
updateGlobalImportAllAssignFiles()
updateGlobalAssignationList()
}
}()
}
......
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