summaryrefslogtreecommitdiffstats
path: root/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java
diff options
context:
space:
mode:
authorNiranjana <niranjana.y60@wipro.com>2022-02-03 04:50:38 +0000
committerNiranjana <niranjana.y60@wipro.com>2022-03-03 13:39:38 +0000
commitf67adad42f2c857ff76b52df39f0beb5c2cabee4 (patch)
treed9c4394a5f52187d9db0a09a0759e78350df8e16 /components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java
parent5f69c24ad78121a2840b5299583791e557f8b535 (diff)
[DCAEGEN2] Calculate slice utilization data
Issue-ID: DCAEGEN2-2942 Signed-off-by: Niranjana <niranjana.y60@wipro.com> Change-Id: Id16d2a36cf964b15495531a54094cad96471bdcb
Diffstat (limited to 'components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java')
-rw-r--r--components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java385
1 files changed, 193 insertions, 192 deletions
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 d802f81d..b4e06896 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* slice-analysis-ms
* ================================================================================
- * Copyright (C) 2020-2021 Wipro Limited.
+ * Copyright (C) 2020-2022 Wipro Limited.
* ==============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
* ============LICENSE_END=========================================================
*
*******************************************************************************/
+
package org.onap.slice.analysis.ms.service;
import java.util.ArrayList;
@@ -29,9 +30,9 @@ import java.util.Objects;
import javax.annotation.PostConstruct;
-import org.onap.slice.analysis.ms.configdb.AaiInterface;
-import org.onap.slice.analysis.ms.configdb.CpsInterface;
+import org.onap.slice.analysis.ms.aai.AaiInterface;
import org.onap.slice.analysis.ms.configdb.IConfigDbService;
+import org.onap.slice.analysis.ms.cps.CpsInterface;
import org.onap.slice.analysis.ms.models.Configuration;
import org.onap.slice.analysis.ms.models.MeasurementObject;
import org.onap.slice.analysis.ms.models.SubCounter;
@@ -48,201 +49,201 @@ import org.springframework.stereotype.Component;
@Component
@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;
-
- @Autowired
- private AaiInterface aaiInterface;
-
- @Autowired
- private CpsInterface cpsInterface;
-
- private List<MeasurementObject> snssaiMeasurementList = new ArrayList<>();
- 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 noOfSamples;
- private List<String> pmsToCompute;
- private Map<String, String> prbThroughputMapping = new HashMap<>();
- private int minPercentageChange;
-
- @PostConstruct
- public void init() {
- Configuration configuration = Configuration.getInstance();
- noOfSamples = configuration.getSamples();
- pmsToCompute = new ArrayList<>();
- pmsToCompute.add("PrbUsedDl");
- pmsToCompute.add("PrbUsedUl");
- prbThroughputMapping = new HashMap<>();
- prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice");
- prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice");
- minPercentageChange = configuration.getMinPercentageChange();
+ private static Logger log = LoggerFactory.getLogger(SnssaiSamplesProcessor.class);
+
+ @Autowired
+ private PolicyService policyService;
+
+ @Autowired
+ private IConfigDbService configDbService;
+
+ @Autowired
+ private PmDataQueue pmDataQueue;
+
+ @Autowired
+ private AverageCalculator averageCalculator;
+
+ @Autowired
+ private AaiInterface aaiInterface;
+
+ @Autowired
+ private CpsInterface cpsInterface;
+
+ private List<MeasurementObject> snssaiMeasurementList = new ArrayList<>();
+ 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 noOfSamples;
+ private List<String> pmsToCompute;
+ private Map<String, String> prbThroughputMapping = new HashMap<>();
+ private int minPercentageChange;
+
+ @PostConstruct
+ public void init() {
+ Configuration configuration = Configuration.getInstance();
+ noOfSamples = configuration.getSamples();
+ pmsToCompute = new ArrayList<>();
+ pmsToCompute.add("PrbUsedDl");
+ pmsToCompute.add("PrbUsedUl");
+ prbThroughputMapping = new HashMap<>();
+ prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice");
+ prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice");
+ minPercentageChange = configuration.getMinPercentageChange();
+ }
+
+ /**
+ * process the measurement data of an S-NSSAI
+ */
+ public boolean processSamplesOfSnnsai(String snssai, List<String> networkFunctions) {
+ Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true
+ : Configuration.getInstance().getConfigDbEnabled();
+ List<MeasurementObject> sample = null;
+ List<List<MeasurementObject>> samples = null;
+ Map<String, String> serviceDetails = null;
+ log.info("Network Functions {} of snssai {}", networkFunctions, snssai);
+ for (String nf : networkFunctions) {
+ log.debug("Average of samples for {}:", snssai);
+ 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;
+ }
}
-
- /**
- * process the measurement data of an S-NSSAI
- */
- public boolean processSamplesOfSnnsai(String snssai, List<String> networkFunctions) {
- Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true
- : Configuration.getInstance().getConfigDbEnabled();
- List<MeasurementObject> sample = null;
- List<List<MeasurementObject>> samples = null;
- Map<String, String> serviceDetails =null;
- log.info("Network Functions {} of snssai {}", networkFunctions, snssai);
- for (String nf : networkFunctions) {
- log.debug("Average of samples for {}:", snssai);
- 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);
- Map<String, Map<String, Object>> ricConfiguration;
- Map<String, Integer> sliceConfiguration;
- if (isConfigDbEnabled) {
- ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai);
- ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai);
- sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai);
- serviceDetails = configDbService.fetchServiceDetails(snssai);
- } else {
- ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai);
- ricConfiguration = cpsInterface.fetchCurrentConfigurationOfRIC(snssai);
- serviceDetails = aaiInterface.fetchServiceDetails(snssai);
- sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai);
- }
- log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping);
- 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, prbThroughputMapping.get(pm));
- });
- updateConfiguration();
- if (ricToThroughputMapping.size() > 0) {
- AdditionalProperties<Map<String, List<Map<String, Integer>>>> addProps = new AdditionalProperties<>();
- addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping));
- policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails);
- }
- return true;
+ log.info("snssai measurement list {}", snssaiMeasurementList);
+ Map<String, Map<String, Object>> ricConfiguration;
+ Map<String, Integer> sliceConfiguration;
+ if (isConfigDbEnabled) {
+ ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai);
+ ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai);
+ sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai);
+ serviceDetails = configDbService.fetchServiceDetails(snssai);
+ } else {
+ ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai);
+ ricConfiguration = cpsInterface.fetchCurrentConfigurationOfRIC(snssai);
+ serviceDetails = aaiInterface.fetchServiceDetails(snssai);
+ sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai);
}
-
- /**
- * change the RICConfig data format to be compatible with SDN-R
- */
- protected Map<String, List<Map<String, Integer>>> getChangedRIConfigFormat(
- Map<String, Map<String, Integer>> ricToThroughputMapping) {
- Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator();
- Map.Entry<String, Map<String, Integer>> entry = null;
- List<Map<String, Integer>> ricConfigList = new ArrayList<>();
- Map<String, List<Map<String, Integer>>> ricConfigData = new HashMap<>();
- while (it.hasNext()) {
- Map<String, Integer> newConfigMap = new HashMap<>();
- entry = it.next();
- newConfigMap = entry.getValue();
- newConfigMap.put("nearRTRICId", Integer.parseInt(entry.getKey()));
- ricConfigList.add(newConfigMap);
- }
- ricConfigData.put("data", ricConfigList);
- return ricConfigData;
+ log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping);
+ 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, prbThroughputMapping.get(pm));
+ });
+ updateConfiguration();
+ if (ricToThroughputMapping.size() > 0) {
+ AdditionalProperties<Map<String, List<Map<String, Integer>>>> addProps = new AdditionalProperties<>();
+ addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping));
+ policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails);
}
-
- /**
- * process the measurement data of an S-NSSAI
- */
- protected void updateConfiguration() {
- Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator();
- Map.Entry<String, Map<String, Integer>> entry = null;
- while (it.hasNext()) {
- entry = it.next();
- if (entry.getValue().size() == 0) {
- it.remove();
- }
- }
+ return true;
+ }
+
+ /**
+ * change the RICConfig data format to be compatible with SDN-R
+ */
+ protected Map<String, List<Map<String, Integer>>> getChangedRIConfigFormat(
+ Map<String, Map<String, Integer>> ricToThroughputMapping) {
+ Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator();
+ Map.Entry<String, Map<String, Integer>> entry = null;
+ List<Map<String, Integer>> ricConfigList = new ArrayList<>();
+ Map<String, List<Map<String, Integer>>> ricConfigData = new HashMap<>();
+ while (it.hasNext()) {
+ Map<String, Integer> newConfigMap = new HashMap<>();
+ entry = it.next();
+ newConfigMap = entry.getValue();
+ newConfigMap.put("nearRTRICId", Integer.parseInt(entry.getKey()));
+ ricConfigList.add(newConfigMap);
}
-
- private void addToMeasurementList(List<MeasurementObject> sample) {
- snssaiMeasurementList.addAll(sample);
+ ricConfigData.put("data", ricConfigList);
+ return ricConfigData;
+ }
+
+ /**
+ * process the measurement data of an S-NSSAI
+ */
+ protected void updateConfiguration() {
+ Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator();
+ Map.Entry<String, Map<String, Integer>> entry = null;
+ while (it.hasNext()) {
+ entry = it.next();
+ if (entry.getValue().size() == 0) {
+ it.remove();
+ }
}
-
- /**
- * 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, 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 = (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());
- }
- }
+ }
+
+ private void addToMeasurementList(List<MeasurementObject> sample) {
+ snssaiMeasurementList.addAll(sample);
+ }
+
+ /**
+ * 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, 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 = (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());
+ }
}
-
- protected void sumOfPrbsAcrossCells(String pmName) {
- ricToCellMapping.forEach((ric, cells) -> {
- int sumOfPrbs = 0;
- for (String cell : cells) {
- int index = MeasurementObject.findIndex(cell, snssaiMeasurementList);
- sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName);
- }
- if (ricToPrbsMapping.containsKey(ric)) {
- ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs);
- } else {
- Map<String, Integer> pmToPrbMapping = new HashMap<>();
- pmToPrbMapping.put(pmName, sumOfPrbs);
- ricToPrbsMapping.put(ric, pmToPrbMapping);
- }
- });
- log.info("PRBs sum computed for RIC {}", ricToPrbsMapping);
- }
-
- protected Integer computeSum(String pm) {
- return ricToPrbsMapping.entrySet().stream().map(x -> x.getValue().get(pm)).reduce(0, Integer::sum);
- }
-
- protected void computeThroughput(Map<String, Integer> sliceConfiguration, int sum, String pm) {
- Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToPrbsMapping.entrySet().iterator();
- Map.Entry<String, Map<String, Integer>> entry = null;
- Map<String, Integer> throughtputMap = null;
- String ric = "";
- int value = 0;
- while (it.hasNext()) {
- entry = it.next();
- ric = entry.getKey();
- value = Math.round(((float) entry.getValue().get(pm) / sum)
- * (float) sliceConfiguration.get(prbThroughputMapping.get(pm)));
- if (ricToThroughputMapping.containsKey(ric)) {
- ricToThroughputMapping.get(ric).put(prbThroughputMapping.get(pm), value);
- } else {
- throughtputMap = new HashMap<>();
- throughtputMap.put(prbThroughputMapping.get(pm), value);
- ricToThroughputMapping.put(ric, throughtputMap);
- }
- }
- log.info("Throughput computed for RIC {}", ricToThroughputMapping);
+ }
+
+ protected void sumOfPrbsAcrossCells(String pmName) {
+ ricToCellMapping.forEach((ric, cells) -> {
+ int sumOfPrbs = 0;
+ for (String cell : cells) {
+ int index = MeasurementObject.findIndex(cell, snssaiMeasurementList);
+ sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName);
+ }
+ if (ricToPrbsMapping.containsKey(ric)) {
+ ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs);
+ } else {
+ Map<String, Integer> pmToPrbMapping = new HashMap<>();
+ pmToPrbMapping.put(pmName, sumOfPrbs);
+ ricToPrbsMapping.put(ric, pmToPrbMapping);
+ }
+ });
+ log.info("PRBs sum computed for RIC {}", ricToPrbsMapping);
+ }
+
+ protected Integer computeSum(String pm) {
+ return ricToPrbsMapping.entrySet().stream().map(x -> x.getValue().get(pm)).reduce(0, Integer::sum);
+ }
+
+ protected void computeThroughput(Map<String, Integer> sliceConfiguration, int sum, String pm) {
+ Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToPrbsMapping.entrySet().iterator();
+ Map.Entry<String, Map<String, Integer>> entry = null;
+ Map<String, Integer> throughtputMap = null;
+ String ric = "";
+ int value = 0;
+ while (it.hasNext()) {
+ entry = it.next();
+ ric = entry.getKey();
+ value = Math.round(((float) entry.getValue().get(pm) / sum)
+ * (float) sliceConfiguration.get(prbThroughputMapping.get(pm)));
+ if (ricToThroughputMapping.containsKey(ric)) {
+ ricToThroughputMapping.get(ric).put(prbThroughputMapping.get(pm), value);
+ } else {
+ throughtputMap = new HashMap<>();
+ throughtputMap.put(prbThroughputMapping.get(pm), value);
+ ricToThroughputMapping.put(ric, throughtputMap);
+ }
}
+ log.info("Throughput computed for RIC {}", ricToThroughputMapping);
+ }
}