summaryrefslogtreecommitdiffstats
path: root/dmaap-dsa
diff options
context:
space:
mode:
authorCongcong Peng <peng.congcong@zte.com.cn>2018-02-24 16:53:03 +0800
committerCongcong Peng <peng.congcong@zte.com.cn>2018-02-24 16:53:03 +0800
commitbe988c78605a1e90e13829db6505d12cd26ea1b4 (patch)
treee9d5c97adb4d7713f6a4d27cc69a71a0bfea2d12 /dmaap-dsa
parent890c2486828e677d790177934a59ae67f68c9762 (diff)
replace Jackson with fastJson
Issue-ID: HOLMES-115 Change-Id: I1dbcd7c0061a930c85afe460614f16c2e6d5514c Signed-off-by: Congcong Peng <peng.congcong@zte.com.cn>
Diffstat (limited to 'dmaap-dsa')
-rw-r--r--dmaap-dsa/pom.xml27
-rw-r--r--dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java97
-rw-r--r--dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java4
3 files changed, 73 insertions, 55 deletions
diff --git a/dmaap-dsa/pom.xml b/dmaap-dsa/pom.xml
index a999176..f0c7bd9 100644
--- a/dmaap-dsa/pom.xml
+++ b/dmaap-dsa/pom.xml
@@ -29,6 +29,13 @@
<packaging>jar</packaging>
<dependencies>
+
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>1.1.23</version>
+ </dependency>
+
<dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
@@ -71,6 +78,14 @@
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -148,12 +163,6 @@
<version>1.1.1</version>
</dependency>
<dependency>
- <groupId>net.sf.json-lib</groupId>
- <artifactId>json-lib</artifactId>
- <version>2.4</version>
- <classifier>jdk15</classifier>
- </dependency>
- <dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
@@ -177,6 +186,12 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
diff --git a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
index 5dffc7d..be30153 100644
--- a/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
+++ b/dmaap-dsa/src/main/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtil.java
@@ -15,95 +15,96 @@
*/
package org.onap.holmes.dsa.dmaappolling;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.api.stat.AlarmAdditionalField;
import org.onap.holmes.common.api.stat.VesAlarm;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
@Service
public class DMaaPResponseUtil {
public VesAlarm convertJsonToVesAlarm(String responseJson) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(responseJson);
- VesAlarm vesAlarm = new VesAlarm();
+ JSONObject jsonNode = JSON.parseObject(responseJson);
- JsonNode eventJson = jsonNode.get("event");
+ VesAlarm vesAlarm = new VesAlarm();
- JsonNode commonEventHeaderJson = eventJson.get("commonEventHeader");
+ JSONObject eventJson = JSON.parseObject(jsonNode.get("event") +"");
+ JSONObject commonEventHeaderJson = JSON.parseObject(eventJson.get("commonEventHeader") +"");
convertCommonEventHeaderJsonToEvent(commonEventHeaderJson, vesAlarm);
- JsonNode faultFieldsJson = eventJson.get("faultFields");
+ JSONObject faultFieldsJson = JSON.parseObject(eventJson.get("faultFields") +"");
convertFaultFieldsJsonToEvent(faultFieldsJson, vesAlarm);
return vesAlarm;
}
- private void convertCommonEventHeaderJsonToEvent(JsonNode commonEventHeaderJson,
- VesAlarm vesAlarm) {
- vesAlarm.setDomain(commonEventHeaderJson.get("domain").asText());
- vesAlarm.setEventId(commonEventHeaderJson.get("eventId").asText());
- vesAlarm.setEventName(commonEventHeaderJson.get("eventName").asText());
+ private void convertCommonEventHeaderJsonToEvent(JSONObject commonEventHeaderJson,
+ VesAlarm vesAlarm) {
+ vesAlarm.setDomain((String) commonEventHeaderJson.get("domain"));
+ vesAlarm.setEventId((String) commonEventHeaderJson.get("eventId"));
+ vesAlarm.setEventName((String) commonEventHeaderJson.get("eventName"));
vesAlarm.setAlarmIsCleared(vesAlarm.getEventName().endsWith("Cleared") ? 1 : 0);
vesAlarm.setEventType(getTextElementByNode(commonEventHeaderJson, "eventType"));
vesAlarm.setInternalHeaderFields(
getTextElementByNode(commonEventHeaderJson, "internalHeaderFields"));
- vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.get("lastEpochMicrosec").asLong());
+ vesAlarm.setLastEpochMicrosec(commonEventHeaderJson.getLong("lastEpochMicrosec"));
vesAlarm.setNfcNamingCode(getTextElementByNode(commonEventHeaderJson, "nfcNamingCode"));
vesAlarm.setNfNamingCode(getTextElementByNode(commonEventHeaderJson, "nfNamingCode"));
- vesAlarm.setPriority(commonEventHeaderJson.get("priority").asText());
+ vesAlarm.setPriority((String) commonEventHeaderJson.get("priority"));
vesAlarm.setReportingEntityId(
getTextElementByNode(commonEventHeaderJson, "reportingEntityId"));
- vesAlarm.setReportingEntityName(commonEventHeaderJson.get("reportingEntityName").asText());
- vesAlarm.setSequence(commonEventHeaderJson.get("sequence").asInt());
+ vesAlarm.setReportingEntityName( (String) commonEventHeaderJson.get("reportingEntityName"));
+ vesAlarm.setSequence((Integer) commonEventHeaderJson.get("sequence"));
vesAlarm.setSourceId(getTextElementByNode(commonEventHeaderJson, "sourceId"));
- vesAlarm.setSourceName(commonEventHeaderJson.get("sourceName").asText());
- vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.get("startEpochMicrosec").asLong());
- vesAlarm.setVersion(commonEventHeaderJson.get("version").asLong());
+ vesAlarm.setSourceName( (String) commonEventHeaderJson.get("sourceName"));
+ vesAlarm.setStartEpochMicrosec(commonEventHeaderJson.getLong("startEpochMicrosec"));
+ vesAlarm.setVersion(commonEventHeaderJson.getLong("version"));
}
- private void convertFaultFieldsJsonToEvent(JsonNode faultFieldsJson, VesAlarm vesAlarm) {
+ private void convertFaultFieldsJsonToEvent(JSONObject faultFieldsJson, VesAlarm vesAlarm) {
vesAlarm.setAlarmAdditionalInformation(getListElementByNode(faultFieldsJson, "alarmAdditionalInformation"));
- vesAlarm.setAlarmCondition(faultFieldsJson.get("alarmCondition").asText());
+ vesAlarm.setAlarmCondition(faultFieldsJson.getString("alarmCondition"));
vesAlarm.setAlarmInterfaceA(getTextElementByNode(faultFieldsJson, "alarmInterfaceA"));
vesAlarm.setEventCategory(getTextElementByNode(faultFieldsJson,"eventCategory"));
- vesAlarm.setEventSeverity(faultFieldsJson.get("eventSeverity").asText());
- vesAlarm.setEventSourceType(faultFieldsJson.get("eventSourceType").asText());
- vesAlarm.setFaultFieldsVersion(faultFieldsJson.get("faultFieldsVersion").asLong());
- vesAlarm.setSpecificProblem(faultFieldsJson.get("specificProblem").asText());
- vesAlarm.setVfStatus(faultFieldsJson.get("vfStatus").asText());
+ vesAlarm.setEventSeverity(faultFieldsJson.getString("eventSeverity"));
+ vesAlarm.setEventSourceType(faultFieldsJson.getString("eventSourceType"));
+ vesAlarm.setFaultFieldsVersion(faultFieldsJson.getLong("faultFieldsVersion"));
+ vesAlarm.setSpecificProblem(faultFieldsJson.getString("specificProblem"));
+ vesAlarm.setVfStatus(faultFieldsJson.getString("vfStatus"));
}
- private String getTextElementByNode(JsonNode jsonNode,String name){
- if(jsonNode.has(name)){
- return jsonNode.get(name).asText();
+ private String getTextElementByNode(JSONObject jsonNode,String name){
+ if(jsonNode.get(name) != null){
+ return jsonNode.getString(name);
}
return null;
}
- private Long getLongElementByNode(JsonNode jsonNode, String name) {
- if(jsonNode.has(name)){
- return jsonNode.get(name).asLong();
+ private Long getLongElementByNode(JSONObject jsonNode, String name) {
+ if(jsonNode.get(name) != null){
+ return jsonNode.getLong(name);
}
return null;
}
- private List<AlarmAdditionalField> getListElementByNode(JsonNode jsonNode, String name){
+ private List<AlarmAdditionalField> getListElementByNode(JSONObject jsonNode, String name){
List<AlarmAdditionalField> alarms = new ArrayList<AlarmAdditionalField>();
- if (jsonNode.has(name)) {
- JsonNode alarmAdditionalInformations = jsonNode.get(name);
- if (alarmAdditionalInformations.isArray()) {
- alarmAdditionalInformations.forEach(alarm -> {
- if(alarm.has("name") && alarm.has("value")) {
- AlarmAdditionalField field = new AlarmAdditionalField();
- field.setName(getTextElementByNode(alarm, "name"));
- field.setValue(getTextElementByNode(alarm, "value"));
- alarms.add(field);
- }
- });
+ if (jsonNode.get(name) != null) {
+ JSONArray alarmAdditionalInformations = jsonNode.getJSONArray(name);
+ for (int i = 0; i < alarmAdditionalInformations.size(); i++) {
+ JSONObject jsonObject = alarmAdditionalInformations.getJSONObject(i);
+ if (jsonObject.get("name") != null
+ && jsonObject.get("value") != null) {
+ AlarmAdditionalField field = new AlarmAdditionalField();
+ field.setName(getTextElementByNode(jsonObject, "name"));
+ field.setValue(getTextElementByNode(jsonObject, "value"));
+ alarms.add(field);
+ }
}
}
return alarms;
diff --git a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
index aacbee3..26fba51 100644
--- a/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
+++ b/dmaap-dsa/src/test/java/org/onap/holmes/dsa/dmaappolling/DMaaPResponseUtilTest.java
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+
+import com.alibaba.fastjson.JSONException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -161,7 +163,7 @@ public class DMaaPResponseUtilTest {
@Test
public void testDMaaPResponseUtil_input_illegal() throws Exception {
String json = "***";
- thrown.expect(IOException.class);
+ thrown.expect(JSONException.class);
dMaaPResponseUtil.convertJsonToVesAlarm(json);
}