Fix dependency injection issues in sliceanalysisms

Issue-ID: DCAEGEN2-2451
Signed-off-by: dhebeha <dhebeha.mj71@wipro.com>
Change-Id: I557c06f2e817ed8bdfe3b9c0540a19a8ceaaab52
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java
index f04e86d..759706e 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java
@@ -65,6 +65,7 @@
 		getConfig();
         log.info("Starting spring boot application");
 		SpringApplication.run(Application.class, args);
+		MainThread.initiateThreads();
 	}
 	
     private static void getConfig() {
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
index 925a196..57a831e 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java
@@ -21,35 +21,28 @@
 
 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();
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java
index 488aca8..b3cd7b1 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java
@@ -25,13 +25,11 @@
 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 @@
  */
 @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 @@
 		responseMap=response.getBody();
 		return responseMap;			
 	}
-	
+
 	/**
 	 *  Fetches the current configuration of RIC from config DB
 	 */
@@ -74,7 +68,7 @@
 		});
 		return response.getBody();
 	}
-	
+
 	/**
 	 *  Fetches all the network functions of an S-NSSAI from config DB
 	 */
@@ -88,32 +82,32 @@
 		}
 		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 @@
 		});
 		return response.getBody();
 	}	
-	
+
 }
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
index 08a8954..6e0f4f2 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java
@@ -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.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 @@
     private static Logger log = LoggerFactory.getLogger(DmaapClient.class);
 
     private DmaapUtils dmaapUtils;
+    
+    @Autowired
+    private IntelligentSlicingCallback intelligentSlicingCallback;
 
     /**
      * init dmaap client.
@@ -113,7 +117,7 @@
  		
 		// 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(),
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java
index dd6760b..b5d79ff 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java
@@ -25,8 +25,9 @@
 
 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 @@
 /**
  * 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
 	 */
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java
index bee7b30..84ff371 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java
@@ -24,15 +24,13 @@
 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 @@
  * 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();
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java
index d9091b3..d8bcbf6 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java
@@ -48,9 +48,9 @@
 	/**
 	 * 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);
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java
index 2e56190..16fb41a 100644
--- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java
+++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java
@@ -33,9 +33,9 @@
 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 @@
  * 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 @@
 		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);
 	}
 
 	/**