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