From 74bc96a289f9bf54a010fa7b027b839ebebead4c Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Mon, 4 Jun 2018 11:26:54 +0530 Subject: Refactoring - TOSCA Consolidation Data handling Tried to handle class members from within class instead of outside Change-Id: Iee6b396562cdcbd1569dd6ce7b31a205e1de6257 Issue-ID: SDC-1330 Signed-off-by: siddharth0905 --- .../consolidation/ComputeConsolidationData.java | 14 + .../ComputeConsolidationDataHandler.java | 4 + .../ComputeTemplateConsolidationData.java | 15 + .../consolidation/EntityConsolidationData.java | 46 +++ .../FileComputeConsolidationData.java | 13 + .../TypeComputeConsolidationData.java | 42 +++ .../services/heattotosca/ConsolidationService.java | 343 ++++++++------------- .../heattotosca/UnifiedCompositionService.java | 141 ++++----- .../heattotosca/UnifiedCompositionUtil.java | 30 +- .../consolidation/EntityConsolidationDataTest.java | 89 ++++++ .../TypeComputeConsolidationDataTest.java | 75 +++++ 11 files changed, 522 insertions(+), 290 deletions(-) (limited to 'openecomp-be/lib') 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> portTypeToIds) { + if (MapUtils.isNotEmpty(ports)) { + for (Map.Entry> 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 entityConsolidationDataList, + Map> portTypeToIds) { + + for (String portType : portTypeToIds.keySet()) { + Set startingGetAttrFunc = + getEntityGetAttrFuncAsSet(portType); + + for (EntityConsolidationData entity : entityConsolidationDataList) { + Set currentGetAttrFuncData = + entity.getEntityGetAttrFuncAsSet(portType); + if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) { + return false; + } + } + } + + return true; + } + + private Set 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 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> collectAllPortsOfEachTypeFromComputes() { + Map> portTypeToIds = new HashMap<>(); + Collection 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> portTypeToIds) { + + Collection 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 computeTemplateConsolidationDataList = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - - Collection computeNodeTemplateIds = - typeComputeConsolidationData.getAllComputeNodeTemplateIds(); + private boolean checkGetAttrBetweenConsolidationDataEntitiesNotFromSameType( + ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Collection computeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds(); - Map> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataList); + Map> 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 computeNodeTemplateIds, @@ -202,29 +199,12 @@ public class ConsolidationService { return true; } - private boolean checkGetAttrOutFromEntityToPortIsLegal(Collection entities, - Map> portTypeToIds) { - - for (String portType : portTypeToIds.keySet()) { - if (CollectionUtils.isEmpty(entities)) { - continue; - } - Set startingGetAttrFunc = - getEntityGetAttrFuncAsSet(portType, - (EntityConsolidationData) entities.iterator().next()); - for (Object entity : entities) { - EntityConsolidationData currentEntity = (EntityConsolidationData) entity; - Set currentGetAttrFuncData = - getEntityGetAttrFuncAsSet(portType, currentEntity); - if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) { - return false; - } - } + private boolean checkGetAttrOutFromEntityToPortIsLegal(Collection entities, + Map> portTypeToIds) { + return CollectionUtils.isEmpty(entities) + || entities.iterator().next().isGetAttrOutFromEntityLegal(entities, portTypeToIds); } - return true; - } - private boolean checkGetAttrOutFromConsolidationEntityToEntityNotFromSameTypeIsLegal( List entityConsolidationDataList, Collection consolidationEntityNodeTemplateIds) { @@ -276,9 +256,8 @@ public class ConsolidationService { return true; } - Map> portTypeToPortIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes( - typeComputeConsolidationData.getAllComputeTemplateConsolidationData()); + Map> portTypeToPortIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); Collection computeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds(); @@ -348,28 +327,6 @@ public class ConsolidationService { .allMatch(element -> element.isNumberOfSubInterfacesPerTypeSimilar(subInterfaceConsolidationData)); } - - private Set getEntityGetAttrFuncAsSet( - String portType, - EntityConsolidationData entityConsolidationData) { - - Set getAttrFuncDataFromPortsWithSameType = new HashSet<>(); - Map> nodesGetAttrOut = - entityConsolidationData.getNodesGetAttrOut(); - - if (MapUtils.isEmpty(nodesGetAttrOut)) { - return getAttrFuncDataFromPortsWithSameType; - } - - for (Map.Entry> entry : nodesGetAttrOut.entrySet()) { - if (portType.equals(ConsolidationDataUtil.getPortType(entry.getKey()))) { - getAttrFuncDataFromPortsWithSameType.addAll(entry.getValue()); - } - } - - return getAttrFuncDataFromPortsWithSameType; - } - private Map> getConsolidationEntityGetAttrOutFuncData( Map> nodesGetAttrOut, Collection computeNodeTemplateIds) { @@ -412,32 +369,29 @@ public class ConsolidationService { EntityConsolidationData::getNodesGetAttrIn); } - private boolean areThereGetAttrRelationsBetweenPortsOfTheSameType( - ServiceTemplate serviceTemplate, - TypeComputeConsolidationData typeComputeConsolidationData, - ConsolidationData consolidationData) { - - Collection computeTemplateConsolidationEntities = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map> portTypeToPortIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationEntities); + private boolean areThereGetAttrRelationsBetweenPortsOfTheSameType( + ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Map> portTypeToPortIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + + FilePortConsolidationData filePortConsolidationData = + consolidationData.getPortConsolidationData().getFilePortConsolidationData( + ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + + for (List portsOfTheSameTypeIds : portTypeToPortIds.values()) { + List portTemplateConsolidationDataOfSameType = + getAllPortTemplateConsolidationData(portsOfTheSameTypeIds, filePortConsolidationData); + if (!checkGetAttrRelationsForEntityConsolidationData(portTemplateConsolidationDataOfSameType, + portsOfTheSameTypeIds, EntityConsolidationData::getNodesGetAttrIn)) { + return false; + } + } - FilePortConsolidationData filePortConsolidationData = - consolidationData.getPortConsolidationData().getFilePortConsolidationData(ToscaUtil - .getServiceTemplateFileName(serviceTemplate)); - - for (List portsOfTheSameTypeIds : portTypeToPortIds.values()) { - List portTemplateConsolidationDataOfSameType = - getAllPortTemplateConsolidationData(portsOfTheSameTypeIds, filePortConsolidationData); - if (!checkGetAttrRelationsForEntityConsolidationData(portTemplateConsolidationDataOfSameType, - portsOfTheSameTypeIds, EntityConsolidationData::getNodesGetAttrIn)) { - return false; - } + return true; } - return true; - } - private boolean areThereGetAttrRelationsBetweenSubInterfacesOfSameType( List subInterfacesIdsFromSameType, List subInterfaceList) { @@ -578,26 +532,23 @@ public class ConsolidationService { } - private boolean validateWantedPortProperties(ServiceTemplate serviceTemplate, - TypeComputeConsolidationData typeComputeConsolidationData) { + private boolean validateWantedPortProperties(ServiceTemplate serviceTemplate, + TypeComputeConsolidationData typeComputeConsolidationData) { + Map> portTypeToIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); - Collection computeTemplateConsolidationDataCollection = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataCollection); - List propertiesWithIdenticalVal = getPortPropertiesWithIdenticalVal(); - List propertiesThatNeedToHaveSameUsage = - getPortPropertiesThatNeedToHaveSameUsage(); - - for (List portsIds : portTypeToIds.values()) { - if (!arePortPropertiesValid(serviceTemplate, propertiesWithIdenticalVal, - propertiesThatNeedToHaveSameUsage, portsIds)) { - return false; - } - } + List propertiesWithIdenticalVal = getPortPropertiesWithIdenticalVal(); + List propertiesThatNeedToHaveSameUsage = getPortPropertiesThatNeedToHaveSameUsage(); - return true; - } + for (List portsIds : portTypeToIds.values()) { + if (!arePortPropertiesValid( + serviceTemplate, propertiesWithIdenticalVal, propertiesThatNeedToHaveSameUsage, portsIds)) { + return false; + } + } + + return true; + } private boolean arePortPropertiesValid(ServiceTemplate serviceTemplate, List propertiesWithIdenticalVal, @@ -620,27 +571,24 @@ public class ConsolidationService { propertiesThatNeedToHaveSameUsage, exists); } - private boolean checkPortRelations(String serviceTemplateName, - TypeComputeConsolidationData typeComputeConsolidationData, - ConsolidationData consolidationData) { - Collection computeTemplateConsolidationDataCollection = - typeComputeConsolidationData.getAllComputeTemplateConsolidationData(); - Map> portTypeToIds = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeTemplateConsolidationDataCollection); + private boolean checkPortRelations(String serviceTemplateName, + TypeComputeConsolidationData typeComputeConsolidationData, + ConsolidationData consolidationData) { + Map> portTypeToIds = + typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); - for (List portIds : portTypeToIds.values()) { - List portTemplateConsolidationDataList = - collectAllPortsTemplateConsolidationData( - portIds, serviceTemplateName, consolidationData); + for (List portIds : portTypeToIds.values()) { + List 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 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 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 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 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 unifiedCompositionImplMap; @@ -1824,31 +1825,26 @@ public class UnifiedCompositionService { } } - private void handleConsolidationPorts(ServiceTemplate serviceTemplate, - ServiceTemplate substitutionServiceTemplate, - List unifiedCompositionDataList, - String connectedComputeNodeType, - TranslationContext context) { - Collection computeConsolidationDataList = - (Collection) getComputeConsolidationDataList(unifiedCompositionDataList); - - Map> portIdsPerPortType = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); + private void handleConsolidationPorts(ServiceTemplate serviceTemplate, + ServiceTemplate substitutionServiceTemplate, + List unifiedCompositionDataList, + String connectedComputeNodeType, + TranslationContext context) { + Map> portIdsPerPortType = + UnifiedCompositionUtil.collectAllPortsOfEachTypeFromComputes(unifiedCompositionDataList); - for (Map.Entry> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { - List portTemplateConsolidationDataList = - getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), - unifiedCompositionDataList); - if (CollectionUtils.isEmpty(portTemplateConsolidationDataList)) { - continue; - } + for (Map.Entry> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { + List 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 computeConsolidationDataList = - (Collection) getComputeConsolidationDataList(unifiedCompositionTo.getUnifiedCompositionDataList()); - - Map> portIdsPerPortType = UnifiedCompositionUtil - .collectAllPortsFromEachTypesFromComputes(computeConsolidationDataList); - - for (Map.Entry> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { - List portEntityConsolidationDataList = - getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), - unifiedCompositionTo.getUnifiedCompositionDataList()); - if (CollectionUtils.isEmpty(portEntityConsolidationDataList)) { - continue; - } - - List portTemplateConsolidationDataList = - portEntityConsolidationDataList.stream() - .map(data -> (PortTemplateConsolidationData) data) - .collect(Collectors.toList()); - - ListMultimap subInterfacesByType = UnifiedCompositionUtil - .collectAllSubInterfacesOfEachTypesFromPorts(portTemplateConsolidationDataList); - Set subInterfaceTypes = subInterfacesByType.keySet(); - for (String subInterfaceType: subInterfaceTypes) { - List subInterfaceTemplateConsolidationDataList = - subInterfacesByType.get(subInterfaceType); - createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, subInterfaceTemplateConsolidationDataList); - } + private void handleConsolidationSubInterfaces(UnifiedCompositionTo unifiedCompositionTo) { + Map> portIdsPerPortType = + UnifiedCompositionUtil.collectAllPortsOfEachTypeFromComputes( + unifiedCompositionTo.getUnifiedCompositionDataList()); + + for (Map.Entry> portIdsPerPortTypeEntry : portIdsPerPortType.entrySet()) { + List portEntityConsolidationDataList = + getPortConsolidationDataList(portIdsPerPortTypeEntry.getValue(), + unifiedCompositionTo.getUnifiedCompositionDataList()); + if (CollectionUtils.isEmpty(portEntityConsolidationDataList)) { + continue; + } + + List portTemplateConsolidationDataList = + portEntityConsolidationDataList.stream().map(data -> (PortTemplateConsolidationData) data) + .collect(Collectors.toList()); + + ListMultimap subInterfacesByType = + UnifiedCompositionUtil.collectAllSubInterfacesOfEachTypesFromPorts( + portTemplateConsolidationDataList); + Set subInterfaceTypes = subInterfacesByType.keySet(); + for (String subInterfaceType : subInterfaceTypes) { + List subInterfaceTemplateConsolidationDataList = + subInterfacesByType.get(subInterfaceType); + createSubInterfaceSubstitutionNodeTemplate(unifiedCompositionTo, + subInterfaceTemplateConsolidationDataList); + } + } } - } private void createSubInterfaceSubstitutionNodeTemplate(UnifiedCompositionTo unifiedCompositionTo, List 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> collectAllPortsOfEachTypeFromComputes( + List unifiedCompositionDataList) { + Map> 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; @@ -34,6 +35,94 @@ public class EntityConsolidationDataTest { private static final String REQUIREMENT_ID_1 = "requirementId1"; private static final String REQUIREMENT_ID_2 = "requirementId2"; + @Test + public void testIsGetAttrOutFromEntityLegal() { + Map> 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> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map> 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 entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertTrue(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalNegative() { + Map> 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> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map> 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 entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalMultiplePortWithDiffAttr() { + Map> 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> 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> 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 entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + @Test public void testAddNodesConnectedIn_SameNodeTemplateIds() { EntityConsolidationData consolidationData = new EntityConsolidationData(); 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> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(Objects.nonNull(stringListMap) && MapUtils.isEmpty(stringListMap)); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputes() { + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + Map> 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> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(stringListMap.containsKey(SERVER_NETWORKROLE_1_PORT) + && stringListMap.get(SERVER_NETWORKROLE_1_PORT).size() == 2); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputesWithMultipleCompute() { + Map> ports = new HashMap<>(); + ports.put(SERVER_NETWORKROLE_1_PORT, + Arrays.asList("server_0_networkrole_1_port_1", "server_1_networkrole_1_port_2")); + + Map> 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> 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() { -- cgit 1.2.3-korg