X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=vnfs%2FDAaaS%2Fmicroservices%2FGoApps%2Fsrc%2Fgo-hdfs-writer%2Fcmd%2Fhdfs-writer%2Fmain.go;fp=vnfs%2FDAaaS%2Fmicroservices%2FGoApps%2Fsrc%2Fgo-hdfs-writer%2Fcmd%2Fhdfs-writer%2Fmain.go;h=a79a3e060d6d9d30459c70cdc6bbeed197eec48b;hb=99f7370360201104ddfc99b5e766b4e32e8524cc;hp=0000000000000000000000000000000000000000;hpb=3289af42fd3af32fd07c565d072c65743249ebce;p=demo.git 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 +}