add vnfcInstanceGroup sequence 04/86004/2
authorzm330 <zhangminyj@chinamobile.com>
Tue, 23 Apr 2019 02:46:53 +0000 (10:46 +0800)
committerZhang Min <zhangminyj@chinamobile.com>
Tue, 23 Apr 2019 03:37:36 +0000 (03:37 +0000)
Issue-ID: SO-1393

Change-Id: Ife3b71dcfa543a693564779da44800f1dd8486e9
Signed-off-by: zm330 <zhangminyj@chinamobile.com>
adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql [new file with mode: 0644]
adapters/mso-openstack-adapters/src/test/resources/schema.sql
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
asdc-controller/src/test/resources/schema.sql
mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql
mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfResourceCustomization.java
mso-catalog-db/src/test/resources/schema.sql

diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql
new file mode 100644 (file)
index 0000000..fabb005
--- /dev/null
@@ -0,0 +1,3 @@
+use catalogdb;
+ALTER TABLE vnf_resource_customization
+ADD VNFCINSTANCEGROUP_ORDER varchar(255);
\ No newline at end of file
index 94c8e55..5e986ab 100644 (file)
@@ -1107,6 +1107,7 @@ CREATE TABLE `vnf_resource_customization` (
   `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL,
   `SERVICE_MODEL_UUID` varchar(200) NOT NULL,
+  `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL,
   PRIMARY KEY (`ID`),
   UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`),
   KEY `fk_vnf_resource_customization__vnf_resource1_idx` (`VNF_RESOURCE_MODEL_UUID`),
index aba70f3..ddf1f3d 100644 (file)
@@ -26,6 +26,7 @@ package org.onap.so.asdc.installer.heat;
 
 import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -142,6 +143,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.util.CollectionUtils;
 
 @Component
 public class ToscaResourceInstaller {
@@ -983,7 +985,13 @@ public class ToscaResourceInstaller {
                     vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
                 }
 
-
+                List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList);
+                if (!CollectionUtils.isEmpty(seqResult)) {
+                    String resultStr = seqResult.stream().collect(Collectors.joining(","));
+                    vnfResource.setVnfcInstanceGroupOrder(resultStr);
+                    logger.debug(
+                            "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr);
+                }
                 // add this vnfResource with existing vnfResource for this service
                 addVnfCustomization(service, vnfResource);
             } else {
@@ -994,6 +1002,85 @@ public class ToscaResourceInstaller {
         }
     }
 
+    private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure,
+            List<Group> groupList) {
+        if (CollectionUtils.isEmpty(groupList)) {
+            return Collections.emptyList();
+        }
+
+        ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
+        List<String> strSequence = new ArrayList<>(groupList.size());
+        List<Group> tempGroupList = new ArrayList<>(groupList.size());
+        List<NodeTemplate> nodes = new ArrayList<>();
+        tempGroupList.addAll(groupList);
+
+        for (Group group : groupList) {
+            List<NodeTemplate> nodeList = group.getMemberNodes();
+            boolean hasRequirements = false;
+            for (NodeTemplate node : nodeList) {
+                RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node);
+                if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) {
+                    hasRequirements = true;
+                    break;
+                }
+            }
+
+            if (!hasRequirements) {
+                strSequence.add(group.getName());
+                tempGroupList.remove(group);
+                nodes.addAll(nodeList);
+            }
+        }
+
+        getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
+
+        return strSequence;
+
+    }
+
+    private void getVNFCGroupSequenceList(List<String> strSequence, List<Group> groupList, List<NodeTemplate> nodes,
+            ISdcCsarHelper iSdcCsarHelper) {
+        if (CollectionUtils.isEmpty(groupList)) {
+            return;
+        }
+
+        List<Group> tempGroupList = new ArrayList<>();
+        tempGroupList.addAll(groupList);
+
+        for (Group group : groupList) {
+            ArrayList<NodeTemplate> members = group.getMemberNodes();
+            for (NodeTemplate memberNode : members) {
+                boolean isAllExists = true;
+                RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode);
+                if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) {
+                    continue;
+                }
+                List<RequirementAssignment> rqaList = requirements.getAll();
+                for (RequirementAssignment rqa : rqaList) {
+                    String name = rqa.getNodeTemplateName();
+                    for (NodeTemplate node : nodes) {
+                        if (name.equals(node.getName())) {
+                            break;
+                        }
+                    }
+
+                    isAllExists = false;
+                    break;
+                }
+
+                if (isAllExists) {
+                    strSequence.add(group.getName());
+                    tempGroupList.remove(group);
+                    nodes.addAll(group.getMemberNodes());
+                }
+            }
+
+            if (tempGroupList.size() != 0 && tempGroupList.size() < groupList.size()) {
+                getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper);
+            }
+        }
+    }
+
     public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
             String consumerId) {
         WatchdogServiceModVerIdLookup modVerIdLookup =
@@ -1704,12 +1791,37 @@ public class ToscaResourceInstaller {
         vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper()
                 .getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName));
         vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
-
+        createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group);
 
         return vfcInstanceGroupCustom;
 
     }
 
+    private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group) {
+        List<NodeTemplate> members = group.getMemberNodes();
+        if (!CollectionUtils.isEmpty(members)) {
+            for (NodeTemplate vfcTemplate : members) {
+                VnfcCustomization vnfcCustomization = new VnfcCustomization();
+
+                Metadata metadata = vfcTemplate.getMetaData();
+                vnfcCustomization
+                        .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                vnfcCustomization.setModelInstanceName(vfcTemplate.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(vfcTemplate.getType()));
+                vnfcCustomization
+                        .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+
+                // @After vfcInstanceGroupCustom merged
+                // vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization);
+            }
+        }
+    }
+
     protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
             ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
             IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service,
@@ -2229,6 +2341,13 @@ public class ToscaResourceInstaller {
 
         }
 
+        if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) {
+            vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
+                    .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
+            vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper()
+                    .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
+        }
+
         toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization);
 
         return vnfResourceCustomization;
index 8cc5ee9..a50b275 100644 (file)
@@ -1109,6 +1109,7 @@ CREATE TABLE `vnf_resource_customization` (
   `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL,
   `SERVICE_MODEL_UUID` varchar(200) NOT NULL,
+  `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL,
   PRIMARY KEY (`ID`),
   UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`),
   KEY `fk_vnf_resource_customization__vnf_resource1_idx` (`VNF_RESOURCE_MODEL_UUID`),
index bc9003f..6b748c1 100644 (file)
@@ -1108,6 +1108,7 @@ CREATE TABLE `vnf_resource_customization` (
   `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL,
   `SERVICE_MODEL_UUID` varchar(200) NOT NULL,
+  `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL,
   PRIMARY KEY (`ID`),
   UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`),
   KEY `fk_vnf_resource_customization__vnf_resource1_idx` (`VNF_RESOURCE_MODEL_UUID`),
index af99aa8..36c9251 100644 (file)
@@ -121,6 +121,9 @@ public class VnfResourceCustomization implements Serializable {
     @Column(name = "SKIP_POST_INSTANTIATION_CONFIGURATION")
     private Boolean skipPostInstConf;
 
+    @Column(name = "VNFCINSTANCEGROUP_ORDER")
+    private String vnfcInstanceGroupOrder;
+
     @Override
     public boolean equals(final Object other) {
         if (!(other instanceof VnfResourceCustomization)) {
@@ -148,6 +151,7 @@ public class VnfResourceCustomization implements Serializable {
                 .append("nfType", nfType).append("nfRole", nfRole).append("nfNamingCode", nfNamingCode)
                 .append("multiStageDesign", multiStageDesign).append("vnfResources", vnfResources)
                 .append("vfModuleCustomizations", vfModuleCustomizations)
+                .append("vnfcInstanceGroupOrder", vnfcInstanceGroupOrder)
                 .append("vnfcInstanceGroupCustomizations", vnfcInstanceGroupCustomizations).toString();
     }
 
@@ -324,4 +328,12 @@ public class VnfResourceCustomization implements Serializable {
     public void setSkipPostInstConf(Boolean skipPostInstConf) {
         this.skipPostInstConf = skipPostInstConf;
     }
+
+    public String getVnfcInstanceGroupOrder() {
+        return vnfcInstanceGroupOrder;
+    }
+
+    public void setVnfcInstanceGroupOrder(String vnfcInstanceGroupOrder) {
+        this.vnfcInstanceGroupOrder = vnfcInstanceGroupOrder;
+    }
 }
index f5e7d52..7a89469 100644 (file)
@@ -1106,6 +1106,7 @@ CREATE TABLE `vnf_resource_customization` (
   `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL,
   `SERVICE_MODEL_UUID` varchar(200) NOT NULL,
+  `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL,
   PRIMARY KEY (`ID`),
   UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`),
   KEY `fk_vnf_resource_customization__vnf_resource1_idx` (`VNF_RESOURCE_MODEL_UUID`),