From 99f7370360201104ddfc99b5e766b4e32e8524cc Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Tue, 15 Oct 2019 00:48:18 +0000 Subject: HDFSWriter microservice working copy Issue-ID: ONAPARC-453 Signed-off-by: Rajamohan Raj Change-Id: I11c91b642e466763c1ca6f5734bf81fb260e2b39 --- .../src/go-hdfs-writer/cmd/hdfs-writer/main.go | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go (limited to 'vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer') diff --git a/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go b/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go new file mode 100644 index 00000000..a79a3e06 --- /dev/null +++ b/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "context" + "fmt" + "net/http" + "os" + "os/signal" + "time" + + handler "hdfs-writer/pkg/handler" + utils "hdfs-writer/pkg/utils" +) + +func main() { + + slogger := utils.GetLoggerInstance() + + // Create the server + httpServer := &http.Server{ + Handler: handler.CreateRouter(), + Addr: ":9393", + } + + connectionsClose := make(chan struct{}) + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + <-c // function literal waiting to receive Interrupt signal + fmt.Printf(":::Got the kill signal:::") + slogger.Info(":::Got the kill signal:::") + for eachWriter, eachChannel := range handler.ChannelMap { + slogger.Infof("Closing writer goroutine :: %s", eachWriter) + slogger.Infof("eachChannel:: %v", eachChannel) + close(eachChannel) + // This wait time ensures that the each of the channel is killed before + // main routine finishes. + time.Sleep(time.Second * 5) + } + //once all goroutines are signalled, send close to main thread + httpServer.Shutdown(context.Background()) + close(connectionsClose) + }() + + // Sever starts listening + err := httpServer.ListenAndServe() + if err != nil && err != http.ErrServerClosed { + slogger.Fatal(err) + } + <-connectionsClose //main thread waiting to receive close signal +} -- cgit