Added support for HTTP Proxy
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / tasks / ProducerSupervision.java
index 3b62fa7..b4c21d4 100644 (file)
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -21,7 +21,9 @@
 package org.oransc.enrichment.tasks;
 
 import org.oransc.enrichment.clients.AsyncRestClient;
+import org.oransc.enrichment.clients.AsyncRestClientFactory;
 import org.oransc.enrichment.configuration.ApplicationConfig;
+import org.oransc.enrichment.controllers.consumer.ConsumerCallbacks;
 import org.oransc.enrichment.repository.EiJobs;
 import org.oransc.enrichment.repository.EiProducer;
 import org.oransc.enrichment.repository.EiProducers;
@@ -45,17 +47,22 @@ import reactor.core.publisher.Mono;
 public class ProducerSupervision {
     private static final Logger logger = LoggerFactory.getLogger(ProducerSupervision.class);
 
-    @Autowired
-    ApplicationConfig applicationConfig;
-
-    @Autowired
-    EiProducers eiProducers;
-
-    @Autowired
-    EiJobs eiJobs;
+    private final EiProducers eiProducers;
+    private final EiJobs eiJobs;
+    private final EiTypes eiTypes;
+    private final AsyncRestClient restClient;
+    private final ConsumerCallbacks consumerCallbacks;
 
     @Autowired
-    EiTypes eiTypes;
+    public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs,
+        EiTypes eiTypes, ConsumerCallbacks consumerCallbacks) {
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig());
+        this.restClient = restClientFactory.createRestClientNoHttpProxy("");
+        this.eiJobs = eiJobs;
+        this.eiProducers = eiProducers;
+        this.eiTypes = eiTypes;
+        this.consumerCallbacks = consumerCallbacks;
+    }
 
     @Scheduled(fixedRate = 1000 * 60 * 5)
     public void checkAllProducers() {
@@ -69,7 +76,7 @@ public class ProducerSupervision {
     }
 
     private Mono<EiProducer> checkOneProducer(EiProducer producer) {
-        return restClient().get(producer.getProducerSupervisionCallbackUrl()) //
+        return restClient.get(producer.getProducerSupervisionCallbackUrl()) //
             .onErrorResume(throwable -> {
                 handleNonRespondingProducer(throwable, producer);
                 return Mono.empty();
@@ -83,6 +90,7 @@ public class ProducerSupervision {
         producer.setAliveStatus(false);
         if (producer.isDead()) {
             this.eiProducers.deregisterProducer(producer, this.eiTypes, this.eiJobs);
+            this.consumerCallbacks.notifyConsumersProducerDeleted(producer);
         }
     }
 
@@ -91,8 +99,4 @@ public class ProducerSupervision {
         producer.setAliveStatus(true);
     }
 
-    private AsyncRestClient restClient() {
-        return new AsyncRestClient("", this.applicationConfig.getWebClientConfig());
-    }
-
 }