Developing lightweight computation at the DSG edge

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

[goclidote] Add DB host and port to functions' arguments



The applications using these functions can now specify which AntidoteDB
instance they connect to.
Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parent f60c16d0
......@@ -11,10 +11,10 @@ import (
)
// DatabaseHost defines the host of the AntidoteDB instance to connect to is running
var DatabaseHost = "localhost"
// var DatabaseHost = "localhost"
// DatabasePort defines the port of the host where the AntidoteDB instance to connect to is running
var DatabasePort = 8087
// var DatabasePort = 8087
// Error levels
......@@ -31,7 +31,7 @@ var WARNING = 3
var INFO = 4
// AntidoteAddItemToSetInBucket save an item to a set in a bucket
func AntidoteAddItemToSetInBucket(bucketName string, setName string, itemValue string) bool {
func AntidoteAddItemToSetInBucket(bucketName string, setName string, itemValue string, DatabaseHost string, DatabasePort int) bool {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteAddItemToSetInBucket]: Unable to create a new AntidoteDB go client")
......@@ -64,7 +64,7 @@ func AntidoteAddItemToSetInBucket(bucketName string, setName string, itemValue s
}
// AntidoteReadRegisterInBucket read a LWWW register in a bucket
func AntidoteReadRegisterInBucket(bucketName string, registerName string) string {
func AntidoteReadRegisterInBucket(bucketName string, registerName string, DatabaseHost string, DatabasePort int) string {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteReadRegisterInBucket]: Unable to create a new AntidoteDB go client")
......@@ -86,7 +86,7 @@ func AntidoteReadRegisterInBucket(bucketName string, registerName string) string
}
// AntidoteSetRegisterInBucket set a LWWW register in a bucket
func AntidoteSetRegisterInBucket(bucketName string, registerName string, itemValue string) bool {
func AntidoteSetRegisterInBucket(bucketName string, registerName string, itemValue string, DatabaseHost string, DatabasePort int) bool {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteSetRegisterInBucket]: Unable to create a new AntidoteDB go client")
......@@ -117,7 +117,7 @@ func AntidoteSetRegisterInBucket(bucketName string, registerName string, itemVal
}
// AntidoteRemoveRegisterInBucket remove (set null) a LWWW register in a bucket
func AntidoteRemoveRegisterInBucket(bucketName string, registerName string) bool {
func AntidoteRemoveRegisterInBucket(bucketName string, registerName string, DatabaseHost string, DatabasePort int) bool {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteRemoveRegisterInBucket]: Unable to create a new AntidoteDB go client")
......@@ -148,7 +148,7 @@ func AntidoteRemoveRegisterInBucket(bucketName string, registerName string) bool
}
// AntidoteReadItemsFromSetInBucket read items from a set in a bucket
func AntidoteReadItemsFromSetInBucket(bucketName string, setName string) []string {
func AntidoteReadItemsFromSetInBucket(bucketName string, setName string, DatabaseHost string, DatabasePort int) []string {
var items []string
......@@ -176,7 +176,7 @@ func AntidoteReadItemsFromSetInBucket(bucketName string, setName string) []strin
}
// AntidoteRemoveItemFromSetInBucket removes an item from a set in a bucket
func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemValue string) bool {
func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemValue string, DatabaseHost string, DatabasePort int) bool {
client, err := antidoteclient.NewClient(antidoteclient.Host{Name: DatabaseHost, Port: DatabasePort})
errCheck(err, ERROR, "[AntidoteRemoveItemFromSetInBucket]: Unable to create a new AntidoteDB go client")
......@@ -211,19 +211,19 @@ func AntidoteRemoveItemFromSetInBucket(bucketName string, setName string, itemVa
}
// ReadDevicesFromAntidote read all the devices from Antidote using the Go client
func ReadDevicesFromAntidote() []cnml.DeviceIpv4sGraphserver {
func ReadDevicesFromAntidote(DatabaseHost string, DatabasePort int) []cnml.DeviceIpv4sGraphserver {
var devices []cnml.DeviceIpv4sGraphserver
for _, v := range AntidoteReadItemsFromSetInBucket("guifi", "devices") {
for _, v := range AntidoteReadItemsFromSetInBucket("guifi", "devices", DatabaseHost, DatabasePort) {
thisDevID, err := strconv.Atoi(v)
errCheck(err, WARNING, fmt.Sprintf("[ReadDevicesFromAntidote]: An error occurred when converting %s to int", v))
var thisDev cnml.DeviceIpv4sGraphserver
thisDev.ID = thisDevID
thisDev.GraphServer, err = strconv.Atoi(AntidoteReadRegisterInBucket(fmt.Sprintf("device-%d", thisDevID), "graphserver"))
thisDev.GraphServer, err = strconv.Atoi(AntidoteReadRegisterInBucket(fmt.Sprintf("device-%d", thisDevID), "graphserver", DatabaseHost, DatabasePort))
if err != nil {
thisDev.GraphServer = 0
}
thisDev.Addresses = AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", thisDevID), "ipv4s")
thisDev.Addresses = AntidoteReadItemsFromSetInBucket(fmt.Sprintf("device-%d", thisDevID), "ipv4s", DatabaseHost, DatabasePort)
devices = append(devices, thisDev)
}
......
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