Append SNSSAI with MeasType string and handle multiple operands 65/130465/4
authormalar <malarvizhi.44@wipro.com>
Mon, 29 Aug 2022 05:10:44 +0000 (05:10 +0000)
committermalar <malarvizhi.44@wipro.com>
Tue, 30 Aug 2022 07:00:11 +0000 (07:00 +0000)
- For Network Slicing usecase, we require the published event to
  have the measType return the SNSSAI along with the string.
- Also handle multiple operands from the incoming PM data with different SNSSAIs.

Issue-ID: DCAEGEN2-3243
Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com>
Change-Id: I6aae7604a5e87a07244cf841762c205836290abe

components/kpi-computation-ms/Changelog.md
components/kpi-computation-ms/pom.xml
components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/computation/KpiComputation.java
components/kpi-computation-ms/src/main/java/org/onap/dcaegen2/kpi/computation/RatioKpiComputation.java
components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java
components/kpi-computation-ms/src/test/resources/kpi/ves_message_slicing_multiplesnssai.json [new file with mode: 0644]
components/kpi-computation-ms/version.properties

index 9c1becc..de62dec 100644 (file)
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## [1.0.7]
+### Changed
+* Append SNSSAI with MeasType string and handle multiple operands (DCAEGEN2-3243)
+
 ## [1.0.6]
 ### Changed
 * CodeCoverage improvement for dcaegen2-services-kpi-computation-ms (DCAEGEN2-3162)
index c71b918..89f83aa 100644 (file)
@@ -29,7 +29,7 @@
 
     <groupId>org.onap.dcaegen2.services.components</groupId>
     <artifactId>kpi-ms</artifactId>
-    <version>1.0.6-SNAPSHOT</version>
+    <version>1.0.7-SNAPSHOT</version>
     <name>dcaegen2-services-kpi-computation-ms</name>
     <description>Kpi ms</description>
     <packaging>jar</packaging>
index 5e6c5a4..8a7b9e0 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.dcaegen2.kpi.computation;
 
+import java.lang.String;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -29,7 +30,7 @@ import java.util.List;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Optional;
-
+import java.util.stream.Collectors;
 import org.apache.commons.lang.StringUtils;
 
 import org.onap.dcaegen2.kpi.config.ControlLoopSchemaType;
@@ -45,6 +46,7 @@ import org.onap.dcaegen2.kpi.models.Configuration;
 import org.onap.dcaegen2.kpi.models.MeasDataCollection;
 import org.onap.dcaegen2.kpi.models.MeasInfo;
 import org.onap.dcaegen2.kpi.models.MeasResult;
+import org.onap.dcaegen2.kpi.models.MeasTypes;
 import org.onap.dcaegen2.kpi.models.MeasValues;
 import org.onap.dcaegen2.kpi.models.Perf3gppFields;
 import org.onap.dcaegen2.kpi.models.PerformanceEvent;
@@ -104,6 +106,29 @@ public class KpiComputation {
         MeasDataCollection measDataCollection = Optional.of(pmEvent).map(PerformanceEvent::getPerf3gppFields)
                 .map(Perf3gppFields::getMeasDataCollection)
                 .orElseThrow(() -> new KpiComputationException("Required Field: MeasData not present"));
+
+        List<MeasInfo> measInfoList = Optional.of(pmEvent).map(PerformanceEvent::getPerf3gppFields)
+                 .map(Perf3gppFields::getMeasDataCollection)
+                 .map(MeasDataCollection::getMeasInfoList)
+                 .orElseThrow(() -> new KpiComputationException("Required Field: MeasInfoList not present"));
+
+        StringBuilder sb = new StringBuilder();
+        for(MeasInfo measInfo: measInfoList){
+           List<String> measTypes = measInfo.getMeasTypes().getMeasTypesList();
+           if(!measTypes.isEmpty()){
+              String anyString = measTypes.get(0);
+              char[] chars = anyString.toCharArray();
+              for(char c : chars){
+                 if(Character.isDigit(c)){
+                    sb.append(c);
+                 }
+              }
+           }
+           else{
+              logger.info("MeasTypesList is empty");
+           }
+        }
+        String snssai = sb.toString();
         // Do computation for each KPI
         List<VesEvent> events = new LinkedList<>();
         List<Kpi> kpis = methodForKpi.getKpis();
@@ -115,7 +140,7 @@ public class KpiComputation {
             }
 
             ControlLoopSchemaType schemaType = methodForKpi.getControlLoopSchemaType();
-            String measType = k.getMeasType();
+            String measType = k.getMeasType() + "." + snssai;
             Operation operation = k.getOperation();
 
             List<VesEvent> kpiVesEvent = CommandHandler.handle(operation.value, pmEvent, schemaType,
@@ -144,10 +169,9 @@ public class KpiComputation {
             flag = false;
             for (String operand : operands) {
                 List<String> measTypesList = measInfo.getMeasTypes().getMeasTypesList();
-                String measValue = measTypesList.stream()
+                List<String> measValue = measTypesList.stream()
                         .filter(s -> StringUtils.substring(s, 0, operand.length()).equalsIgnoreCase(operand))
-                        .findFirst()
-                        .orElse(null);
+                        .collect(Collectors.toList());
                 if (measValue == null) {
                     flag = true;
                 }
@@ -157,19 +181,19 @@ public class KpiComputation {
                 curatedMeasInfoList.add(measInfo);
             }
         }
-        
+
         for (String operand: operands) {
             String key = null;
             List<KpiOperand> kpiOperands = new ArrayList<>();
             for (MeasInfo m: curatedMeasInfoList) {
                 List<String> measTypesList = m.getMeasTypes().getMeasTypesList();
-                String measValue = measTypesList.stream()
+                List<String> measValueList = measTypesList.stream()
                         .filter(s -> StringUtils.substring(s, 0, operand.length()).equalsIgnoreCase(operand))
-                        .findFirst()
-                        .orElse(null);
-                if (measValue != null) {
+                        .collect(Collectors.toList());
+                if (measValueList != null) {
+                  for(String measValue:measValueList){
                     key = new StringBuilder().append(operand).toString();
-                    int index = measTypesList.indexOf(measValue);
+                    int index = measTypesList.indexOf(measValue);          
                     List<MeasValues> measValuesList = m.getMeasValuesList();
                     for ( MeasValues measValues : measValuesList) {
                          List<MeasResult> measResults = measValues.getMeasResults();
@@ -185,6 +209,7 @@ public class KpiComputation {
                              logger.info("measResults mis-matched - incorrect ves msg construction");
                          }
                     }
+                  }
                 }
             }
             if (kpiOperands.size() <= 0) {
index 754c357..c228b59 100644 (file)
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.LinkedList;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.Optional;
 import java.util.UUID;
 
 import org.onap.dcaegen2.kpi.config.ControlLoopSchemaType;
@@ -71,10 +72,75 @@ public class RatioKpiComputation extends BaseKpiComputation {
             while (listIteratorK1.hasNext()) {
                 final KpiOperand myK1 = listIteratorK1.next();
                 final KpiOperand myK2 = listIteratorK2.next();
+
+                String value = myK1.getValue().toString();
+                List<MeasInfo> measInfoList = Optional.of(pmEvent).map(PerformanceEvent::getPerf3gppFields)
+                      .map(Perf3gppFields::getMeasDataCollection)
+                      .map(MeasDataCollection::getMeasInfoList)
+                      .orElseThrow(() -> new KpiComputationException("MeasInfoList not present"));
+
+                int pValue = 0;
+
+                for(MeasInfo meas: measInfoList){
+                   for(MeasValues measValue: meas.getMeasValuesList()){
+                      for(MeasResult measResult: measValue.getMeasResults()){
+                          String s = measResult.getSvalue();
+                          if(s.equalsIgnoreCase(value)){
+                               pValue = measResult.getPvalue();
+                          }
+                      }
+                   }
+                }
+
+                String operand = null;
+
+                for(MeasInfo measInfo: measInfoList){
+                   List<String> measTypesList = measInfo.getMeasTypes().getMeasTypesList();
+                   if(!measTypesList.isEmpty()){
+                      for(String s : measTypesList){
+                         int index = measTypesList.indexOf(s);
+                         if( index == (pValue-1)){
+                            operand = s;
+                         }
+                      }
+                   }
+               }
+
+                StringBuilder sb = new StringBuilder();
+                if(!operand.isEmpty()){
+                   char[] chars = operand.toCharArray();
+                   for(char c : chars){
+                      if(Character.isDigit(c)){
+                         sb.append(c);
+                      }
+                   }
+                }
+                else{
+                   logger.info("operand is empty");
+                }
+
+                String snssai = sb.toString();
+
+                StringBuilder sb1 = new StringBuilder();
+                if(!measType.isEmpty()){
+                   char[] chars = measType.toCharArray();
+                   for(char c : chars){
+                      if(!Character.isDigit(c)){
+                        sb1.append(c);
+                      }
+                   }
+                }
+                else{
+                   logger.info("measType is empty");
+                }
+
+                String meas = sb1.toString();
+                String measTypes = meas + snssai;
+
                 if (myK2.getValue().compareTo(BigDecimal.ZERO) != 0) {
                     final BigDecimal result = myK1.getValue().multiply(new BigDecimal("100"))
                         .divide(myK2.getValue(), 0, RoundingMode.HALF_UP);
-                    vesEvents.add(generateVesEvent(pmEvent, schemaType.toString(), result, measType));
+                    vesEvents.add(generateVesEvent(pmEvent, schemaType.toString(), result, measTypes));
                 }
             }
         }
index dc1becb..79f7e49 100644 (file)
@@ -57,12 +57,11 @@ public class KpiComputationTest {
     private static final String VES_MESSAGE_SLICING_FILE = "kpi/ves_message_slicing.json";
     private static final String VES_MESSAGE_EVENTNAME_FILE = "kpi/ves_message_eventname.json";
     private static final String VES_MESSAGE_FIELD_MISSING ="kpi/ves_message_missing_field.json";
-    
-    
+    private static final String VES_MESSAGE_MULTIPLESNSSAI_SLICING_FILE = "kpi/ves_message_slicing_multiplesnssai.json";
+
     @Test
     public void testKpiComputation() {
 
-
         String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
 
         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
@@ -99,6 +98,33 @@ public class KpiComputationTest {
         assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
                      .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "158");
     }
+
+    @Test
+    public void testKpiComputationSlicingMeasType() {
+        String strKpiConfigRatio = FileUtils.getFileContents(KPI_CONFIG_SLICING_RATIO_FILE);
+        String vesMessage = FileUtils.getFileContents(VES_MESSAGE_SLICING_FILE);
+        Configuration config = mock(Configuration.class);
+        when(config.getKpiConfig()).thenReturn(strKpiConfigRatio);
+        List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
+        VesEvent vesEvent = vesList.get(0);
+        assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
+                .getMeasTypes().getMeasTypesList().get(0), "PDUSessionEstSR.00110010");
+    }
+
+    @Test
+    public void testKpiComputationSlicingMultipleSNSSAI() {
+        String strKpiConfigRatio = FileUtils.getFileContents(KPI_CONFIG_SLICING_RATIO_FILE);
+        String vesMessage = FileUtils.getFileContents(VES_MESSAGE_MULTIPLESNSSAI_SLICING_FILE);
+        Configuration config = mock(Configuration.class);
+        when(config.getKpiConfig()).thenReturn(strKpiConfigRatio);
+        List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
+        VesEvent vesEvent = vesList.get(0);
+        VesEvent anotherVesEvent = vesList.get(18);
+        assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
+                .getMeasTypes().getMeasTypesList().get(0), "PDUSessionEstSR.00110010");
+        assertEquals(anotherVesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
+                      .getMeasTypes().getMeasTypesList().get(0), "PDUSessionEstSR.00101110");
+    }
     
     @Test
     public void testKpiComputationSumRatio() {
@@ -116,7 +142,6 @@ public class KpiComputationTest {
     @Test
     public void testKpiComputationSumRatioEmptyCheck() {
         String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE);
-
         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_EMPTY_FILE);
         Configuration config = mock(Configuration.class);
         when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
@@ -154,7 +179,7 @@ public class KpiComputationTest {
         Configuration config = mock(Configuration.class);
         when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
         KpiComputationException kpiException = Assertions.assertThrows(KpiComputationException.class, () -> {
-               List<VesEvent>  vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
+          List<VesEvent>  vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
         });
         Assertions.assertEquals("Required Field: EventName not present", kpiException.getMessage());
     }
@@ -166,23 +191,23 @@ public class KpiComputationTest {
     }
     @Test
     public void testEmptyOperands() throws Exception {
-        Map<String, List<KpiOperand>> operands = null;
-        List<String> inputOperands = new ArrayList<String>();
-         operands = Whitebox.invokeMethod(new KpiComputation(), "getOperands", new MeasDataCollection(), inputOperands);
-         Assertions.assertNull(operands);
+        Map<String, List<KpiOperand>> operands = null;
+        List<String> inputOperands = new ArrayList<String>();
+        operands = Whitebox.invokeMethod(new KpiComputation(), "getOperands", new MeasDataCollection(), inputOperands);
+        Assertions.assertNull(operands);
     }
     @Test
     public void testNullVESMessage() {
-       String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE);
-       Configuration config = mock(Configuration.class);
+        String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE);
+        Configuration config = mock(Configuration.class);
         when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
         List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(null, config);
         Assertions.assertNull(vesList);
     }
     @Test
     public void testEmptyVESMessage() {
-       String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE);
-       Configuration config = mock(Configuration.class);
+        String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE);
+        Configuration config = mock(Configuration.class);
         when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
         String vesMessage = "{}";
         List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
diff --git a/components/kpi-computation-ms/src/test/resources/kpi/ves_message_slicing_multiplesnssai.json b/components/kpi-computation-ms/src/test/resources/kpi/ves_message_slicing_multiplesnssai.json
new file mode 100644 (file)
index 0000000..fe87d1a
--- /dev/null
@@ -0,0 +1 @@
+{  "event": {    "commonEventHeader": {      "domain": "perf3gpp",      "eventId": "42b8917b-aa11-49aa-84ca-084147ca7a3c",      "sequence": 0,      "eventName": "perf3gpp_CORE-cucpserver2_pmMeasResult",      "sourceName": "oteNB5309",      "reportingEntityName": "",      "priority": "Normal",      "startEpochMicrosec": 1606743157914,      "lastEpochMicrosec": 1606743157915,      "version": "4.0",      "vesEventListenerVersion": "7.1",      "timeZoneOffset": "UTC+05:00"    },    "perf3gppFields": {      "perf3gppFieldsVersion": "1.0",      "measDataCollection": {        "granularityPeriod": 900,        "measuredEntityUserName": "",        "measuredEntityDn": "cucpserver2",        "measuredEntitySoftwareVersion": "r0.1",        "measInfoList": [          {            "measInfoId": {              "sMeasInfoId": "measInfoIsVal"            },            "measTypes": {              "sMeasTypesList": [                "SM.PduSessionCreationReq.0011-0010",                "SM.PduSessionCreationSucc.0011-0010",                "SM.PduSessionCreationReq.0010-1110",                "SM.PduSessionCreationSucc.0010-1110",                "SM.PduSessionSetupFail.0"              ]            },            "measValuesList": [              {                "measObjInstId": "10896",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "1400.0"                  },                  {                    "p": 2,                    "sValue": "1008.0"                  },                  {                    "p": 4,                    "sValue": "2853.0"                  },                  {                    "p": 5,                    "sValue": "1819.0"                  },                  {                    "p": 3,                    "sValue": "1297.0"                  }                ]              },              {                "measObjInstId": "10897",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "1765.0"                  },                  {                    "p": 2,                    "sValue": "1105.0"                  },                  {                    "p": 4,                    "sValue": "2757.0"                  },                  {                    "p": 5,                    "sValue": "1684.0"                  },                  {                    "p": 3,                    "sValue": "1612.0"                  }                ]              },              {                "measObjInstId": "11561",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "2113.0"                  },                  {                    "p": 2,                    "sValue": "1442.0"                  },                  {                    "p": 4,                    "sValue": "3550.0"                  },                  {                    "p": 5,                    "sValue": "2298.0"                  },                  {                    "p": 3,                    "sValue": "1731.0"                  }                ]              },              {                "measObjInstId": "11562",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "1414.0"                  },                  {                    "p": 2,                    "sValue": "1020.0"                  },                  {                    "p": 4,                    "sValue": "2778.0"                  },                  {                    "p": 5,                    "sValue": "1753.0"                  },                  {                    "p": 3,                    "sValue": "1299.0"                  }                ]              },              {                "measObjInstId": "11568",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "2338.0"                  },                  {                    "p": 2,                    "sValue": "1469.0"                  },                  {                    "p": 4,                    "sValue": "3140.0"                  },                  {                    "p": 5,                    "sValue": "2264.0"                  },                  {                    "p": 3,                    "sValue": "1635.0"                  }                ]              },              {                "measObjInstId": "11569",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "2200.0"                  },                  {                    "p": 2,                    "sValue": "1486.0"                  },                  {                    "p": 4,                    "sValue": "2297.0"                  },                  {                    "p": 5,                    "sValue": "1485.0"                  },                  {                    "p": 3,                    "sValue": "1447.0"                  }                ]              },              {                "measObjInstId": "13905",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "4541.0"                  },                  {                    "p": 2,                    "sValue": "3054.0"                  },                  {                    "p": 4,                    "sValue": "7301.0"                  },                  {                    "p": 5,                    "sValue": "5351.0"                  },                  {                    "p": 3,                    "sValue": "3209.0"                  }                ]              },              {                "measObjInstId": "13910",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "4699.0"                  },                  {                    "p": 2,                    "sValue": "3104.0"                  },                  {                    "p": 4,                    "sValue": "7467.0"                  },                  {                    "p": 5,                    "sValue": "5141.0"                  },                  {                    "p": 3,                    "sValue": "3532.0"                  }                ]              },              {                "measObjInstId": "14427",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "5840.0"                  },                  {                    "p": 2,                    "sValue": "4264.0"                  },                  {                    "p": 4,                    "sValue": "7445.0"                  },                  {                    "p": 5,                    "sValue": "4974.0"                  },                  {                    "p": 3,                    "sValue": "3746.0"                  }                ]              },              {                "measObjInstId": "14655",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "2536.0"                  },                  {                    "p": 2,                    "sValue": "1895.0"                  },                  {                    "p": 4,                    "sValue": "3227.0"                  },                  {                    "p": 5,                    "sValue": "2113.0"                  },                  {                    "p": 3,                    "sValue": "1618.0"                  }                ]              },              {                "measObjInstId": "14656",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "2322.0"                  },                  {                    "p": 2,                    "sValue": "1520.0"                  },                  {                    "p": 4,                    "sValue": "1889.0"                  },                  {                    "p": 5,                    "sValue": "1212.0"                  },                  {                    "p": 3,                    "sValue": "1374.0"                  }                ]              },              {                "measObjInstId": "15360",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "5859.0"                  },                  {                    "p": 2,                    "sValue": "3894.0"                  },                  {                    "p": 4,                    "sValue": "6347.0"                  },                  {                    "p": 5,                    "sValue": "3922.0"                  },                  {                    "p": 3,                    "sValue": "4080.0"                  }                ]              },              {                "measObjInstId": "15361",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "5753.0"                  },                  {                    "p": 2,                    "sValue": "4194.0"                  },                  {                    "p": 4,                    "sValue": "8075.0"                  },                  {                    "p": 5,                    "sValue": "5585.0"                  },                  {                    "p": 3,                    "sValue": "3746.0"                  }                ]              },              {                "measObjInstId": "15548",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "4562.0"                  },                  {                    "p": 2,                    "sValue": "2896.0"                  },                  {                    "p": 4,                    "sValue": "6591.0"                  },                  {                    "p": 5,                    "sValue": "4534.0"                  },                  {                    "p": 3,                    "sValue": "3504.0"                  }                ]              },              {                "measObjInstId": "15549",                "suspectFlag": "false",                "measResults": [                  {                    "p": 1,                    "sValue": "4918.0"                  },                  {                    "p": 2,                    "sValue": "3244.0"                  },                  {                    "p": 4,                    "sValue": "6916.0"                  },                  {                    "p": 5,                    "sValue": "4883.0"                  },                  {                    "p": 3,                    "sValue": "3491.0"                  }                ]              }            ]          }        ]      }    }  }}
index 7cecbb4..a112fe0 100644 (file)
@@ -21,7 +21,7 @@
 ###############################################################################
 major=1
 minor=0
-patch=6
+patch=7
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
 snapshot_version=${base_version}-SNAPSHOT