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

include pnp in local deployment

parent 1b4a8200
Pipeline #299935 passed with stages
in 2 minutes and 34 seconds
......@@ -64,9 +64,5 @@ func task(ag *agency.Agent) (err error) {
time.Sleep(2 * time.Second)
id := ag.GetAgentID()
ag.Logger.NewLog("app", "This is agent "+strconv.Itoa(id), "")
msg, _ := ag.ACL.NewMessage((id+1)%2, 0, 0, "Message from agent "+strconv.Itoa(id))
ag.ACL.SendMessage(msg)
msg, _ = ag.ACL.RecvMessageWait()
ag.Logger.NewLog("app", msg.Content, "")
return
}
......@@ -45,9 +45,14 @@ THE SOFTWARE.
package main
import (
"fmt"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/plugnplay"
)
func main() {
plugnplay.StartPnP()
err := plugnplay.StartPnP()
if err != nil {
fmt.Println(err)
}
}
......@@ -256,6 +256,41 @@ func (stub *LocalStub) deleteDF() (err error) {
return
}
// createPnP starts a new PnP docker image
func (stub *LocalStub) createPnP() (err error) {
com := "docker run -d"
com += " --name=pnp"
com += " --hostname=pnp"
com += " --network=clonemap-net"
com += " -e CLONEMAP_DEPLOYMENT_TYPE=\"local\""
com += " -e CLONEMAP_LOG_LEVEL=\"info\""
com += " plugnplay"
cmd := exec.Command("bash", "-c", com)
cmdOut, err := cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
}
return
}
// deletePnP stops amd removes PnP docker image
func (stub *LocalStub) deletePnP() (err error) {
com := "docker stop pnp"
cmd := exec.Command("bash", "-c", com)
cmdOut, err := cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
return
}
com = "docker rm pnp"
cmd = exec.Command("bash", "-c", com)
cmdOut, err = cmd.Output()
if err != nil {
err = errors.New(err.Error() + " " + string(cmdOut))
}
return
}
// createMQTT starts a new MQTT Broker docker image
func (stub *LocalStub) createMQTT() (err error) {
com := "docker run -d"
......
......@@ -111,6 +111,12 @@ func StartLocalStub(fiware bool) {
fmt.Println(err)
return
}
fmt.Println("Create Plugnplay Container")
err = cntxt.createPnP()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Ready")
// catch kill signal in order to terminate MAP parts before exiting
......@@ -162,6 +168,12 @@ func (stub *LocalStub) terminate(gracefulStop chan os.Signal) {
fmt.Println(err)
os.Exit(0)
}
fmt.Println("Stop Plugnplay Container")
err = stub.deletePnP()
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println("Stop MQTT Broker Container")
err = stub.deleteMQTT()
if err != nil {
......
......@@ -52,6 +52,7 @@ import (
"io/ioutil"
"log"
"os"
"time"
)
// PnP implements the plug and play mechanism
......@@ -71,7 +72,9 @@ func StartPnP() (err error) {
}
// start to listen and serve requests
// err = pnp.listen()
return
for {
time.Sleep(time.Millisecond * 10)
}
}
// init initializes the storage.
......@@ -89,7 +92,10 @@ func (pnp *PnP) init() (err error) {
pnp.logInfo.Println("Starting Plug&Play")
pnp.mqttCli = newMQTTClient("mqtt", 1883, "pnp", pnp.logError, pnp.logInfo)
pnp.mqttCli.init()
err = pnp.mqttCli.init()
if err != nil {
return
}
err = pnp.mqttCli.subscribe("register", 0)
// storType := os.Getenv("CLONEMAP_STORAGE_TYPE")
......
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