From 2d38a7a70549ad7f86f10464ab8c46346f37a443 Mon Sep 17 00:00:00 2001
From: Martin Stiemerling <martin.stiemerling@h-da.de>
Date: Fri, 25 Sep 2020 08:59:14 +0000
Subject: [PATCH] Develop gosdn cli t2

---
 cliInterface/gosdnCLI.proto | 13 +++++++++++++
 gosdn-cli/gosdn-cli.go      |  7 +++++++
 nucleus/nucleus-core.go     | 12 ++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/cliInterface/gosdnCLI.proto b/cliInterface/gosdnCLI.proto
index e53443f18..2139a3301 100644
--- a/cliInterface/gosdnCLI.proto
+++ b/cliInterface/gosdnCLI.proto
@@ -12,6 +12,8 @@ package cliInterface;
 service Greeter {
   // Sends a greeting
   rpc SayHello (HelloRequest) returns (HelloReply) {}
+  // Shutdown goSDN
+  rpc Shutdown (ShutdownRequest) returns (ShutdownReply) {}
 }
 
 // The request message containing the user's name.
@@ -23,3 +25,14 @@ message HelloRequest {
 message HelloReply {
   string message = 1;
 }
+
+// Request to shutdown goSDN
+message ShutdownRequest {
+  string name = 1;
+}
+
+// The response message containing some shutdown notes of goSDN
+message ShutdownReply {
+  string message = 1;
+}
+
diff --git a/gosdn-cli/gosdn-cli.go b/gosdn-cli/gosdn-cli.go
index bb3502200..1c15073d8 100644
--- a/gosdn-cli/gosdn-cli.go
+++ b/gosdn-cli/gosdn-cli.go
@@ -18,6 +18,7 @@ const (
 
 func main() {
 	// Set up a connection to the server.
+	address := "localhost:55055"
 	conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
 	if err != nil {
 		log.Fatalf("did not connect: %v", err)
@@ -37,4 +38,10 @@ func main() {
 		log.Fatalf("could not greet: %v", err)
 	}
 	log.Printf("Greeting: %s", r.GetMessage())
+
+	r2, err := c.Shutdown(ctx, &pb.ShutdownRequest{Name: name})
+	if err != nil {
+		log.Fatalf("could not greet: %v", err)
+	}
+	log.Printf("Greeting: %s", r2.GetMessage())
 }
diff --git a/nucleus/nucleus-core.go b/nucleus/nucleus-core.go
index 93d9bbe39..d07c6e28e 100644
--- a/nucleus/nucleus-core.go
+++ b/nucleus/nucleus-core.go
@@ -26,6 +26,13 @@ func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloRe
 	return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
 }
 
+func (s *server) Shutdown(ctx context.Context, in *pb.ShutdownRequest) (*pb.ShutdownReply, error) {
+	log.Printf("Received: %v", in.GetName())
+	isRunning = false
+	return &pb.ShutdownReply{Message: "Shutdown " + in.GetName()}, nil
+}
+
+
 func getCLIGoing() {
 	log.Println("Starting: GetCLIGoing")
 	// Boot-up the control interface for the cli
@@ -63,12 +70,13 @@ func StartUp() {
  * nucleus.Run() is the "main loop" of the controller
  */
 
+var isRunning = true
+
 func Run() {
-	isRunning := true
 
 	for isRunning {
 		time.Sleep(10 * time.Second)
-		isRunning = false
+		log.Println(("Still alive..."))
 	}
 
 	log.Println("Good bye....!")
-- 
GitLab