VOL-3433 Make timeouts of inter-adapter communication configurable

Change-Id: I3944737701546203262f95ffeb563716ff540c8a
diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go
index 0e446a9..7d6c4e4 100644
--- a/internal/pkg/config/config.go
+++ b/internal/pkg/config/config.go
@@ -53,9 +53,10 @@
 	// defaultHearbeatFailReportInterval is the time adapter will wait before updating the state to the core.
 	defaultHearbeatFailReportInterval = 180 * time.Second
 	//defaultKafkaReconnectRetries -1: reconnect endlessly.
-	defaultKafkaReconnectRetries = -1
-	defaultCurrentReplica        = 1
-	defaultTotalReplicas         = 1
+	defaultKafkaReconnectRetries      = -1
+	defaultCurrentReplica             = 1
+	defaultTotalReplicas              = 1
+	defaultMaxTimeoutInterAdapterComm = 30 * time.Second
 )
 
 // AdapterFlags represents the set of configurations used by the read-write adaptercore service
@@ -87,6 +88,7 @@
 	KafkaReconnectRetries       int
 	CurrentReplica              int
 	TotalReplicas               int
+	MaxTimeoutInterAdapterComm  time.Duration
 }
 
 // NewAdapterFlags returns a new RWCore config
@@ -118,6 +120,7 @@
 		KafkaReconnectRetries:       defaultKafkaReconnectRetries,
 		CurrentReplica:              defaultCurrentReplica,
 		TotalReplicas:               defaultTotalReplicas,
+		MaxTimeoutInterAdapterComm:  defaultMaxTimeoutInterAdapterComm,
 	}
 	return &adapterFlags
 }
@@ -200,6 +203,10 @@
 	help = "Total number of instances for this adapter"
 	flag.IntVar(&(so.TotalReplicas), "total_replica", defaultTotalReplicas, help)
 
+	help = fmt.Sprintf("Maximum Number of seconds for the default interadapter communication timeout")
+	flag.DurationVar(&(so.MaxTimeoutInterAdapterComm), "max_timeout_interadapter_comm",
+		defaultMaxTimeoutInterAdapterComm, help)
+
 	flag.Parse()
 	containerName := getContainerInfo()
 	if len(containerName) > 0 {
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index ee8e1b3..2951a2f 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -318,7 +318,7 @@
 
 		// deadline context to ensure completion of background routines waited for
 		//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
-		deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution
+		deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 		dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 		dh.pOnuTP.resetTpProcessingErrorIndication()
@@ -374,7 +374,7 @@
 
 	if bTpModify := pDevEntry.updateOnuUniTpPath(uniID, ""); bTpModify {
 		// deadline context to ensure completion of background routines waited for
-		deadline := time.Now().Add(10 * time.Second) //allowed run time to finish before execution
+		deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 		dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 		dh.pOnuTP.resetTpProcessingErrorIndication()
@@ -430,7 +430,7 @@
 
 	if bTpModify := pDevEntry.updateOnuUniTpPath(uniID, ""); bTpModify {
 		// deadline context to ensure completion of background routines waited for
-		deadline := time.Now().Add(10 * time.Second) //allowed run time to finish before execution
+		deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 		dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 		dh.pOnuTP.resetTpProcessingErrorIndication()
@@ -634,7 +634,7 @@
 	for _, uniData := range pDevEntry.sOnuPersistentData.PersUniConfig {
 		// deadline context to ensure completion of background routines waited for
 		//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
-		deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution
+		deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 		dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 		dh.pOnuTP.resetTpProcessingErrorIndication()
@@ -703,7 +703,7 @@
 
 	// deadline context to ensure completion of background routines waited for
 	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
-	deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution
+	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 	dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 	pDevEntry.resetKvProcessingErrorIndication()
@@ -2061,7 +2061,7 @@
 
 	// deadline context to ensure completion of background routines waited for
 	//20200721: 10s proved to be less in 8*8 ONU test on local vbox machine with debug, might be further adapted
-	deadline := time.Now().Add(30 * time.Second) //allowed run time to finish before execution
+	deadline := time.Now().Add(dh.pOpenOnuAc.maxTimeoutInterAdapterComm) //allowed run time to finish before execution
 	dctx, cancel := context.WithDeadline(context.Background(), deadline)
 
 	pDevEntry.resetKvProcessingErrorIndication()
diff --git a/internal/pkg/onuadaptercore/openonu.go b/internal/pkg/onuadaptercore/openonu.go
index b1994d7..7ad98f0 100644
--- a/internal/pkg/onuadaptercore/openonu.go
+++ b/internal/pkg/onuadaptercore/openonu.go
@@ -54,8 +54,9 @@
 	HeartbeatFailReportInterval time.Duration
 	AcceptIncrementalEvto       bool
 	//GrpcTimeoutInterval         time.Duration
-	lockDeviceHandlersMap sync.RWMutex
-	pSupportedFsms        *OmciDeviceFsms
+	lockDeviceHandlersMap      sync.RWMutex
+	pSupportedFsms             *OmciDeviceFsms
+	maxTimeoutInterAdapterComm time.Duration
 }
 
 //NewOpenONUAC returns a new instance of OpenONU_AC
@@ -79,6 +80,7 @@
 	openOnuAc.HeartbeatCheckInterval = cfg.HeartbeatCheckInterval
 	openOnuAc.HeartbeatFailReportInterval = cfg.HeartbeatFailReportInterval
 	openOnuAc.AcceptIncrementalEvto = cfg.AccIncrEvto
+	openOnuAc.maxTimeoutInterAdapterComm = cfg.MaxTimeoutInterAdapterComm
 	//openOnuAc.GrpcTimeoutInterval = cfg.GrpcTimeoutInterval
 	openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}