From 458cc8d407f27bc360f9d7c93164bae6b764947f Mon Sep 17 00:00:00 2001 From: zm330 Date: Tue, 23 Apr 2019 10:46:53 +0800 Subject: add vnfcInstanceGroup sequence Issue-ID: SO-1393 Change-Id: Ife3b71dcfa543a693564779da44800f1dd8486e9 Signed-off-by: zm330 --- .../installer/heat/ToscaResourceInstaller.java | 123 ++++++++++++++++++++- 1 file changed, 121 insertions(+), 2 deletions(-) (limited to 'asdc-controller/src/main') diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index aba70f33e3..ddf1f3d84b 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -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 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 processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure, + List groupList) { + if (CollectionUtils.isEmpty(groupList)) { + return Collections.emptyList(); + } + + ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); + List strSequence = new ArrayList<>(groupList.size()); + List tempGroupList = new ArrayList<>(groupList.size()); + List nodes = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + List 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 strSequence, List groupList, List nodes, + ISdcCsarHelper iSdcCsarHelper) { + if (CollectionUtils.isEmpty(groupList)) { + return; + } + + List tempGroupList = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + ArrayList 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 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 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 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; -- cgit 1.2.3-korg