Fix dependency injection issues in sliceanalysisms 75/112975/2 1.0.0-slice-analysis-ms
authordhebeha <dhebeha.mj71@wipro.com>
Tue, 22 Sep 2020 12:28:44 +0000 (17:58 +0530)
committerdhebeha <dhebeha.mj71@wipro.com>
Tue, 22 Sep 2020 13:35:32 +0000 (19:05 +0530)
Issue-ID: DCAEGEN2-2451
Signed-off-by: dhebeha <dhebeha.mj71@wipro.com>
Change-Id: I557c06f2e817ed8bdfe3b9c0540a19a8ceaaab52

components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java

index f04e86d..759706e 100644 (file)
@@ -65,6 +65,7 @@ public class Application {
                getConfig();
         log.info("Starting spring boot application");
                SpringApplication.run(Application.class, args);
+               MainThread.initiateThreads();
        }
        
     private static void getConfig() {
index 925a196..57a831e 100644 (file)
 
 package org.onap.slice.analysis.ms;
 
-import javax.annotation.PostConstruct;
-
-import org.onap.slice.analysis.ms.dmaap.NewPmNotification;
 import org.onap.slice.analysis.ms.service.ConsumerThread;
 import org.onap.slice.analysis.ms.service.PmThread;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
 
 /** 
  * This class starts the pm thread and consumer thread
  */
-@Component
 public class MainThread {
 
        private static Logger log = LoggerFactory.getLogger(MainThread.class);
-
-       @Autowired
-       private NewPmNotification newPmNotification;
-
-
+       
+       private MainThread() {
+               
+       }
+       
        /**
         * main thread initialization.
         */
-       @PostConstruct
-       public void init() {
-               log.debug("initializing main thread");
-               Thread pmThread = new Thread(new PmThread(newPmNotification));
+       public static void initiateThreads() {
+               log.debug("initializing Pm thread & Consumer thread");
+               Thread pmThread = new Thread(new PmThread());
                pmThread.start();
                Thread consumerThread = new Thread(new ConsumerThread());
                consumerThread.start();
index 488aca8..b3cd7b1 100644 (file)
@@ -25,13 +25,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.annotation.PostConstruct;
-
 import org.onap.slice.analysis.ms.models.Configuration;
 import org.onap.slice.analysis.ms.models.configdb.CellsModel;
 import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel;
 import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient;
-import org.onap.slice.analysis.ms.utils.BeanUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.ParameterizedTypeReference;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
@@ -43,15 +41,11 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class ConfigDbInterfaceService implements IConfigDbService {
-       
+
+       @Autowired
        private ConfigDbRestClient restclient;
        private String configDbBaseUrl = Configuration.getInstance().getConfigDbService();
-       
-       @PostConstruct
-       public void init() {
-               this.restclient = BeanUtil.getBean(ConfigDbRestClient.class);
-       }
-       
+
        /**
         *  Fetches the current configuration of an S-NSSAI from config DB
         */
@@ -64,7 +58,7 @@ public class ConfigDbInterfaceService implements IConfigDbService {
                responseMap=response.getBody();
                return responseMap;                     
        }
-       
+
        /**
         *  Fetches the current configuration of RIC from config DB
         */
@@ -74,7 +68,7 @@ public class ConfigDbInterfaceService implements IConfigDbService {
                });
                return response.getBody();
        }
-       
+
        /**
         *  Fetches all the network functions of an S-NSSAI from config DB
         */
@@ -88,32 +82,32 @@ public class ConfigDbInterfaceService implements IConfigDbService {
                }
                return responseList;
        }
-       
+
        /**
         *  Fetches the RICS of an S-NSSAI from config DB
         */
        public Map<String, List<String>> fetchRICsOfSnssai(String snssai){
-               
+
                Map<String,List<String>> responseMap=new HashMap<>();
-               
+
                String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-cell-list/"+snssai;
-               
+
                ResponseEntity<Map<String,List<CellsModel>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,List<CellsModel>>>() {
                });
 
-               
+
                for (Map.Entry<String, List<CellsModel>> entry : response.getBody().entrySet()) {
                        List<String> cellslist=new ArrayList<>();
                        for(CellsModel cellmodel:entry.getValue()) {
-                               
+
                                cellslist.add(cellmodel.getCellLocalId());
                        }
                        responseMap.put(entry.getKey(), cellslist);
                }
-               
+
                return responseMap;
        }
-       
+
        /**
         *  Fetches the details of a service 
         */
@@ -123,5 +117,5 @@ public class ConfigDbInterfaceService implements IConfigDbService {
                });
                return response.getBody();
        }       
-       
+
 }
index 08a8954..6e0f4f2 100644 (file)
@@ -21,8 +21,6 @@
 
 package org.onap.slice.analysis.ms.dmaap;
 
-import com.att.nsa.cambria.client.CambriaConsumer;
-
 import java.util.Map;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -34,8 +32,11 @@ import org.onap.slice.analysis.ms.models.Configuration;
 import org.onap.slice.analysis.ms.utils.DmaapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import com.att.nsa.cambria.client.CambriaConsumer;
+
 /**
  * This class initializes and starts the dmaap client 
  * to listen on application required dmaap events
@@ -47,6 +48,9 @@ public class DmaapClient {
     private static Logger log = LoggerFactory.getLogger(DmaapClient.class);
 
     private DmaapUtils dmaapUtils;
+    
+    @Autowired
+    private IntelligentSlicingCallback intelligentSlicingCallback;
 
     /**
      * init dmaap client.
@@ -113,7 +117,7 @@ public class DmaapClient {
                
                // create notification consumers for ML MS
                NotificationConsumer intelligentSlicingConsumer = new NotificationConsumer(intelligentSlicingCambriaConsumer,
-                               new IntelligentSlicingCallback());
+                               intelligentSlicingCallback);
                // start intelligent Slicing notification consumer threads
                executorPool = Executors.newScheduledThreadPool(10);
                executorPool.scheduleAtFixedRate(intelligentSlicingConsumer, 0, configuration.getPollingInterval(),
index dd6760b..b5d79ff 100644 (file)
@@ -25,8 +25,9 @@ import java.io.IOException;
 
 import org.onap.slice.analysis.ms.models.MLOutputModel;
 import org.onap.slice.analysis.ms.service.MLMessageProcessor;
-import org.onap.slice.analysis.ms.utils.BeanUtil;
 import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -34,14 +35,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 /**
  * Handles Notification on dmaap for ML ms events
  */
+@Component
 public class IntelligentSlicingCallback implements NotificationCallback {
        private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentSlicingCallback.class);
+       
+       @Autowired
        private MLMessageProcessor mlMsMessageProcessor;
 
-       public IntelligentSlicingCallback() {
-               mlMsMessageProcessor = BeanUtil.getBean(MLMessageProcessor.class);
-       }
-
        /**
         * Trigger on Notification from ML ms
         */
index bee7b30..84ff371 100644 (file)
@@ -24,15 +24,13 @@ package org.onap.slice.analysis.ms.service;
 import java.util.List;
 import java.util.Map;
 
-import javax.annotation.PostConstruct;
-
 import org.onap.slice.analysis.ms.configdb.IConfigDbService;
 import org.onap.slice.analysis.ms.models.CUModel;
 import org.onap.slice.analysis.ms.models.MLOutputModel;
 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
-import org.onap.slice.analysis.ms.utils.BeanUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
@@ -40,18 +38,15 @@ import org.springframework.stereotype.Component;
  * Process the message sent by ML service and sends notification to policy
  */
 @Component
-@Scope("Prototype")
+@Scope("prototype")
 public class MLMessageProcessor {
        private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class);
-
+       
+       @Autowired
        private IConfigDbService configDbService;
+       
+       @Autowired
        private PolicyService policyService;
-
-
-       @PostConstruct
-       public void init() {
-               configDbService = BeanUtil.getBean(IConfigDbService.class);
-       }
        
        public void processMLMsg(MLOutputModel mlOutputMsg) {
                String snssai = mlOutputMsg.getSnssai();
index d9091b3..d8bcbf6 100644 (file)
@@ -48,9 +48,9 @@ public class PmThread extends Thread {
        /**
         * parameterized constructor.
         */
-       public PmThread(NewPmNotification newPmNotification) {
+       public PmThread() {
                super();
-               this.newPmNotification = newPmNotification;
+               this.newPmNotification = BeanUtil.getBean(NewPmNotification.class);
                this.performanceNotificationsRepository = BeanUtil.getBean(PerformanceNotificationsRepository.class);
                this.pmEventProcessor = BeanUtil.getBean(IPmEventProcessor.class);
                this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class);
index 2e56190..16fb41a 100644 (file)
@@ -33,9 +33,9 @@ import org.onap.slice.analysis.ms.models.Configuration;
 import org.onap.slice.analysis.ms.models.MeasurementObject;
 import org.onap.slice.analysis.ms.models.SubCounter;
 import org.onap.slice.analysis.ms.models.policy.AdditionalProperties;
-import org.onap.slice.analysis.ms.utils.BeanUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
@@ -43,14 +43,22 @@ import org.springframework.stereotype.Component;
  * This class process the measurement data of an S-NSSAI
  */
 @Component
-@Scope("Prototype")
+@Scope("prototype")
 public class SnssaiSamplesProcessor {
        private static Logger log = LoggerFactory.getLogger(SnssaiSamplesProcessor.class);
 
+       @Autowired
        private PolicyService policyService;
+       
+       @Autowired
        private IConfigDbService configDbService;
+       
+       @Autowired
        private PmDataQueue pmDataQueue;
+       
+       @Autowired
        private AverageCalculator averageCalculator;
+       
        private List<MeasurementObject> snssaiMeasurementList = new ArrayList<>();
        private Map<String, List<String>> ricToCellMapping = new HashMap<>();
        private Map<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>();
@@ -71,10 +79,6 @@ public class SnssaiSamplesProcessor {
                prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice");
                prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice");
                minPercentageChange = configuration.getMinPercentageChange();
-               policyService = BeanUtil.getBean(PolicyService.class);
-               configDbService = BeanUtil.getBean(IConfigDbService.class);
-               pmDataQueue = BeanUtil.getBean(PmDataQueue.class);
-               averageCalculator = BeanUtil.getBean(AverageCalculator.class);
        }
 
        /**