diff options
author | GuangrongFu <fu.guangrong@zte.com.cn> | 2018-08-22 08:27:29 +0800 |
---|---|---|
committer | GuangrongFu <fu.guangrong@zte.com.cn> | 2018-08-22 08:27:29 +0800 |
commit | 96e0893e38e4bb8c69947f255ac27fb89a72122f (patch) | |
tree | df980d3ed4233bd14e4cd6b3ecffbf97bafd98d3 /holmes-actions | |
parent | 88350d3c9580855053aabc6d83ff8f54919137de (diff) |
Fixed Some Data Format Anormaly
Change-Id: I703cc9c96156ac85832a5200d3a24b0402b4b0f4
Issue-ID: HOLMES-160
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r-- | holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java | 30 | ||||
-rw-r--r-- | holmes-actions/src/test/resources/ccvpn.data.json | 40 |
2 files changed, 47 insertions, 23 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; + } } diff --git a/holmes-actions/src/test/resources/ccvpn.data.json b/holmes-actions/src/test/resources/ccvpn.data.json index 6632cc2..ecdb7d5 100644 --- a/holmes-actions/src/test/resources/ccvpn.data.json +++ b/holmes-actions/src/test/resources/ccvpn.data.json @@ -13,10 +13,12 @@ { "related-to": "logical-link", "related-link": "url of logical-link", - "relationship-data": { - "relationship-key": "logical-link.link-name", - "relationship-value": "logic-link-1" - } + "relationship-data": [ + { + "relationship-key": "logical-link.link-name", + "relationship-value": "logic-link-1" + } + ] } ] } @@ -38,10 +40,12 @@ { "related-to": "vpn-binding", "related-link": "url of vpn-binding", - "relationship-data": { - "relationship-key": "vpn-binding.vpn-id", - "relationship-value": "some id" - } + "relationship-data": [ + { + "relationship-key": "vpn-binding.vpn-id", + "relationship-value": "some id" + } + ] } ] } @@ -68,10 +72,12 @@ { "related-to": "connectivity", "related-link": "url of connectivity", - "relationship-data": { - "relationship-key": "connectivity. connectivity-id", - "relationship-value": "some id" - } + "relationship-data": [ + { + "relationship-key": "connectivity. connectivity-id", + "relationship-value": "some id" + } + ] } ] } @@ -106,10 +112,12 @@ { "related-to": "service-instance", "related-link": "/aai/v14/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances?service-instance-id=service-1", - "relationship-data": { - "relationship-key": "service-instance.service-instance-id", - "relationship-value": "some id" - } + "relationship-data": [ + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "some id" + } + ] } ] } |