Fix new sonar issue with vfModuleItem 15/65115/4
authorPiyush Garg <piyush.garg1@amdocs.com>
Fri, 7 Sep 2018 03:41:00 +0000 (09:11 +0530)
committerPiyush Garg <piyush.garg1@amdocs.com>
Mon, 10 Sep 2018 13:26:50 +0000 (18:56 +0530)
find the last non-base vf module item from AAI response and use the same
to construct create or delete vf module SO request

Change-Id: I3b9b97ac3008f6e4f7952662d9e4262f77dbeec4
Issue-ID: POLICY-1079
Signed-off-by: Piyush Garg <piyush.garg1@amdocs.com>
controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java

index ce49dda..5285d54 100644 (file)
@@ -166,9 +166,10 @@ public class SOActorServiceProvider implements Actor {
 
         // Construct SO Request for a policy's recipe
         if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
-            return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem);
+            return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem,
+                    vfModuleItem);
         } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
-            return constructDeleteRequest(aaiResponseWrapper, tenantItem, vnfItem, vnfServiceItem);
+            return constructDeleteRequest(aaiResponseWrapper, tenantItem, vnfItem, vnfServiceItem, vfModuleItem);
         } else {
             return null;
         }
@@ -182,11 +183,13 @@ public class SOActorServiceProvider implements Actor {
      * @param tenantItem         tenant item from A&AI named-query response
      * @param vnfItem            vnf item from A&AI named-query response
      * @param vnfServiceItem     vnf service item from A&AI named-query response
+     * @param vfModuleItem       vf module item from A&AI named-query response
      * @return SO create vf-module request
      */
-    private SORequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, AaiNqInventoryResponseItem
-            tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem) {
-        AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false);
+    private SORequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy,
+                                             AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
+                                             AaiNqInventoryResponseItem vnfServiceItem,
+                                             AaiNqInventoryResponseItem vfModuleItem) {
         SORequest request = new SORequest();
         request.setOperationType(SoOperationType.SCALE_OUT);
         //
@@ -291,13 +294,12 @@ public class SOActorServiceProvider implements Actor {
      * @param tenantItem         tenant item from A&AI named-query response
      * @param vnfItem            vnf item from A&AI named-query response
      * @param vnfServiceItem     vnf service item from A&AI named-query response
+     * @param vfModuleItem       vf module item from A&AI named-query response
      * @return SO delete vf-module request
      */
     private SORequest constructDeleteRequest(AaiNqResponseWrapper aaiResponseWrapper, AaiNqInventoryResponseItem
-            tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem) {
-        // find the last non-base vf-module to delete
-        AaiNqInventoryResponseItem vfModuleItem = findVfModuleToDelete(aaiResponseWrapper);
-
+            tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem,
+                                             AaiNqInventoryResponseItem vfModuleItem) {
         SORequest request = new SORequest();
         request.setOperationType(SoOperationType.DELETE_VF_MODULE);
         request.setRequestDetails(new SORequestDetails());
@@ -385,6 +387,7 @@ public class SOActorServiceProvider implements Actor {
 
     /**
      * Find the base or non base VF module item in an AAI response.
+     * If there is more than one item, then the <i>last</i> item is returned
      *
      * @param aaiResponseWrapper the AAI response containing the VF modules
      * @param baseFlag true if we are searching for the base, false if we are searching
@@ -393,21 +396,9 @@ public class SOActorServiceProvider implements Actor {
      */
     private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) {
         List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(baseFlag);
-        return (lst == null || lst.isEmpty() ? null : lst.get(0));
-    }
-
-    /**
-     * Find the VF module item to delete from AAI response.
-     *
-     * @param aaiResponseWrapper the AAI response containing the VF modules
-     * @return VF module item to delete or null if the non-base vfModule was not found
-     */
-    private AaiNqInventoryResponseItem findVfModuleToDelete(AaiNqResponseWrapper aaiResponseWrapper) {
-        List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(false);
         return (lst == null || lst.isEmpty() ? null : lst.get(lst.size() - 1));
     }
 
-
     /**
      * Builds the request parameters from the policy payload.
      *
@@ -455,7 +446,8 @@ public class SOActorServiceProvider implements Actor {
      * @param serviceInstanceId update the last service instance ID to this value
      * @param vfModuleId update the vfModule instance ID to this value
      */
-    private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId, final String vfModuleId) {
+    private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId,
+                                            final String vfModuleId) {
         lastVNFItemVnfId = vnfInstanceId;
         lastServiceItemServiceInstanceId = serviceInstanceId;
         lastVfModuleItemVfModuleInstanceId = vfModuleId;