aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java99
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java65
-rw-r--r--src/test/resources/measurement5x.json98
-rw-r--r--src/test/resources/measurement7x.json107
4 files changed, 366 insertions, 3 deletions
diff --git a/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java b/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java
index e3d59098..a9d6b981 100644
--- a/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java
+++ b/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java
@@ -38,6 +38,7 @@ public class ConfigProcessors {
private static final String REGEX = "\\[\\]";
private static final String OBJECT_NOT_FOUND = "ObjectNotFound";
private static final String FILTER_NOT_MET = "Filter not met";
+ private static final String MAP_TYPE = "mapType";
private static final String COMP_FALSE = "==false";
private final JSONObject event;
@@ -155,17 +156,43 @@ public class ConfigProcessors {
log.info(FILTER_NOT_MET);
}
+ private void renameObject(JSONObject jsonObject) // map
+ {
+ log.info("renameArrayInArray");
+ final String field = jsonObject.getString(FIELD);
+ final String oldField = jsonObject.getString(OLD_FIELD);
+ final JSONObject filter = jsonObject.optJSONObject(FILTER);
+ if (filter == null || isFilterMet(filter)) {
+
+ final JSONObject oldValue = (JSONObject) getEventObjectVal(oldField);
+ if (!oldValue.equals(OBJECT_NOT_FOUND)) {
+ setEventObjectVal(field, oldValue);
+ removeEventKey(oldField);
+ }
+ } else
+ log.info(FILTER_NOT_MET);
+ }
+
public void map(JSONObject jsonObject) {
final String field = jsonObject.getString(FIELD);
+ final String mapType = jsonObject.optString(MAP_TYPE, "");
if (field.contains("[]")) {
if (field.matches(".*\\[\\]\\..*\\[\\]"))
renameArrayInArray(jsonObject);
else
mapToJArray(jsonObject);
- } else
- mapAttribute(jsonObject);
+ }
+ else if (mapType.equals("hashmapToNameValueArray"))
+ mapHashmapToNameValueArray(jsonObject);
+ else if (mapType.equals("nameValueArrayToHashmap"))
+ mapNameValueArrayToHashmap(jsonObject);
+ else if (mapType.equals("renameObject"))
+ renameObject(jsonObject);
+
+ else
+ mapAttribute(jsonObject);
}
private String performOperation(String operation, String value) {
@@ -252,6 +279,74 @@ public class ConfigProcessors {
} else
log.info(FILTER_NOT_MET);
}
+
+ // this method is to support the mapping 5.x to VES7.x format for additionalInformation field
+ private void mapNameValueArrayToHashmap(JSONObject jsonObject) {
+ log.info("mapNameValueArrayToHashmap");
+ String field = jsonObject.getString(FIELD);
+ String oldField = jsonObject.getString(FIELD);
+ final JSONObject filter = jsonObject.optJSONObject(FILTER);
+
+ if (filter == null || isFilterMet(filter)) {
+ JSONObject newHashMap = new JSONObject(); // this will hold the newly mapped hashmap elements
+ JSONArray arrayValue = (JSONArray) getEventObjectVal(oldField); // old Array structure value
+ JSONObject tempJObj = null;
+ String tempName = "";
+ String tempValue = "";
+ if (!arrayValue.equals(OBJECT_NOT_FOUND)) {
+ log.info("old value ==" + arrayValue.toString());
+ // Loop thru the JSONArray, get the name:value pair and write to new JSONObject as hashmap elements
+ for (int i = 0; i < arrayValue.length(); i++) {
+
+ tempJObj = arrayValue.getJSONObject(i);
+ if (tempJObj != null) {
+ tempName = tempJObj.get("name").toString();
+ tempValue = tempJObj.get("value").toString();
+ newHashMap.put(tempName, tempValue);
+ }
+ }
+ // remove the old Array structure
+ removeEventKey(oldField);
+ //Add the new Hashmap
+ setEventObjectVal(field, newHashMap);
+ }
+ } else
+ log.info(FILTER_NOT_MET);
+ }
+
+ // this method is to support the mapping 7.x to VES5.x format for additionalInformation field
+ private void mapHashmapToNameValueArray(JSONObject jsonObject) {
+ log.info("mapHashmapToNameValueArray");
+ System.out.println("mapHashmapToNameValueArray");
+ String field = jsonObject.getString(FIELD);
+ String oldField = jsonObject.getString(FIELD);
+ final JSONObject filter = jsonObject.optJSONObject(FILTER);
+
+ if (filter == null || isFilterMet(filter)) {
+ JSONArray newArray = new JSONArray(); // this will hold the new name:value JSONObject
+ JSONObject nameValJObj;
+ System.out.println("object ==" + getEventObjectVal(oldField).toString());
+ if (!getEventObjectVal(oldField).toString().equals(OBJECT_NOT_FOUND)) {
+
+ JSONObject hashMap = (JSONObject) getEventObjectVal(oldField); // old hashmap structure value
+ if (hashMap != null) {
+ log.info("old value ==" + hashMap.toString());
+ // Loop thru the hashMap JSONObject, get the hashmap elements add them as name:value JsonObject into the newArray
+ for (String key : hashMap.keySet()) {
+ nameValJObj = new JSONObject(); //create new object so not to overwrite in memory for Array insertion
+ nameValJObj.put("name", key);
+ nameValJObj.put("value", hashMap.get(key));
+ newArray.put(nameValJObj);
+ }
+ // remove the old hashMap structure
+ removeEventKey(oldField);
+ //Add the newArray containing the name:value Object
+ setEventObjectVal(field, newArray);
+ }
+ }
+ } else
+ log.info(FILTER_NOT_MET);
+ }
/**
* example - { "functionName": "concatenateValue", "args":{ "filter":
diff --git a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
index 09517ae3..310e8be3 100644
--- a/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
+++ b/src/test/java/org/onap/dcae/vestest/TestConfigProcessor.java
@@ -20,6 +20,7 @@
package org.onap.dcae.vestest;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import java.io.FileReader;
import java.io.IOException;
@@ -116,8 +117,70 @@ public class TestConfigProcessor {
System.out.println("responseData==" + responseData);
assertEquals(receiveDiscards, responseData);
}
+
+ @Test
+ public void testMapRenameObject() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.faultVFScalingFields\",\"oldField\": \"event.faultFields.errors\",\"mapType\":\"renameObject\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.errors").toString();
+ System.out.println("receiveDiscards==" + receiveDiscards);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent
+ .getEventObjectVal("event.faultFields.faultVFScalingFields")
+ .toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertEquals(receiveDiscards, responseData);
+ }
+ @Test
+ public void testMapHashmapToNameValueArray() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.errors\",\"mapType\":\"hashmapToNameValueArray\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.errors").toString();
+ System.out.println("receiveDiscards==" + receiveDiscards);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent
+ .getEventObjectVal("event.faultFields.errors")
+ .toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertNotEquals(receiveDiscards, responseData);
+ }
@Test
+ public void testMapNameValueArrayToHashmap() {
+
+ final JSONObject jsonObject = getFileAsJsonObject();
+ //final String receiveDiscards = (((jsonObject.getJSONObject("event")).getJSONObject("faultFields")).get("errors")).get("receiveDiscards").toString();
+ System.out.println("event==" + jsonObject.toString());
+ //System.out.println("alarmAdditionalInformation==" + alarmAdditionalInformation);
+ final JSONObject jsonArgs = new JSONObject(
+ "{\"field\": \"event.faultFields.alarmAdditionalInformation\",\"mapType\":\"nameValueArrayToHashmap\"}");
+ ConfigProcessors cpEvent = new ConfigProcessors(jsonObject);
+ final String receiveDiscards = cpEvent.getEventObjectVal("event.faultFields.alarmAdditionalInformation").toString();
+ System.out.println("receiveDiscards==" + receiveDiscards);
+ cpEvent.map(jsonArgs);
+ final String responseData = cpEvent
+ .getEventObjectVal("event.faultFields.alarmAdditionalInformation")
+ .toString();
+ System.out.println("modified event==" + jsonObject.toString());
+ System.out.println("responseData==" + responseData);
+ assertNotEquals(receiveDiscards, responseData);
+ }
+
+ @Test
public void testAttrAdd() {
final JSONObject jsonObject = getFileAsJsonObject();
@@ -304,6 +367,6 @@ public class TestConfigProcessor {
System.out.println("responseData==" + responseData);
assertEquals("true", responseData);
- }
+ }
}
diff --git a/src/test/resources/measurement5x.json b/src/test/resources/measurement5x.json
new file mode 100644
index 00000000..585ec370
--- /dev/null
+++ b/src/test/resources/measurement5x.json
@@ -0,0 +1,98 @@
+ {
+ "VESversion":"v5",
+ "event": {
+ "commonEventHeader": {
+ "startEpochMicrosec": 1534868302434191,
+ "eventId": "measurementsForVfScaling_vAfx_127.0.0.1",
+ "nfcNamingCode": "AFX",
+ "reportingEntityId": "bgtnj05vmh01afx",
+ "eventType": "applicationVnf",
+ "priority": "Normal",
+ "version": 3,
+ "reportingEntityName": "AFXM",
+ "sequence": 0,
+ "domain": "measurementsForVfScaling",
+ "lastEpochMicrosec": 1534868602564759,
+ "eventName": "measurementsForVfScaling_vAfx",
+ "sourceName": "bgtnj05vmh01afx",
+ "nfNamingCode": "AFX"
+ },
+ "measurementsForVfScalingFields": {
+ "cpuUsageArray": [{
+ "cpuUsageNice": 0,
+ "percentUsage": 0.39,
+ "cpuIdentifier": "all",
+ "cpuIdle": 99.61,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.22
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.36,
+ "cpuIdentifier": "cpu0",
+ "cpuIdle": 99.64,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.21
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.34,
+ "cpuIdentifier": "cpu1",
+ "cpuIdle": 99.66,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.2
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.52,
+ "cpuIdentifier": "cpu2",
+ "cpuIdle": 99.48,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.3
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.33,
+ "cpuIdentifier": "cpu3",
+ "cpuIdle": 99.67,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.19
+ }],
+ "measurementInterval": 300,
+ "measurementsForVfScalingVersion": 2,
+ "vNicPerformanceArray": [{
+ "transmittedOctetsDelta": 1533682,
+ "receivedMulticastPacketsAccumulated": 0,
+ "receivedMulticastPacketsDelta": 0,
+ "receivedOctetsAccumulated": 1.215192543E9,
+ "receivedTotalPacketsDelta": 7988,
+ "vNicIdentifier": "ens2 DNS2_RSLOTPORT_VLAN_CLASSTYPE",
+ "valuesAreSuspect": "true",
+ "transmittedTotalPacketsDelta": 9326,
+ "transmittedTotalPacketsAccumulated": 7460880,
+ "receivedOctetsDelta": 548159,
+ "transmittedOctetsAccumulated": 1.055825979E9,
+ "receivedTotalPacketsAccumulated": 1.3555845E7
+ }, {
+ "transmittedOctetsDelta": 0,
+ "receivedMulticastPacketsAccumulated": 0,
+ "receivedMulticastPacketsDelta": 0,
+ "receivedOctetsAccumulated": 5412138,
+ "receivedTotalPacketsDelta": 0,
+ "vNicIdentifier": "lo DNS1_RSLOTPORT_VLAN_CLASSTYPE",
+ "valuesAreSuspect": "true",
+ "transmittedTotalPacketsDelta": 0,
+ "transmittedTotalPacketsAccumulated": 53567,
+ "receivedOctetsDelta": 0,
+ "transmittedOctetsAccumulated": 5412138,
+ "receivedTotalPacketsAccumulated": 53567
+ }],
+ "memoryUsageArray": [{
+ "memorySlabUnrecl": 17560,
+ "memoryCached": 976988,
+ "memoryFree": 6446628,
+ "memorySlabRecl": 83908,
+ "memoryBuffered": 198020,
+ "memoryUsed": 353492,
+ "vmIdentifier": "RAM",
+ "memoryConfigured": 8076596
+ }]
+ }
+ }
+ } \ No newline at end of file
diff --git a/src/test/resources/measurement7x.json b/src/test/resources/measurement7x.json
new file mode 100644
index 00000000..6e9fd1f4
--- /dev/null
+++ b/src/test/resources/measurement7x.json
@@ -0,0 +1,107 @@
+ {
+ "VESversion":"v7",
+ "event": {
+ "commonEventHeader": {
+ "startEpochMicrosec": 1534868302434191,
+ "eventId": "measurementsForVfScaling_vAfx_127.0.0.1",
+ "nfcNamingCode": "AFX",
+ "reportingEntityId": "bgtnj05vmh01afx",
+ "eventType": "applicationVnf",
+ "priority": "Normal",
+ "version": "4.0.1",
+ "reportingEntityName": "AFXM",
+ "sequence": 0,
+ "domain": "measurement",
+ "lastEpochMicrosec": 1534868602564759,
+ "eventName": "measurement",
+ "sourceName": "bgtnj05vmh01afx",
+ "nfNamingCode": "AFX",
+ "vesEventListenerVersion" : "7.0.1"
+ },
+ "measurementFields": {
+ "cpuUsageArray": [{
+ "cpuUsageNice": 0,
+ "percentUsage": 0.39,
+ "cpuIdentifier": "all",
+ "cpuIdle": 99.61,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.22,
+ "cpuCapacityContention": 0,
+ "cpuDemandAvg": 0,
+ "cpuDemandMhz": 0,
+ "cpuDemandPct": 0,
+ "cpuLatencyAvg": 0,
+ "cpuOverheadAvg": 0,
+ "cpuSwapWaitTime": 0
+
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.36,
+ "cpuIdentifier": "cpu0",
+ "cpuIdle": 99.64,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.21
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.34,
+ "cpuIdentifier": "cpu1",
+ "cpuIdle": 99.66,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.2
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.52,
+ "cpuIdentifier": "cpu2",
+ "cpuIdle": 99.48,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.3
+ }, {
+ "cpuUsageNice": 0,
+ "percentUsage": 0.33,
+ "cpuIdentifier": "cpu3",
+ "cpuIdle": 99.67,
+ "cpuUsageSystem": 0,
+ "cpuUsageUser": 0.19
+ }],
+ "measurementInterval": 300,
+ "measurementFieldsVersion": "4.0",
+ "nicPerformanceArray": [{
+ "transmittedOctetsDelta": 1533682,
+ "receivedMulticastPacketsAccumulated": 0,
+ "receivedMulticastPacketsDelta": 0,
+ "receivedOctetsAccumulated": 1.215192543E9,
+ "receivedTotalPacketsDelta": 7988,
+ "nicIdentifier": "ens2 DNS2_RSLOTPORT_VLAN_CLASSTYPE",
+ "valuesAreSuspect": "true",
+ "transmittedTotalPacketsDelta": 9326,
+ "transmittedTotalPacketsAccumulated": 7460880,
+ "receivedOctetsDelta": 548159,
+ "transmittedOctetsAccumulated": 1.055825979E9,
+ "receivedTotalPacketsAccumulated": 1.3555845E7
+ }, {
+ "transmittedOctetsDelta": 0,
+ "receivedMulticastPacketsAccumulated": 0,
+ "receivedMulticastPacketsDelta": 0,
+ "receivedOctetsAccumulated": 5412138,
+ "receivedTotalPacketsDelta": 0,
+ "nicIdentifier": "lo DNS1_RSLOTPORT_VLAN_CLASSTYPE",
+ "valuesAreSuspect": "true",
+ "transmittedTotalPacketsDelta": 0,
+ "transmittedTotalPacketsAccumulated": 53567,
+ "receivedOctetsDelta": 0,
+ "transmittedOctetsAccumulated": 5412138,
+ "receivedTotalPacketsAccumulated": 53567
+ }],
+ "memoryUsageArray": [{
+ "memorySlabUnrecl": 17560,
+ "memoryCached": 976988,
+ "memoryFree": 6446628,
+ "memorySlabRecl": 83908,
+ "memoryBuffered": 198020,
+ "memoryUsed": 353492,
+ "vmIdentifier": "RAM",
+ "memoryConfigured": 8076596
+ }]
+ }
+ }
+ } \ No newline at end of file