diff options
author | 2018-03-27 15:01:07 +0530 | |
---|---|---|
committer | 2018-03-27 10:53:03 +0000 | |
commit | 4345677a2732d0a713300180d83f529a1adc63ff (patch) | |
tree | ed431dc9262d8d8ecc7ff0885fd343498e5aefc8 /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp | |
parent | 4a065a54483b0d64e2bb2b54c82f167e28d4dcf8 (diff) |
VLAN tagging - Pattern 4 VFC Instance Group
1. Create VFC instance group per sub-interface
network role for pattern 4 heats
2. Added tests and updated existing test data
Change-Id: Id4f84c5a7dac3adfddde1192947ecaa5502f21df
Issue-ID: SDC-1073
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp')
5 files changed, 191 insertions, 140 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceTemplateConsolidationData.java index 9a6826d644..9b80b91ce5 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceTemplateConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceTemplateConsolidationData.java @@ -16,6 +16,12 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; + +import java.util.Optional; + public class SubInterfaceTemplateConsolidationData extends EntityConsolidationData { //Value of the property count in the resource group representing the sub-interface @@ -48,4 +54,27 @@ public class SubInterfaceTemplateConsolidationData extends EntityConsolidationDa public void setParentPortNodeTemplateId(String parentPortNodeTemplateId) { this.parentPortNodeTemplateId = parentPortNodeTemplateId; } + + public Optional<PortTemplateConsolidationData> getParentPortTemplateConsolidationData(ServiceTemplate serviceTemplate, + TranslationContext context) { + FilePortConsolidationData filePortConsolidationData = context.getConsolidationData().getPortConsolidationData() + .getFilePortConsolidationData(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + PortTemplateConsolidationData portTemplateConsolidationData = null; + if (filePortConsolidationData != null) { + portTemplateConsolidationData = filePortConsolidationData + .getPortTemplateConsolidationData(parentPortNodeTemplateId); + } + return Optional.ofNullable(portTemplateConsolidationData); + } + + public Optional<String> getParentPortNetworkRole(ServiceTemplate serviceTemplate, + TranslationContext context) { + Optional<PortTemplateConsolidationData> subInterfacePortTemplateConsolidationData = + getParentPortTemplateConsolidationData(serviceTemplate, context); + if (!subInterfacePortTemplateConsolidationData.isPresent()) { + return Optional.empty(); + } + return Optional.ofNullable(subInterfacePortTemplateConsolidationData.get().getNetworkRole()); + } + } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java index cb6a3bc351..9fe2ea0fbd 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java @@ -834,7 +834,7 @@ public class ConsolidationService { if (substitutionConsolidationRuleResult) { List<UnifiedCompositionData> unifiedCompositionDataList = createSubstitutionUnifiedCompositionDataList(substituteNodeTemplateId, - serviceTemplate, consolidationData); + serviceTemplate, substitutionServiceTemplate, consolidationData); unifiedCompositionService .createUnifiedComposition(serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, UnifiedCompositionMode.NestedSingleCompute, @@ -939,33 +939,22 @@ public class ConsolidationService { for (ComputeTemplateConsolidationData computeTemplateConsolidationData : typeComputeConsolidationData .getAllComputeTemplateConsolidationData()) { - UnifiedCompositionData unifiedCompositionData = new UnifiedCompositionData(); unifiedCompositionData.setComputeTemplateConsolidationData(computeTemplateConsolidationData); - - Collection<List<String>> portCollection = - computeTemplateConsolidationData.getPorts() == null ? Collections.emptyList() - : computeTemplateConsolidationData.getPorts().values(); - FilePortConsolidationData filePortConsolidationData = consolidationData.getPortConsolidationData().getFilePortConsolidationData(ToscaUtil .getServiceTemplateFileName(serviceTemplate)); - List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = new ArrayList<>(); - portCollection.stream() - .flatMap(Collection::stream) - .forEach(portId -> setUnifiedCompositionDataWithPortTemplateData(filePortConsolidationData, portId, - unifiedCompositionData, subInterfaceTemplateConsolidationDataList)); - unifiedCompositionData.setSubInterfaceTemplateConsolidationDataList( - subInterfaceTemplateConsolidationDataList); + setUnifiedCompositionDataWithPortTemplateData(computeTemplateConsolidationData, filePortConsolidationData, + unifiedCompositionData); unifiedCompositionDataList.add(unifiedCompositionData); } return unifiedCompositionDataList; } - private void setUnifiedCompositionDataWithPortTemplateData(FilePortConsolidationData filePortConsolidationData, - String portId, - UnifiedCompositionData unifiedCompositionData, - List<SubInterfaceTemplateConsolidationData> + private void setPortTemplateConsolidationData(FilePortConsolidationData filePortConsolidationData, + String portId, + UnifiedCompositionData unifiedCompositionData, + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList) { if (Objects.isNull(filePortConsolidationData)) { return; @@ -981,6 +970,7 @@ public class ConsolidationService { private List<UnifiedCompositionData> createSubstitutionUnifiedCompositionDataList( String substituteNodeTemplateId, ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate, ConsolidationData consolidationData) { List<UnifiedCompositionData> unifiedCompositionDataList = new ArrayList<>(); FileNestedConsolidationData fileNestedConsolidationData = @@ -993,12 +983,51 @@ public class ConsolidationService { UnifiedCompositionData unifiedCompositionData = new UnifiedCompositionData(); unifiedCompositionData.setNestedTemplateConsolidationData(nestedTemplateConsolidationData); unifiedCompositionDataList.add(unifiedCompositionData); - return unifiedCompositionDataList; + addSubInterfaceDataToNestedCompositionData(substitutionServiceTemplate, consolidationData, + unifiedCompositionData); } return unifiedCompositionDataList; } + private void addSubInterfaceDataToNestedCompositionData(ServiceTemplate substitutionServiceTemplate, + ConsolidationData consolidationData, + UnifiedCompositionData unifiedCompositionData) { + FileComputeConsolidationData nestedFileComputeConsolidationData = consolidationData.getComputeConsolidationData() + .getFileComputeConsolidationData(ToscaUtil.getServiceTemplateFileName(substitutionServiceTemplate)); + FilePortConsolidationData nestedFilePortConsolidationData = consolidationData.getPortConsolidationData() + .getFilePortConsolidationData(ToscaUtil.getServiceTemplateFileName(substitutionServiceTemplate)); + if (Objects.isNull(nestedFileComputeConsolidationData) + || Objects.isNull(nestedFilePortConsolidationData)) { + return; + } + TypeComputeConsolidationData computeType = + nestedFileComputeConsolidationData.getAllTypeComputeConsolidationData().iterator().next(); + if (Objects.isNull(computeType)) { + return; + } + ComputeTemplateConsolidationData computeTemplateConsolidationData = + computeType.getAllComputeTemplateConsolidationData().iterator().next(); + setUnifiedCompositionDataWithPortTemplateData(computeTemplateConsolidationData, nestedFilePortConsolidationData, + unifiedCompositionData); + } + + private void setUnifiedCompositionDataWithPortTemplateData(ComputeTemplateConsolidationData + computeTemplateConsolidationData, + FilePortConsolidationData filePortConsolidationData, + UnifiedCompositionData unifiedCompositionData) { + Collection<List<String>> portCollection = + computeTemplateConsolidationData.getPorts() == null ? Collections.emptyList() + : computeTemplateConsolidationData.getPorts().values(); + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = new ArrayList<>(); + portCollection.stream() + .flatMap(Collection::stream) + .forEach(portId -> setPortTemplateConsolidationData(filePortConsolidationData, portId, + unifiedCompositionData, subInterfaceTemplateConsolidationDataList)); + unifiedCompositionData.setSubInterfaceTemplateConsolidationDataList( + subInterfaceTemplateConsolidationDataList); + } + private boolean consolidationPreCondition( ServiceTemplate serviceTemplate, ConsolidationData consolidationData, diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java index f064fb6b60..0217d02328 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java @@ -36,7 +36,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositi import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewComputeNodeTemplateId; import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewPortNodeTemplateId; import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getNewSubInterfaceNodeTemplateId; -import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfacePortTemplateConsolidationData; import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfaceTemplateConsolidationDataList; import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionUtil.getSubInterfaceTypeSuffix; @@ -282,46 +281,53 @@ public class UnifiedCompositionService { if (!TranslationContext.isVfcInstanceGroupingEnabled()) { return; } - for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { - List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = - getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); - if (CollectionUtils.isNotEmpty(subInterfaceTemplateConsolidationDataList)) { - createVfcInstanceGroupPerSubInterface(abstractNodeTemplateId, serviceTemplate, - subInterfaceTemplateConsolidationDataList, context); - } - } + UnifiedCompositionTo unifiedCompositionTo = new UnifiedCompositionTo(serviceTemplate, null, + unifiedCompositionDataList, context); + unifiedCompositionDataList.forEach(unifiedCompositionData -> + createSubInterfaceVfcInstanceGroup(abstractNodeTemplateId, unifiedCompositionTo, unifiedCompositionData)); } - private void createVfcInstanceGroupPerSubInterface(String abstractNodeTemplateId, - ServiceTemplate serviceTemplate, - List<SubInterfaceTemplateConsolidationData> - subInterfaceList, - TranslationContext context) { - for (SubInterfaceTemplateConsolidationData subInterface : subInterfaceList) { - PortTemplateConsolidationData subInterfacePortTemplateConsolidationData = - getSubInterfacePortTemplateConsolidationData(serviceTemplate, subInterface, context); - String subInterfaceNetworkRole = subInterface.getNetworkRole(); - if (Objects.isNull(subInterfaceNetworkRole) - || Objects.isNull(subInterfacePortTemplateConsolidationData.getNetworkRole())) { - continue; + private void createSubInterfaceVfcInstanceGroup(String abstractNodeTemplateId, + UnifiedCompositionTo unifiedCompositionTo, + UnifiedCompositionData unifiedCompositionData) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + getSubInterfaceTemplateConsolidationDataList(unifiedCompositionData); + for (SubInterfaceTemplateConsolidationData subInterface : subInterfaceTemplateConsolidationDataList) { + Optional<String> parentPortNetworkRole; + if (Objects.isNull(unifiedCompositionTo.getSubstitutionServiceTemplate())) { + parentPortNetworkRole = subInterface.getParentPortNetworkRole(unifiedCompositionTo.getServiceTemplate(), + unifiedCompositionTo.getContext()); + } else { + parentPortNetworkRole = subInterface.getParentPortNetworkRole(unifiedCompositionTo + .getSubstitutionServiceTemplate(), unifiedCompositionTo.getContext()); } - String vfcNetworkRoleGroupId = getVfcNetworkRoleGroupId(subInterfaceNetworkRole); - Map<String, GroupDefinition> groups = DataModelUtil.getGroups(serviceTemplate); - if (!groups.containsKey(vfcNetworkRoleGroupId)) { - createNewVfcInstanceGroup(serviceTemplate, subInterfacePortTemplateConsolidationData, - subInterfaceNetworkRole, vfcNetworkRoleGroupId); + String subInterfaceNetworkRole = subInterface.getNetworkRole(); + if (Objects.nonNull(subInterfaceNetworkRole) && parentPortNetworkRole.isPresent()) { + createVfcInstanceGroupPerSubInterfaceNetworkRole(abstractNodeTemplateId, subInterfaceNetworkRole, + parentPortNetworkRole.get(), unifiedCompositionTo.getServiceTemplate()); } - DataModelUtil.addGroupMember(serviceTemplate, vfcNetworkRoleGroupId, abstractNodeTemplateId); } } + private void createVfcInstanceGroupPerSubInterfaceNetworkRole(String abstractNodeTemplateId, + String subInterfaceNetworkRole, + String parentPortNetworkRole, + ServiceTemplate serviceTemplate) { + String vfcNetworkRoleGroupId = getVfcNetworkRoleGroupId(subInterfaceNetworkRole); + Map<String, GroupDefinition> groups = DataModelUtil.getGroups(serviceTemplate); + if (!groups.containsKey(vfcNetworkRoleGroupId)) { + createNewVfcInstanceGroup(serviceTemplate, parentPortNetworkRole, subInterfaceNetworkRole, vfcNetworkRoleGroupId); + } + DataModelUtil.addGroupMember(serviceTemplate, vfcNetworkRoleGroupId, abstractNodeTemplateId); + } + private void createNewVfcInstanceGroup(ServiceTemplate serviceTemplate, - PortTemplateConsolidationData portTemplate, + String parentPortNetworkRole, String subInterfaceNetworkRole, String vfcNetworkRoleGroupId) { Map<String, Object> properties = new HashMap<>(); properties.put(SUB_INTERFACE_ROLE, subInterfaceNetworkRole); - properties.put(VFC_PARENT_PORT_ROLE, portTemplate.getNetworkRole()); + properties.put(VFC_PARENT_PORT_ROLE, parentPortNetworkRole); updateVfcInstanceGroupExposedProperties(subInterfaceNetworkRole, serviceTemplate, properties); @@ -494,18 +500,15 @@ public class UnifiedCompositionService { /** * Handle unified nested definition. * - * @param mainServiceTemplate the main service template - * @param nestedServiceTemplate the nested service template - * @param unifiedCompositionData the unified composition data - * @param context the context + * @param unifiedCompositionTo the unified composition data transfer object + * @param unifiedCompositionData the unified composition data */ - public void handleUnifiedNestedDefinition(ServiceTemplate mainServiceTemplate, - ServiceTemplate nestedServiceTemplate, - UnifiedCompositionData unifiedCompositionData, - TranslationContext context) { - handleUnifiedNestedNodeType(mainServiceTemplate, nestedServiceTemplate, context); - updateUnifiedNestedTemplates(mainServiceTemplate, nestedServiceTemplate, - unifiedCompositionData, context); + public void handleUnifiedNestedDefinition(UnifiedCompositionTo unifiedCompositionTo, + UnifiedCompositionData unifiedCompositionData) { + handleUnifiedNestedNodeType(unifiedCompositionTo.getServiceTemplate(), unifiedCompositionTo + .getSubstitutionServiceTemplate(), unifiedCompositionTo.getContext()); + updateUnifiedNestedTemplates(unifiedCompositionTo.getServiceTemplate(), unifiedCompositionTo + .getSubstitutionServiceTemplate(), unifiedCompositionData, unifiedCompositionTo.getContext()); } private void handleGetAttrInConnectivity(ServiceTemplate serviceTemplate, @@ -687,51 +690,55 @@ public class UnifiedCompositionService { return; } handleNestedNodeTemplateInMainServiceTemplate( - nestedTemplateConsolidationData.getNodeTemplateId(), mainServiceTemplate, - nestedServiceTemplate, context); - + nestedTemplateConsolidationData.getNodeTemplateId(), mainServiceTemplate, + nestedServiceTemplate, context); } /** * Update connectivity for unified nested patterns. * - * @param serviceTemplate the service template - * @param nestedServiceTemplate the nested service template - * @param unifiedCompositionData the unified composition data - * @param context the context + * @param unifiedCompositionTo the unified composition data transfer object + * @param unifiedCompositionData the unified composition data */ - public void updateUnifiedNestedConnectivity(ServiceTemplate serviceTemplate, - ServiceTemplate nestedServiceTemplate, - UnifiedCompositionData unifiedCompositionData, - TranslationContext context) { + public void updateUnifiedNestedConnectivity(UnifiedCompositionTo unifiedCompositionTo, + UnifiedCompositionData unifiedCompositionData) { - updNestedCompositionNodesConnectedInConnectivity(serviceTemplate, unifiedCompositionData, - context); - updNestedCompositionNodesConnectedOutConnectivity(serviceTemplate, nestedServiceTemplate, - unifiedCompositionData, context); - updNestedCompositionNodesGetAttrInConnectivity(serviceTemplate, unifiedCompositionData, - context); - updNestedCompositionOutputParamGetAttrInConnectivity(serviceTemplate, - unifiedCompositionData, context); + updNestedCompositionNodesConnectedInConnectivity(unifiedCompositionTo.getServiceTemplate(), unifiedCompositionData, + unifiedCompositionTo.getContext()); + updNestedCompositionNodesConnectedOutConnectivity(unifiedCompositionTo.getServiceTemplate(), + unifiedCompositionTo.getSubstitutionServiceTemplate(), unifiedCompositionData, unifiedCompositionTo + .getContext()); + updNestedCompositionNodesGetAttrInConnectivity(unifiedCompositionTo.getServiceTemplate(), unifiedCompositionData, + unifiedCompositionTo.getContext()); + updNestedCompositionOutputParamGetAttrInConnectivity(unifiedCompositionTo.getServiceTemplate(), + unifiedCompositionData, unifiedCompositionTo.getContext()); } /** * Clean unified nested entities. Update the heat stack group with the new node template ids. * - * @param serviceTemplate the service template + * @param unifiedCompositionTo the unified composition data transfer object * @param unifiedCompositionData the unified composition data - * @param context the context */ - public void cleanUnifiedNestedEntities(ServiceTemplate serviceTemplate, - UnifiedCompositionData unifiedCompositionData, - TranslationContext context) { + public void cleanUnifiedNestedEntities(UnifiedCompositionTo unifiedCompositionTo, + UnifiedCompositionData unifiedCompositionData) { EntityConsolidationData entityConsolidationData = - unifiedCompositionData.getNestedTemplateConsolidationData(); - updateHeatStackGroupNestedComposition(serviceTemplate, entityConsolidationData, context); + unifiedCompositionData.getNestedTemplateConsolidationData(); + updateHeatStackGroupNestedComposition(unifiedCompositionTo.getServiceTemplate(), entityConsolidationData, + unifiedCompositionTo.getContext()); } + public void createNestedVfcInstanceGroup(String nestedNodeTemplateId, + UnifiedCompositionTo unifiedCompositionTo, + UnifiedCompositionData unifiedCompositionData) { + if (!TranslationContext.isVfcInstanceGroupingEnabled()) { + return; + } + createSubInterfaceVfcInstanceGroup(nestedNodeTemplateId, unifiedCompositionTo, unifiedCompositionData); + } + public void handleComplexVfcType(ServiceTemplate serviceTemplate, TranslationContext context) { SubstitutionMapping substitutionMapping = serviceTemplate.getTopology_template().getSubstitution_mappings(); @@ -1936,18 +1943,17 @@ public class UnifiedCompositionService { subInterfaceTemplateConsolidationDataList) { SubInterfaceTemplateConsolidationData subInterfaceTemplateConsolidationData = subInterfaceTemplateConsolidationDataList.get(0); - PortTemplateConsolidationData portTemplateConsolidationData = - getSubInterfacePortTemplateConsolidationData(unifiedCompositionTo.getServiceTemplate(), - subInterfaceTemplateConsolidationData, unifiedCompositionTo.getContext()); - - if (Objects.isNull(portTemplateConsolidationData)) { + Optional<PortTemplateConsolidationData> portTemplateConsolidationDataOptional = + subInterfaceTemplateConsolidationData.getParentPortTemplateConsolidationData(unifiedCompositionTo + .getServiceTemplate(), unifiedCompositionTo.getContext()); + if (!portTemplateConsolidationDataOptional.isPresent()) { return; } - + PortTemplateConsolidationData portTemplateConsolidationData = portTemplateConsolidationDataOptional.get(); String originalSubInterfaceNodeTemplateId = subInterfaceTemplateConsolidationDataList.get(0) .getNodeTemplateId(); - NodeTemplate originalSubInterfaceNodeTemplate = - DataModelUtil.getNodeTemplate(unifiedCompositionTo.getServiceTemplate(), originalSubInterfaceNodeTemplateId); + NodeTemplate originalSubInterfaceNodeTemplate = DataModelUtil.getNodeTemplate(unifiedCompositionTo + .getServiceTemplate(), originalSubInterfaceNodeTemplateId); if (Objects.isNull(originalSubInterfaceNodeTemplate)) { return; } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java index 223dc8760a..528dc5e0e2 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionUtil.java @@ -19,33 +19,29 @@ package org.openecomp.sdc.translator.services.heattotosca; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; import org.apache.commons.collections4.MapUtils; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; -import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData; -import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; /** * Utility class for consolidation data collection helper methods. */ public class UnifiedCompositionUtil { - protected static Logger logger = LoggerFactory.getLogger(UnifiedCompositionUtil.class); - private UnifiedCompositionUtil() { //Hiding the implicit public constructor } @@ -155,34 +151,17 @@ public class UnifiedCompositionUtil { StringBuilder newSubInterfaceNodeTemplateId = new StringBuilder(); newSubInterfaceNodeTemplateId.append(getNewPortNodeTemplateId(subInterfaceTemplateConsolidationData .getParentPortNodeTemplateId(), connectedComputeNodeType, computeTemplateConsolidationData)); - PortTemplateConsolidationData portTemplateConsolidationData = - getSubInterfacePortTemplateConsolidationData(serviceTemplate, subInterfaceTemplateConsolidationData, context); + Optional<PortTemplateConsolidationData> portTemplateConsolidationData = + subInterfaceTemplateConsolidationData.getParentPortTemplateConsolidationData(serviceTemplate, context); NodeTemplate subInterfaceNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, subInterfaceTemplateConsolidationData.getNodeTemplateId()); - if (Objects.nonNull(portTemplateConsolidationData)) { - String subInterfaceSuffix = (portTemplateConsolidationData.isSubInterfaceNodeTemplateIdParameter(subInterfaceNodeTemplate.getType()))? - //If there are more than one subinterfaces with same type use node template id - subInterfaceTemplateConsolidationData.getNodeTemplateId(): - //Add sub interface type since we have only one subinterface per type - getSubInterfaceTypeSuffix(subInterfaceNodeTemplate.getType()); - newSubInterfaceNodeTemplateId.append("_").append(subInterfaceSuffix); - return newSubInterfaceNodeTemplateId.toString(); - } - return subInterfaceTemplateConsolidationData.getNodeTemplateId(); - } - - static PortTemplateConsolidationData getSubInterfacePortTemplateConsolidationData(ServiceTemplate serviceTemplate, - SubInterfaceTemplateConsolidationData - subInterfaceTemplateConsolidationData, - TranslationContext context) { - FilePortConsolidationData filePortConsolidationData = context.getConsolidationData().getPortConsolidationData() - .getFilePortConsolidationData(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); - PortTemplateConsolidationData portTemplateConsolidationData = null; - if (filePortConsolidationData != null) { - portTemplateConsolidationData = filePortConsolidationData - .getPortTemplateConsolidationData(subInterfaceTemplateConsolidationData.getParentPortNodeTemplateId()); + if (portTemplateConsolidationData.isPresent()) { + String subInterfaceSuffix = getSubInterfaceSuffix(portTemplateConsolidationData.get(), + subInterfaceNodeTemplate, subInterfaceTemplateConsolidationData); + newSubInterfaceNodeTemplateId.append("_").append(subInterfaceSuffix); + return newSubInterfaceNodeTemplateId.toString(); } - return portTemplateConsolidationData; + return subInterfaceTemplateConsolidationData.getNodeTemplateId(); } static String getSubInterfaceTypeSuffix(String nodeType) { @@ -191,8 +170,19 @@ public class UnifiedCompositionUtil { public static List<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationDataList( UnifiedCompositionData unifiedCompositionData) { - return unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList() == null ? new - ArrayList<>() : unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList(); + return unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList() == null ? Collections.emptyList() : + unifiedCompositionData.getSubInterfaceTemplateConsolidationDataList(); } + private static String getSubInterfaceSuffix(PortTemplateConsolidationData portTemplateConsolidationData, + NodeTemplate subInterfaceNodeTemplate, + SubInterfaceTemplateConsolidationData + subInterfaceTemplateConsolidationData) { + if (portTemplateConsolidationData.isSubInterfaceNodeTemplateIdParameter(subInterfaceNodeTemplate.getType())) { + //If there are more than one subinterfaces with same type use node template id + return subInterfaceTemplateConsolidationData.getNodeTemplateId(); + } + //Add sub interface type since we have only one subinterface per type + return getSubInterfaceTypeSuffix(subInterfaceNodeTemplate.getType()); + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/unifiedcomposition/UnifiedCompositionNestedSingleCompute.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/unifiedcomposition/UnifiedCompositionNestedSingleCompute.java index d6b49ec35e..a48e107370 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/unifiedcomposition/UnifiedCompositionNestedSingleCompute.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/unifiedcomposition/UnifiedCompositionNestedSingleCompute.java @@ -4,17 +4,17 @@ import org.apache.commons.collections4.CollectionUtils; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.to.UnifiedCompositionTo; import org.openecomp.sdc.translator.services.heattotosca.UnifiedComposition; import org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionService; -import java.util.ArrayList; import java.util.List; public class UnifiedCompositionNestedSingleCompute implements UnifiedComposition { - // There is no consolidation in NestedSingleCompute implemetation. + // There is no consolidation in NestedSingleCompute implementation. // In case of nested single compute, if there is more than one entry in the - // unifiedComposotionDataList, each one should be handed seperatly, no consolidation between + // unifiedCompositionDataList, each one should be handed separately, no consolidation between // them. @Override public void createUnifiedComposition(ServiceTemplate serviceTemplate, @@ -26,18 +26,15 @@ public class UnifiedCompositionNestedSingleCompute implements UnifiedComposition return; } - for (int i = 0; i < unifiedCompositionDataList.size(); i++) { - List<UnifiedCompositionData> nestedUnifiedCompositionDataList = new ArrayList<>(); - nestedUnifiedCompositionDataList.add(unifiedCompositionDataList.get(i)); - - unifiedCompositionService - .handleUnifiedNestedDefinition(serviceTemplate, nestedServiceTemplate, - unifiedCompositionDataList.get(i), context); - unifiedCompositionService - .updateUnifiedNestedConnectivity(serviceTemplate, nestedServiceTemplate, - unifiedCompositionDataList.get(i), context); + UnifiedCompositionTo unifiedCompositionTo = new UnifiedCompositionTo(serviceTemplate, nestedServiceTemplate, + unifiedCompositionDataList, context); + for (UnifiedCompositionData unifiedCompositionData : unifiedCompositionDataList) { + unifiedCompositionService.handleUnifiedNestedDefinition(unifiedCompositionTo, unifiedCompositionData); + String nestedNodeTemplateId = unifiedCompositionData.getNestedTemplateConsolidationData().getNodeTemplateId(); unifiedCompositionService - .cleanUnifiedNestedEntities(serviceTemplate, unifiedCompositionDataList.get(i), context); + .createNestedVfcInstanceGroup(nestedNodeTemplateId, unifiedCompositionTo, unifiedCompositionData); + unifiedCompositionService.updateUnifiedNestedConnectivity(unifiedCompositionTo, unifiedCompositionData); + unifiedCompositionService.cleanUnifiedNestedEntities(unifiedCompositionTo, unifiedCompositionData); unifiedCompositionService.updateSubstitutionNodeTypePrefix(nestedServiceTemplate); } } |