Developing lightweight computation at the DSG edge

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

[monitor-assign] 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 f7f26ef1
......@@ -18,6 +18,11 @@ import (
"github.com/golang/glog"
)
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"
// The Timestamp struct contains a monitor's timestamp and a local timestamp
type Timestamps struct {
monitor int64
......@@ -103,6 +108,14 @@ func main() {
// The initialize() function manages the execution parameters, sets timers, etc.
func initialize() {
dbHostPtr := flag.String("db_host", dbHost, dbHostHelp )
dbPortPtr := flag.Int("db_port", dbPort, dbPortHelp )
flag.Parse()
dbHost = *dbHostPtr
dbPort = *dbPortPtr
fmt.Println("Initializing...")
// Manage command line flags and execution settings
......@@ -208,7 +221,7 @@ func readDevsaddsFile(filename string, errLevel int) []cnml.DeviceIpv4sGraphserv
// Get the global devices list from AntidoteDB
func getCnmlDevicesList() []cnml.DeviceIpv4sGraphserver {
return goclidote.ReadDevicesFromAntidote()
return goclidote.ReadDevicesFromAntidote(dbHost, dbPort)
}
//Import all the monitor=>device assignations
......@@ -216,11 +229,11 @@ func updateGlobalAssignationList() {
for _, v := range cnmlDevices {
if isDeviceInAssignationSlice(v.ID, globalAssign) {
globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors")
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.MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors")
newDev.MonitorID = goclidote.AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", dbHost, dbPort)
globalAssign = append(globalAssign, newDev)
}
}
......@@ -255,7 +268,7 @@ func manageMonitorsList() {
fmt.Println("I am monitor", ID)
// Fetch the current monitors list
currentMonitors := goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors")
currentMonitors := goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors", dbHost, dbPort)
fmt.Println(len(currentMonitors), "monitors registered in the database:")
var monitors = ""
for _, v := range currentMonitors {
......@@ -273,7 +286,7 @@ func manageMonitorsList() {
for _, v := range currentMonitors {
var thisMonitor MonitorTimestamp
mts, err := strconv.ParseInt(goclidote.AntidoteReadRegisterInBucket("guifi", fmt.Sprintf("%s_ts", v)), 10, 64)
mts, err := strconv.ParseInt(goclidote.AntidoteReadRegisterInBucket("guifi", fmt.Sprintf("%s_ts", v), dbHost, dbPort), 10, 64)
errCheck(err, WARNING, fmt.Sprintf("Unable to read the timestamp from Antidote for monitor %s", v))
thisMonitor.id = v
......@@ -360,11 +373,11 @@ func sanitizeAssignationsInDatabase() {
}
func getCurrentMonitorsList() []string {
return goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors")
return goclidote.AntidoteReadItemsFromSetInBucket("guifi", "monitors", dbHost, dbPort)
}
func unassignMonitorFromDevice(monitorID string, deviceID int) bool {
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", deviceID), "monitors", monitorID)
return goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", deviceID), "monitors", monitorID, dbHost, dbPort)
}
func reassignDevs() {
......@@ -438,7 +451,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)
goclidote.AntidoteAddItemToSetInBucket(fmt.Sprintf("device-%d", v.DeviceID), "monitors", ID, dbHost, dbPort)
}
}
}
......@@ -463,7 +476,7 @@ func reassignDevs() {
// if assgnchanges {
// localAssign = newlocalAssign
// for _, v := range deldevs {
// goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", ID)
// goclidote.AntidoteRemoveItemFromSetInBucket(fmt.Sprintf("device-%d", v.ID), "monitors", ID, dbHost, dbPort)
// }
// }
// }
......@@ -607,12 +620,12 @@ func startLocalAssignTimer() {
func registerMonitorInAntidote() {
updateMonitorTimestampInAntidote()
goclidote.AntidoteAddItemToSetInBucket("guifi", "monitors", ID)
goclidote.AntidoteAddItemToSetInBucket("guifi", "monitors", ID, dbHost, dbPort)
}
func updateMonitorTimestampInAntidote() {
timestamp := time.Now().Unix()
goclidote.AntidoteSetRegisterInBucket("guifi", IDts, fmt.Sprintf("%d", timestamp))
goclidote.AntidoteSetRegisterInBucket("guifi", IDts, fmt.Sprintf("%d", timestamp), dbHost, dbPort)
fmt.Println("Setting timestamp to", timestamp)
}
......@@ -621,7 +634,7 @@ func deregisterMonitorInAntidote(monitorID string) {
// Try up to 3 times
for i := 0; i < 3; i++ {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", monitorID) {
if goclidote.AntidoteRemoveItemFromSetInBucket("guifi", "monitors", monitorID, dbHost, dbPort) {
fmt.Println("Deregistration successful")
break
} else {
......@@ -629,7 +642,7 @@ func deregisterMonitorInAntidote(monitorID string) {
}
}
goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID))
goclidote.AntidoteRemoveRegisterInBucket("guifi", fmt.Sprintf("%s_ts", monitorID), dbHost, dbPort)
}
func errCheck(e error, level int, message string) {
......
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