Developing lightweight computation at the DSG edge

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

[monitor-fetch] Add DB host and port to goclidote calls



The AntidoteDB host and port the application connects to now can be
specified as a paramenter.
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent a4648072
......@@ -25,6 +25,10 @@ var nodesFile = "nodes.json"
var nodesFileHelp = "Filename where the nodes list in JSON format will be saved"
var devicesFile = "devices.json"
var devicesFileHelp = "Filename where the devices list in JSON format will be saved"
var dbHost = "localhost"
var dbHostHelp = "The hostname or IP address where AntidoteDB is running"
var dbPort = 8087
var dbPortHelp = "The TCP port on which AntidoteDB is listening"
func initialize() {
......@@ -33,6 +37,8 @@ func initialize() {
outDirPtr := flag.String("out_dir", outDir, outDirHelp)
nodesFilePtr := flag.String("nodes_file", nodesFile, nodesFileHelp)
devicesFilePtr := flag.String("devices_file", devicesFile, devicesFileHelp)
dbHostPtr := flag.String("db_host", dbHost, dbHostHelp )
dbPortPtr := flag.Int("db_port", dbPort, dbPortHelp )
flag.Parse()
......@@ -40,6 +46,8 @@ func initialize() {
outDir = *outDirPtr
nodesFile = *nodesFilePtr
devicesFile = *devicesFilePtr
dbHost = *dbHostPtr
dbPort = *dbPortPtr
// Add a trailing slash to outDir, if missing
if outDir[len(outDir)-1:] != "/" {
......@@ -178,7 +186,7 @@ func main() {
fmt.Println(len(cnmlDevsIpv4sGraphs), "devices exported to", dasfile.Name())
// Read current AntidoteDB devices
antidoteDevices := goclidote.ReadDevicesFromAntidote()
antidoteDevices := goclidote.ReadDevicesFromAntidote(dbHost, dbPort)
var oldAntidoteDevices []cnml.DeviceIpv4sGraphserver
var keepAntidoteDevices []cnml.DeviceIpv4sGraphserver
......@@ -539,13 +547,13 @@ func getZonesInZoneExc(zone cnml.Zone) []cnml.Zone {
// Remove a device by its ID from Antidote using João's REST server
func removeDeviceFromAntidote(ID int) bool {
return goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "devices", strconv.Itoa(ID))
return goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "devices", strconv.Itoa(ID), dbHost, dbPort)
}
// Read all the devices from Antidote using João's REST server
func readDeviceIpv4AddressesFromAntidote(device cnml.DeviceIpv4Adddresses) cnml.DeviceIpv4Adddresses {
for _, v := range goclidote.AntidoteReadItemsFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID)) {
for _, v := range goclidote.AntidoteReadItemsFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), dbHost, dbPort) {
device.Addresses = append(device.Addresses, v)
}
......@@ -555,7 +563,7 @@ func readDeviceIpv4AddressesFromAntidote(device cnml.DeviceIpv4Adddresses) cnml.
// Read all the devices from Antidote using João's REST server
func readDeviceIpv4sGraphserverFromAntidote(device cnml.DeviceIpv4sGraphserver) cnml.DeviceIpv4sGraphserver {
for _, v := range goclidote.AntidoteReadItemsFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID)) {
for _, v := range goclidote.AntidoteReadItemsFromSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), dbHost, dbPort) {
device.Addresses = append(device.Addresses, v)
}
......@@ -564,39 +572,39 @@ func readDeviceIpv4sGraphserverFromAntidote(device cnml.DeviceIpv4sGraphserver)
// Save a device ID to Antidote using João's REST server
func saveDeviceToAntidote(device cnml.DeviceIpv4Adddresses) bool {
return goclidote.AntidoteAddItemToSetInBucket("guifi", "devices", fmt.Sprintf("%d", device.ID))
return goclidote.AntidoteAddItemToSetInBucket("guifi", "devices", fmt.Sprintf("%d", device.ID), dbHost, dbPort)
}
// Save a device ID to Antidote using João's REST server
func saveDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver) bool {
return goclidote.AntidoteAddItemToSetInBucket("guifi", "devices", fmt.Sprintf("%d", device.ID))
return goclidote.AntidoteAddItemToSetInBucket("guifi", "devices", fmt.Sprintf("%d", device.ID), dbHost, dbPort)
}
// Save an IPv4 address to a device
func saveIpv4addresToDeviceToAntidote(device cnml.DeviceIpv4Adddresses, address string) bool {
return goclidote.AntidoteAddItemToSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), address)
return goclidote.AntidoteAddItemToSetInBucket("guifi", fmt.Sprintf("device-%d", device.ID), address, dbHost, dbPort)
}
// Save an IPv4 address to a device
func saveIpv4addressToDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver, address string) bool {
return goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
return goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address, dbHost, dbPort)
}
// Save the GraphServer to a device
func saveGraphserverToDeviceIpv4sGraphserverToAntidote(device cnml.DeviceIpv4sGraphserver) bool {
return goclidote.AntidoteSetRegisterInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver", strconv.Itoa(device.GraphServer))
return goclidote.AntidoteSetRegisterInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver", strconv.Itoa(device.GraphServer), dbHost, dbPort)
}
func removeGraphserverFromDeviceIpv4sGraphserver(device cnml.DeviceIpv4sGraphserver) bool {
return goclidote.AntidoteRemoveRegisterInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver")
return goclidote.AntidoteRemoveRegisterInBucket(fmt.Sprintf("device-%d", device.ID), "graphserver", dbHost, dbPort)
}
func removeIpv4addressFromDeviceIpv4Adddresses(device cnml.DeviceIpv4Adddresses, address string) bool {
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address, dbHost, dbPort)
}
func removeIpv4addressFromDeviceIpv4sGraphserver(device cnml.DeviceIpv4sGraphserver, address string) bool {
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address)
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", device.ID), "ipv4s", address, dbHost, dbPort)
}
// Compare two arrays of strings
......
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