diff options
author | 2020-07-16 16:11:50 +0800 | |
---|---|---|
committer | 2020-07-17 08:57:08 +0800 | |
commit | 490fc3c1fafe50d5fb0e23db5cfd10730be96866 (patch) | |
tree | 7c6aa468714460bc584666956d7fb8ff2df0edc9 /holmes-actions/src/main/java | |
parent | 3e5ddaee6984869b67dda89b7f8e1932a2b27045 (diff) |
Fixed the CLM Issues
Change-Id: I8e6703078c400e94eec6eaa9a65a7e7dc3f0218e
Issue-ID: HOLMES-331
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java')
11 files changed, 306 insertions, 223 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java index e6cd207..8bc006a 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.holmes.common.aai * ================================================================================ - * Copyright (C) 2018-2019 Huawei. All rights reserved. + * Copyright (C) 2018-2020 Huawei. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,10 @@ package org.onap.holmes.common.aai; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.config.AaiConfig; @@ -77,14 +79,14 @@ public class AaiJsonParserUtil { } } - public static JSONObject getInfo(String response, String field) { - JSONObject jObject = JSONObject.parseObject(response); - JSONObject relationshipList = extractJsonObject(jObject, "relationship-list"); - JSONArray relationShip = extractJsonArray(relationshipList, "relationship"); + public static JsonObject getInfo(String response, String field) { + JsonObject jObject = JsonParser.parseString(response).getAsJsonObject(); + JsonObject relationshipList = extractJsonObject(jObject, "relationship-list"); + JsonArray relationShip = extractJsonArray(relationshipList, "relationship"); if (relationShip != null) { for (int i = 0; i < relationShip.size(); ++i) { - final JSONObject object = relationShip.getJSONObject(i); - if (object.getString("related-to").equals(field)) { + final JsonObject object = relationShip.get(i).getAsJsonObject(); + if (object.get("related-to").getAsString().equals(field)) { return object; } } @@ -92,16 +94,16 @@ public class AaiJsonParserUtil { return null; } - public static JSONObject extractJsonObject(JSONObject obj, String key) { - if (obj != null && key != null && obj.containsKey(key)) { - return obj.getJSONObject(key); + public static JsonObject extractJsonObject(JsonObject obj, String key) { + if (obj != null && key != null && obj.has(key)) { + return obj.get(key).getAsJsonObject(); } return null; } - public static JSONArray extractJsonArray(JSONObject obj, String key) { - if (obj != null && key != null && obj.containsKey(key)) { - return obj.getJSONArray(key); + public static JsonArray extractJsonArray(JsonObject obj, String key) { + if (obj != null && key != null && obj.has(key)) { + return obj.get(key).getAsJsonArray(); } return null; } @@ -111,11 +113,12 @@ public class AaiJsonParserUtil { } public static String getErrorMsg(String url, Map<String, Object> body, Response response) { + Gson gson = new Gson(); StringBuilder sb = new StringBuilder(); sb.append("Rerquest URL: ").append(url).append("\n"); - sb.append("Request Header: ").append(JSONObject.toJSONString(getAaiHeaders())).append("\n"); + sb.append("Request Header: ").append(gson.toJson(getAaiHeaders())).append("\n"); if (body != null) { - sb.append("Request Body: ").append(JSONObject.toJSONString(body)).append("\n"); + sb.append("Request Body: ").append(gson.toJson(body)).append("\n"); } if (response != null) { sb.append("Request Body: ").append(response.readEntity(String.class)); 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 b11cafc..f409c27 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 @@ -13,12 +13,6 @@ */ package org.onap.holmes.common.aai; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.inject.Inject; - import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -30,6 +24,12 @@ import org.onap.holmes.common.aai.entity.VnfEntity; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.HttpsUtils; +import javax.inject.Inject; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @Service @Slf4j public class AaiQuery { @@ -94,30 +94,6 @@ public class AaiQuery { return "https://aai.onap:8443" + suffixUrl; } - private String getMsbSuffixAddr(String suffixUrl) { - if (suffixUrl.length() <= 0) { - return ""; - } - String[] addrSplits = suffixUrl.substring(1).split("/"); - String[] conv = addrSplits[2].split("-"); - addrSplits[2] = conv[0]; - if (conv.length > 1) { - for (int i = 1; i < conv.length; i++) { - addrSplits[2] = addrSplits[2] + conv[i].substring(0, 1).toUpperCase() + conv[i] - .substring(1); - } - } - String ret = addrSplits[1]; - addrSplits[1] = addrSplits[0] + "-" + addrSplits[2]; - addrSplits[2] = ret; - addrSplits[0] = "api"; - StringBuilder stringBuffer = new StringBuilder(); - for (String split : addrSplits) { - stringBuffer.append("/" + split); - } - return stringBuffer.toString(); - } - private String getResponse(String url) throws CorrelationException { String response; CloseableHttpClient httpClient = null; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java index 4cf2aba..9feba18 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java @@ -1,5 +1,5 @@ /** - * Copyright 2018 ZTE Corporation. + * Copyright 2018-2020 ZTE Corporation. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -14,13 +14,16 @@ package org.onap.holmes.common.aai; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.glassfish.jersey.client.HttpUrlConnectorProvider; import org.onap.holmes.common.aai.config.AaiConfig; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -34,11 +37,10 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import lombok.extern.slf4j.Slf4j; - -@Slf4j public class AaiQuery4Ccvpn { + private final Logger log = LoggerFactory.getLogger(AaiQuery4Ccvpn.class); + private MultivaluedMap<String, Object> headers; public static AaiQuery4Ccvpn newInstance() { @@ -47,7 +49,7 @@ public class AaiQuery4Ccvpn { private static final String EMPTY_STR = ""; - private static final JSONObject EMPTY_JSON = new JSONObject(); + private static final JsonObject EMPTY_JSON = new JsonObject(); private AaiQuery4Ccvpn() { headers = new MultivaluedHashMap<>(); @@ -77,13 +79,13 @@ public class AaiQuery4Ccvpn { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_QUERY, params) + (status == null ? "" : String.format("&operational-status=%s", status))); - JSONObject linkInfo = getInfo(response.readEntity(String.class), "p-interface", "logical-link"); + JsonObject linkInfo = getInfo(response.readEntity(String.class), "p-interface", "logical-link"); if (linkInfo == null) { log.warn(String.format("Link information is missing from AAI. Method: [getLogicLink], " + "params: [networkId - %s, pnfName - %s, ifName - %s].", networkId, pnfName, ifName)); return EMPTY_STR; } - return extractValueFromJsonArray(linkInfo.getJSONArray("relationship-data"), "logical-link.link-name"); + return extractValueFromJsonArray(linkInfo.get("relationship-data").getAsJsonArray(), "logical-link.link-name"); } /** @@ -99,37 +101,37 @@ public class AaiQuery4Ccvpn { * @param status * @return service instances in JSONObject format */ - public JSONObject getServiceInstance(String networkId, String pnfName, String ifName, String status) { + public JsonObject getServiceInstance(String networkId, String pnfName, String ifName, String status) { try { - JSONObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status); + JsonObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status); if (vpnBindingInfo == null) { log.warn(String.format("VPN binding information is missing from AAI. " + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); return EMPTY_JSON; } - String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.getJSONArray("relationship-data"), + String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.get("relationship-data").getAsJsonArray(), "vpn-binding.vpn-id"); - JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId); + JsonObject connectivityInfo = getConnectivityInfo(vpnBindingId); if (connectivityInfo == null) { log.warn(String.format("Connectivity information is missing from AAI. " + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); return EMPTY_JSON; } - String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"), + String connectivityId = extractValueFromJsonArray(connectivityInfo.get("relationship-data").getAsJsonArray(), "connectivity.connectivity-id"); - JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); + JsonObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); if (serviceInstanceInfo == null) { log.warn(String.format("Service instance information is missing from AAI. " + "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " + "ifName - %s, status - %s].", networkId, pnfName, ifName, status)); return EMPTY_JSON; } - String serviceInstancePath = serviceInstanceInfo.getString("related-link"); + String serviceInstancePath = serviceInstanceInfo.get("related-link").getAsString(); Response response = get(getHostAddr(), getPath(serviceInstancePath)); - JSONObject instance = JSON.parseObject(response.readEntity(String.class)); + JsonObject instance = JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject(); String[] params = new String[2]; Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)" + @@ -140,8 +142,8 @@ public class AaiQuery4Ccvpn { params[0] = matcher.group(1); params[1] = matcher.group(2); } - instance.put("globalSubscriberId", params[0]); - instance.put("serviceType", params[1]); + instance.addProperty("globalSubscriberId", params[0]); + instance.addProperty("serviceType", params[1]); return instance; } catch (CorrelationException e) { throw new RuntimeException(e.getMessage(), e); @@ -155,7 +157,7 @@ public class AaiQuery4Ccvpn { params.put("pnfName", pnfName); params.put("ifName", ifName); Response r = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, params)); - JSONObject jsonObject = JSONObject.parseObject(r.readEntity(String.class)); + JsonObject jsonObject = JsonParser.parseString(r.readEntity(String.class)).getAsJsonObject(); body.put("resource-version", jsonObject.get("resource-version").toString()); put(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, params), body); @@ -163,13 +165,13 @@ public class AaiQuery4Ccvpn { public void updateLogicLinkStatus(String linkName, Map<String, Object> body) throws CorrelationException { Response r = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_UPDATE, "linkName", linkName)); - JSONObject jsonObject = JSONObject.parseObject(r.readEntity(String.class)); + JsonObject jsonObject = JsonParser.parseString(r.readEntity(String.class)).getAsJsonObject(); body.put("resource-version", jsonObject.get("resource-version").toString()); body.put("link-type", jsonObject.get("link-type").toString()); put(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_UPDATE, "linkName", linkName), body); } - private JSONObject getVpnBindingInfo(String networkId, String pnfName, + private JsonObject getVpnBindingInfo(String networkId, String pnfName, String ifName, String status) throws CorrelationException { Map<String, String> params = new HashMap(); params.put("networkId", networkId); @@ -180,23 +182,23 @@ public class AaiQuery4Ccvpn { return getInfo(response.readEntity(String.class), "p-interface", "vpn-binding"); } - private JSONObject getConnectivityInfo(String vpnId) throws CorrelationException { + private JsonObject getConnectivityInfo(String vpnId) throws CorrelationException { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_CONN_ADDR, "vpnId", vpnId)); return getInfo(response.readEntity(String.class), "vpn-binding", "connectivity"); } - private JSONObject getServiceInstanceByConn(String connectivityId) throws CorrelationException { + private JsonObject getServiceInstanceByConn(String connectivityId) throws CorrelationException { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN, "connectivityId", connectivityId)); return getInfo(response.readEntity(String.class), "connectivity", "service-instance"); } - private JSONObject getServiceInstance(String globalCustomerId, String serviceType) throws CorrelationException { + private JsonObject getServiceInstance(String globalCustomerId, String serviceType) throws CorrelationException { Map<String, String> params = new HashMap(); params.put("global-customer-id", globalCustomerId); params.put("service-type", serviceType); Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCES_ADDR_4_CCVPN, params)); - return JSON.parseObject(response.readEntity(String.class)); + return JsonParser.parseString(response.readEntity(String.class)).getAsJsonObject(); } private String getPath(String urlTemplate, Map<String, String> pathParams) { @@ -260,18 +262,18 @@ public class AaiQuery4Ccvpn { } } - private JSONObject getInfo(String response, String pField, String field) { - JSONObject jObject = JSONObject.parseObject(response); - JSONObject pInterface = extractJsonObject(jObject, pField); + private JsonObject getInfo(String response, String pField, String field) { + JsonObject jObject = JsonParser.parseString(response).getAsJsonObject(); + JsonObject pInterface = extractJsonObject(jObject, pField); if (pInterface == null) { pInterface = jObject; } - JSONObject relationshipList = extractJsonObject(pInterface, "relationship-list"); - JSONArray relationShip = extractJsonArray(relationshipList, "relationship"); + JsonObject relationshipList = extractJsonObject(pInterface, "relationship-list"); + JsonArray relationShip = extractJsonArray(relationshipList, "relationship"); if (relationShip != null) { for (int i = 0; i < relationShip.size(); ++i) { - final JSONObject object = relationShip.getJSONObject(i); - if (object.getString("related-to").equals(field)) { + final JsonObject object = relationShip.get(i).getAsJsonObject(); + if (object.get("related-to").getAsString().equals(field)) { return object; } } @@ -279,16 +281,16 @@ public class AaiQuery4Ccvpn { return null; } - private JSONObject extractJsonObject(JSONObject obj, String key) { - if (obj != null && key != null && obj.containsKey(key)) { - return obj.getJSONObject(key); + private JsonObject extractJsonObject(JsonObject obj, String key) { + if (obj != null && key != null && obj.has(key)) { + return obj.get(key).getAsJsonObject(); } return null; } - private JSONArray extractJsonArray(JSONObject obj, String key) { - if (obj != null && key != null && obj.containsKey(key)) { - return obj.getJSONArray(key); + private JsonArray extractJsonArray(JsonObject obj, String key) { + if (obj != null && key != null && obj.has(key)) { + return obj.get(key).getAsJsonArray(); } return null; } @@ -301,12 +303,12 @@ public class AaiQuery4Ccvpn { return MicroServiceConfig.getMsbServerAddrWithHttpPrefix(); } - private String extractValueFromJsonArray(JSONArray relationshipData, String keyName) { + private String extractValueFromJsonArray(JsonArray relationshipData, String keyName) { if (relationshipData != null) { for (int i = 0; i < relationshipData.size(); ++i) { - JSONObject item = relationshipData.getJSONObject(i); - if (item.getString("relationship-key").equals(keyName)) { - return item.getString("relationship-value"); + JsonObject item = relationshipData.get(i).getAsJsonObject(); + if (item.get("relationship-key").getAsString().equals(keyName)) { + return item.get("relationship-value").getAsString(); } } } @@ -314,11 +316,12 @@ public class AaiQuery4Ccvpn { } private String getErrorMsg(String url, Map<String, Object> body, Response response) { + Gson gson = new Gson(); StringBuilder sb = new StringBuilder(); sb.append("Rerquest URL: ").append(url).append("\n"); - sb.append("Request Header: ").append(JSONObject.toJSONString(headers)).append("\n"); + sb.append("Request Header: ").append(gson.toJson(headers)).append("\n"); if (body != null) { - sb.append("Request Body: ").append(JSONObject.toJSONString(body)).append("\n"); + sb.append("Request Body: ").append(gson.toJson(body)).append("\n"); } if (response != null) { sb.append("Request Body: ").append(response.readEntity(String.class)); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java index aff064b..cf39910 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.holmes.common.aai * ================================================================================ - * Copyright (C) 2018-2019 Huawei. All rights reserved. + * Copyright (C) 2018-2020 Huawei. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ package org.onap.holmes.common.aai; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.config.AaiConfig; @@ -34,11 +34,7 @@ import javax.ws.rs.core.Response; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.onap.holmes.common.aai.AaiJsonParserUtil.extractJsonArray; -import static org.onap.holmes.common.aai.AaiJsonParserUtil.get; -import static org.onap.holmes.common.aai.AaiJsonParserUtil.getHostAddr; -import static org.onap.holmes.common.aai.AaiJsonParserUtil.getInfo; -import static org.onap.holmes.common.aai.AaiJsonParserUtil.getPath; +import static org.onap.holmes.common.aai.AaiJsonParserUtil.*; @Service @Slf4j @@ -62,14 +58,14 @@ public class AaiQuery4Ccvpn2 { private String getSiteVNFId(String siteService) throws CorrelationException { Response response = get(getHostAddr(), AaiConfig.MsbConsts.AAI_SITE_RESOURCES_QUERY); String resStr = response.readEntity(String.class); - JSONObject resObj = JSON.parseObject(resStr); - JSONArray siteResources = extractJsonArray(resObj, "site-resource"); + JsonObject resObj = JsonParser.parseString(resStr).getAsJsonObject(); + JsonArray siteResources = extractJsonArray(resObj, "site-resource"); if (siteResources != null) { for (int i = 0; i < siteResources.size(); i++) { - final JSONObject object = siteResources.getJSONObject(i); - if (siteService.equals(object.getString("site-resource-name"))) { - JSONObject vnfInfo = getInfo(object.toJSONString(), "generic-vnf"); - String vnfPath = vnfInfo.getString("related-link"); + final JsonObject object = siteResources.get(i).getAsJsonObject(); + if (siteService.equals(object.get("site-resource-name").getAsString())) { + JsonObject vnfInfo = getInfo(object.toString(), "generic-vnf"); + String vnfPath = vnfInfo.get("related-link").getAsString(); String vnfId = null; Pattern pattern = Pattern.compile("/aai/v\\d+/network/generic-vnfs/generic-vnf/(.+)"); @@ -85,23 +81,23 @@ public class AaiQuery4Ccvpn2 { return null; } - private JSONObject getServiceInstanceByVnfId(String vnfId) throws CorrelationException { + private JsonObject getServiceInstanceByVnfId(String vnfId) throws CorrelationException { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SITE_VNF_QUERY, "vnfId", vnfId)); String resStr = response.readEntity(String.class); return getInfo(resStr, "service-instance"); } - public JSONObject getSiteServiceInstance(String siteService) throws CorrelationException { + public JsonObject getSiteServiceInstance(String siteService) throws CorrelationException { String vnfId = getSiteVNFId(siteService); if (vnfId == null) { return null; } - JSONObject serviceInstanceInfo = getServiceInstanceByVnfId(vnfId); - String serviceInstancePath = serviceInstanceInfo.getString("related-link"); + JsonObject serviceInstanceInfo = getServiceInstanceByVnfId(vnfId); + String serviceInstancePath = serviceInstanceInfo.get("related-link").getAsString(); Response response = get(getHostAddr(), getPath(serviceInstancePath)); String res = response.readEntity(String.class); - JSONObject instance = JSON.parseObject(res); + JsonObject instance = JsonParser.parseString(res).getAsJsonObject(); String[] params = new String[2]; Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)" + "/service-subscriptions/service-subscription/(.+)" + @@ -111,9 +107,9 @@ public class AaiQuery4Ccvpn2 { params[0] = matcher.group(1); params[1] = matcher.group(2); } - instance.put("globalSubscriberId", params[0]); - instance.put("serviceType", params[1]); - instance.put("vnfId", vnfId); + instance.addProperty("globalSubscriberId", params[0]); + instance.addProperty("serviceType", params[1]); + instance.addProperty("vnfId", vnfId); return instance; } } 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 5df05ca..5ad4984 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 @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2020 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,9 @@ */ package org.onap.holmes.common.aai; -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 com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.entity.RelationshipList; import org.onap.holmes.common.aai.entity.RelationshipList.RelatedToProperty; @@ -31,6 +27,10 @@ import org.onap.holmes.common.aai.entity.VmEntity; import org.onap.holmes.common.aai.entity.VmResourceLink; import org.onap.holmes.common.aai.entity.VnfEntity; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @Service public class AaiResponseUtil { @@ -40,17 +40,17 @@ public class AaiResponseUtil { { List<VmResourceLink> vmResourceLinkList = new ArrayList<>(); String resultDataKey = "result-data"; - JSONObject jsonNode = JSON.parseObject(responseJson); + JsonObject jsonNode = JsonParser.parseString(responseJson).getAsJsonObject(); if (jsonNode != null && jsonNode.get(resultDataKey) != null) { - JSONArray resultData = jsonNode.getJSONArray(resultDataKey); + JsonArray resultData = jsonNode.getAsJsonArray(resultDataKey); vmResourceLinkList = convertResultDataList(resultData); } return vmResourceLinkList; } public VmEntity convertJsonToVmEntity(String responseJson) { - JSONObject jsonObject = JSON.parseObject(responseJson); - if (jsonObject == null ||jsonObject.isEmpty()) { + JsonObject jsonObject = JsonParser.parseString(responseJson).getAsJsonObject(); + if (jsonObject == null ||jsonObject.size() == 0) { return null; } VmEntity vmEntity = new VmEntity(); @@ -72,9 +72,9 @@ public class AaiResponseUtil { } public VnfEntity convertJsonToVnfEntity(String responseJson) { - JSONObject jsonObject = JSON.parseObject(responseJson); + JsonObject jsonObject = JsonParser.parseString(responseJson).getAsJsonObject(); - if (jsonObject.isEmpty()) { + if (jsonObject.size() == 0) { return null; } @@ -97,24 +97,24 @@ public class AaiResponseUtil { return vnfEntity; } - private void setRelationShips(JSONObject jsonObject, RelationshipList relationshipList) { + private void setRelationShips(JsonObject jsonObject, RelationshipList relationshipList) { if (jsonObject.get(RELATIONSHIP_LIST) != null) { - JSONObject relationshipListNode = jsonObject.getJSONObject(RELATIONSHIP_LIST); + JsonObject relationshipListNode = jsonObject.getAsJsonObject(RELATIONSHIP_LIST); String relationship = "relationship"; if (relationshipListNode.get(relationship) != null) { - JSONArray relationshipNode = relationshipListNode.getJSONArray(relationship); + JsonArray relationshipNode = relationshipListNode.getAsJsonArray(relationship); relationshipList .setRelationships(convertRelationships(relationshipNode)); } } } - private List<VmResourceLink> convertResultDataList(JSONArray resultData) { + private List<VmResourceLink> convertResultDataList(JsonArray resultData) { List<VmResourceLink> vmResourceLinkList = new ArrayList<>(); String resourceLink = "resource-link"; String resourceType = "resource-type"; for (int i = 0; i < resultData.size(); i++) { - JSONObject jsonObject = resultData.getJSONObject(i); + JsonObject jsonObject = resultData.get(i).getAsJsonObject(); if (jsonObject.get(resourceLink) != null && jsonObject.get(resourceType) != null) { VmResourceLink vmResourceLink = new VmResourceLink(); @@ -126,23 +126,23 @@ public class AaiResponseUtil { return vmResourceLinkList; } - private List<Relationship> convertRelationships(JSONArray relationshipNode) { + private List<Relationship> convertRelationships(JsonArray relationshipNode) { List<Relationship> relationshipList = new ArrayList<>(); for (int i = 0; i < relationshipNode.size(); i++) { Relationship relationship = new Relationship(); - JSONObject jsonObject = relationshipNode.getJSONObject(i); + JsonObject jsonObject = relationshipNode.get(i).getAsJsonObject(); 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"); + JsonArray relatedToPropertyNode = jsonObject.getAsJsonArray("related-to-property"); relationship.setRelatedToPropertyList( convertRelatedToProperty(relatedToPropertyNode)); } else { relationship.setRelatedToPropertyList(Collections.emptyList()); } if (jsonObject.get("relationship-data") != null) { - JSONArray relationshipDataNode = jsonObject.getJSONArray("relationship-data"); + JsonArray relationshipDataNode = jsonObject.getAsJsonArray("relationship-data"); relationship .setRelationshipDataList(convertRelationshipDate(relationshipDataNode)); } else { @@ -154,10 +154,10 @@ public class AaiResponseUtil { return relationshipList; } - private List<RelationshipData> convertRelationshipDate(JSONArray relationshipDataNode) { + private List<RelationshipData> convertRelationshipDate(JsonArray relationshipDataNode) { List<RelationshipData> relationshipDataList = new ArrayList<>(); for (int i = 0; i < relationshipDataNode.size(); i++) { - JSONObject jsonObject = relationshipDataNode.getJSONObject(i); + JsonObject jsonObject = relationshipDataNode.get(i).getAsJsonObject(); RelationshipData relationshipData = new RelationshipData(); relationshipData.setRelationshipKey( getTextElementByNode(jsonObject, "relationship-key")); @@ -170,10 +170,10 @@ public class AaiResponseUtil { return relationshipDataList; } - private List<RelatedToProperty> convertRelatedToProperty(JSONArray relatedToPropertyNode) { + private List<RelatedToProperty> convertRelatedToProperty(JsonArray relatedToPropertyNode) { List<RelatedToProperty> relatedToPropertyList = new ArrayList<>(); for (int i = 0; i < relatedToPropertyNode.size(); i++) { - JSONObject jsonObject = relatedToPropertyNode.getJSONObject(i); + JsonObject jsonObject = relatedToPropertyNode.get(i).getAsJsonObject(); RelatedToProperty relatedToProperty = new RelatedToProperty(); relatedToProperty .setPropertyKey(getTextElementByNode(jsonObject, "property-key")); @@ -184,16 +184,16 @@ public class AaiResponseUtil { return relatedToPropertyList; } - private String getTextElementByNode(JSONObject jsonNode, String name) { + private String getTextElementByNode(JsonObject jsonNode, String name) { if (jsonNode.get(name) != null) { - return jsonNode.getString(name); + return jsonNode.get(name).getAsString(); } return null; } - private Boolean getBooleanElementByNode(JSONObject jsonNode, String name) { + private Boolean getBooleanElementByNode(JsonObject jsonNode, String name) { if (jsonNode.get(name) != null) { - return jsonNode.getBoolean(name); + return jsonNode.get(name).getAsBoolean(); } return null; } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java index 6d9d602..5a61cc0 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/Alarm.java @@ -16,7 +16,7 @@ package org.onap.holmes.common.api.stat;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;
@@ -90,7 +90,7 @@ public class Alarm implements AplusData, Cloneable, Serializable { @Override
public String toString() {
- return JSONObject.toJSONString(this);
+ return new Gson().toJson(this);
}
@Override
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 3d94325..33bd1d2 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 @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,19 +15,17 @@ */
package org.onap.holmes.common.config;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.onap.holmes.common.constant.AlarmConst;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
-
-import lombok.extern.slf4j.Slf4j;
-import org.onap.holmes.common.constant.AlarmConst;
-
import java.util.regex.Pattern;
-@Slf4j
public class MicroServiceConfig {
final static public String CONSUL_ADDR_SUF = ":8500/v1/catalog/service/";
@@ -40,6 +38,8 @@ public class MicroServiceConfig { final static public Pattern IP_REG = Pattern.compile("(http(s)?://)?(\\d+\\.\\d+\\.\\d+\\.\\d+)(:(\\d+))?");
final static public String AAI_HOSTNAME = "aai.onap";
+ final static public Logger log = LoggerFactory.getLogger(MicroServiceConfig.class);
+
public static String getEnv(String name) {
String value = System.getenv(name);
if (value == null) {
@@ -57,11 +57,14 @@ public class MicroServiceConfig { String queryString = getConsulAddrInfo() + hostname;
log.info("Query the " + hostname + " address using the URL: " + queryString);
try {
- JSONObject addrJson = (JSONObject) JSON.parseArray(execQuery(queryString)).get(0);
+ JsonObject addrJson = JsonParser.parseString(execQuery(queryString))
+ .getAsJsonArray()
+ .get(0)
+ .getAsJsonObject();
if (addrJson != null && addrJson.get("ServiceAddress") != null
&& addrJson.get("ServicePort") != null) {
- ret = "http://" + addrJson.getString("ServiceAddress") + ":" + addrJson
- .getString("ServicePort");
+ ret = "http://" + addrJson.get("ServiceAddress").getAsString() + ":" + addrJson
+ .get("ServicePort").getAsString();
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java index 2c878b0..c1eede7 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParser.java @@ -1,5 +1,5 @@ /*
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,19 +15,21 @@ */
package org.onap.holmes.common.dcae.utils;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.stream.Stream;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.apache.commons.lang3.StringUtils;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.Rule;
import org.onap.holmes.common.dcae.entity.SecurityInfo;
import org.onap.holmes.common.exception.CorrelationException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Stream;
+
public class DcaeConfigurationParser {
private static final String RULE_CONTENT_SPLIT = "\\$\\$\\$";
@@ -43,9 +45,9 @@ public class DcaeConfigurationParser { DcaeConfigurations ret = new DcaeConfigurations();
- JSONObject jsonObject = null;
+ JsonObject jsonObject = null;
try {
- jsonObject = JSON.parseObject(jsonStr);
+ jsonObject = JsonParser.parseString(jsonStr).getAsJsonObject();
} catch (Exception e) {
throw new CorrelationException(e.getMessage(), e);
}
@@ -54,73 +56,73 @@ public class DcaeConfigurationParser { fillInPublishesInfo(ret, jsonObject);
fillInSubscribesInfo(ret, jsonObject);
- JSONObject finalJsonObject = jsonObject;
+ JsonObject finalJsonObject = jsonObject;
Stream.of(jsonObject.keySet().toArray(new String[0]))
.filter(key -> !OBJECT_ATTRS.contains(key))
- .forEach(key -> ret.put(key, finalJsonObject.getString(String.valueOf(key))));
+ .forEach(key -> ret.put(key, finalJsonObject.get(String.valueOf(key)).getAsString()));
return ret;
}
- private static void fillInPublishesInfo(DcaeConfigurations ret, JSONObject jsonObject) {
- if (jsonObject.containsKey("streams_publishes")) {
- JSONObject publishes = jsonObject.getJSONObject("streams_publishes");
+ private static void fillInPublishesInfo(DcaeConfigurations ret, JsonObject jsonObject) {
+ if (jsonObject.has("streams_publishes")) {
+ JsonObject publishes = jsonObject.get("streams_publishes").getAsJsonObject();
for (Object key : publishes.keySet()) {
ret.addPubSecInfo((String) key,
- createSecurityInfo((String) key, publishes.getJSONObject((String) key)));
+ createSecurityInfo((String) key, publishes.get((String) key).getAsJsonObject()));
}
}
}
- private static void fillInSubscribesInfo(DcaeConfigurations ret, JSONObject jsonObject) {
- if (jsonObject.containsKey("streams_subscribes")) {
- JSONObject subscribes = jsonObject.getJSONObject("streams_subscribes");
+ private static void fillInSubscribesInfo(DcaeConfigurations ret, JsonObject jsonObject) {
+ if (jsonObject.has("streams_subscribes")) {
+ JsonObject subscribes = jsonObject.get("streams_subscribes").getAsJsonObject();
for (Object key : subscribes.keySet()) {
ret.addSubSecInfo((String) key,
- createSecurityInfo((String) key, subscribes.getJSONObject((String) key)));
+ createSecurityInfo((String) key, subscribes.get((String) key).getAsJsonObject()));
}
}
}
- private static SecurityInfo createSecurityInfo(String key, JSONObject entity) {
+ private static SecurityInfo createSecurityInfo(String key, JsonObject entity) {
SecurityInfo securityInfo = new SecurityInfo();
- if (entity.containsKey("type")) {
- securityInfo.setType(entity.getString("type"));
+ if (entity.has("type") && !entity.get("type").isJsonNull()) {
+ securityInfo.setType(entity.get("type").getAsString());
}
- if (entity.containsKey("aaf_password")) {
- securityInfo.setAafPassword(entity.getString("aaf_password"));
+ if (entity.has("aaf_password") && !entity.get("aaf_password").isJsonNull()) {
+ securityInfo.setAafPassword(entity.get("aaf_password").getAsString());
}
- if (entity.containsKey("aaf_username")) {
- securityInfo.setAafUsername(entity.getString("aaf_username"));
+ if (entity.has("aaf_username") && !entity.get("aaf_username").isJsonNull()) {
+ securityInfo.setAafUsername(entity.get("aaf_username").getAsString());
}
securityInfo.setSecureTopic(!key.endsWith("unsecure"));
- fillInDmaapInfo(securityInfo, entity.getJSONObject("dmaap_info"));
+ fillInDmaapInfo(securityInfo, entity.get("dmaap_info").getAsJsonObject());
return securityInfo;
}
- private static void fillInDmaapInfo(SecurityInfo securityInfo, JSONObject jsonDmaapInfo) {
+ private static void fillInDmaapInfo(SecurityInfo securityInfo, JsonObject jsonDmaapInfo) {
SecurityInfo.DmaapInfo dmaapInfo = securityInfo.getDmaapInfo();
- if (jsonDmaapInfo.containsKey("location")){
- dmaapInfo.setLocation(jsonDmaapInfo.getString("location"));
+ if (jsonDmaapInfo.has("location") && !jsonDmaapInfo.get("location").isJsonNull()){
+ dmaapInfo.setLocation(jsonDmaapInfo.get("location").getAsString());
}
- if (jsonDmaapInfo.containsKey("topic_url")) {
- dmaapInfo.setTopicUrl(jsonDmaapInfo.getString("topic_url"));
+ if (jsonDmaapInfo.has("topic_url") && !jsonDmaapInfo.get("topic_url").isJsonNull()) {
+ dmaapInfo.setTopicUrl(jsonDmaapInfo.get("topic_url").getAsString());
}
- if (jsonDmaapInfo.containsKey("client_id")) {
- dmaapInfo.setClientId(jsonDmaapInfo.getString("client_id"));
+ if (jsonDmaapInfo.has("client_id") && !jsonDmaapInfo.get("client_id").isJsonNull()) {
+ dmaapInfo.setClientId(jsonDmaapInfo.get("client_id").getAsString());
}
- if (jsonDmaapInfo.containsKey("client_role")) {
- dmaapInfo.setClientRole(jsonDmaapInfo.getString("client_role"));
+ if (jsonDmaapInfo.has("client_role") && !jsonDmaapInfo.get("client_role").isJsonNull()) {
+ dmaapInfo.setClientRole(jsonDmaapInfo.get("client_role").getAsString());
}
- if (jsonDmaapInfo.containsKey("type")) {
- dmaapInfo.setType(jsonDmaapInfo.getString("type"));
+ if (jsonDmaapInfo.has("type") && !jsonDmaapInfo.get("type").isJsonNull()) {
+ dmaapInfo.setType(jsonDmaapInfo.get("type").getAsString());
}
}
- private static void fillInRules(DcaeConfigurations ret, JSONObject jsonObject) {
- Set<Entry<String, Object>> entries = jsonObject.entrySet();
- for (Entry<String, Object> entry : entries) {
+ private static void fillInRules(DcaeConfigurations ret, JsonObject jsonObject) {
+ Set<Entry<String, JsonElement>> entries = jsonObject.entrySet();
+ for (Entry<String, JsonElement> entry : entries) {
if (entry.getKey().startsWith("holmes.default.rule")) {
- String value = (String) entry.getValue();
+ String value = entry.getValue().getAsString();
String[] contents = value.split(RULE_CONTENT_SPLIT);
ret.addDefaultRule(new Rule(entry.getKey(), contents[0], contents[1], 1));
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java index ba52262..f29f1d9 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2020 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,6 @@ */ package org.onap.holmes.common.dmaap; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import javax.inject.Inject; -import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.AaiQuery; import org.onap.holmes.common.aai.entity.RelationshipList.Relationship; @@ -30,17 +24,41 @@ import org.onap.holmes.common.api.stat.VesAlarm; import org.onap.holmes.common.dcae.DcaeConfigurationsCache; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS; +import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache; +import org.onap.holmes.common.dmaap.store.UniqueRequestIdCache; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.GsonUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.UUID; -@Slf4j @Service public class DmaapService { - @Inject + private static final Logger log = LoggerFactory.getLogger(DmaapService.class); + private AaiQuery aaiQuery; - public static final ConcurrentHashMap<String, String> loopControlNames = new ConcurrentHashMap<>(); - public static final ConcurrentHashMap<String, String> alarmUniqueRequestID = new ConcurrentHashMap<>(); + private ClosedLoopControlNameCache closedLoopControlNameCache; + private UniqueRequestIdCache uniqueRequestIdCache; + + @Inject + public void setAaiQuery(AaiQuery aaiQuery) { + this.aaiQuery = aaiQuery; + } + + @Inject + public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) { + this.closedLoopControlNameCache = closedLoopControlNameCache; + } + + @Inject + public void setUniqueRequestIdCache(UniqueRequestIdCache uniqueRequestIdCache) { + this.uniqueRequestIdCache = uniqueRequestIdCache; + } public void publishPolicyMsg(PolicyMsg policyMsg, String dmaapConfigKey) { try { @@ -48,7 +66,7 @@ public class DmaapService { publisher.setUrl(DcaeConfigurationsCache.getPubSecInfo(dmaapConfigKey).getDmaapInfo() .getTopicUrl()); publisher.publish(policyMsg); - deleteRequestId(policyMsg); + deleteRequestIdIfNecessary(policyMsg); log.info("send policyMsg: " + GsonUtil.beanToJson(policyMsg)); } catch (CorrelationException e) { log.error("Failed to publish the control loop event to DMaaP", e); @@ -79,7 +97,7 @@ public class DmaapService { policyMsg.setClosedLoopAlarmEnd(rootAlarm.getLastEpochMicrosec()); policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED); } - policyMsg.setClosedLoopControlName(loopControlNames.get(packageName)); + policyMsg.setClosedLoopControlName(closedLoopControlNameCache.get(packageName)); policyMsg.setClosedLoopAlarmStart(rootAlarm.getStartEpochMicrosec()); policyMsg.getAai().put("vserver.vserver-id", vmEntity.getVserverId()); policyMsg.getAai().put("vserver.vserver-name", vmEntity.getVserverName()); @@ -92,7 +110,7 @@ public class DmaapService { private PolicyMsg getDefaultPolicyMsg(VesAlarm rootAlarm, String packageName) { PolicyMsg policyMsg = new PolicyMsg(); policyMsg.setRequestID(getUniqueRequestId(rootAlarm)); - policyMsg.setClosedLoopControlName(loopControlNames.get(packageName)); + policyMsg.setClosedLoopControlName(closedLoopControlNameCache.get(packageName)); policyMsg.setClosedLoopAlarmStart(rootAlarm.getStartEpochMicrosec()); policyMsg.setTarget("vserver.vserver-name"); policyMsg.setTargetType("VM"); @@ -112,11 +130,11 @@ public class DmaapService { } else { alarmUniqueKey = rootAlarm.getSourceId() + ":" + rootAlarm.getEventName(); } - if (alarmUniqueRequestID.containsKey(alarmUniqueKey)) { - return alarmUniqueRequestID.get(alarmUniqueKey); + if (uniqueRequestIdCache.containsKey(alarmUniqueKey)) { + return uniqueRequestIdCache.get(alarmUniqueKey); } else { String requestID = UUID.randomUUID().toString(); - alarmUniqueRequestID.put(alarmUniqueKey, requestID); + uniqueRequestIdCache.put(alarmUniqueKey, requestID); return requestID; } } @@ -176,13 +194,13 @@ public class DmaapService { return vmEntity; } - private void deleteRequestId(PolicyMsg policyMsg){ + private void deleteRequestIdIfNecessary(PolicyMsg policyMsg){ EVENT_STATUS status = policyMsg.getClosedLoopEventStatus(); if(EVENT_STATUS.ABATED.equals(status)) { String requestId = policyMsg.getRequestID(); - for(Entry<String, String> kv: alarmUniqueRequestID.entrySet()) { + for(Entry<String, String> kv: uniqueRequestIdCache.entrySet()) { if(kv.getValue().equals(requestId)) { - alarmUniqueRequestID.remove(kv.getKey()); + uniqueRequestIdCache.remove(kv.getKey()); break; } } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java new file mode 100644 index 0000000..8a692b2 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java @@ -0,0 +1,41 @@ +/* + * Copyright 2020 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.dmaap.store; + +import org.jvnet.hk2.annotations.Service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Singleton; +import java.util.concurrent.ConcurrentHashMap; + +@Service +@Singleton +public class ClosedLoopControlNameCache extends ConcurrentHashMap<String, String> { + + private static final Logger log = LoggerFactory.getLogger(ClosedLoopControlNameCache.class); + + @Override + public String put(String packageName, String controlLoopName) { + log.info(String.format("<%s:%s> was added into ClosedLoopControlNameCache.", packageName, controlLoopName)); + return super.put(packageName, controlLoopName); + } + + public String remove(String packageName) { + log.info(String.format("<%s> was removed into ClosedLoopControlNameCache.", packageName)); + return super.remove(packageName); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java new file mode 100644 index 0000000..070159e --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java @@ -0,0 +1,41 @@ +/* + * Copyright 2020 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.dmaap.store; + +import org.jvnet.hk2.annotations.Service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Singleton; +import java.util.concurrent.ConcurrentHashMap; + +@Service +@Singleton +public class UniqueRequestIdCache extends ConcurrentHashMap<String, String> { + + private static final Logger log = LoggerFactory.getLogger(UniqueRequestIdCache.class); + + @Override + public String put(String alarmId, String requestId) { + log.info(String.format("<%s:%s> was added into UniqueRequestIdCache.", alarmId, requestId)); + return super.put(alarmId, requestId); + } + + public String remove(String alarmId) { + log.info(String.format("<%s> was removed into UniqueRequestIdCache.", alarmId)); + return super.remove(alarmId); + } +} |