Use retry when calling DMaaP and ECS
Issue-ID: NONRTRIC-617
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: I43b0a3e8d7ebb439a22154b0246af5b05342af27
diff --git a/dmaap-mediator-producer/main.go b/dmaap-mediator-producer/main.go
index beeb995..1a91af4 100644
--- a/dmaap-mediator-producer/main.go
+++ b/dmaap-mediator-producer/main.go
@@ -26,6 +26,7 @@
"sync"
"time"
+ "github.com/hashicorp/go-retryablehttp"
log "github.com/sirupsen/logrus"
"oransc.org/nonrtric/dmaapmediatorproducer/internal/config"
"oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs"
@@ -33,11 +34,12 @@
"oransc.org/nonrtric/dmaapmediatorproducer/internal/server"
)
-const timeoutHTTPClient = time.Second * 5
-const timeoutPollClient = time.Second * 15
+const timeoutDistributionClient = time.Second * 5
+const retryWaitMax = time.Minute
+const retryMax = int(^uint(0) >> 1)
var configuration *config.Config
-var httpClient restclient.HTTPClient
+var retryClient restclient.HTTPClient
var jobHandler *jobs.JobHandlerImpl
func init() {
@@ -52,13 +54,16 @@
}
callbackAddress := fmt.Sprintf("%v:%v", configuration.InfoProducerHost, configuration.InfoProducerPort)
- httpClient = &http.Client{
- Timeout: timeoutHTTPClient,
+ distributionClient := &http.Client{
+ Timeout: timeoutDistributionClient,
}
- pollClient := &http.Client{
- Timeout: timeoutPollClient,
- }
- jobHandler = jobs.NewJobHandlerImpl("configs/type_config.json", pollClient, httpClient)
+
+ rawRetryClient := retryablehttp.NewClient()
+ rawRetryClient.RetryWaitMax = retryWaitMax
+ rawRetryClient.RetryMax = retryMax
+ retryClient = rawRetryClient.StandardClient()
+
+ jobHandler = jobs.NewJobHandlerImpl("configs/type_config.json", retryClient, distributionClient)
if err := registerTypesAndProducer(jobHandler, configuration.InfoCoordinatorAddress, callbackAddress); err != nil {
log.Fatalf("Stopping producer due to: %v", err)
}
@@ -94,7 +99,7 @@
}
func registerTypesAndProducer(jobHandler jobs.JobTypeHandler, infoCoordinatorAddress string, callbackAddress string) error {
- registrator := config.NewRegistratorImpl(infoCoordinatorAddress, httpClient)
+ registrator := config.NewRegistratorImpl(infoCoordinatorAddress, retryClient)
if types, err := jobHandler.GetTypes(); err == nil {
if regErr := registrator.RegisterTypes(types); regErr != nil {
return fmt.Errorf("unable to register all types due to: %v", regErr)