diff options
author | 2018-08-22 00:44:11 +0000 | |
---|---|---|
committer | 2018-08-22 00:44:11 +0000 | |
commit | aa6978f0ab8e81ad3f5b8de549894b63131fde68 (patch) | |
tree | 51bf3298a1e47375b249a7152649a5944643346c /holmes-actions/src/main/java/org/onap | |
parent | b6f78979786fdc4eb1e67d40cdd0d246c3db44d3 (diff) | |
parent | 96e0893e38e4bb8c69947f255ac27fb89a72122f (diff) |
Merge "Fixed Some Data Format Anormaly"
Diffstat (limited to 'holmes-actions/src/main/java/org/onap')
-rw-r--r-- | holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java | 30 |
1 files changed, 23 insertions, 7 deletions
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 e49b289..42b7bd7 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 @@ -60,15 +60,17 @@ public class AaiQuery4Ccvpn { } JSONObject linkInfo = getInfo(JSONObject.toJSONString(response.getEntity()), "p-interface", "logical-link"); - return linkInfo.getJSONObject("relationship-data").getString("relationship-value"); + return extractValueFromJsonArray(linkInfo.getJSONArray("relationship-data"), "logical-link.link-name"); } public JSONArray getServiceInstances(String networkId, String pnfName, String ifName, String status) { try { JSONObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status); - String vpnBindingId = vpnBindingInfo.getJSONObject("relationship-data").getString("relationship-value"); + String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.getJSONArray("relationship-data"), + "vpn-binding.vpn-id"); JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId); - String connectivityId = connectivityInfo.getJSONObject("relationship-data").getString("relationship-value"); + String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"), + "connectivity. connectivity-id"); JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); String serviceInstancePath = serviceInstanceInfo.getString("related-link"); serviceInstancePath = serviceInstancePath.substring(0, serviceInstancePath.lastIndexOf('/')); @@ -84,7 +86,8 @@ public class AaiQuery4Ccvpn { } } - public void updateTerminalPointStatus(String networkId, String pnfName, String ifName, Map<String, Object> body) throws CorrelationException { + public void updateTerminalPointStatus(String networkId, String pnfName, String ifName, + Map<String, Object> body) throws CorrelationException { Map<String, String> params = new HashMap<>(); params.put("networkId", networkId); params.put("pnfName", pnfName); @@ -97,14 +100,16 @@ public class AaiQuery4Ccvpn { } public void updateLogicLinkStatus(String linkName, Map<String, Object> body) throws CorrelationException { - Response response = patch(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, "linkName", linkName), body); + Response response = patch(getHostAddr(), + getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, "linkName", linkName), body); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connecto to AAI. Cause: " + response.getStatusInfo().getReasonPhrase()); } } - public JSONObject getVpnBindingInfo(String networkId, String pnfName, String ifName, String status) throws CorrelationException { + public JSONObject getVpnBindingInfo(String networkId, String pnfName, + String ifName, String status) throws CorrelationException { Map<String, String> params = new HashMap(); params.put("networkId", networkId); params.put("pnfName", pnfName); @@ -128,7 +133,8 @@ public class AaiQuery4Ccvpn { } public JSONObject getServiceInstanceByConn(String connectivityId) throws CorrelationException { - Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN, "connectivityId", connectivityId)); + Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN, + "connectivityId", connectivityId)); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. Cause: " + response.getStatusInfo().getReasonPhrase()); @@ -231,4 +237,14 @@ public class AaiQuery4Ccvpn { sb.append(msbInfo[0]).append(msbInfo[1]); return sb.toString(); } + + private String extractValueFromJsonArray(JSONArray relationshipData, String keyName) { + 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"); + } + } + return null; + } } |