Developing lightweight computation at the DSG edge

Commit 76ee86a8 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[fetch] Write devices' graphservers to AntidoteDB


Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent 7364fdec
......@@ -204,10 +204,14 @@ func main() {
antidoteAddDeviceFail := 0
antidoteAddAddressSuccess := 0
antidoteAddAddressFail := 0
antidoteAddGraphserverSuccess := 0
antidoteAddGraphserverFail := 0
antidoteDeleteDeviceSuccess := 0
antidoteDeleteDeviceFail := 0
antidoteDeleteAddressSuccess := 0
antidoteDeleteAddressFail := 0
antidoteDeleteGraphserverSuccess := 0
antidoteDeleteGraphserverFail := 0
// Remove from AntidoteDB those devices that are not in the CNML file anymore
for k, v := range antidoteDevices {
......@@ -220,6 +224,12 @@ func main() {
antidoteDeleteAddressFail++
}
}
//Remove the Graphserver
if removeGraphserverFromDeviceIpv4sGraphserver(v) {
antidoteDeleteGraphserverSuccess++
} else {
antidoteDeleteGraphserverFail++
}
// Remove the device from the list
if removeDeviceFromAntidote(v.ID) {
antidoteDeleteDeviceSuccess++
......@@ -244,14 +254,17 @@ func main() {
if k == 0 {
fmt.Printf("%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteDeviceSuccess+antidoteDeleteDeviceFail, antidoteDeleteDeviceSuccess, antidoteDeleteDeviceFail)
fmt.Printf("%d graphservers removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteGraphserverSuccess+antidoteDeleteGraphserverFail, antidoteDeleteGraphserverSuccess, antidoteDeleteGraphserverFail)
fmt.Printf("%d IPv4 addresses removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteAddressSuccess+antidoteDeleteAddressFail, antidoteDeleteAddressSuccess, antidoteDeleteAddressFail)
} else {
fmt.Printf("\033[2A\r%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteDeviceSuccess+antidoteDeleteDeviceFail, antidoteDeleteDeviceSuccess, antidoteDeleteDeviceFail)
fmt.Printf("\033[3A\r%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteDeviceSuccess+antidoteDeleteDeviceFail, antidoteDeleteDeviceSuccess, antidoteDeleteDeviceFail)
fmt.Printf("\r%d graphservers removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteGraphserverSuccess+antidoteDeleteGraphserverFail, antidoteDeleteGraphserverSuccess, antidoteDeleteGraphserverFail)
fmt.Printf("\r%d IPv4 addresses removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteAddressSuccess+antidoteDeleteAddressFail, antidoteDeleteAddressSuccess, antidoteDeleteAddressFail)
}
}
fmt.Printf("\033[2A\r%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteDeviceSuccess+antidoteDeleteDeviceFail, antidoteDeleteDeviceSuccess, antidoteDeleteDeviceFail)
fmt.Printf("\033[3A\r%d devices removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteDeviceSuccess+antidoteDeleteDeviceFail, antidoteDeleteDeviceSuccess, antidoteDeleteDeviceFail)
fmt.Printf("\r%d graphservers removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteGraphserverSuccess+antidoteDeleteGraphserverFail, antidoteDeleteGraphserverSuccess, antidoteDeleteGraphserverFail)
fmt.Printf("\r%d IPv4 addresses removed from AntidoteDB (%d success, %d fail)\n", antidoteDeleteAddressSuccess+antidoteDeleteAddressFail, antidoteDeleteAddressSuccess, antidoteDeleteAddressFail)
// Add to AntidoteDB those devices that are new in the CNML file
......@@ -268,25 +281,40 @@ func main() {
}
}
saveGraphserverFail := false
if !saveDevFail {
// Save the default graph server
if saveGraphserverToDeviceIpv4sGraphserverToAntidote(v) {
antidoteAddGraphserverSuccess++
} else {
antidoteAddGraphserverFail++
saveGraphserverFail = true
}
}
if !saveDevFail && !saveGraphserverFail {
// Iterate through all the device's addresses and add them if new
for _, w := range v.Addresses {
if saveIpv4addresToDeviceIpv4sGraphserverToAntidote(v, w) {
if saveIpv4addressToDeviceIpv4sGraphserverToAntidote(v, w) {
antidoteAddAddressSuccess++
} else {
antidoteAddAddressFail++
}
}
}
if k == 0 {
fmt.Printf("%d devices added to AntidoteDB (%d success, %d fail)\n", antidoteAddDeviceSuccess+antidoteAddDeviceFail, antidoteAddDeviceSuccess, antidoteAddDeviceFail)
fmt.Printf("%d graphservers added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddGraphserverSuccess+antidoteAddGraphserverFail, antidoteAddGraphserverSuccess, antidoteAddGraphserverFail)
fmt.Printf("%d IPv4 addresses added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddAddressSuccess+antidoteAddAddressFail, antidoteAddAddressSuccess, antidoteAddAddressFail)
} else {
fmt.Printf("\033[2A\r%d devices added to AntidoteDB (%d success, %d fail)\n", antidoteAddDeviceSuccess+antidoteAddDeviceFail, antidoteAddDeviceSuccess, antidoteAddDeviceFail)
fmt.Printf("\033[3A\r%d devices added to AntidoteDB (%d success, %d fail)\n", antidoteAddDeviceSuccess+antidoteAddDeviceFail, antidoteAddDeviceSuccess, antidoteAddDeviceFail)
fmt.Printf("\r%d graphservers added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddGraphserverSuccess+antidoteAddGraphserverFail, antidoteAddGraphserverSuccess, antidoteAddGraphserverFail)
fmt.Printf("\r%d IPv4 addresses added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddAddressSuccess+antidoteAddAddressFail, antidoteAddAddressSuccess, antidoteAddAddressFail)
}
}
fmt.Printf("\033[2A\r%d devices added to AntidoteDB (%d success, %d fail)\n", antidoteAddDeviceSuccess+antidoteAddDeviceFail, antidoteAddDeviceSuccess, antidoteAddDeviceFail)
fmt.Printf("\033[3A\r%d devices added to AntidoteDB (%d success, %d fail)\n", antidoteAddDeviceSuccess+antidoteAddDeviceFail, antidoteAddDeviceSuccess, antidoteAddDeviceFail)
fmt.Printf("\r%d graphservers added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddGraphserverSuccess+antidoteAddGraphserverFail, antidoteAddGraphserverSuccess, antidoteAddGraphserverFail)
fmt.Printf("\r%d IPv4 addresses added or updated to AntidoteDB (%d success, %d fail)\n", antidoteAddAddressSuccess+antidoteAddAddressFail, antidoteAddAddressSuccess, antidoteAddAddressFail)
if antidoteAddDeviceSuccess+antidoteAddDeviceFail == 0 {
......@@ -541,16 +569,25 @@ func saveIpv4addresToDeviceToAntidote(device cnml.DeviceIpv4Adddresses, address
}
// Save an IPv4 address to a device
func saveIpv4addresToDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver, address string) bool {
return apidote.AntidoteAddItemToSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), address)
func saveIpv4addressToDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver, address string) bool {
return apidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
}
// Save the GraphServer to a device
func saveGraphserverToDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver) bool {
return apidote.AntidoteSetRegisterInInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver", strconv.Itoa(device.GraphServer))
}
func removeGraphserverFromDeviceIpv4sGraphserver(device cnml.DeviceIpv4sGraphserver) bool {
return apidote.AntidoteRemoveRegisterInInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver")
}
func removeIpv4addressFromDeviceIpv4Adddresses(device cnml.DeviceIpv4Adddresses, address string) bool {
return apidote.AntidoteRemoveItemFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), address)
return apidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
}
func removeIpv4addressFromDeviceIpv4sGraphserver(device cnml.DeviceIpv4sGraphserver, address string) bool {
return apidote.AntidoteRemoveItemFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), address)
return apidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
}
// Check if an int item is in an ints array
......
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