- Update ResourceInput column length and check 19/97319/2
authorMerkel, Jeff <jeff.merkel@att.com>
Fri, 18 Oct 2019 14:56:10 +0000 (10:56 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Fri, 18 Oct 2019 19:39:49 +0000 (15:39 -0400)
- Update ResourceInput column length and check for existing vnfc's.

Issue-ID: SO-2462
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I0b0168453d3c20bb6d88a33ec82788f449bf3593

adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.3__UpdateVnfcCustResourceInputLength.sql [new file with mode: 0644]
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java

diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.3__UpdateVnfcCustResourceInputLength.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.3__UpdateVnfcCustResourceInputLength.sql
new file mode 100644 (file)
index 0000000..66c0153
--- /dev/null
@@ -0,0 +1,4 @@
+use catalogdb;
+
+ALTER TABLE vnfc_customization
+  MODIFY IF EXISTS RESOURCE_INPUT varchar(20000);
\ No newline at end of file
index 8b3bccf..00ca74b 100644 (file)
@@ -1068,10 +1068,11 @@ public class ToscaResourceInstaller {
                     EntityQuery.newBuilder("org.openecomp.groups.VfcInstanceGroup"),
                     TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(vfCustomizationUUID), false);
 
+            Set<VnfcCustomization> existingVnfcGroupSet = new HashSet<>();
 
             for (IEntityDetails groupEntity : vfcEntityList) {
-                VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization =
-                        createVNFCInstanceGroup(groupEntity, nodeTemplate, vnfResource, toscaResourceStruct);
+                VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(groupEntity,
+                        nodeTemplate, vnfResource, toscaResourceStruct, existingVnfcGroupSet);
                 vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
             }
 
@@ -1888,7 +1889,7 @@ public class ToscaResourceInstaller {
 
     protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(IEntityDetails vfcInstanceEntity,
             NodeTemplate vnfcNodeTemplate, VnfResourceCustomization vnfResourceCustomization,
-            ToscaResourceStructure toscaResourceStructure) {
+            ToscaResourceStructure toscaResourceStructure, Set<VnfcCustomization> existingVnfcGroupSet) {
 
         Metadata instanceMetadata = vfcInstanceEntity.getMetadata();
 
@@ -1958,39 +1959,47 @@ public class ToscaResourceInstaller {
         vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
 
         ArrayList<Input> inputs = vnfcNodeTemplate.getSubMappingToscaTemplate().getInputs();
-        createVFCInstanceGroupMembers(vfcInstanceGroupCustom, vfcInstanceEntity, inputs);
+        createVFCInstanceGroupMembers(vfcInstanceGroupCustom, vfcInstanceEntity, inputs, existingVnfcGroupSet);
 
         return vfcInstanceGroupCustom;
     }
 
     private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom,
-            IEntityDetails vfcModuleEntity, List<Input> inputList) {
+            IEntityDetails vfcModuleEntity, List<Input> inputList, Set<VnfcCustomization> existingVnfcGroupSet) {
         List<IEntityDetails> members = vfcModuleEntity.getMemberNodes();
         if (!CollectionUtils.isEmpty(members)) {
             for (IEntityDetails vfcEntity : members) {
-                VnfcCustomization vnfcCustomization = new VnfcCustomization();
-
-                Metadata metadata = vfcEntity.getMetadata();
-                vnfcCustomization
-                        .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
-                vnfcCustomization.setModelInstanceName(vfcEntity.getName());
-                vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
-                vnfcCustomization
-                        .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
-                vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
-                vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
-                vnfcCustomization.setToscaNodeType(testNull(vfcEntity.getToscaType()));
-                vnfcCustomization
-                        .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
-                vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcEntity, inputList));
-                vnfcCustomization.setVnfcInstanceGroupCustomization(vfcInstanceGroupCustom);
-                List<VnfcCustomization> vnfcCustomizations = vfcInstanceGroupCustom.getVnfcCustomizations();
-
-                if (vnfcCustomizations == null) {
-                    vnfcCustomizations = new ArrayList<>();
-                    vfcInstanceGroupCustom.setVnfcCustomizations(vnfcCustomizations);
+
+                VnfcCustomization existingVfcGroup = findExistingVfc(existingVnfcGroupSet,
+                        vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+
+                if (existingVfcGroup == null) {
+                    VnfcCustomization vnfcCustomization = new VnfcCustomization();
+
+                    Metadata metadata = vfcEntity.getMetadata();
+                    vnfcCustomization.setModelCustomizationUUID(
+                            metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                    vnfcCustomization.setModelInstanceName(vfcEntity.getName());
+                    vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+                    vnfcCustomization
+                            .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+                    vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
+                    vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+                    vnfcCustomization.setToscaNodeType(testNull(vfcEntity.getToscaType()));
+                    vnfcCustomization
+                            .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+                    vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcEntity, inputList));
+                    vnfcCustomization.setVnfcInstanceGroupCustomization(vfcInstanceGroupCustom);
+                    List<VnfcCustomization> vnfcCustomizations = vfcInstanceGroupCustom.getVnfcCustomizations();
+
+                    if (vnfcCustomizations == null) {
+                        vnfcCustomizations = new ArrayList<>();
+                        vfcInstanceGroupCustom.setVnfcCustomizations(vnfcCustomizations);
+                    }
+                    vnfcCustomizations.add(vnfcCustomization);
+
+                    existingVnfcGroupSet.add(vnfcCustomization);
                 }
-                vnfcCustomizations.add(vnfcCustomization);
             }
         }
     }