aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPATRACHARI <gp2421@att.com>2018-08-23 10:08:30 -0400
committerPATRACHARI <gp2421@att.com>2018-08-23 10:41:23 -0400
commit4ecf5ae18225d7792c337a42f1b57fbb599beda2 (patch)
tree0b520d6e96b81acccb8465991e821e6f324eb8f2
parentd161143571eec74f877e5be6b85e479c44aae881 (diff)
VES7.x to 5.x transformation
Update transformation code based on Min's requirement. This includes all Measurement transformations. Issue-ID: DCAEGEN2-600 Change-Id: I082df846e159a4f158619e700a6dfed6de43cd95 Signed-off-by: PATRACHARI <gp2421@att.com>
-rw-r--r--etc/eventTransform.json114
-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
5 files changed, 478 insertions, 5 deletions
diff --git a/etc/eventTransform.json b/etc/eventTransform.json
index cdefda07..838fca02 100644
--- a/etc/eventTransform.json
+++ b/etc/eventTransform.json
@@ -5,14 +5,29 @@
"event.commonEventHeader.domain":"heartbeat",
"VESversion":"v7"
},
-
"processors":
[
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.commonEventHeader.version",
+ "value": "3.0",
+ "fieldType": "number"
+ }
+ },
{
"functionName": "addAttribute",
"args":{
"field": "event.heartbeatFields.heartbeatFieldsVersion",
- "value": "2.0"
+ "value": "2.0",
+ "fieldType": "number"
+ }
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.heartbeatFields.additionalFields",
+ "mapType": "HashmapToNameValueArray"
}
}
]
@@ -25,6 +40,14 @@
},
"processors":
[
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.commonEventHeader.version",
+ "value": "3.0",
+ "fieldType": "number"
+ }
+ },
{
"functionName": "addAttribute",
"args":{
@@ -32,6 +55,13 @@
"value": "3.0",
"fieldType": "number"
}
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.faultFields.alarmAdditionalInformation",
+ "mapType": "HashmapToNameValueArray"
+ }
}
]
},
@@ -43,6 +73,14 @@
},
"processors":
[
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.commonEventHeader.version",
+ "value": "3.0",
+ "fieldType": "number"
+ }
+ },
{
"functionName": "addAttribute",
"args":{
@@ -50,6 +88,78 @@
"value": "3.0",
"fieldType": "number"
}
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.thresholdCrossingFields.additionalFields",
+ "mapType": "HashmapToNameValueArray"
+ }
+ }
+ ]
+ },
+ {
+ "filter":
+ {
+ "event.commonEventHeader.domain":"measurement",
+ "VESversion":"v7"
+ },
+ "processors":
+ [
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.commonEventHeader.version",
+ "value": "3.0",
+ "fieldType": "number"
+ }
+ },
+ {
+ "functionName": "removeAttribute",
+ "args":{
+ "field": "event.measurementFields.measurementFieldsVersion"
+ }
+ },
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.measurementFields.measurementsForVfScalingVersion",
+ "value": "3.0",
+ "fieldType": "number"
+ }
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.measurementFields.vNicPerformanceArray[]",
+ "oldField": "event.measurementFields.nicPerformanceArray[]",
+ "attrMap":{
+ "nicIdentifier":"vNicIdentifier"
+ }
+ }
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.measurementFields.additionalFields",
+ "oldField": "event.measurementFields.additionalFields",
+ "mapType": "hashmapToNameValueArray"
+ }
+ },
+ {
+ "functionName": "map",
+ "args":{
+ "field": "event.measurementsForVfScalingFields",
+ "oldField": "event.measurementFields",
+ "mapType": "renameObject"
+ }
+ },
+ {
+ "functionName": "addAttribute",
+ "args":{
+ "field": "event.commonEventHeader.domain",
+ "value": "measurementsForVfScaling"
+ }
}
]
},
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