diff options
author | dhebeha <dhebeha.mj71@wipro.com> | 2020-10-13 21:24:08 +0530 |
---|---|---|
committer | Vijay Venkatesh Kumar <vv770d@att.com> | 2020-10-29 15:51:08 +0000 |
commit | d62189b6e58dae52beec4a7324b8c4954c54f734 (patch) | |
tree | fd7ee41364619a83cfbefee6fd0df20dd7acaa2d | |
parent | 282c334df41f73d2afbc22a3abc5e665f046e7d0 (diff) |
Fix Issues7.0.0-ONAPguilin
- Fix certificate issue for authenticated topic
- Fix consumer thread issue
Issue-ID: DCAEGEN2-2485
Signed-off-by: dhebeha <dhebeha.mj71@wipro.com>
Change-Id: I91fe9b1b86579da7142955ac7adaa25ac4bc22e9
(cherry picked from commit fadaccdb8396a178134ef95982e96ed8a5cddc26)
22 files changed, 245 insertions, 125 deletions
diff --git a/components/slice-analysis-ms/entry.sh b/components/slice-analysis-ms/entry.sh new file mode 100644 index 00000000..2859fe93 --- /dev/null +++ b/components/slice-analysis-ms/entry.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export trustpass=`cat /opt/app/sliceanalysisms/etc/cert/trust.pass` +java -Djavax.net.ssl.trustStore=/opt/app/sliceanalysisms/etc/cert/trust.jks -Djavax.net.ssl.trustStorePassword=$trustpass -jar /bin/application.jar
\ No newline at end of file diff --git a/components/slice-analysis-ms/pom.xml b/components/slice-analysis-ms/pom.xml index 08028404..1eac47fe 100644 --- a/components/slice-analysis-ms/pom.xml +++ b/components/slice-analysis-ms/pom.xml @@ -32,7 +32,7 @@ <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>slice-analysis-ms</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.1-SNAPSHOT</version> <name>dcaegen2-services-slice-analysis-ms</name> <description>Network slice PM analyser</description> <packaging>jar</packaging> @@ -313,17 +313,23 @@ <directory>${project.build.directory}</directory> <include>${project.artifactId}-${project.version}.jar</include> </resource> + <resource> + <targetPath>/bin</targetPath> + <directory>${project.basedir}</directory> + <include>entry.sh</include> + </resource> </resources> <runs> <!-- Maven is loosing file permissions during artifacts copy --> <run>adduser --disabled-password sliceanalysis </run> <run>mv /bin/*.jar /bin/application.jar</run> <run>chmod -R 777 /bin</run> + <run>chmod +x /bin/entry.sh</run> </runs> <exposes> <expose>8080</expose> </exposes> - <entryPoint>java -jar /bin/application.jar</entryPoint> + <entryPoint>./bin/entry.sh</entryPoint> </configuration> </plugin> </plugins> 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 759706e4..2ecaf7e4 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 @@ -22,13 +22,6 @@ package org.onap.slice.analysis.ms; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - import java.io.BufferedReader; import java.io.FileReader; import java.lang.reflect.Type; @@ -42,9 +35,16 @@ import org.onap.slice.analysis.ms.models.ConfigPolicy; import org.onap.slice.analysis.ms.models.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.web.client.RestTemplate; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; /** * @@ -121,6 +121,11 @@ public class Application { return DataSourceBuilder.create().url(url).username(configuration.getPgUsername()) .password(configuration.getPgPassword()).build(); } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } private static String readFromFile(String file) { String content = ""; 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 b3cd7b1c..8a11bdb5 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 @@ -62,9 +62,9 @@ public class ConfigDbInterfaceService implements IConfigDbService { /** * Fetches the current configuration of RIC from config DB */ - public Map<String,Map<String,Integer>> fetchCurrentConfigurationOfRIC(String snssai){ + public Map<String,Map<String,Object>> fetchCurrentConfigurationOfRIC(String snssai){ String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/slice-config/"+snssai; - ResponseEntity<Map<String,Map<String,Integer>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,Map<String,Integer>>>() { + ResponseEntity<Map<String,Map<String,Object>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,Map<String,Object>>>() { }); return response.getBody(); } @@ -87,24 +87,18 @@ public class ConfigDbInterfaceService implements IConfigDbService { * 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>>>() { + 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; } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java index 3c8a9f8a..7413c181 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java @@ -34,6 +34,6 @@ public interface IConfigDbService { public Map<String, List<String>> fetchRICsOfSnssai(String snssai); public List<String> fetchNetworkFunctionsOfSnssai(String snssai); public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai); - public Map<String, Map<String,Integer>> fetchCurrentConfigurationOfRIC(String snssai); + public Map<String, Map<String,Object>> fetchCurrentConfigurationOfRIC(String snssai); public Map<String ,String> fetchServiceDetails(String snssai); } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java index 25a80463..8bdbb1a8 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java @@ -260,6 +260,9 @@ public class Configuration { minPercentageChange = jsonObject.get("sliceanalysisms.minPercentageChange").getAsInt(); initialDelaySeconds = jsonObject.get("sliceanalysisms.initialDelaySeconds").getAsLong(); + aafUsername = jsonObject.get("aafUsername").getAsString(); + aafPassword = jsonObject.get("aafPassword").getAsString(); + log.info("configuration from CBS {}", this); } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java index 047c9856..b94d75da 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java @@ -22,6 +22,7 @@ package org.onap.slice.analysis.ms.models; +import java.util.List; import java.util.Map; /** @@ -31,6 +32,17 @@ public class MeasurementObject { private String measurementObjectId; private Map<String, Integer> pmData; + public static int findIndex(String measurementObjectId, List<MeasurementObject> list) { + int index = -1; + int len = list.size(); + for(int i=0; i<len ; i++) { + if(measurementObjectId.equals(list.get(i).getMeasurementObjectId())) { + index = i; + } + } + return index; + } + public String getMeasurementObjectId() { return measurementObjectId; } @@ -67,9 +79,10 @@ public class MeasurementObject { final int prime = 31; int result = 1; result = prime * result + ((measurementObjectId == null) ? 0 : measurementObjectId.hashCode()); + result = prime * result + ((pmData == null) ? 0 : pmData.hashCode()); return result; } - + @Override public boolean equals(Object obj) { if (this == obj) @@ -84,6 +97,11 @@ public class MeasurementObject { return false; } else if (!measurementObjectId.equals(other.measurementObjectId)) return false; + if (pmData == null) { + if (other.pmData != null) + return false; + } else if (!pmData.equals(other.pmData)) + return false; return true; } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java index 5946fd1d..65de9838 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java @@ -21,8 +21,8 @@ package org.onap.slice.analysis.ms.restclients; -import org.onap.slice.analysis.ms.utils.BeanUtil; import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -40,7 +40,9 @@ public class RestClient { private static final String EXCEPTION_MSG = "Exception caught during request {}"; private static final Logger log = org.slf4j.LoggerFactory.getLogger(RestClient.class); - + + @Autowired + private RestTemplate restTemplate; protected RestClient() { } @@ -53,7 +55,6 @@ public class RestClient { ParameterizedTypeReference<T> responseType) { HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); try { - RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); } catch (Exception e) { log.debug(EXCEPTION_MSG, e.getMessage()); @@ -68,7 +69,6 @@ public class RestClient { public <T> ResponseEntity<T> sendGetRequest(HttpHeaders headers, String requestUrl, ParameterizedTypeReference<T> responseType) { HttpEntity<Void> requestEntity = new HttpEntity<>(headers); try { - RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); return restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, responseType); } catch (Exception e) { log.debug(EXCEPTION_MSG, e.getMessage()); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java index a003e9c0..52670d53 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java @@ -50,19 +50,22 @@ public class AverageCalculator { * Find average of samples */ public List<MeasurementObject> findAverageOfSamples(List<List<MeasurementObject>> samples) { + log.debug("find average for samples {}", samples); int numOfSamples = samples.size(); List<MeasurementObject> result = new ArrayList<>(); - samples.forEach(sample -> - sample.forEach(cellMeasObj -> { - int index = result.indexOf(cellMeasObj); - if(index != -1) { - result.set(index, findSum(result.get(index), cellMeasObj)); + if(!samples.isEmpty()) { + for(List<MeasurementObject> sample : samples) { + for(MeasurementObject cellMeasObj : sample) { + int index = MeasurementObject.findIndex(cellMeasObj.getMeasurementObjectId(), result); + if(index != -1) { + result.set(index, findSum(result.get(index), cellMeasObj)); + } + else { + result.add(cellMeasObj); + } + } } - else { - result.add(cellMeasObj); - } - }) - ); + } return findAvg(result, numOfSamples); } @@ -81,13 +84,15 @@ public class AverageCalculator { * Calculate the average */ public List<MeasurementObject> findAvg(List<MeasurementObject> result, int numOfSamples) { - result.forEach(cellMeasObj -> - pmNames.forEach(pmName -> { - int value = (cellMeasObj.getPmData().get(pmName))/numOfSamples; - cellMeasObj.getPmData().put(pmName, value); - }) - ); - log.debug("Average of measurement data samples {}",result); + if(!result.isEmpty()) { + result.forEach(cellMeasObj -> + pmNames.forEach(pmName -> { + int value = (cellMeasObj.getPmData().get(pmName))/numOfSamples; + cellMeasObj.getPmData().put(pmName, value); + }) + ); + log.debug("Average of measurement data samples {}",result); + } return result; } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java index 39235cd5..6868bc46 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java @@ -21,6 +21,8 @@ package org.onap.slice.analysis.ms.service; +import java.util.List; + import org.onap.slice.analysis.ms.configdb.IConfigDbService; import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.utils.BeanUtil; @@ -31,7 +33,7 @@ import org.slf4j.LoggerFactory; * This Thread class consumes message from pm data queue and sends onset message to policy */ public class ConsumerThread extends Thread { - private static Logger log = LoggerFactory.getLogger(PmThread.class); + private static Logger log = LoggerFactory.getLogger(ConsumerThread.class); private PmDataQueue pmDataQueue; private IConfigDbService configDbService; private SnssaiSamplesProcessor snssaiSamplesProcessor; @@ -55,16 +57,31 @@ public class ConsumerThread extends Thread { public void run() { boolean done = false; String snssai = ""; + boolean result = false; + List<String> nfs = null; while (!done) { try { Thread.sleep(initialDelaySec); snssai = pmDataQueue.getSnnsaiFromQueue(); if (!snssai.equals("")) { - log.info("Consumer thread started for s-nssai {}",snssai); - snssaiSamplesProcessor.processSamplesOfSnnsai(snssai, configDbService.fetchNetworkFunctionsOfSnssai(snssai)); + log.info("Consumer thread processing data for s-nssai {}",snssai); + try { + nfs = configDbService.fetchNetworkFunctionsOfSnssai(snssai); + } + catch(Exception e) { + pmDataQueue.putSnssaiToQueue(snssai); + log.error("Exception caught while fetching nfs of snssai {}, {}", snssai, e.getMessage()); + } + if(nfs != null) { + result = snssaiSamplesProcessor.processSamplesOfSnnsai(snssai, nfs); + if(!result) { + log.info("Not enough samples to process for {}",snssai); + pmDataQueue.putSnssaiToQueue(snssai); + } + } } } catch (Exception e) { - log.error("Exception in Consumer Thread ", e); + log.error("Exception in Consumer Thread, {}", e.getMessage()); done = true; } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java index d907bfed..4f196979 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java @@ -31,6 +31,8 @@ import java.util.concurrent.LinkedBlockingQueue; import org.onap.slice.analysis.ms.models.MeasurementObject; import org.onap.slice.analysis.ms.models.SubCounter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; /** @@ -38,6 +40,8 @@ import org.springframework.stereotype.Component; */ @Component public class PmDataQueue { + private static Logger log = LoggerFactory.getLogger(PmDataQueue.class); + private Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMap = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>()); private Queue<String> snssaiList = new LinkedBlockingQueue<>(); @@ -54,6 +58,7 @@ public class PmDataQueue { measQueue.add(measurementObjectData); subCounterMap.put(subCounter, measQueue); } + log.debug("Queue: {}", subCounterMap); } /** @@ -61,12 +66,15 @@ public class PmDataQueue { * returns the specified number of samples */ public List<List<MeasurementObject>> getSamplesFromQueue(SubCounter subCounter, int samples) { - List<List<MeasurementObject>> sampleList = new LinkedList<>(); + List<List<MeasurementObject>> sampleList = null; if (subCounterMap.containsKey(subCounter)){ Queue<List<MeasurementObject>> measQueue = subCounterMap.get(subCounter); - while(samples > 0) { - sampleList.add(measQueue.remove()); - samples --; + if(measQueue.size() >= samples) { + sampleList = new LinkedList<>(); + while(samples > 0) { + sampleList.add(measQueue.remove()); + samples --; + } } } return sampleList; @@ -86,10 +94,12 @@ public class PmDataQueue { public String getSnnsaiFromQueue() { String snssai = ""; try { - snssai = snssaiList.remove(); + if(!snssaiList.isEmpty()){ + snssai = snssaiList.remove(); + } } catch(Exception e) { - + log.error("Problem fetching from the Queue, {}", e.getMessage()); } return snssai; } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java index 99c24c8a..51a04660 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java @@ -31,6 +31,8 @@ import org.onap.slice.analysis.ms.models.pmnotification.Event; import org.onap.slice.analysis.ms.models.pmnotification.MeasInfoList; import org.onap.slice.analysis.ms.models.pmnotification.MeasResult; import org.onap.slice.analysis.ms.models.pmnotification.MeasValuesList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @@ -41,7 +43,7 @@ import org.springframework.stereotype.Component; @Scope("prototype") public class PmEventProcessor implements IPmEventProcessor{ protected Map<String, List<MeasurementObject>> instanceMap = new HashMap<>(); - + private static Logger log = LoggerFactory.getLogger(PmEventProcessor.class); /** * Process the PM event @@ -53,6 +55,7 @@ public class PmEventProcessor implements IPmEventProcessor{ List<MeasValuesList> subCounterMeasurements = measurement.getMeasValuesList(); subCounterMeasurements.forEach(subCounterMeasurement -> processMeasurementObjectData(collectedSubCounters, subCounterMeasurement)); }); + log.info("Processed Event: {}", instanceMap); return instanceMap; } @@ -65,26 +68,28 @@ public class PmEventProcessor implements IPmEventProcessor{ measResultList.forEach(measResult -> { String pmName = collectedSubCounters.get(measResult.getP()-1); Integer pmValue = Integer.valueOf(measResult.getsValue()); - Map<String,String> pmMapping = getMapKey(pmName); - String snssai = pmMapping.get("snssai"); - String pm = pmMapping.get("pm"); - Map<String, Integer> pmData = new HashMap<>(); - pmData.put(pm, pmValue); - if (instanceMap.containsKey(snssai)) { - int index = instanceMap.get(snssai).indexOf(new MeasurementObject(measObjId)); - if (index == -1) { - instanceMap.get(snssai).add(new MeasurementObject(measObjId,pmData)); + if(pmName.contains("PrbUsedUl") || pmName.contains("PrbUsedDl")) { + Map<String,String> pmMapping = getMapKey(pmName); + String snssai = pmMapping.get("snssai"); + String pm = pmMapping.get("pm"); + Map<String, Integer> pmData = new HashMap<>(); + pmData.put(pm, pmValue); + if (instanceMap.containsKey(snssai)) { + int index = MeasurementObject.findIndex(measObjId, instanceMap.get(snssai)); + if (index == -1) { + instanceMap.get(snssai).add(new MeasurementObject(measObjId,pmData)); + } + else { + instanceMap.get(snssai).get(index).getPmData().put(pm, pmValue); + } } else { - instanceMap.get(snssai).get(index).getPmData().put(pmName, pmValue); - } - } - else { - List<MeasurementObject> l = new LinkedList<>(); - l.add(new MeasurementObject(measObjId,pmData)); - instanceMap.put(snssai, l); + List<MeasurementObject> l = new LinkedList<>(); + l.add(new MeasurementObject(measObjId,pmData)); + instanceMap.put(snssai, l); + } } - }); + }); } /** @@ -92,14 +97,10 @@ public class PmEventProcessor implements IPmEventProcessor{ */ public Map<String, String> getMapKey(String pmName) { String [] pmNameArr = pmName.split("\\."); - String snssai = ""; String pm = pmNameArr[1]; Map<String, String> result = new HashMap<>(); result.put("pm", pm); - if ((pm.equalsIgnoreCase("PrbUsedDl")) || (pm.equalsIgnoreCase("PrbUsedUl"))){ - snssai = pmNameArr[2]; - } - result.put("snssai", snssai); + result.put("snssai", pmNameArr[2]); return result; } }
\ No newline at end of file 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 d8bcbf64..e2903ae1 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 @@ -52,7 +52,6 @@ public class PmThread extends Thread { super(); this.newPmNotification = BeanUtil.getBean(NewPmNotification.class); this.performanceNotificationsRepository = BeanUtil.getBean(PerformanceNotificationsRepository.class); - this.pmEventProcessor = BeanUtil.getBean(IPmEventProcessor.class); this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class); } @@ -68,12 +67,13 @@ public class PmThread extends Thread { while (!done) { try { Thread.sleep(1000); - if (newPmNotification.getNewNotif()) { - log.info("New PM notification from Dmaap"); + if (newPmNotification.getNewNotif()) { String pmNotificationString = performanceNotificationsRepository.getPerformanceNotificationFromQueue(); if(pmNotificationString != null) { + log.info("New PM notification"); ObjectMapper mapper = new ObjectMapper(); pmNotification = mapper.readValue(pmNotificationString, PmNotification.class); + this.pmEventProcessor = BeanUtil.getBean(IPmEventProcessor.class); processedData = pmEventProcessor.processEvent(pmNotification.getEvent()); String networkFunction = pmNotification.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasuredEntityDn(); processedData.forEach((key,value) -> { diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java index 80063398..165bef90 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java @@ -99,8 +99,8 @@ public class PolicyService { ObjectMapper obj = new ObjectMapper(); String msg = ""; try { - log.debug("Policy onset message for S-NSSAI: {} is {}", snssai, msg); msg = obj.writeValueAsString(onsetMessage); + log.info("Policy onset message for S-NSSAI: {} is {}", snssai, msg); policyDmaapClient.sendNotificationToPolicy(msg); } catch (Exception e) { 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 16fb41ad..e8d5de3e 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 @@ -63,7 +63,7 @@ public class SnssaiSamplesProcessor { private Map<String, List<String>> ricToCellMapping = new HashMap<>(); private Map<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>(); private Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); - private int samples; + private int noOfSamples; private List<String> pmsToCompute; private Map<String, String> prbThroughputMapping = new HashMap<>(); private int minPercentageChange; @@ -71,7 +71,7 @@ public class SnssaiSamplesProcessor { @PostConstruct public void init() { Configuration configuration = Configuration.getInstance(); - samples = configuration.getSamples(); + noOfSamples = configuration.getSamples(); pmsToCompute = new ArrayList<>(); pmsToCompute.add("PrbUsedDl"); pmsToCompute.add("PrbUsedUl"); @@ -84,22 +84,34 @@ public class SnssaiSamplesProcessor { /** * process the measurement data of an S-NSSAI */ - public void processSamplesOfSnnsai(String snssai, List<String> networkFunctions) { - networkFunctions.forEach(nf -> { + public boolean processSamplesOfSnnsai(String snssai, List<String> networkFunctions) { + List<MeasurementObject> sample = null; + List<List<MeasurementObject>> samples = null; + log.info("Network Functions {} of snssai {}", networkFunctions, snssai); + for(String nf : networkFunctions) { log.debug("Average of samples for {}:", snssai); - addToMeasurementList(averageCalculator.findAverageOfSamples(pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), samples))); - }); + samples = pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), noOfSamples); + if(samples != null) { + sample = averageCalculator.findAverageOfSamples(samples); + addToMeasurementList(sample); + } + else { + log.info("Not enough samples present for nf {}", nf); + return false; + } + } + log.info("snssai measurement list {}", snssaiMeasurementList); ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); - log.debug("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); - Map<String, Map<String, Integer>> ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); + log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); + Map<String, Map<String, Object>> ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); Map<String, Integer> sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); - log.debug("RIC Configuration: {}", ricConfiguration); - log.debug("Slice Configuration: {}", sliceConfiguration); + log.info("RIC Configuration {} and Slice Configuration {}", ricConfiguration, sliceConfiguration); pmsToCompute.forEach(pm -> { + log.debug("processing for pm {}", pm); sumOfPrbsAcrossCells(pm); int sum = computeSum(pm); computeThroughput(sliceConfiguration, sum, pm); - calculatePercentageChange(ricConfiguration, pm); + calculatePercentageChange(ricConfiguration, prbThroughputMapping.get(pm)); }); updateConfiguration(); if(ricToThroughputMapping.size() > 0) { @@ -107,7 +119,7 @@ public class SnssaiSamplesProcessor { addProps.setResourceConfig(ricToThroughputMapping); policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai)); } - + return true; } /** @@ -132,17 +144,18 @@ public class SnssaiSamplesProcessor { * Calculate the change in the configuration value and keep the configuration only if it is greater than a * specific limit */ - protected void calculatePercentageChange(Map<String, Map<String, Integer>> ricConfiguration, String pm) { + protected void calculatePercentageChange(Map<String, Map<String, Object>> ricConfiguration, String pm) { Iterator<Map.Entry<String, Map<String,Integer>>> it = ricToThroughputMapping.entrySet().iterator(); Map.Entry<String, Map<String,Integer>> entry = null; float existing = 0; float change = 0; while(it.hasNext()) { entry = it.next(); - existing = ricConfiguration.get(entry.getKey()).get(pm); + existing = (float)((int)ricConfiguration.get(entry.getKey()).get(pm)); change = ((Math.abs(entry.getValue().get(pm) - existing))/existing)*100; if (change <= minPercentageChange) { ricToThroughputMapping.get(entry.getKey()).remove(pm); + log.info("Removing pm data {} for RIC {}", pm, entry.getKey()); } } } @@ -151,7 +164,7 @@ public class SnssaiSamplesProcessor { ricToCellMapping.forEach((ric,cells) -> { int sumOfPrbs = 0; for(String cell : cells) { - int index = snssaiMeasurementList.indexOf(new MeasurementObject(cell)); + int index = MeasurementObject.findIndex(cell, snssaiMeasurementList); sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName); } if(ricToPrbsMapping.containsKey(ric)) { @@ -163,6 +176,7 @@ public class SnssaiSamplesProcessor { ricToPrbsMapping.put(ric, pmToPrbMapping); } }); + log.info("PRBs sum computed for RIC {}", ricToPrbsMapping); } protected Integer computeSum(String pm) { @@ -188,7 +202,6 @@ public class SnssaiSamplesProcessor { ricToThroughputMapping.put(ric, throughtputMap); } } - + log.info("Throughput computed for RIC {}", ricToThroughputMapping); } - } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java index b19b4801..95da3667 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java @@ -22,6 +22,7 @@ package org.onap.slice.analysis.ms.restclients; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; import java.util.Collections; import java.util.HashMap; @@ -31,49 +32,39 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; +import org.onap.slice.analysis.ms.service.SnssaiSamplesProcessorTest; import org.onap.slice.analysis.ms.utils.BeanUtil; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; -@RunWith(PowerMockRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) -@PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ BeanUtil.class }) -@SpringBootTest(classes = RestClient.class) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestClientTest.class) public class RestClientTest { - @Mock RestTemplate restTemplate; - @InjectMocks RestClient restclient; - - @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @SuppressWarnings({ "static-access"}) @Test public void sendGetRequestTest() { - - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.when(BeanUtil.getBean(Mockito.any())).thenReturn(restTemplate); - ParameterizedTypeReference<Map<String,Integer>> responseType = null; + ParameterizedTypeReference<Map<String,Integer>> responseType = null; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); @@ -82,7 +73,7 @@ public class RestClientTest { responsemap.put("dLThptPerSlice", 1); responsemap.put("uLThptPerSlice", 2); String requestUrl=""; - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); + when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); ResponseEntity<Map<String,Integer>> resp = restclient.sendGetRequest(headers, requestUrl, responseType); assertEquals(resp.getBody(),responsemap); } @@ -90,15 +81,13 @@ public class RestClientTest { @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) @Test public void sendPostRequestTest() { - PowerMockito.mockStatic(BeanUtil.class); - PowerMockito.when(BeanUtil.getBean(RestTemplate.class)).thenReturn(restTemplate); ParameterizedTypeReference<String> responseType = null; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); String requestUrl = "Url"; String requestBody = null; HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); + when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); assertEquals(resp.getStatusCode(), HttpStatus.OK); } @@ -111,7 +100,7 @@ public class RestClientTest { headers.setContentType(MediaType.APPLICATION_JSON); String requestUrl = "Url"; String requestBody = null; HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); - PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); + when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); assertEquals(resp.getStatusCode(), HttpStatus.NOT_FOUND); } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java index e9c134f7..05e60171 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java @@ -70,7 +70,6 @@ public class AverageCalculatorTest { catch (IOException e) { e.printStackTrace(); } - assertEquals(output, averageCalculator.findAverageOfSamples(input)); } @@ -113,5 +112,4 @@ public class AverageCalculatorTest { assertEquals(new MeasurementObject("cell1", result), averageCalculator.findSum(new MeasurementObject("cell1", existingMap), new MeasurementObject("cell1", currentMap))); } -} - +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java index b8316dfe..e8cc2145 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java @@ -130,7 +130,7 @@ public class SnssaiSamplesProcessorTest { @Test public void calculatePercentageChangeTest() { - Map<String, Map<String, Integer>> ricConfiguration = null; + Map<String, Map<String, Object>> ricConfiguration = null; Map<String, Map<String, Integer>> exp = new HashMap<>(); Map<String, Integer> ric1 = new HashMap<>(); Map<String, Integer> ric2 = new HashMap<>(); @@ -140,7 +140,7 @@ public class SnssaiSamplesProcessorTest { exp.put("1", ric1); exp.put("2", ric2); try { - ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference<Map<String, Map<String, Object>>>(){}); } catch (IOException e) { e.printStackTrace(); diff --git a/components/slice-analysis-ms/src/test/resources/appendData.json b/components/slice-analysis-ms/src/test/resources/appendData.json index 39802dd2..8cd06727 100644 --- a/components/slice-analysis-ms/src/test/resources/appendData.json +++ b/components/slice-analysis-ms/src/test/resources/appendData.json @@ -54,7 +54,7 @@ }, {"measurementObjectId":"cell3", "pmData":{ - "PrbUsedDl":"25", + "PrbUsedDl":"30", "PrbUsedUl":"40" } } diff --git a/components/slice-analysis-ms/src/test/resources/av.json b/components/slice-analysis-ms/src/test/resources/av.json new file mode 100644 index 00000000..f9e8ecef --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/av.json @@ -0,0 +1,14 @@ +[ + {"measurementObjectId":"103593989", + "pmData":{ + "PrbUsedDl":"33", + "PrbUsedUl":"42" + } + }, + {"measurementObjectId":"103593999", + "pmData":{ + "PrbUsedDl":"53", + "PrbUsedUl":"53" + } + } +]
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/average.json b/components/slice-analysis-ms/src/test/resources/average.json index 81838b6d..e0b0779b 100644 --- a/components/slice-analysis-ms/src/test/resources/average.json +++ b/components/slice-analysis-ms/src/test/resources/average.json @@ -13,7 +13,7 @@ }, {"measurementObjectId":"cell3", "pmData":{ - "PrbUsedDl":"25", + "PrbUsedDl":"30", "PrbUsedUl":"40" } } diff --git a/components/slice-analysis-ms/src/test/resources/test.json b/components/slice-analysis-ms/src/test/resources/test.json new file mode 100644 index 00000000..e852e244 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/test.json @@ -0,0 +1,44 @@ +[ +[ + {"measurementObjectId":"103593989", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"103593999", + "pmData":{ + "PrbUsedDl":"60", + "PrbUsedUl":"80" + } + } + ], +[ + {"measurementObjectId":"103593989", + "pmData":{ + "PrbUsedDl":"35", + "PrbUsedUl":"44" + } + }, + {"measurementObjectId":"103593999", + "pmData":{ + "PrbUsedDl":"50", + "PrbUsedUl":"40" + } + } + ], +[ + {"measurementObjectId":"103593989", + "pmData":{ + "PrbUsedDl":"35", + "PrbUsedUl":"44" + } + }, + {"measurementObjectId":"103593999", + "pmData":{ + "PrbUsedDl":"50", + "PrbUsedUl":"40" + } + } + ] +]
\ No newline at end of file |