aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2019-10-31 23:51:29 +0000
committerMarco Platania <platania@research.att.com>2019-11-04 14:02:09 +0000
commit68d118176bb53c36b31a7060cfa16ad5acac1765 (patch)
treec6dfd74445126f24e8d63457e33720fc5e0d38bb /vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go
parent68042495ef1e1e6dff7fed7fc2691b01cf672fe1 (diff)
HDFS-WriterApp-Fixed all the code review comments
Fixed all the code review comments by Kiran 1. Implemented a boolean channel instead of empty struct channel for signal, use WaitGroup to ensure all writers finish cleanup. 2. Introduce JSON tags for configs 4. remove all panic and fatalf code to ensure that the app doesnt crash anytime. 5. remove unneccessary hdfsWriter null checks. 6.remove the 'run' variable used in the infinite loop, replaced with 'return' Issue-ID: ONAPARC-453 Change-Id: Ic77c59dc75a8898a3cf34999850e6687d40e7faa Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com>
Diffstat (limited to 'vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go')
-rw-r--r--vnfs/DAaaS/microservices/GoApps/src/go-hdfs-writer/cmd/hdfs-writer/main.go20
1 files changed, 11 insertions, 9 deletions
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
index a79a3e06..4f3cfcbc 100644
--- 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
@@ -6,9 +6,9 @@ import (
"net/http"
"os"
"os/signal"
- "time"
handler "hdfs-writer/pkg/handler"
+ pipeline "hdfs-writer/pkg/pipeline"
utils "hdfs-writer/pkg/utils"
)
@@ -22,23 +22,24 @@ func main() {
Addr: ":9393",
}
- connectionsClose := make(chan struct{})
+ connectionsClose := make(chan bool)
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 {
+ for eachWriter, eachChannel := range pipeline.ChannelMap {
+ slogger.Info("Begin:: Closing writer goroutines::")
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)
+ delete(pipeline.ChannelMap, eachWriter)
+ eachChannel <- true
}
- //once all goroutines are signalled, send close to main thread
+
httpServer.Shutdown(context.Background())
+ /*once all goroutines are signalled and httpServer is shutdown,
+ send close to main thread */
+ connectionsClose <- true
close(connectionsClose)
}()
@@ -47,5 +48,6 @@ func main() {
if err != nil && err != http.ErrServerClosed {
slogger.Fatal(err)
}
+ pipeline.Wg.Wait()
<-connectionsClose //main thread waiting to receive close signal
}