Skip to content
Snippets Groups Projects
Commit fc971085 authored by Martin Stiemerling's avatar Martin Stiemerling
Browse files

addresses issue #27 and move to channels for starting the shutdown

parent 44e6c9ba
Branches
Tags
1 merge request!18Develop
Pipeline #52156 passed
......@@ -17,10 +17,12 @@ func main() {
cliSocket := *cliListenAddr + ":" + *cliListenPort
log.Loglevel(log.DEBUG)
// Setup a channel to communicate if goSDN should shutdown.
IsRunningChannel := make(chan bool)
// hand off to cmd for further processing
nucleus.StartUp(cliSocket, *configFileName)
log.Info("Startup completed")
nucleus.Run()
nucleus.StartAndRun(cliSocket, *configFileName, IsRunningChannel)
// nothing to see here, please move on!
}
......@@ -28,8 +28,8 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
}
func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) {
log.Info("Received: %v", in.GetName())
isRunning = false
log.Info("Shutdown Received: %v", in.GetName())
s.core.IsRunning <- false
return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil
}
......
......@@ -23,9 +23,10 @@ type Core struct {
clients map[string]interfaces.Client
database database.Database
config controllerConfig
IsRunning chan bool
}
func (c *Core) Init(socket, configfile string) {
func (c *Core) Init(socket, configfile string, IsRunningChannel chan bool) {
if configfile == "" {
configfile = "gosdn.toml"
}
......@@ -47,8 +48,11 @@ func (c *Core) Init(socket, configfile string) {
c.AttachDatabase()
c.IsRunning = IsRunningChannel
//TODO: Create client config/CLI adapter
c.clients["ciena-mcp"] = ciena.NewMCPClient("141.100.70.170", "", "", &c.database)
}
func (c *Core) AttachDatabase() {
......@@ -56,6 +60,15 @@ func (c *Core) AttachDatabase() {
}
func (c *Core) Shutdown() {
stopIt := <- c.IsRunning
if(stopIt == false) {
log.Debug("Shutdown() received action to shutdown")
}else {
log.Debug("Shutdown() received something else.")
}
f, err := os.Create(c.config.ConfigPath)
if err != nil {
log.Fatal(err)
......@@ -64,4 +77,6 @@ func (c *Core) Shutdown() {
if err := enc.Encode(c.config); err != nil {
log.Fatal(err)
}
os.Exit(0)
}
......@@ -11,32 +11,24 @@ import (
* This function is used to start the core of the controller and any auxiliary services.
*/
// Next-up: backend database.
func StartUp(socket, filename string) {
func StartAndRun(socket, filename string, IsRunningChannel chan bool) {
log.Info("This is the network superintendent...")
log.Info("Starting my ducks")
// Init the Core
core := Core{
clients: make(map[string]interfaces.Client),
database: database.Database{},
}
core.Init(socket, filename)
core.Init(socket, filename, IsRunningChannel)
// Start the GRCP CLI
go getCLIGoing(&core)
log.Info("and ready for take off")
}
go core.Shutdown()
/*
* nucleus.Run() is the "main loop" of the controller
*/
var isRunning = true
func Run() {
log.Info("and ready for take off")
for isRunning {
//Just to produce some signs of vitality...
for (true) {
time.Sleep(10 * time.Second)
log.Debug("Still alive...")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment