[SLICEANALYSIS] Filter data from AAI to avoid possible exceptions, remove null parame... 80/128480/1
authorNiranjana <niranjana.y60@wipro.com>
Tue, 12 Apr 2022 09:03:51 +0000 (09:03 +0000)
committerNiranjana <niranjana.y60@wipro.com>
Tue, 12 Apr 2022 09:03:51 +0000 (09:03 +0000)
Issue-ID: DCAEGEN2-3142
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: I3734c666e030b010a1922ba0282fd0ccae83fce6

components/slice-analysis-ms/ChangeLog.md
components/slice-analysis-ms/pom.xml
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java
components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java
components/slice-analysis-ms/version.properties

index db38068..1528744 100644 (file)
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## [1.1.1] - 2022/04/12
+         - [DCAEGEN2-3142](https://jira.onap.org/browse/DCAEGEN2-3142) - Filter data from AAI to avoid possible exceptions, remove null parameters in policy payload and add logs
+
 ## [1.1.0] - 2022/3/10
          - [DCAEGEN2-3063](https://jira.onap.org/browse/DCAEGEN2-3063) - IBN user-triggered CLoud Leased Line update and CCVPN closed-loop
 
index d9ab31f..1f68fe5 100644 (file)
@@ -34,7 +34,7 @@
         </parent>
         <groupId>org.onap.dcaegen2.services.components</groupId>
         <artifactId>slice-analysis-ms</artifactId>
-        <version>1.1.0-SNAPSHOT</version>
+        <version>1.1.1-SNAPSHOT</version>
         <name>dcaegen2-services-slice-analysis-ms</name>
         <description>Network slice PM analyser</description>
         <packaging>jar</packaging>
index eb5d243..289fedf 100644 (file)
@@ -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();
index 743ac3c..27f37ab 100644 (file)
@@ -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();
index e335154..ceaeb73 100644 (file)
  *******************************************************************************/
 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;
index 9469634..1d53892 100644 (file)
@@ -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());
index d5c0592..612bdf0 100644 (file)
@@ -21,7 +21,7 @@
 ###############################################################################
 major=1
 minor=1
-patch=0
+patch=1
 base_version=${major}.${minor}.${patch}
 release_version=${base_version}
 snapshot_version=${base_version}-SNAPSHOT