Commit ea342ae5 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

usage of fiware storage in local deployment

parent 4d1ead9c
Pipeline #272609 passed with stages
in 1 minute and 31 seconds
......@@ -46,9 +46,18 @@ THE SOFTWARE.
package main
import (
"os"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/kubestub"
)
func main() {
kubestub.StartLocalStub()
fiware := false
if len(os.Args) > 1 {
if os.Args[1] == "-fiware" {
fiware = true
}
}
kubestub.StartLocalStub(fiware)
}
......@@ -132,6 +132,9 @@ func (ams *AMS) init() (err error) {
}
ams.logInfo.Println("ectd storage")
ams.stor, err = newEtcdStorage(ams.logError)
case "fiware":
ams.logInfo.Println("FiWare storage")
ams.stor, err = newFiwareStorage(ams.logError)
default:
err = errors.New("Wrong storage type: " + storType)
}
......
......@@ -201,26 +201,18 @@ func (stor *fiwareStorage) getGroups(masID int) (ret schemas.ImageGroups, err er
return
}
// get all im entities
imEntities, err := stor.cli.GetAllEntitiesPattern("^mas"+strconv.Itoa(masID)+"im",
"clonemap")
for i := range imEntities {
ret.Counter++
imInfo := schemas.ImageGroupInfo{
ID: i,
}
attr, ok := imEntities[i].Attributes["config"]
if !ok {
err = errors.New("missing config attribute")
return
}
var conf schemas.ImageGroupConfig
err = extractAttributeValue(attr, &conf)
if err != nil {
return
}
imInfo.Config = conf
imInfo.Agencies, err = stor.getAgenciesGroup(masID, i)
// im counter
var imCounter int
imCounter, err = stor.getImCounter(masID)
if err != nil {
return
}
ret.Counter = imCounter
// im instances
for i := 0; i < imCounter; i++ {
var imInfo schemas.ImageGroupInfo
imInfo, err = stor.getGroupInfo(masID, i)
if err != nil {
return
}
......@@ -243,6 +235,7 @@ func (stor *fiwareStorage) getGroupInfo(masID int, imID int) (ret schemas.ImageG
err = errors.New("im does not exist")
return
}
ret.ID = imID
// get im entity
var imEnt orion.Entity
......
......@@ -51,6 +51,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"
)
// createBridge creates a new docker bridge network for MAP parts to connect to
......@@ -75,6 +76,63 @@ func (stub *LocalStub) deleteBridge() (err error) {
return
}
// createFiware starts orion and mongodb
func (stub *LocalStub) createFiware() (err error) {
com := "docker run -d -p 27017:27017 --name=mongodb --hostname=mongodb --network=clonemap-net " +
"-e ALLOW_EMPTY_PASSWORD=yes -e MONGODB_SYSTEM_LOG_VERBOSITY=3 -e MONGO_DATA_DIR=/data/db " +
"-e MONGO_LOG_DIR=/dev/null mongo:4.2 --bind_ip_all --quiet"
cmd := exec.Command("bash", "-c", com)
cmdOut, err := cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
com = "docker run -d -p 1026:1026 --name=orion --hostname=orion --network=clonemap-net " +
"fiware/orion-ld -dbhost mongodb -logForHumans"
// fmt.Println(com)
cmd = exec.Command("bash", "-c", com)
cmdOut, err = cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
time.Sleep(time.Second * 10)
return
}
// deleteFiware stops amd removes orion and mongodb
func (stub *LocalStub) deleteFiware() (err error) {
com := "docker stop orion"
cmd := exec.Command("bash", "-c", com)
cmdOut, err := cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
com = "docker rm orion"
cmd = exec.Command("bash", "-c", com)
cmdOut, err = cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
com = "docker stop mongodb"
cmd = exec.Command("bash", "-c", com)
cmdOut, err = cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
com = "docker rm mongodb"
cmd = exec.Command("bash", "-c", com)
cmdOut, err = cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
}
return
}
// createAMS starts a new AMS docker image
func (stub *LocalStub) createAMS() (err error) {
com := "ip route show | grep docker0 | awk '{print $9}'"
......@@ -91,7 +149,11 @@ func (stub *LocalStub) createAMS() (err error) {
com += " --hostname=ams"
com += " --network=clonemap-net"
com += " -e CLONEMAP_DEPLOYMENT_TYPE=\"local\""
com += " -e CLONEMAP_STORAGE_TYPE=\"local\""
if stub.fiware {
com += " -e CLONEMAP_STORAGE_TYPE=\"fiware\""
} else {
com += " -e CLONEMAP_STORAGE_TYPE=\"local\""
}
com += " -e CLONEMAP_SUFFIX=\".clonemap\""
com += " -e CLONEMAP_LOG_LEVEL=\"error\""
com += " ams"
......
......@@ -64,20 +64,29 @@ type LocalStub struct {
// list of all agencies; necessary in order to prevent from starting agencies with same name
// and to stop all agencies upon termination
agencies []schemas.StubAgencyConfig
fiware bool
}
// StartLocalStub starts the local stub. The AMS is started and a server for AMS interaction is
// created
func StartLocalStub() {
func StartLocalStub(fiware bool) {
var err error
// initialization
cntxt := &LocalStub{}
cntxt := &LocalStub{fiware: fiware}
fmt.Println("Create Bridge Network")
err = cntxt.createBridge()
if err != nil {
fmt.Println(err)
return
}
if fiware {
fmt.Println("Ceate Fiware Containers")
err = cntxt.createFiware()
if err != nil {
fmt.Println(err)
return
}
}
fmt.Println("Create AMS Container")
err = cntxt.createAMS()
if err != nil {
......@@ -159,6 +168,15 @@ func (stub *LocalStub) terminate(gracefulStop chan os.Signal) {
fmt.Println(err)
os.Exit(0)
}
if stub.fiware {
fmt.Println("Stop FIWARE Containers")
err = stub.deleteFiware()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
}
fmt.Println("Delete Bridge Network")
err = stub.deleteBridge()
if err != nil {
......
Supports Markdown
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