diff options
11 files changed, 522 insertions, 290 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/ComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java index fe0bf24d76..5e1d264f83 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationData.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 ComputeConsolidationData { @@ -62,4 +63,17 @@ public class ComputeConsolidationData { } return consolidationData; } + + /** + * Is number of compute types legal. + * + * @param serviceTemplateName the service template name + * @return the boolean + */ + public boolean isNumberOfComputeTypesLegal(String serviceTemplateName) { + FileComputeConsolidationData fileComputeConsolidationData = + getFileComputeConsolidationData(serviceTemplateName); + return Objects.nonNull(fileComputeConsolidationData) + && fileComputeConsolidationData.isNumberOfComputeTypesLegal(); + } } 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/ComputeConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java index b0c0479e11..dc2fc96169 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java @@ -134,4 +134,8 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler return computeNodeTemplate.getType(); } + + public boolean isNumberOfComputeTypesLegal(String serviceTemplateName) { + return computeConsolidationData.isNumberOfComputeTypesLegal(serviceTemplateName); + } }
\ No newline at end of file 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 e2f3be12fb..854cf51aa2 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 @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.collections4.MapUtils; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; public class ComputeTemplateConsolidationData extends EntityConsolidationData { @@ -65,4 +66,18 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData { .add(new RequirementAssignmentData(requirementId, requirementAssignment)); } + + /** + * Collect all ports of each type from compute. + * + * @param portTypeToIds will be populated with all port of each type + */ + public void collectAllPortsOfEachTypeFromCompute(Map<String, List<String>> portTypeToIds) { + if (MapUtils.isNotEmpty(ports)) { + for (Map.Entry<String, List<String>> portTypeToIdEntry : ports.entrySet()) { + portTypeToIds.putIfAbsent(portTypeToIdEntry.getKey(), new ArrayList<>()); + portTypeToIds.get(portTypeToIdEntry.getKey()).addAll(portTypeToIdEntry.getValue()); + } + } + } } 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 1360677d78..7101037562 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 @@ -17,10 +17,17 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.commons.collections4.MapUtils; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; +import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil; /** * The type Entity consolidation data. @@ -261,4 +268,43 @@ public class EntityConsolidationData { outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName())); } + + /** + * Per port type compare get attr of entity with given consolidation data list. + * + * @param entityConsolidationDataList consolidation data list + * @param portTypeToIds the port type to ids + * @return true in case get attr list same for all port types. + * otherwise return false + */ + public boolean isGetAttrOutFromEntityLegal( + Collection<? extends EntityConsolidationData> entityConsolidationDataList, + Map<String, List<String>> portTypeToIds) { + + for (String portType : portTypeToIds.keySet()) { + Set<GetAttrFuncData> startingGetAttrFunc = + getEntityGetAttrFuncAsSet(portType); + + for (EntityConsolidationData entity : entityConsolidationDataList) { + Set<GetAttrFuncData> currentGetAttrFuncData = + entity.getEntityGetAttrFuncAsSet(portType); + if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) { + return false; + } + } + } + + return true; + } + + private Set<GetAttrFuncData> getEntityGetAttrFuncAsSet(String portType) { + if (MapUtils.isEmpty(nodesGetAttrOut)) { + return new HashSet<>(); + } + + return nodesGetAttrOut.entrySet().stream() + .filter(entry -> portType.equals(ConsolidationDataUtil.getPortType(entry.getKey()))) + .flatMap(entry -> entry.getValue().stream()) + .collect(Collectors.toSet()); + } } 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/FileComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java index 58f59f965b..bde0dc0ede 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationData.java @@ -68,4 +68,17 @@ public class FileComputeConsolidationData { } return consolidationData; } + + /** + * Is number of compute types legal boolean. + * + * @return the boolean + */ + public boolean isNumberOfComputeTypesLegal() { + Collection<TypeComputeConsolidationData> typeComputeConsolidationDataCollection = + getAllTypeComputeConsolidationData(); + return typeComputeConsolidationDataCollection.size() == 1 + && typeComputeConsolidationDataCollection.iterator().next() + .isNumberOfComputeConsolidationDataPerTypeLegal(); + } } 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 a77cc21077..7b99ec1514 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 @@ -18,8 +18,11 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.apache.commons.collections4.CollectionUtils; + public class TypeComputeConsolidationData { //key - compute node template id @@ -69,4 +72,43 @@ public class TypeComputeConsolidationData { return consolidationData; } + /** + * Gets all ports per port type, which are connected to the computes consolidation data entities + * computeTemplateConsolidationDataCollection. + * + * @return Map containing key as port type and value as ports id + */ + public Map<String, List<String>> collectAllPortsOfEachTypeFromComputes() { + Map<String, List<String>> portTypeToIds = new HashMap<>(); + Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataCollection = + getAllComputeTemplateConsolidationData(); + + computeTemplateConsolidationDataCollection + .forEach(computeTemplateConsolidationData1 -> + computeTemplateConsolidationData1.collectAllPortsOfEachTypeFromCompute(portTypeToIds)); + + return portTypeToIds; + } + + /** + * Check if get attr out from entity are legal for given port list + * + * @param portTypeToIds list of port Ids per port type + * @return true if get attr out are legal else false + */ + public boolean isGetAttrOutFromEntityLegal(Map<String, List<String>> portTypeToIds) { + + Collection<ComputeTemplateConsolidationData> entities = getAllComputeTemplateConsolidationData(); + + if (CollectionUtils.isEmpty(entities)) { + return true; + } + + EntityConsolidationData firstEntity = entities.iterator().next(); + return firstEntity.isGetAttrOutFromEntityLegal(entities, portTypeToIds); + } + + public boolean isNumberOfComputeConsolidationDataPerTypeLegal() { + return getAllComputeTemplateConsolidationData().size() == 1; + } } 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 7f3ab7384d..1000554975 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,13 +18,28 @@ package org.openecomp.sdc.translator.services.heattotosca; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; 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.tosca.datatypes.ToscaNodeType; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; @@ -49,20 +64,6 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.stream.Collectors; - public class ConsolidationService { private UnifiedCompositionService unifiedCompositionService; @@ -162,25 +163,21 @@ public class ConsolidationService { typeComputeConsolidationData, consolidationData); } - private boolean checkGetAttrBetweenConsolidationDataEntitiesNotFromSameType( - ServiceTemplate serviceTemplate, - TypeComputeConsolidationData typeComputeConsolidationData, - ConsolidationData consolidationData) { - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataList = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - - Collection<String> computeNodeTemplateIds = - typeComputeConsolidationData.getAllComputeNodeTemplateIds(); + private boolean checkGetAttrBetweenConsolidationDataEntitiesNotFromSameType( + ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Collection<String> computeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds(); - Map<String, List<String>> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataList); + Map<String, List<String>> portTypeToIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); - return - checkGetAttrOutFromEntityToPortIsLegal(computeTemplateConsolidationDataList, portTypeToIds) - && checkGetAttrOutFromPortLegal(ToscaUtil.getServiceTemplateFileName(serviceTemplate), - computeNodeTemplateIds, portTypeToIds, consolidationData); + return typeComputeConsolidationData.isGetAttrOutFromEntityLegal(portTypeToIds) + && checkGetAttrOutFromPortLegal( + ToscaUtil.getServiceTemplateFileName(serviceTemplate), + computeNodeTemplateIds, portTypeToIds, consolidationData); - } + } private boolean checkGetAttrOutFromPortLegal(String serviceTemplateName, Collection<String> computeNodeTemplateIds, @@ -202,29 +199,12 @@ public class ConsolidationService { return true; } - private boolean checkGetAttrOutFromEntityToPortIsLegal(Collection entities, - Map<String, List<String>> portTypeToIds) { - - for (String portType : portTypeToIds.keySet()) { - if (CollectionUtils.isEmpty(entities)) { - continue; - } - Set<GetAttrFuncData> startingGetAttrFunc = - getEntityGetAttrFuncAsSet(portType, - (EntityConsolidationData) entities.iterator().next()); - for (Object entity : entities) { - EntityConsolidationData currentEntity = (EntityConsolidationData) entity; - Set<GetAttrFuncData> currentGetAttrFuncData = - getEntityGetAttrFuncAsSet(portType, currentEntity); - if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) { - return false; - } - } + private boolean checkGetAttrOutFromEntityToPortIsLegal(Collection<? extends EntityConsolidationData> entities, + Map<String, List<String>> portTypeToIds) { + return CollectionUtils.isEmpty(entities) + || entities.iterator().next().isGetAttrOutFromEntityLegal(entities, portTypeToIds); } - return true; - } - private boolean checkGetAttrOutFromConsolidationEntityToEntityNotFromSameTypeIsLegal( List entityConsolidationDataList, Collection<String> consolidationEntityNodeTemplateIds) { @@ -276,9 +256,8 @@ public class ConsolidationService { return true; } - Map<String, List<String>> portTypeToPortIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes( - typeComputeConsolidationData.getAllComputeTemplateConsolidationData()); + Map<String, List<String>> portTypeToPortIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); Collection<String> computeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds(); @@ -348,28 +327,6 @@ public class ConsolidationService { .allMatch(element -> element.isNumberOfSubInterfacesPerTypeSimilar(subInterfaceConsolidationData)); } - - private Set<GetAttrFuncData> getEntityGetAttrFuncAsSet( - String portType, - EntityConsolidationData entityConsolidationData) { - - Set<GetAttrFuncData> getAttrFuncDataFromPortsWithSameType = new HashSet<>(); - Map<String, List<GetAttrFuncData>> nodesGetAttrOut = - entityConsolidationData.getNodesGetAttrOut(); - - if (MapUtils.isEmpty(nodesGetAttrOut)) { - return getAttrFuncDataFromPortsWithSameType; - } - - for (Map.Entry<String, List<GetAttrFuncData>> entry : nodesGetAttrOut.entrySet()) { - if (portType.equals(ConsolidationDataUtil.getPortType(entry.getKey()))) { - getAttrFuncDataFromPortsWithSameType.addAll(entry.getValue()); - } - } - - return getAttrFuncDataFromPortsWithSameType; - } - private Map<String, Set<GetAttrFuncData>> getConsolidationEntityGetAttrOutFuncData( Map<String, List<GetAttrFuncData>> nodesGetAttrOut, Collection<String> computeNodeTemplateIds) { @@ -412,32 +369,29 @@ public class ConsolidationService { EntityConsolidationData::getNodesGetAttrIn); } - private boolean areThereGetAttrRelationsBetweenPortsOfTheSameType( - ServiceTemplate serviceTemplate, - TypeComputeConsolidationData typeComputeConsolidationData, - ConsolidationData consolidationData) { - - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationEntities = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map<String, List<String>> portTypeToPortIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationEntities); + private boolean areThereGetAttrRelationsBetweenPortsOfTheSameType( + ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Map<String, List<String>> portTypeToPortIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + + FilePortConsolidationData filePortConsolidationData = + consolidationData.getPortConsolidationData().getFilePortConsolidationData( + ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + + for (List<String> portsOfTheSameTypeIds : portTypeToPortIds.values()) { + List<PortTemplateConsolidationData> portTemplateConsolidationDataOfSameType = + getAllPortTemplateConsolidationData(portsOfTheSameTypeIds, filePortConsolidationData); + if (!checkGetAttrRelationsForEntityConsolidationData(portTemplateConsolidationDataOfSameType, + portsOfTheSameTypeIds, EntityConsolidationData::getNodesGetAttrIn)) { + return false; + } + } - FilePortConsolidationData filePortConsolidationData = - consolidationData.getPortConsolidationData().getFilePortConsolidationData(ToscaUtil - .getServiceTemplateFileName(serviceTemplate)); - - for (List<String> portsOfTheSameTypeIds : portTypeToPortIds.values()) { - List<PortTemplateConsolidationData> portTemplateConsolidationDataOfSameType = - getAllPortTemplateConsolidationData(portsOfTheSameTypeIds, filePortConsolidationData); - if (!checkGetAttrRelationsForEntityConsolidationData(portTemplateConsolidationDataOfSameType, - portsOfTheSameTypeIds, EntityConsolidationData::getNodesGetAttrIn)) { - return false; - } + return true; } - return true; - } - private boolean areThereGetAttrRelationsBetweenSubInterfacesOfSameType( List<String> subInterfacesIdsFromSameType, List<SubInterfaceTemplateConsolidationData> subInterfaceList) { @@ -578,26 +532,23 @@ public class ConsolidationService { } - private boolean validateWantedPortProperties(ServiceTemplate serviceTemplate, - TypeComputeConsolidationData typeComputeConsolidationData) { + private boolean validateWantedPortProperties(ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData) { + Map<String, List<String>> portTypeToIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataCollection = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map<String, List<String>> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataCollection); - List<String> propertiesWithIdenticalVal = getPortPropertiesWithIdenticalVal(); - List<String> propertiesThatNeedToHaveSameUsage = - getPortPropertiesThatNeedToHaveSameUsage(); - - for (List<String> portsIds : portTypeToIds.values()) { - if (!arePortPropertiesValid(serviceTemplate, propertiesWithIdenticalVal, - propertiesThatNeedToHaveSameUsage, portsIds)) { - return false; - } - } + List<String> propertiesWithIdenticalVal = getPortPropertiesWithIdenticalVal(); + List<String> propertiesThatNeedToHaveSameUsage = getPortPropertiesThatNeedToHaveSameUsage(); - return true; - } + for (List<String> portsIds : portTypeToIds.values()) { + if (!arePortPropertiesValid( + serviceTemplate, propertiesWithIdenticalVal, propertiesThatNeedToHaveSameUsage, portsIds)) { + return false; + } + } + + return true; + } private boolean arePortPropertiesValid(ServiceTemplate serviceTemplate, List<String> propertiesWithIdenticalVal, @@ -620,27 +571,24 @@ public class ConsolidationService { propertiesThatNeedToHaveSameUsage, exists); } - private boolean checkPortRelations(String serviceTemplateName, - TypeComputeConsolidationData typeComputeConsolidationData, - ConsolidationData consolidationData) { - Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataCollection = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map<String, List<String>> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataCollection); + private boolean checkPortRelations(String serviceTemplateName, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Map<String, List<String>> portTypeToIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); - for (List<String> portIds : portTypeToIds.values()) { - List<PortTemplateConsolidationData> portTemplateConsolidationDataList = - collectAllPortsTemplateConsolidationData( - portIds, serviceTemplateName, consolidationData); + for (List<String> portIds : portTypeToIds.values()) { + List<PortTemplateConsolidationData> portTemplateConsolidationDataList = + collectAllPortsTemplateConsolidationData(portIds, serviceTemplateName, consolidationData); - if (!checkEntityConsolidationDataRelations(portTemplateConsolidationDataList) - || !checkSubInterfaceRules(portTemplateConsolidationDataList)) { - return false; - } - } + if (!checkEntityConsolidationDataRelations(portTemplateConsolidationDataList) || !checkSubInterfaceRules( + portTemplateConsolidationDataList)) { + return false; + } + } - return true; - } + return true; + } private boolean checkSubInterfaceRules(List<PortTemplateConsolidationData> portTemplateConsolidationDataList) { @@ -816,85 +764,64 @@ public class ConsolidationService { || nodeTemplate.getProperties().get(propertyToCheck) == null); } - void substitutionServiceTemplateConsolidation(String substituteNodeTemplateId, - ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate, - TranslationContext translationContext) { - - ConsolidationData consolidationData = translationContext.getConsolidationData(); - - FileComputeConsolidationData fileComputeConsolidationData = - translationContext.getConsolidationData().getComputeConsolidationData() - .getFileComputeConsolidationData( - ToscaUtil.getServiceTemplateFileName(substitutionServiceTemplate)); - boolean substitutionConsolidationRuleResult = - substitutionServiceTemplateConsolidationRule(substitutionServiceTemplate, - fileComputeConsolidationData, translationContext); - - if (substitutionConsolidationRuleResult) { - List<UnifiedCompositionData> unifiedCompositionDataList = - createSubstitutionUnifiedCompositionDataList(substituteNodeTemplateId, - serviceTemplate, substitutionServiceTemplate, consolidationData); - unifiedCompositionService - .createUnifiedComposition(serviceTemplate, substitutionServiceTemplate, - unifiedCompositionDataList, UnifiedCompositionMode.NestedSingleCompute, - translationContext); - } else { - //The node template does not represent unified VFC but complexVFC - //Adding the id in the context for fixing connectivity from/to nested non-unified nodes - translationContext.addUnifiedNestedNodeTemplateId(ToscaUtil - .getServiceTemplateFileName(serviceTemplate), - substituteNodeTemplateId, substituteNodeTemplateId); - - if (!translationContext.isUnifiedHandledServiceTemplate(substitutionServiceTemplate)) { - serviceTemplateConsolidation(substitutionServiceTemplate, translationContext); - } + void substitutionServiceTemplateConsolidation(String substituteNodeTemplateId, + ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate, + TranslationContext translationContext) { + + ConsolidationData consolidationData = translationContext.getConsolidationData(); + + boolean substitutionConsolidationRuleResult = + substitutionServiceTemplateConsolidationRule(substitutionServiceTemplate, translationContext); + + if (substitutionConsolidationRuleResult) { + List<UnifiedCompositionData> unifiedCompositionDataList = + createSubstitutionUnifiedCompositionDataList(substituteNodeTemplateId, serviceTemplate, + substitutionServiceTemplate, consolidationData); + unifiedCompositionService + .createUnifiedComposition(serviceTemplate, substitutionServiceTemplate, unifiedCompositionDataList, + UnifiedCompositionMode.NestedSingleCompute, translationContext); + } else { + //The node template does not represent unified VFC but complexVFC + //Adding the id in the context for fixing connectivity from/to nested non-unified nodes + translationContext.addUnifiedNestedNodeTemplateId(ToscaUtil.getServiceTemplateFileName(serviceTemplate), + substituteNodeTemplateId, substituteNodeTemplateId); + + if (!translationContext.isUnifiedHandledServiceTemplate(substitutionServiceTemplate)) { + serviceTemplateConsolidation(substitutionServiceTemplate, translationContext); + } + } } - } - private boolean substitutionServiceTemplateConsolidationRule( - ServiceTemplate nestedServiceTemplate, - FileComputeConsolidationData fileComputeConsolidationData, - TranslationContext context) { - - return Objects.nonNull(fileComputeConsolidationData) - && isNumberOfComputeTypesLegal(fileComputeConsolidationData) - && isNumberOfComputeConsolidationDataPerTypeLegal( - fileComputeConsolidationData.getAllTypeComputeConsolidationData().iterator().next()) - && !isThereMoreThanOneNestedLevel(nestedServiceTemplate, context); - } + private boolean substitutionServiceTemplateConsolidationRule(ServiceTemplate nestedServiceTemplate, + TranslationContext context) { + ConsolidationData consolidationData = context.getConsolidationData(); - private boolean isNumberOfComputeTypesLegal( - FileComputeConsolidationData fileComputeConsolidationData) { - return fileComputeConsolidationData.getAllTypeComputeConsolidationData().size() == 1; - } + return consolidationData.getComputeConsolidationDataHandler().isNumberOfComputeTypesLegal( + ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate)) + && !isThereMoreThanOneNestedLevel(nestedServiceTemplate, context); + } - private boolean isNumberOfComputeConsolidationDataPerTypeLegal( - TypeComputeConsolidationData typeComputeConsolidationData) { - return typeComputeConsolidationData.getAllComputeTemplateConsolidationData().size() == 1; - } + private boolean isThereMoreThanOneNestedLevel(ServiceTemplate nestedServiceTemplate, + TranslationContext context) { + FileNestedConsolidationData fileNestedConsolidationData = null; + String nestedServiceTemplateName = ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate); + if (Objects.isNull(nestedServiceTemplateName)) { + return false; + } - 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); + } - NestedConsolidationData nestedConsolidationData = context.getConsolidationData() - .getNestedConsolidationData(); - if (Objects.nonNull(nestedConsolidationData)) { - fileNestedConsolidationData = - nestedConsolidationData.getFileNestedConsolidationData(nestedServiceTemplateName); + //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); } - //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); - } - private boolean ifNestedFileContainsOnlySubInterface(ServiceTemplate serviceTemplate, TranslationContext context) { Map<String, NodeTemplate> nestedNodeTemplateMap = 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 217b5775a9..253b864301 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,21 @@ import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositi import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -49,14 +64,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.onap.config.api.Configuration; import org.onap.config.api.ConfigurationManager; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.sdc.common.togglz.ToggleableFeature; -import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; -import org.openecomp.sdc.heat.services.HeatConstants; -import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; -import org.openecomp.sdc.tosca.datatypes.ToscaGroupType; -import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; -import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; import org.onap.sdc.tosca.datatypes.model.AttributeDefinition; import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition; import org.onap.sdc.tosca.datatypes.model.Constraint; @@ -72,6 +79,14 @@ import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; 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.togglz.ToggleableFeature; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; +import org.openecomp.sdc.heat.services.HeatConstants; +import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; +import org.openecomp.sdc.tosca.datatypes.ToscaGroupType; +import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; @@ -97,20 +112,6 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - public class UnifiedCompositionService { private static final Map<String, ImplementationConfiguration> unifiedCompositionImplMap; @@ -1824,31 +1825,26 @@ public class UnifiedCompositionService { } } - private void handleConsolidationPorts(ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate, - List<UnifiedCompositionData> unifiedCompositionDataList, - String connectedComputeNodeType, - TranslationContext context) { - Collection<ComputeTemplateConsolidationData> computeConsolidationDataList = - (Collection) getComputeConsolidationDataList(unifiedCompositionDataList); - - Map<String, List<String>> portIdsPerPortType = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); + private void handleConsolidationPorts(ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate, + List<UnifiedCompositionData> unifiedCompositionDataList, + String connectedComputeNodeType, + TranslationContext context) { + Map<String, List<String>> portIdsPerPortType = + UnifiedCompositionUtil.collectAllPortsOfEachTypeFromComputes(unifiedCompositionDataList); - for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { - List<EntityConsolidationData> portTemplateConsolidationDataList = - getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), - unifiedCompositionDataList); - if (CollectionUtils.isEmpty(portTemplateConsolidationDataList)) { - continue; - } + for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { + List<EntityConsolidationData> portTemplateConsolidationDataList = + getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), unifiedCompositionDataList); + if (CollectionUtils.isEmpty(portTemplateConsolidationDataList)) { + continue; + } - handlePortNodeTemplate(serviceTemplate, substitutionServiceTemplate, - portTemplateConsolidationDataList, connectedComputeNodeType, - unifiedCompositionDataList.get(0).getComputeTemplateConsolidationData(), - unifiedCompositionDataList, context); + handlePortNodeTemplate(serviceTemplate, substitutionServiceTemplate, portTemplateConsolidationDataList, + connectedComputeNodeType, unifiedCompositionDataList.get(0).getComputeTemplateConsolidationData(), + unifiedCompositionDataList, context); + } } - } private void handlePortNodeTemplate( ServiceTemplate serviceTemplate, @@ -1914,36 +1910,35 @@ public class UnifiedCompositionService { } } - private void handleConsolidationSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { - Collection<ComputeTemplateConsolidationData> computeConsolidationDataList = - (Collection) getComputeConsolidationDataList(unifiedCompositionTo.getUnifiedCompositionDataList()); - - Map<String, List<String>> portIdsPerPortType = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); - - for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { - List<EntityConsolidationData> portEntityConsolidationDataList = - getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), - unifiedCompositionTo.getUnifiedCompositionDataList()); - if (CollectionUtils.isEmpty(portEntityConsolidationDataList)) { - continue; - } - - List<PortTemplateConsolidationData> portTemplateConsolidationDataList = - portEntityConsolidationDataList.stream() - .map(data -> (PortTemplateConsolidationData) data) - .collect(Collectors.toList()); - - ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfacesByType = UnifiedCompositionUtil - .collectAllSubInterfacesOfEachTypesFromPorts(portTemplateConsolidationDataList); - Set<String> subInterfaceTypes = subInterfacesByType.keySet(); - for (String subInterfaceType: subInterfaceTypes) { - List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = - subInterfacesByType.get(subInterfaceType); - createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, subInterfaceTemplateConsolidationDataList); - } + private void handleConsolidationSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { + Map<String, List<String>> portIdsPerPortType = + UnifiedCompositionUtil.collectAllPortsOfEachTypeFromComputes( + unifiedCompositionTo.getUnifiedCompositionDataList()); + + for (Map.Entry<String, List<String>> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { + List<EntityConsolidationData> portEntityConsolidationDataList = + getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), + unifiedCompositionTo.getUnifiedCompositionDataList()); + if (CollectionUtils.isEmpty(portEntityConsolidationDataList)) { + continue; + } + + List<PortTemplateConsolidationData> portTemplateConsolidationDataList = + portEntityConsolidationDataList.stream().map(data -> (PortTemplateConsolidationData) data) + .collect(Collectors.toList()); + + ListMultimap<String, SubInterfaceTemplateConsolidationData> subInterfacesByType = + UnifiedCompositionUtil.collectAllSubInterfacesOfEachTypesFromPorts( + portTemplateConsolidationDataList); + Set<String> subInterfaceTypes = subInterfacesByType.keySet(); + for (String subInterfaceType : subInterfaceTypes) { + List<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationDataList = + subInterfacesByType.get(subInterfaceType); + createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, + subInterfaceTemplateConsolidationDataList); + } + } } - } private void createSubInterfaceSubstitutionNodeTemplate(UnifiedCompositionTo unifiedCompositionTo, List<SubInterfaceTemplateConsolidationData> 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 8729ca590e..e2a79fb862 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 @@ -18,15 +18,6 @@ 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.onap.sdc.tosca.datatypes.model.NodeTemplate; -import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.openecomp.sdc.tosca.services.DataModelUtil; -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.PortTemplateConsolidationData; -import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; import java.util.ArrayList; import java.util.Collection; @@ -37,6 +28,16 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import org.apache.commons.collections4.MapUtils; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.DataModelUtil; +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.PortTemplateConsolidationData; +import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData; + /** * Utility class for consolidation data collection helper methods. */ @@ -185,4 +186,15 @@ public class UnifiedCompositionUtil { //Add sub interface type since we have only one subinterface per type return getSubInterfaceTypeSuffix(subInterfaceNodeTemplate.getType()); } + + public static Map<String, List<String>> collectAllPortsOfEachTypeFromComputes( + List<UnifiedCompositionData> unifiedCompositionDataList) { + Map<String, List<String>> portIdsPerPortType = new HashMap<>(); + unifiedCompositionDataList + .forEach(unifiedCompositionData -> + unifiedCompositionData.getComputeTemplateConsolidationData() + .collectAllPortsOfEachTypeFromCompute(portIdsPerPortType)); + + return portIdsPerPortType; + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java index ec65b43fef..fd96f93bb5 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,6 +36,94 @@ public class EntityConsolidationDataTest { private static final String REQUIREMENT_ID_2 = "requirementId2"; @Test + public void testIsGetAttrOutFromEntityLegal() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap1.put("server_1_networkrole_1_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertTrue(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalNegative() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_0_networkrole_2_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_2_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + //entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalMultiplePortWithDiffAttr() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + ports.put("server_networkrole_2_port", + Arrays.asList("server_0_networkrole_2_port", "server_0_networkrole_2_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + getAttOutMap.put("server_0_networkrole_2_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test public void testAddNodesConnectedIn_SameNodeTemplateIds() { EntityConsolidationData consolidationData = new EntityConsolidationData(); Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java index 7a3c8fa526..6388620e7c 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java @@ -16,10 +16,16 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; +import org.apache.commons.collections4.MapUtils; import org.junit.Assert; import org.junit.Test; @@ -27,6 +33,75 @@ public class TypeComputeConsolidationDataTest { private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1"; private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2"; + private static final String SERVER_NETWORKROLE_1_PORT = "server_networkrole_1_port"; + private static final String SERVER_NETWORKROLE_2_PORT = "server_networkrole_2_port"; + + @Test + public void testCollectAllPortsOfEachTypeFromComputesNoPorts() { + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(Objects.nonNull(stringListMap) && MapUtils.isEmpty(stringListMap)); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputes() { + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + Map<String, List<String>> ports = new HashMap<>(); + ports.put(SERVER_NETWORKROLE_1_PORT, + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData.setPorts(ports); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(stringListMap.containsKey(SERVER_NETWORKROLE_1_PORT) + && stringListMap.get(SERVER_NETWORKROLE_1_PORT).size() == 2); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputesWithMultipleCompute() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put(SERVER_NETWORKROLE_1_PORT, + Arrays.asList("server_0_networkrole_1_port_1", "server_1_networkrole_1_port_2")); + + Map<String, List<String>> ports1 = new HashMap<>(); + ports1.put(SERVER_NETWORKROLE_2_PORT, + Arrays.asList("server_0_networkrole_2_port_1", "server_1_networkrole_2_port_2")); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData.setPorts(ports); + + ComputeTemplateConsolidationData computeTemplateConsolidationData1 = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData1.setPorts(ports1); + + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type1", + computeTemplateConsolidationData1); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(stringListMap.size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_1_PORT).size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_1_PORT).contains("server_0_networkrole_1_port_1") + && stringListMap.get(SERVER_NETWORKROLE_1_PORT).contains("server_1_networkrole_1_port_2")); + + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_2_PORT).size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_2_PORT).contains("server_0_networkrole_2_port_1") + && stringListMap.get(SERVER_NETWORKROLE_2_PORT).contains("server_1_networkrole_2_port_2")); + } @Test public void testAddComputeTemplateConsolidationData() { |