diff options
author | 2022-04-12 09:03:51 +0000 | |
---|---|---|
committer | 2022-04-12 09:03:51 +0000 | |
commit | b5ffdfa0e652e7d7b6c320d28fc78eded8a0763a (patch) | |
tree | aaa30f637cc5978d5983da1f7a1f5d4e060a4ab8 /components/slice-analysis-ms/src/main | |
parent | 7f3cd41c7b6a843066ea3776193edcf267cc3220 (diff) |
[SLICEANALYSIS] Filter data from AAI to avoid possible exceptions, remove null parameters in policy payload and add logs.
Issue-ID: DCAEGEN2-3142
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: I3734c666e030b010a1922ba0282fd0ccae83fce6
Diffstat (limited to 'components/slice-analysis-ms/src/main')
4 files changed, 26 insertions, 9 deletions
diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java index eb5d243c..289fedfd 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java @@ -70,6 +70,7 @@ public class AaiService implements AaiInterface { Map<String, String> responseMap = fetchSubscriberAndSubscriptionServiceType(); String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + log.info("serviceReqUrl {}", serviceReqUrl); String serviceRole = "AN-NF"; try { String serviceInstance = @@ -78,7 +79,7 @@ public class AaiService implements AaiInterface { JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); for (int i = 0; i < serviceInstanceList.length(); i++) { JSONObject serviceObj = serviceInstanceList.getJSONObject(i); - if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + if (serviceObj.has("environment-context") && serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { responseMap.put("sliceProfileId", serviceObj.getString("service-instance-id")); } } @@ -86,7 +87,7 @@ public class AaiService implements AaiInterface { String serviceRoleReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/?service-role=nssi&depth=2"; - + log.info("serviceRoleReqUrl {}", serviceRoleReqUrl); String serviceInstanceForServiceRole = restclient.sendGetRequest(serviceRoleReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); JSONObject serviceInstanceForServiceRoleJson = new JSONObject(serviceInstanceForServiceRole); @@ -94,7 +95,7 @@ public class AaiService implements AaiInterface { serviceInstanceForServiceRoleJson.getJSONArray("service-instance"); for (int i = 0; i < serviceInstanceListForServiceRole.length(); i++) { JSONObject serviceObj = serviceInstanceListForServiceRole.getJSONObject(i); - if (serviceObj.getString("workload-context").trim().equalsIgnoreCase(serviceRole)) { + if (serviceObj.has("workload-context") && serviceObj.getString("workload-context").trim().equalsIgnoreCase(serviceRole)) { responseMap.put("ranNFNSSIId", serviceObj.getString("service-instance-id")); } } @@ -117,6 +118,7 @@ public class AaiService implements AaiInterface { String serviceInstaneId = null; String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + log.info("serviceReqUrl {}", serviceReqUrl); Map<String, Integer> responseMap = new HashMap<String, Integer>(); try { String serviceInstance = @@ -126,7 +128,7 @@ public class AaiService implements AaiInterface { JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); for (int i = 0; i < serviceInstanceList.length(); i++) { JSONObject serviceObj = serviceInstanceList.getJSONObject(i); - if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + if (serviceObj.has("environment-context") && serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { serviceInstaneId = serviceObj.getString("service-instance-id"); } } @@ -134,7 +136,7 @@ public class AaiService implements AaiInterface { String sliceProfileReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/service-instance/" + serviceInstaneId + "/slice-profiles"; - + log.info("sliceProfileReqUrl {}", sliceProfileReqUrl); String sliceProfile = restclient .sendGetRequest(sliceProfileReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); JSONObject sliceProfileJson = new JSONObject(sliceProfile); @@ -163,6 +165,7 @@ public class AaiService implements AaiInterface { log.info("Get GlobalSubscriberId"); String subscriberReqUrl = aaiBaseUrl + "/business/customers"; + log.info("subscriberReqUrl {}", subscriberReqUrl); try { String subscriberReq = restclient.sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); @@ -178,7 +181,7 @@ public class AaiService implements AaiInterface { log.info("Get subscriptionServiceType"); String subscriptionServiceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions"; - + log.info("subscriptionServiceReqUrl: {}", subscriptionServiceReqUrl); String subscriptionService = restclient .sendGetRequest(subscriptionServiceReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); JSONObject subscriptionServiceJson = new JSONObject(subscriptionService); @@ -214,14 +217,14 @@ public class AaiService implements AaiInterface { String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/service-instance/" + sliceInstanceId; - + log.info("serviceReqUrl {}", serviceReqUrl); try { String serviceInstanceString = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); ServiceInstance serviceInstance = objectMapper.readValue(serviceInstanceString, ServiceInstance.class); if (serviceInstance.getServiceRole().equalsIgnoreCase("nsi")) { serviceInstance.getRelationshipList().getRelationship().forEach(relationship -> { - if (relationship.getRelatedTo().equalsIgnoreCase("allotted-resource")) { + if (Objects.nonNull(relationship.getRelatedTo()) && relationship.getRelatedTo().equalsIgnoreCase("allotted-resource")) { relationship.getRelationshipData().forEach(data -> { if (data.get("relationship-key").equalsIgnoreCase("service-instance.service-instance-id")) { allotedResource.add(data.get("relationship-value")); @@ -280,6 +283,7 @@ public class AaiService implements AaiInterface { String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/service-instance/" + serviceInstanceId; + log.info("serviceReqUrl {}", serviceReqUrl); String serviceInstanceString = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); ServiceInstance serviceInstance = objectMapper.readValue(serviceInstanceString, ServiceInstance.class); @@ -326,7 +330,7 @@ public class AaiService implements AaiInterface { String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/" + "service-instance/" + serviceInstanceId; - + log.info("serviceReqUrl {}", serviceReqUrl); try { String serviceInstanceString = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() {}).getBody(); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java index 743ac3cf..27f37aba 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java @@ -58,7 +58,9 @@ public class CpsService implements CpsInterface { Map<String, Map<String, Object>> responseMap = new HashMap<String, Map<String, Object>>(); String reqUrl = cpsBaseUrl + "/get-nearrtric-config"; log.info("fetching current configuration of RIC from Cps: {s-NSSAI: " + snssai + "}"); + log.info("reqUrl {}", reqUrl); String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + log.info("requestBody {}", requestBody); try { String response = restclient .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference<String>() {}).getBody(); @@ -93,7 +95,9 @@ public class CpsService implements CpsInterface { List<String> responseList = new ArrayList<>(); String reqUrl = cpsBaseUrl + "/get-gnbdufunction-by-snssai"; log.info("fetching network functions of snssai from Cps: {s-NSSAI: " + snssai + "}"); + log.info("reqUrl {}", reqUrl); String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + log.info("requestBody {}", requestBody); try { String response = restclient .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference<String>() {}).getBody(); @@ -115,7 +119,9 @@ public class CpsService implements CpsInterface { Map<String, List<String>> responseMap = new HashMap<>(); String reqUrl = cpsBaseUrl + "/get-nrcelldu-by-snssai"; log.info("fetching RIC of s-NSSAI from Cps: {s-NSSAI: " + snssai + "}"); + log.info("reqUrl {}", reqUrl); String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + log.info("requestBody {}", requestBody); try { String response = restclient .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference<String>() {}).getBody(); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java index e3351541..ceaeb730 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java @@ -21,9 +21,14 @@ *******************************************************************************/ package org.onap.slice.analysis.ms.models.policy; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * Model class for the Paylaod Object */ +@JsonInclude(Include.NON_NULL) public class Payload { private String name; diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java index 94696343..1d53892c 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java @@ -134,6 +134,8 @@ public class SliceUtilization { String jsonRequestBody = new ObjectMapper().writeValueAsString(inputParameter); log.info("fetching PM Data for : {}", snssai); + log.info("desUrl {}", desUrl); + log.info("jsonRequestBody {}", jsonRequestBody); response = desRestClient.sendPostRequest(desUrl, jsonRequestBody, new ParameterizedTypeReference<String>() {}); pmData = new JSONObject(response.getBody()); |