Add resources summarizing function in service instance. 96/99796/3
authorAlexey Sandler <alexey.sandler@intl.att.com>
Thu, 19 Dec 2019 09:05:40 +0000 (11:05 +0200)
committerAlexey Sandler <alexey.sandler@intl.att.com>
Thu, 19 Dec 2019 10:48:07 +0000 (12:48 +0200)
Issue-ID: VID-724
Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
Change-Id: I9f4d6201cadd31e84ef90f25a619d95bf74eb9ae
Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
vid-app-common/src/test/resources/payload_jsons/templateSummarize4vnfs6vfmodules.json [new file with mode: 0644]

index c77eb82..d1b475c 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.onap.vid.services;
 
+import static java.util.stream.Collectors.counting;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.groupingBy;
 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
 import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
 import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
@@ -30,11 +33,16 @@ import java.io.IOException;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.hibernate.SessionFactory;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
@@ -178,6 +186,28 @@ public class AsyncInstantiationBusinessLogicImpl implements
         return uuids;
     }
 
+    public  Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
+        List<String> existingTypesList = new ArrayList<>();
+        Map<String, Long> existingTypesCounters;
+
+        existingTypesList = getChildrenList(serviceInstantiation, existingTypesList);
+        existingTypesCounters =  existingTypesList.stream().collect(groupingBy(identity(), counting()));
+
+        return existingTypesCounters;
+    }
+
+    private List<String> getChildrenList(BaseResource resource, List<String> list){
+        Collection<? extends BaseResource> children =  resource.getChildren();
+        if (CollectionUtils.isNotEmpty(children)){
+            children.forEach( child -> {
+                String childType = child.getModelInfo().getModelType();
+                getChildrenList(child, list);
+                list.add(childType);
+            });
+        }
+        return list;
+    }
+
     private ServiceInfo.ServiceAction getAction(ServiceInstantiation request) {
         if (request.getAction() == null) {
             //throw new GenericUncheckedException("Required 'action' field not provided at service level");
index d1124f3..4b4aa4d 100644 (file)
@@ -491,6 +491,17 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
         return prepareServiceInstantiation(PROJECT_NAME, isUserProvidedNaming, bulkSize);
     }
 
+    @Test
+    public void getSummarizedMap(){
+        ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
+            "/payload_jsons/templateSummarize4vnfs6vfmodules.json", ServiceInstantiation.class);
+        Map<String, Long> childrenMap =  asyncInstantiationBL.getSummarizedChildrenMap(serviceInstantiation);
+        HashMap<String, Long> expectedMap = new HashMap<>();
+        expectedMap.put("vnf", Long.valueOf(4));
+        expectedMap.put("vfModule", Long.valueOf(6));
+        assertEquals(childrenMap,expectedMap);
+
+    }
 
 
     @Test
diff --git a/vid-app-common/src/test/resources/payload_jsons/templateSummarize4vnfs6vfmodules.json b/vid-app-common/src/test/resources/payload_jsons/templateSummarize4vnfs6vfmodules.json
new file mode 100644 (file)
index 0000000..b004482
--- /dev/null
@@ -0,0 +1,77 @@
+{
+  "action": "Create",
+  "instanceName": "vProbe_NC_Service_DG_new_SI",
+  "modelInfo": {
+    "modelType": "service"
+  },
+  "vnfs": {
+    "vProbe_NC_VNF 0": {
+      "modelInfo": {
+        "modelType": "vnf"
+      },
+      "vfModules": {
+        "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0": {
+          "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0ahubg": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        },
+        "vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1": {
+          "vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1yprvi": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        }
+      }
+    },
+    "2017-488_PASQUALE-vPE 0": {
+      "modelInfo": {
+        "modelType": "vnf"
+      }
+    },
+    "2017-488_PASQUALE-vPE 0:0001": {
+      "vfModules": {
+        "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0": {
+          "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0uvfot": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        },
+        "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1": {
+          "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1fshmc": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        }
+      },
+      "modelInfo": {
+        "modelType": "vnf"
+      }
+    },
+    "2017-488_PASQUALE-vPE 0:0002": {
+      "vfModules": {
+        "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0": {
+          "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0uvfot": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        },
+        "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1": {
+          "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1fshmc": {
+            "modelInfo": {
+              "modelType": "vfModule"
+            }
+          }
+        }
+      },
+      "modelInfo": {
+        "modelType": "vnf"
+      }
+    }
+  }
+}