summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/main/java/org/onap
diff options
context:
space:
mode:
authorYiLi <li.yi101@zte.com.cn>2018-02-11 17:39:05 +0800
committerYiLi <li.yi101@zte.com.cn>2018-02-12 11:56:57 +0800
commit83307e37a264972f4f9c60a114f40a375e32634b (patch)
treeed6639132fb0a97d8853ded37e9faa9f6eab4e24 /holmes-actions/src/main/java/org/onap
parentd4a991ad631f16831d380eef8e7405d9c2ea85c5 (diff)
Test Replace Jackson with GSON
Change-Id: I7ac92dd83a4bf7dcfb70199f1d0f61e600db8904 Issue-ID: HOLMES-115 Signed-off-by: YiLi <li.yi101@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java/org/onap')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java6
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java173
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java3
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java12
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java24
5 files changed, 107 insertions, 111 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index b80c40e..48e6ec0 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -65,11 +65,7 @@ public class AaiQuery {
private String getVmResourceLinks(String vserverId, String vserverName) throws CorrelationException {
String response = getResourceLinksResponse(vserverId, vserverName);
- try {
- return aaiResponseUtil.convertJsonToVmResourceLink(response).get(0).getResourceLink();
- } catch (Exception e) {
- throw new CorrelationException("Failed to get aai resource link", e);
- }
+ return aaiResponseUtil.convertJsonToVmResourceLink(response).get(0).getResourceLink();
}
private String getResourceLinksResponse(String vserverId, String vserverName) throws CorrelationException {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
index 37bfc1d..a8d3c0d 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,13 +15,15 @@
*/
package org.onap.holmes.common.aai;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jvnet.hk2.annotations.Service;
+import org.onap.holmes.common.aai.entity.RelationshipList;
import org.onap.holmes.common.aai.entity.RelationshipList.RelatedToProperty;
import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
@@ -33,41 +35,36 @@ import org.onap.holmes.common.aai.entity.VnfEntity;
public class AaiResponseUtil {
public static final String RELATIONSHIP_LIST = "relationship-list";
- public List<VmResourceLink> convertJsonToVmResourceLink(String responseJson) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(responseJson);
+ public List<VmResourceLink> convertJsonToVmResourceLink(String responseJson)
+ {
List<VmResourceLink> vmResourceLinkList = new ArrayList<>();
- if (jsonNode.has("result-data")) {
- JsonNode resultData = jsonNode.get("result-data");
+ String resultDataKey = "result-data";
+ JSONObject jsonNode = JSON.parseObject(responseJson);
+ if (jsonNode.get(resultDataKey) != null) {
+ JSONArray resultData = jsonNode.getJSONArray(resultDataKey);
vmResourceLinkList = convertResultDataList(resultData);
}
return vmResourceLinkList;
}
- public VmEntity convertJsonToVmEntity(String responseJson) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(responseJson);
- if (!jsonNode.iterator().hasNext()) {
+ public VmEntity convertJsonToVmEntity(String responseJson) {
+ JSONObject jsonObject = JSON.parseObject(responseJson);
+ if (jsonObject == null ||jsonObject.isEmpty()) {
return null;
}
VmEntity vmEntity = new VmEntity();
- vmEntity.setInMaint(getBooleanElementByNode(jsonNode, "in-maint"));
- vmEntity.setClosedLoopDisable(getBooleanElementByNode(jsonNode,"is-closed-loop-disabled"));
- vmEntity.setProvStatus(getTextElementByNode(jsonNode, "prov-status"));
- vmEntity.setResourceVersion(getTextElementByNode(jsonNode,"resource-version"));
- vmEntity.setVserverId(getTextElementByNode(jsonNode,"vserver-id"));
- vmEntity.setVserverName(getTextElementByNode(jsonNode,"vserver-name"));
- vmEntity.setVserverName2(getTextElementByNode(jsonNode,"vserver-name2"));
- vmEntity.setVserverSelflink(getTextElementByNode(jsonNode,"vserver-selflink"));
-
- if (jsonNode.has(RELATIONSHIP_LIST)) {
- JsonNode relationshipListNode = jsonNode.get(RELATIONSHIP_LIST);
- if (relationshipListNode.has("relationship")) {
- JsonNode relationshipNode = relationshipListNode.get("relationship");
- vmEntity.getRelationshipList().setRelationships(convertRelationships(relationshipNode));
- }
- }
+ vmEntity.setInMaint(getBooleanElementByNode(jsonObject, "in-maint"));
+ vmEntity.setClosedLoopDisable(
+ getBooleanElementByNode(jsonObject, "is-closed-loop-disabled"));
+ vmEntity.setProvStatus(getTextElementByNode(jsonObject, "prov-status"));
+ vmEntity.setResourceVersion(getTextElementByNode(jsonObject, "resource-version"));
+ vmEntity.setVserverId(getTextElementByNode(jsonObject, "vserver-id"));
+ vmEntity.setVserverName(getTextElementByNode(jsonObject, "vserver-name"));
+ vmEntity.setVserverName2(getTextElementByNode(jsonObject, "vserver-name2"));
+ vmEntity.setVserverSelflink(getTextElementByNode(jsonObject, "vserver-selflink"));
+
+ setRelationShips(jsonObject, vmEntity.getRelationshipList());
if (vmEntity.getRelationshipList().getRelationships() == null) {
vmEntity.getRelationshipList().setRelationships(Collections.emptyList());
}
@@ -75,110 +72,128 @@ public class AaiResponseUtil {
}
public VnfEntity convertJsonToVnfEntity(String responseJson) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode jsonNode = mapper.readTree(responseJson);
+ JSONObject jsonObject = JSON.parseObject(responseJson);
- if(!jsonNode.elements().hasNext())
+ if (jsonObject.isEmpty()) {
return null;
+ }
VnfEntity vnfEntity = new VnfEntity();
- vnfEntity.setInMaint(getBooleanElementByNode(jsonNode, "in-maint"));
- vnfEntity.setClosedLoopDisabled(getBooleanElementByNode(jsonNode, "is-closed-loop-disabled"));
- vnfEntity.setOrchestrationStatus(getTextElementByNode(jsonNode, "orchestration-status"));
- vnfEntity.setProvStatus(getTextElementByNode(jsonNode, "prov-status"));
- vnfEntity.setResourceVersion(getTextElementByNode(jsonNode,"resource-version"));
- vnfEntity.setServiceId(getTextElementByNode(jsonNode,"service-id"));
- vnfEntity.setVnfId(getTextElementByNode(jsonNode,"vnf-id"));
- vnfEntity.setVnfName(getTextElementByNode(jsonNode,"vnf-name"));
- vnfEntity.setVnfType(getTextElementByNode(jsonNode,"vnf-type"));
-
- if (jsonNode.has(RELATIONSHIP_LIST)) {
- JsonNode relationshipListNode = jsonNode.get(RELATIONSHIP_LIST);
- if (relationshipListNode.has("relationship")) {
- JsonNode relationshipNode = relationshipListNode.get("relationship");
- vnfEntity.getRelationshipList().setRelationships(convertRelationships(relationshipNode));
- }
- }
+ vnfEntity.setInMaint(getBooleanElementByNode(jsonObject, "in-maint"));
+ vnfEntity.setClosedLoopDisabled(
+ getBooleanElementByNode(jsonObject, "is-closed-loop-disabled"));
+ vnfEntity.setOrchestrationStatus(getTextElementByNode(jsonObject, "orchestration-status"));
+ vnfEntity.setProvStatus(getTextElementByNode(jsonObject, "prov-status"));
+ vnfEntity.setResourceVersion(getTextElementByNode(jsonObject, "resource-version"));
+ vnfEntity.setServiceId(getTextElementByNode(jsonObject, "service-id"));
+ vnfEntity.setVnfId(getTextElementByNode(jsonObject, "vnf-id"));
+ vnfEntity.setVnfName(getTextElementByNode(jsonObject, "vnf-name"));
+ vnfEntity.setVnfType(getTextElementByNode(jsonObject, "vnf-type"));
+
+ setRelationShips(jsonObject, vnfEntity.getRelationshipList());
if (vnfEntity.getRelationshipList().getRelationships() == null) {
vnfEntity.getRelationshipList().setRelationships(Collections.emptyList());
}
return vnfEntity;
}
- private List<VmResourceLink> convertResultDataList(JsonNode resultData) {
+ private void setRelationShips(JSONObject jsonObject, RelationshipList relationshipList) {
+ if (jsonObject.get(RELATIONSHIP_LIST) != null) {
+ JSONObject relationshipListNode = jsonObject.getJSONObject(RELATIONSHIP_LIST);
+ String relationship = "relationship";
+ if (relationshipListNode.get(relationship) != null) {
+ JSONArray relationshipNode = relationshipListNode.getJSONArray(relationship);
+ relationshipList
+ .setRelationships(convertRelationships(relationshipNode));
+ }
+ }
+ }
+
+ private List<VmResourceLink> convertResultDataList(JSONArray resultData) {
List<VmResourceLink> vmResourceLinkList = new ArrayList<>();
- resultData.forEach(node ->{
- if (node.has("resource-link") && node.has("resource-type")) {
+ String resourceLink = "resource-link";
+ String resourceType = "resource-type";
+ for (int i = 0; i < resultData.size(); i++) {
+ JSONObject jsonObject = resultData.getJSONObject(i);
+ if (jsonObject.get(resourceLink) != null
+ && jsonObject.get(resourceType) != null) {
VmResourceLink vmResourceLink = new VmResourceLink();
- vmResourceLink.setResourceLink(getTextElementByNode(node, "resource-link"));
- vmResourceLink.setResourceType(getTextElementByNode(node, "resource-type"));
+ vmResourceLink.setResourceLink(getTextElementByNode(jsonObject, resourceLink));
+ vmResourceLink.setResourceType(getTextElementByNode(jsonObject, resourceType));
vmResourceLinkList.add(vmResourceLink);
}
- });
+ }
return vmResourceLinkList;
}
- private List<Relationship> convertRelationships(JsonNode relationshipNode) {
+ private List<Relationship> convertRelationships(JSONArray relationshipNode) {
List<Relationship> relationshipList = new ArrayList<>();
- relationshipNode.forEach(node ->{
+ for (int i = 0; i < relationshipNode.size(); i++) {
Relationship relationship = new Relationship();
- relationship.setRelatedLink(getTextElementByNode(node, "related-link"));
- relationship.setRelatedTo(getTextElementByNode(node, "related-to"));
- if (node.has("related-to-property")) {
- JsonNode relatedToPropertyNode = node.get("related-to-property");
+ JSONObject jsonObject = relationshipNode.getJSONObject(i);
+
+ relationship.setRelatedLink(getTextElementByNode(jsonObject, "related-link"));
+ relationship.setRelatedTo(getTextElementByNode(jsonObject, "related-to"));
+ if (jsonObject.get("related-to-property") != null) {
+ JSONArray relatedToPropertyNode = jsonObject.getJSONArray("related-to-property");
relationship.setRelatedToPropertyList(
convertRelatedToProperty(relatedToPropertyNode));
} else {
relationship.setRelatedToPropertyList(Collections.emptyList());
}
- if (node.has("relationship-data")) {
- JsonNode relationshipDataNode = node.get("relationship-data");
+ if (jsonObject.get("relationship-data") != null) {
+ JSONArray relationshipDataNode = jsonObject.getJSONArray("relationship-data");
relationship
.setRelationshipDataList(convertRelationshipDate(relationshipDataNode));
} else {
relationship.setRelationshipDataList(Collections.emptyList());
}
relationshipList.add(relationship);
- });
+ }
+
return relationshipList;
}
- private List<RelationshipData> convertRelationshipDate(JsonNode relationshipDataNode) {
+ private List<RelationshipData> convertRelationshipDate(JSONArray relationshipDataNode) {
List<RelationshipData> relationshipDataList = new ArrayList<>();
- relationshipDataNode.forEach(node ->{
+ for (int i = 0; i < relationshipDataNode.size(); i++) {
+ JSONObject jsonObject = relationshipDataNode.getJSONObject(i);
RelationshipData relationshipData = new RelationshipData();
relationshipData.setRelationshipKey(
- getTextElementByNode(node,"relationship-key"));
+ getTextElementByNode(jsonObject, "relationship-key"));
relationshipData.setRelationshipValue(
- getTextElementByNode(node,"relationship-value"));
+ getTextElementByNode(jsonObject, "relationship-value"));
relationshipDataList.add(relationshipData);
- });
+ relationshipDataList.add(relationshipData);
+
+ }
return relationshipDataList;
}
- private List<RelatedToProperty> convertRelatedToProperty(JsonNode relatedToPropertyNode) {
+ private List<RelatedToProperty> convertRelatedToProperty(JSONArray relatedToPropertyNode) {
List<RelatedToProperty> relatedToPropertyList = new ArrayList<>();
- relatedToPropertyNode.forEach(node ->{
+ for (int i = 0; i < relatedToPropertyNode.size(); i++) {
+ JSONObject jsonObject = relatedToPropertyNode.getJSONObject(i);
RelatedToProperty relatedToProperty = new RelatedToProperty();
relatedToProperty
- .setPropertyKey(getTextElementByNode(node, "property-key"));
+ .setPropertyKey(getTextElementByNode(jsonObject, "property-key"));
relatedToProperty.setPropertyValue(
- getTextElementByNode(node, "property-value"));
+ getTextElementByNode(jsonObject, "property-value"));
relatedToPropertyList.add(relatedToProperty);
- });
+ }
return relatedToPropertyList;
}
- 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 Boolean getBooleanElementByNode(JsonNode jsonNode,String name){
- if(jsonNode.has(name)){
- return jsonNode.get(name).asBoolean();
+ private Boolean getBooleanElementByNode(JSONObject jsonNode, String name) {
+ if (jsonNode.get(name) != null) {
+ return jsonNode.getBoolean(name);
}
return null;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
index 204f352..9a1b0ea 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
@@ -21,7 +21,6 @@ import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-import org.glassfish.jersey.client.ClientConfig;
import org.onap.holmes.common.constant.AlarmConst;
@Slf4j
@@ -63,7 +62,7 @@ public class MicroServiceConfig {
}
private static String execQuery(String queryString) {
- Client client = ClientBuilder.newClient(new ClientConfig());
+ Client client = ClientBuilder.newBuilder().build();
Response response = client.target(queryString).request().get();
return response.readEntity(String.class);
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
index 91e9d42..5c6965a 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
@@ -15,8 +15,7 @@
*/
package org.onap.holmes.common.dmaap;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.alibaba.fastjson.JSON;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
@@ -43,14 +42,7 @@ public class Publisher {
public boolean publish(PolicyMsg msg) throws CorrelationException {
Client client = ClientBuilder.newClient(new ClientConfig());
- ObjectMapper mapper = new ObjectMapper();
- String content = null;
- try {
- content = mapper.writeValueAsString(msg);
- } catch (JsonProcessingException e) {
- throw new CorrelationException("Failed to convert the message object to a json string.",
- e);
- }
+ String content = JSON.toJSONString(msg);
WebTarget webTarget = client.target(url);
Response response = null;
try {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
index 2b8e114..b8552b2 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
@@ -15,16 +15,23 @@
*/
package org.onap.holmes.common.dropwizard.ioc.bundle;
+import com.codahale.metrics.health.HealthCheck;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import io.dropwizard.Configuration;
+import io.dropwizard.ConfiguredBundle;
+import io.dropwizard.lifecycle.ServerLifecycleListener;
+import io.dropwizard.servlets.tasks.Task;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
-
import org.eclipse.jetty.util.component.LifeCycle;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.ServiceLocatorFactory;
@@ -49,19 +56,6 @@ import org.reflections.util.FilterBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.codahale.metrics.health.HealthCheck;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.Lists;
-
-import io.dropwizard.Configuration;
-import io.dropwizard.ConfiguredBundle;
-import io.dropwizard.configuration.ConfigurationSourceProvider;
-import io.dropwizard.lifecycle.Managed;
-import io.dropwizard.lifecycle.ServerLifecycleListener;
-import io.dropwizard.servlets.tasks.Task;
-import io.dropwizard.setup.Bootstrap;
-import io.dropwizard.setup.Environment;
-
/**
* complete the integration of hK2 container and dropwizard
*