diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc')
7 files changed, 289 insertions, 293 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/ComputeTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java index 854cf51aa2..639bcfbfcd 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java @@ -16,10 +16,15 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.collections4.MapUtils; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; @@ -28,17 +33,17 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData { // key - volume node template id // value - List of requirement id and the requirement assignment on the // compute node which connect to this volume - private Map<String,List<RequirementAssignmentData>> volumes; + private Multimap<String, RequirementAssignmentData> volumes; // key - port type (port id excluding index), // value - List of connected port node template ids, with this port type private Map<String, List<String>> ports; - public Map<String,List<RequirementAssignmentData>> getVolumes() { + public Multimap<String, RequirementAssignmentData> getVolumes() { return volumes; } - public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) { + public void setVolumes(Multimap<String, RequirementAssignmentData> volumes) { this.volumes = volumes; } @@ -60,10 +65,9 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData { public void addVolume(String requirementId, RequirementAssignment requirementAssignment) { if (this.volumes == null) { - this.volumes = new HashMap<>(); + this.volumes = ArrayListMultimap.create(); } - this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>()) - .add(new RequirementAssignmentData(requirementId, + this.volumes.put(requirementAssignment.getNode(), new RequirementAssignmentData(requirementId, requirementAssignment)); } @@ -80,4 +84,23 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData { } } } + + /** + * Is number of port from each compute type legal. + * + * @return the boolean + */ + public boolean isNumberOfPortFromEachTypeLegal() { + Map<String, List<String>> currPortsMap = getPorts(); + return MapUtils.isEmpty(currPortsMap) || currPortsMap.values().stream() + .allMatch(portList -> portList.size() == 1); + } + + public Set<String> getPortsIds() { + return MapUtils.isEmpty(getPorts()) ? new HashSet<>() : getPorts().keySet(); + } + + public int getNumberOfPorts() { + return getPortsIds().size(); + } } 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/EntityConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java index 3987c54054..1c272770b3 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java @@ -16,6 +16,9 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -25,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil; @@ -41,11 +45,11 @@ public class EntityConsolidationData { // key - node template id which has connection to this entity // value - List of Requirement assignment data which connect to this entity - private Map<String, List<RequirementAssignmentData>> nodesConnectedIn; + private Multimap<String, RequirementAssignmentData> nodesConnectedIn; // key - node template id which connected from this entity // List of Requirement assignment data which connect to the key node template id - private Map<String, List<RequirementAssignmentData>> nodesConnectedOut; + private Multimap<String, RequirementAssignmentData> nodesConnectedOut; //key - node template id which include get attribute function from this entity //value - List of getAttr data @@ -90,7 +94,7 @@ public class EntityConsolidationData { * * @param nodesConnectedIn the node connected to me */ - public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) { + public void setNodesConnectedIn(Multimap<String, RequirementAssignmentData> nodesConnectedIn) { this.nodesConnectedIn = nodesConnectedIn; } @@ -105,10 +109,9 @@ public class EntityConsolidationData { RequirementAssignment requirementAssignment) { if (this.nodesConnectedIn == null) { - this.nodesConnectedIn = new HashMap<>(); + this.nodesConnectedIn = ArrayListMultimap.create(); } - this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>()); this.nodesConnectedIn.get(nodeTemplateId).add( new RequirementAssignmentData(requirementId, requirementAssignment)); } @@ -118,7 +121,7 @@ public class EntityConsolidationData { * * @return the node connected to me */ - public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() { + public Multimap<String, RequirementAssignmentData> getNodesConnectedIn() { return nodesConnectedIn; } @@ -128,7 +131,7 @@ public class EntityConsolidationData { * * @return the node connected from me */ - public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() { + public Multimap<String, RequirementAssignmentData> getNodesConnectedOut() { return nodesConnectedOut; } @@ -137,7 +140,7 @@ public class EntityConsolidationData { * * @param nodesConnectedOut the node connected from me */ - public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) { + public void setNodesConnectedOut(Multimap<String, RequirementAssignmentData> nodesConnectedOut) { this.nodesConnectedOut = nodesConnectedOut; } @@ -152,10 +155,9 @@ public class EntityConsolidationData { RequirementAssignment requirementAssignment) { if (this.nodesConnectedOut == null) { - this.nodesConnectedOut = new HashMap<>(); + this.nodesConnectedOut = ArrayListMultimap.create(); } - this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>()); this.nodesConnectedOut.get(nodeTemplateId).add( new RequirementAssignmentData(requirementId, requirementAssignment)); } @@ -279,6 +281,11 @@ public class EntityConsolidationData { */ public boolean isGetAttrOutFromEntityLegal(Collection<? extends EntityConsolidationData> entityConsolidationDataList, Map<String, List<String>> portTypeToIds) { + if (CollectionUtils.isEmpty(entityConsolidationDataList) + || MapUtils.isEmpty(portTypeToIds)) { + return true; + } + for (String portType : portTypeToIds.keySet()) { Set<GetAttrFuncData> startingGetAttrFunc = getEntityGetAttrFuncAsSet(portType); 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/NestedConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java index afad4a9b0f..1521d9d31e 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java @@ -18,6 +18,7 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; public class NestedConsolidationData { @@ -62,4 +63,8 @@ public class NestedConsolidationData { } return consolidationData; } + + public boolean isNestedConsolidationDataExist(String nestedServiceTemplateName) { + return Objects.nonNull(getFileNestedConsolidationData(nestedServiceTemplateName)); + } } 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/NestedConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java index 62c0164d04..44f18afe4b 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java @@ -177,4 +177,8 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler return Objects.nonNull(nestedHeatFileName) && context.getAllTranslatedResourceIdsFromDiffNestedFiles( nestedHeatFileName).contains(nestedNodeTemplateId); } + + public boolean isNestedConsolidationDataExist(String serviceTemplateName) { + return nestedConsolidationData.isNestedConsolidationDataExist(serviceTemplateName); + } } 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/TypeComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java index 7b99ec1514..09b97b26f6 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.collections4.CollectionUtils; @@ -111,4 +112,29 @@ public class TypeComputeConsolidationData { public boolean isNumberOfComputeConsolidationDataPerTypeLegal() { return getAllComputeTemplateConsolidationData().size() == 1; } + + public boolean isThereMoreThanOneComputeTypeInstance() { + return getAllComputeNodeTemplateIds().size() > 1; + } + + public boolean isNumberOfPortFromEachTypeLegal() { + return getAllComputeTemplateConsolidationData().stream().allMatch( + ComputeTemplateConsolidationData::isNumberOfPortFromEachTypeLegal); + } + + public boolean isPortTypesEqualsBetweenComputeNodes() { + Set<String> startingPortTypes = getAllComputeTemplateConsolidationData().iterator().next().getPortsIds(); + + return getAllComputeTemplateConsolidationData() + .stream().allMatch(compute -> compute.getPortsIds().equals(startingPortTypes)); + } + + public boolean isNumberOfPortsEqualsBetweenComputeNodes() { + int startingNumberOfPorts = + getAllComputeTemplateConsolidationData().iterator().next().getNumberOfPorts(); + + return getAllComputeTemplateConsolidationData() + .stream().allMatch(compute -> compute.getNumberOfPorts() == startingNumberOfPorts); + + } } 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 1000554975..45f12cea85 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 @@ -18,6 +18,7 @@ package org.openecomp.sdc.translator.services.heattotosca; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import com.google.common.collect.Multimap; import java.util.ArrayList; import java.util.Collection; @@ -39,6 +40,7 @@ import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; @@ -56,7 +58,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FileNestedConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.GetAttrFuncData; -import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationDataHandler; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData; @@ -483,17 +485,16 @@ public class ConsolidationService { secondEntity.getNodesConnectedOut()); } - private boolean compareNodeConnectivity( - Map<String, List<RequirementAssignmentData>> firstEntityMap, - Map<String, List<RequirementAssignmentData>> secondEntityMap) { + private boolean compareNodeConnectivity( + Multimap<String, RequirementAssignmentData> firstEntityMap, + Multimap<String, RequirementAssignmentData> secondEntityMap) { - if (MapUtils.isEmpty(firstEntityMap) - && MapUtils.isEmpty(secondEntityMap)) { - return true; + if (CommonUtil.isMultimapEmpty(firstEntityMap) && CommonUtil.isMultimapEmpty(secondEntityMap)) { + return true; + } + return !firstEntityMap.isEmpty() && !secondEntityMap.isEmpty() + && firstEntityMap.keySet().equals(secondEntityMap.keySet()); } - return !MapUtils.isEmpty(firstEntityMap) && !MapUtils.isEmpty(secondEntityMap) - && firstEntityMap.keySet().equals(secondEntityMap.keySet()); - } private boolean checkGroupIdsRelations(EntityConsolidationData startingEntity, EntityConsolidationData currentEntity) { @@ -503,23 +504,23 @@ public class ConsolidationService { } - private boolean checkComputesRelationsToVolume( - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationEntities) { - Iterator<ComputeTemplateConsolidationData> iterator = - computeTemplateConsolidationEntities.iterator(); + private boolean checkComputesRelationsToVolume( + Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationEntities) { + Iterator<ComputeTemplateConsolidationData> iterator = + computeTemplateConsolidationEntities.iterator(); - Map<String, List<RequirementAssignmentData>> startingVolumes = - iterator.next().getVolumes(); + Multimap<String, RequirementAssignmentData> startingVolumes = + iterator.next().getVolumes(); - for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationEntities) { - Map<String, List<RequirementAssignmentData>> currentVolumes = - compute.getVolumes(); - if (!compareNodeConnectivity(startingVolumes, currentVolumes)) { - return false; - } + for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationEntities) { + Multimap<String, RequirementAssignmentData> currentVolumes = + compute.getVolumes(); + if (!compareNodeConnectivity(startingVolumes, currentVolumes)) { + return false; + } + } + return true; } - return true; - } private boolean checkPortConsolidation(ServiceTemplate serviceTemplate, @@ -804,58 +805,60 @@ public class ConsolidationService { private boolean isThereMoreThanOneNestedLevel(ServiceTemplate nestedServiceTemplate, TranslationContext context) { - FileNestedConsolidationData fileNestedConsolidationData = null; String nestedServiceTemplateName = ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate); if (Objects.isNull(nestedServiceTemplateName)) { return false; } - NestedConsolidationData nestedConsolidationData = context.getConsolidationData().getNestedConsolidationData(); - if (Objects.nonNull(nestedConsolidationData)) { - fileNestedConsolidationData = - nestedConsolidationData.getFileNestedConsolidationData(nestedServiceTemplateName); - } + NestedConsolidationDataHandler nestedConsolidationDataHandler = context.getNestedConsolidationDataHandler(); //Condition to check if there is nested file and if file contains only sub interfaces then // return false - return Objects.nonNull(fileNestedConsolidationData) && !ifNestedFileContainsOnlySubInterface( - nestedServiceTemplate, context); + return nestedConsolidationDataHandler.isNestedConsolidationDataExist(nestedServiceTemplateName) + && !ifNestedFileContainsOnlySubInterface(nestedServiceTemplate, context); } - private boolean ifNestedFileContainsOnlySubInterface(ServiceTemplate serviceTemplate, - TranslationContext context) { - Map<String, NodeTemplate> nestedNodeTemplateMap = - DataModelUtil.getNodeTemplates(serviceTemplate); - - ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); - Set<Object> nestedHeatFileNames = nestedNodeTemplateMap.entrySet().stream() - .filter(entry -> toscaAnalyzerService.isSubstitutableNodeTemplate(entry.getValue()) - && toscaAnalyzerService - .getSubstituteServiceTemplateName(entry.getKey(), entry.getValue()).isPresent()) - .map(entry -> toscaAnalyzerService - .getSubstituteServiceTemplateName(entry.getKey(), entry.getValue()).get()) - .collect(Collectors.toSet()); - - if (CollectionUtils.isNotEmpty(nestedHeatFileNames)) { - for (Object fileName : nestedHeatFileNames) { - String heatFileName = context.getNestedHeatFileName().get(String.valueOf(fileName)); - - if (Objects.nonNull(heatFileName) - && !ifAllResourceAreSubInterface(context.getTranslatedServiceTemplates() - .get(heatFileName).getTopology_template().getNode_templates().values())) { - return false; - } - } + private boolean ifNestedFileContainsOnlySubInterface(ServiceTemplate serviceTemplate, TranslationContext context) { + Map<String, NodeTemplate> nestedNodeTemplateMap = DataModelUtil.getNodeTemplates(serviceTemplate); + + Set<String> nestedHeatFileNames = getNestedHeatFileNames(nestedNodeTemplateMap); + + return ifAllResourceAreSubInterface(nestedHeatFileNames, context); } - return true; - } + private Set<String> getNestedHeatFileNames(Map<String, NodeTemplate> nestedNodeTemplateMap) { + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); - // Method returns true if all of the resource are sub interface - private boolean ifAllResourceAreSubInterface(Collection<NodeTemplate> nodeTemplates) { - return nodeTemplates.stream().allMatch(nodeTemplate -> - ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE.equals(nodeTemplate.getType())); - } + return nestedNodeTemplateMap.entrySet().stream() + .filter(entry -> toscaAnalyzerService.isSubstitutableNodeTemplate(entry.getValue()) + && toscaAnalyzerService.getSubstituteServiceTemplateName( + entry.getKey(), entry.getValue()).isPresent()) + .map(entry -> toscaAnalyzerService.getSubstituteServiceTemplateName( + entry.getKey(), entry.getValue()).get()) + .collect(Collectors.toSet()); + } + + // Method returns true if all of the resource are sub interface + private boolean ifAllResourceAreSubInterface(Set<String> nestedHeatFileNames, + TranslationContext context) { + if (nestedHeatFileNames.isEmpty()) { + return true; + } + + for (String fileName : nestedHeatFileNames) { + String heatFileName = context.getNestedHeatFileName().get(fileName); + + if (Objects.nonNull(heatFileName) + && !context.getTranslatedServiceTemplates().get(heatFileName).getTopology_template() + .getNode_templates().values().stream() + .allMatch(nodeTemplate -> ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE + .equals(nodeTemplate.getType()))) { + return false; + } + } + + return true; + } private List<UnifiedCompositionData> createUnifiedCompositionDataList( ServiceTemplate serviceTemplate, @@ -960,10 +963,10 @@ public class ConsolidationService { ConsolidationData consolidationData, TypeComputeConsolidationData typeComputeConsolidationData) { - return (isThereMoreThanOneComputeTypeInstance(typeComputeConsolidationData) - && isNumberOfPortsEqualsBetweenComputeNodes(typeComputeConsolidationData) - && isNumberOfPortFromEachTypeLegal(typeComputeConsolidationData) - && isPortTypesEqualsBetweenComputeNodes(typeComputeConsolidationData) + return (typeComputeConsolidationData.isThereMoreThanOneComputeTypeInstance() + && typeComputeConsolidationData.isNumberOfPortsEqualsBetweenComputeNodes() + && typeComputeConsolidationData.isNumberOfPortFromEachTypeLegal() + && typeComputeConsolidationData.isPortTypesEqualsBetweenComputeNodes() && checkGetAttrBetweenConsolidationDataEntitiesNotFromSameType(serviceTemplate, typeComputeConsolidationData, consolidationData) && checkSubInterfaceConsolidationPreCondition(serviceTemplate, consolidationData, @@ -971,75 +974,6 @@ public class ConsolidationService { } - private boolean isThereMoreThanOneComputeTypeInstance( - TypeComputeConsolidationData typeComputeConsolidationData) { - return typeComputeConsolidationData.getAllComputeNodeTemplateIds().size() > 1; - } - - private boolean isNumberOfPortsEqualsBetweenComputeNodes( - TypeComputeConsolidationData typeComputeConsolidationData) { - int startingNumberOfPorts = - getNumberOfPortsPerCompute(typeComputeConsolidationData - .getAllComputeTemplateConsolidationData().iterator().next()); - - for (ComputeTemplateConsolidationData compute : typeComputeConsolidationData - .getAllComputeTemplateConsolidationData()) { - if (getNumberOfPortsPerCompute(compute) != startingNumberOfPorts) { - return false; - } - } - - return true; - } - - - private boolean isNumberOfPortFromEachTypeLegal( - TypeComputeConsolidationData typeComputeConsolidationData) { - - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataList = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - - for (ComputeTemplateConsolidationData computeTemplate : computeTemplateConsolidationDataList) { - Map<String, List<String>> currPortsMap = computeTemplate.getPorts(); - if (MapUtils.isEmpty(currPortsMap)) { - return true; - } - for (List<String> portList : currPortsMap.values()) { - if (portList.size() > 1) { - return false; - } - } - } - - return true; - } - - private boolean isPortTypesEqualsBetweenComputeNodes( - TypeComputeConsolidationData typeComputeConsolidationData) { - Set<String> staringPortIds = getPortsIds( - typeComputeConsolidationData.getAllComputeTemplateConsolidationData().iterator().next()); - - for (ComputeTemplateConsolidationData compute : typeComputeConsolidationData - .getAllComputeTemplateConsolidationData()) { - Set<String> currentPortIds = getPortsIds(compute); - if (!currentPortIds.equals(staringPortIds)) { - return false; - } - } - return true; - } - - private int getNumberOfPortsPerCompute( - ComputeTemplateConsolidationData computeTemplateConsolidationData) { - return getPortsIds(computeTemplateConsolidationData).size(); - } - - private Set<String> getPortsIds( - ComputeTemplateConsolidationData computeTemplateConsolidationData) { - return MapUtils.isEmpty(computeTemplateConsolidationData.getPorts()) ? new HashSet<>() - : computeTemplateConsolidationData.getPorts().keySet(); - } - List<String> getPropertiesWithIdenticalVal(UnifiedCompositionEntity entity) { switch (entity) { case COMPUTE: 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 e0d12e7f79..7eec4e0c72 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 @@ -41,6 +41,7 @@ import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositi import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import com.google.common.collect.Multimap; import java.util.ArrayList; import java.util.Collection; @@ -80,6 +81,7 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; import org.onap.sdc.tosca.datatypes.model.heatextend.PropertyTypeExt; import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.heat.services.HeatConstants; import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; @@ -770,7 +772,7 @@ public class UnifiedCompositionService { //Add requirements in the abstract node template for nodes connected out for computes String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate, computeTemplateConsolidationData.getNodeTemplateId()); - Map<String, List<RequirementAssignmentData>> computeNodesConnectedOut = + Multimap<String, RequirementAssignmentData> computeNodesConnectedOut = computeTemplateConsolidationData.getNodesConnectedOut(); if (computeNodesConnectedOut != null) { updateRequirementInAbstractNodeTemplate(serviceTemplate, computeTemplateConsolidationData, @@ -785,7 +787,7 @@ public class UnifiedCompositionService { portTemplateConsolidationDataList) { String newPortNodeTemplateId = getNewPortNodeTemplateId(portTemplateConsolidationData .getNodeTemplateId(), computeType, computeTemplateConsolidationData); - Map<String, List<RequirementAssignmentData>> portNodesConnectedOut = + Multimap<String, RequirementAssignmentData> portNodesConnectedOut = portTemplateConsolidationData.getNodesConnectedOut(); if (portNodesConnectedOut != null) { updateRequirementInAbstractNodeTemplate(serviceTemplate, portTemplateConsolidationData, @@ -810,7 +812,7 @@ public class UnifiedCompositionService { subInterfaceTemplateConsolidationDataList) { String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType, computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context); - Map<String, List<RequirementAssignmentData>> subInterfaceNodesConnectedOut = + Multimap<String, RequirementAssignmentData> subInterfaceNodesConnectedOut = subInterfaceTemplateConsolidationData.getNodesConnectedOut(); if (subInterfaceNodesConnectedOut != null) { updateRequirementInAbstractNodeTemplate(serviceTemplate, subInterfaceTemplateConsolidationData, @@ -825,8 +827,8 @@ public class UnifiedCompositionService { TranslationContext context) { NestedTemplateConsolidationData nestedTemplateConsolidationData = unifiedCompositionData.getNestedTemplateConsolidationData(); - Map<String, List<RequirementAssignmentData>> nodesConnectedOut = - Objects.isNull(nestedTemplateConsolidationData) ? new HashMap<>() + Multimap<String, RequirementAssignmentData> nodesConnectedOut = + Objects.isNull(nestedTemplateConsolidationData) ? ArrayListMultimap.create() : nestedTemplateConsolidationData.getNodesConnectedOut(); FileComputeConsolidationData nestedFileComputeConsolidationData = @@ -882,41 +884,41 @@ public class UnifiedCompositionService { } } - private void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate, - EntityConsolidationData entityConsolidationData, - String newNodeTemplateId, - TranslationContext context, - boolean isNested) { - Map<String, List<RequirementAssignmentData>> nodesConnectedIn = - entityConsolidationData.getNodesConnectedIn(); - if (nodesConnectedIn == null) { - //No nodes connected in info - return; - } - for (Map.Entry<String, List<RequirementAssignmentData>> entry : nodesConnectedIn - .entrySet()) { - List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue(); - for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { - RequirementAssignment requirementAssignment = requirementAssignmentData - .getRequirementAssignment(); - if (!requirementAssignment.getNode().equals(entityConsolidationData - .getNodeTemplateId())) { - //The requirement assignment target node should be the one which we are handling in the - //consolidation object - continue; - } - //Update the requirement assignment object in the original node template - if (isNested) { - updateRequirementForNestedCompositionNodesConnectedIn(serviceTemplate, - requirementAssignmentData, newNodeTemplateId); - } else { - updateRequirementForNodesConnectedIn(serviceTemplate, requirementAssignmentData, - entityConsolidationData, entry.getKey(), newNodeTemplateId, context); + private void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate, + EntityConsolidationData entityConsolidationData, + String newNodeTemplateId, + TranslationContext context, + boolean isNested) { + Multimap<String, RequirementAssignmentData> nodesConnectedIn = + entityConsolidationData.getNodesConnectedIn(); + if (nodesConnectedIn == null) { + //No nodes connected in info + return; } - } + for (String key : nodesConnectedIn.keySet()) { + Collection<RequirementAssignmentData> requirementAssignmentDataList = nodesConnectedIn.get(key); + for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { + RequirementAssignment requirementAssignment = requirementAssignmentData + .getRequirementAssignment(); + if (!requirementAssignment.getNode().equals(entityConsolidationData + .getNodeTemplateId())) { + //The requirement assignment target node should be the one which we are handling in the + //consolidation object + continue; + } + //Update the requirement assignment object in the original node template + if (isNested) { + updateRequirementForNestedCompositionNodesConnectedIn(serviceTemplate, + requirementAssignmentData, newNodeTemplateId); + } else { + updateRequirementForNodesConnectedIn(serviceTemplate, requirementAssignmentData, + entityConsolidationData, key, newNodeTemplateId, context); + } + + } + } } - } private void updateSubInterfaceNodesConnectedIn(ServiceTemplate serviceTemplate, UnifiedCompositionData unifiedCompositionData, @@ -961,7 +963,7 @@ public class UnifiedCompositionService { //Add requirements in the abstract node template for compute volumes String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate, computeTemplateConsolidationData.getNodeTemplateId()); - Map<String, List<RequirementAssignmentData>> computeVolumes = + Multimap<String, RequirementAssignmentData> computeVolumes = computeTemplateConsolidationData.getVolumes(); if (computeVolumes != null) { updateRequirementInAbstractNodeTemplate(serviceTemplate, computeTemplateConsolidationData, @@ -1271,84 +1273,81 @@ public class UnifiedCompositionService { } - private void updateRequirementInAbstractNodeTemplate(ServiceTemplate serviceTemplate, - EntityConsolidationData - entityConsolidationData, - String newNodeTemplateId, - Map<String, List<RequirementAssignmentData>> - requirementAssignmentDataMap, - TranslationContext context) { - ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); - for (Map.Entry<String, List<RequirementAssignmentData>> entry : requirementAssignmentDataMap - .entrySet()) { - String abstractNodeTemplateId = context.getUnifiedAbstractNodeTemplateId( - serviceTemplate, entityConsolidationData.getNodeTemplateId()); - NodeTemplate abstractNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, - abstractNodeTemplateId); - if (abstractNodeTemplate == null) { - //The abstract node template is not found from id in the context - return; - } - List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue(); - for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { - String oldRequirementId = requirementAssignmentData.getRequirementId(); - RequirementAssignment abstractRequirementAssignment = (RequirementAssignment) - getClonedObject(requirementAssignmentData.getRequirementAssignment(), - RequirementAssignment.class); - String newRequirementId = oldRequirementId + "_" + newNodeTemplateId; - //Check if the requirement is not already present in the list of requirements of the - // abstract node template - if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(abstractNodeTemplate, - newRequirementId, abstractRequirementAssignment)) { - DataModelUtil.addRequirementAssignment(abstractNodeTemplate, newRequirementId, - abstractRequirementAssignment); - //Update the volume relationship template if required - updateVolumeRelationshipTemplate(serviceTemplate, abstractRequirementAssignment - .getRelationship(), context); + private void updateRequirementInAbstractNodeTemplate(ServiceTemplate serviceTemplate, + EntityConsolidationData + entityConsolidationData, + String newNodeTemplateId, + Multimap<String, RequirementAssignmentData> + requirementAssignmentDataMap, + TranslationContext context) { + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + for (String key : requirementAssignmentDataMap.keySet()) { + String abstractNodeTemplateId = context.getUnifiedAbstractNodeTemplateId( + serviceTemplate, entityConsolidationData.getNodeTemplateId()); + NodeTemplate abstractNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, + abstractNodeTemplateId); + if (abstractNodeTemplate == null) { + //The abstract node template is not found from id in the context + return; + } + Collection<RequirementAssignmentData> requirementAssignmentDataList = requirementAssignmentDataMap.get(key); + for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { + String oldRequirementId = requirementAssignmentData.getRequirementId(); + RequirementAssignment abstractRequirementAssignment = (RequirementAssignment) + getClonedObject(requirementAssignmentData.getRequirementAssignment(), + RequirementAssignment.class); + String newRequirementId = oldRequirementId + "_" + newNodeTemplateId; + //Check if the requirement is not already present in the list of requirements of the + // abstract node template + if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(abstractNodeTemplate, + newRequirementId, abstractRequirementAssignment)) { + DataModelUtil.addRequirementAssignment(abstractNodeTemplate, newRequirementId, + abstractRequirementAssignment); + //Update the volume relationship template if required + updateVolumeRelationshipTemplate(serviceTemplate, abstractRequirementAssignment + .getRelationship(), context); + } + } } - } } - } - private void updateRequirementInNestedNodeTemplate(ServiceTemplate serviceTemplate, - EntityConsolidationData - entityConsolidationData, - String newNodeTemplateId, - Map<String, List<RequirementAssignmentData>> - requirementAssignmentDataMap) { - ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); + private void updateRequirementInNestedNodeTemplate(ServiceTemplate serviceTemplate, + EntityConsolidationData entityConsolidationData, + String newNodeTemplateId, + Multimap<String, RequirementAssignmentData> + requirementAssignmentDataMap) { + ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); - if (MapUtils.isEmpty(requirementAssignmentDataMap)) { - return; - } + if (CommonUtil.isMultimapEmpty(requirementAssignmentDataMap)) { + return; + } - for (Map.Entry<String, List<RequirementAssignmentData>> entry : requirementAssignmentDataMap - .entrySet()) { - String nodeTemplateId = entityConsolidationData.getNodeTemplateId(); - NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, nodeTemplateId); - if (nodeTemplate == null) { - //The node template is not found from id in the context - return; - } - List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue(); - for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { - String oldRequirementId = requirementAssignmentData.getRequirementId(); - RequirementAssignment clonedRequirementAssignment = (RequirementAssignment) - getClonedObject(requirementAssignmentData.getRequirementAssignment(), - RequirementAssignment.class); - String newRequirementId = oldRequirementId + "_" + newNodeTemplateId; - //Check if the requirement is not already present in the list of requirements of the - // node template - if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(nodeTemplate, - newRequirementId, clonedRequirementAssignment)) { - DataModelUtil.removeRequirementAssignment(nodeTemplate, oldRequirementId, - requirementAssignmentData.getRequirementAssignment()); - DataModelUtil.addRequirementAssignment(nodeTemplate, newRequirementId, - clonedRequirementAssignment); + for (String key : requirementAssignmentDataMap.keySet()) { + String nodeTemplateId = entityConsolidationData.getNodeTemplateId(); + NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, nodeTemplateId); + if (nodeTemplate == null) { + //The node template is not found from id in the context + return; + } + Collection<RequirementAssignmentData> requirementAssignmentDataList = requirementAssignmentDataMap.get(key); + for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { + String oldRequirementId = requirementAssignmentData.getRequirementId(); + RequirementAssignment clonedRequirementAssignment = (RequirementAssignment) + getClonedObject(requirementAssignmentData.getRequirementAssignment(), + RequirementAssignment.class); + String newRequirementId = oldRequirementId + "_" + newNodeTemplateId; + //Check if the requirement is not already present in the list of requirements of the + // node template + if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(nodeTemplate, + newRequirementId, clonedRequirementAssignment)) { + DataModelUtil.removeRequirementAssignment(nodeTemplate, oldRequirementId, + requirementAssignmentData.getRequirementAssignment()); + DataModelUtil.addRequirementAssignment(nodeTemplate, newRequirementId, + clonedRequirementAssignment); + } + } } - } } - } private void updNodeGetAttrInConnectivity( ServiceTemplate serviceTemplate, @@ -2725,42 +2724,40 @@ public class UnifiedCompositionService { + subInterfaceType + "_" + propertyId; } - private void removeConnectivityOut(EntityConsolidationData entityConsolidationData, - NodeTemplate nodeTemplate) { - if (MapUtils.isEmpty(entityConsolidationData.getNodesConnectedOut())) { - return; - } + private void removeConnectivityOut(EntityConsolidationData entityConsolidationData, + NodeTemplate nodeTemplate) { - for (List<RequirementAssignmentData> requirementAssignmentDataList : entityConsolidationData - .getNodesConnectedOut().values()) { - for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { - DataModelUtil.removeRequirementsAssignment(nodeTemplate.getRequirements(), - requirementAssignmentData.getRequirementId()); - } - if (nodeTemplate.getRequirements().isEmpty()) { - nodeTemplate.setRequirements(null); - } - } - } + Multimap<String, RequirementAssignmentData> nodesConnectedOut = entityConsolidationData.getNodesConnectedOut(); - private void removeVolumeConnectivity( - ComputeTemplateConsolidationData computeTemplateConsolidationData, - NodeTemplate computeNodeTemplate) { - if (MapUtils.isEmpty(computeTemplateConsolidationData.getVolumes())) { - return; - } - Collection<List<RequirementAssignmentData>> volumeCollection = - computeTemplateConsolidationData.getVolumes().values(); - for (List<RequirementAssignmentData> requirementAssignmentDataList : volumeCollection) { - for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) { - DataModelUtil.removeRequirementsAssignment(computeNodeTemplate.getRequirements(), - requirementAssignmentData.getRequirementId()); - } + if (CommonUtil.isMultimapEmpty(nodesConnectedOut)) { + return; + } + + nodesConnectedOut.values().forEach(requirementAssignmentData -> + DataModelUtil.removeRequirementsAssignment(nodeTemplate.getRequirements(), + requirementAssignmentData.getRequirementId()) + ); + + if (nodeTemplate.getRequirements().isEmpty()) { + nodeTemplate.setRequirements(null); + } } - if (computeNodeTemplate.getRequirements().isEmpty()) { - computeNodeTemplate.setRequirements(null); + + private void removeVolumeConnectivity(ComputeTemplateConsolidationData computeTemplateConsolidationData, + NodeTemplate computeNodeTemplate) { + if (CommonUtil.isMultimapEmpty(computeTemplateConsolidationData.getVolumes())) { + return; + } + + computeTemplateConsolidationData.getVolumes().values().forEach(requirementAssignmentData -> + DataModelUtil.removeRequirementsAssignment(computeNodeTemplate.getRequirements(), + requirementAssignmentData.getRequirementId()) + ); + + if (computeNodeTemplate.getRequirements().isEmpty()) { + computeNodeTemplate.setRequirements(null); + } } - } private void createIndexInputParameter(ServiceTemplate substitutionServiceTemplate) { ParameterDefinition indexParameterDefinition = |