summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-07-23 17:01:41 +0300
committersiddharth0905 <siddharth.singh4@amdocs.com>2018-07-27 19:28:56 +0530
commit9200382f2ce7b4bb729aa287d0878004b2d2b4f9 (patch)
treeceb5b59cad31fe7b9d507ca6399119aa398205e3 /openecomp-be/lib/openecomp-sdc-translator-lib
parentae5a3714376a5f4492470fbf9b54046c1229171d (diff)
Refactoring Consolidation Service
Changes as per comments Change-Id: Ic2c800513265daf4bbed1f15920864ba0cb28859 Issue-ID: SDC-1330 Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java35
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java27
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java5
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java26
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java206
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java279
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/TestUtils.java24
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java119
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java20
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java135
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java85
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandlerTest.java47
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataTest.java40
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java177
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionServiceTest.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/buildconsolidationdata/ConsolidationDataTestUtil.java1140
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceTranslationTest.java15
19 files changed, 1403 insertions, 1041 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
index 854cf51aa2..639bcfbfcd 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationData.java
@@ -16,10 +16,15 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
@@ -28,17 +33,17 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData {
// key - volume node template id
// value - List of requirement id and the requirement assignment on the
// compute node which connect to this volume
- private Map<String,List<RequirementAssignmentData>> volumes;
+ private Multimap<String, RequirementAssignmentData> volumes;
// key - port type (port id excluding index),
// value - List of connected port node template ids, with this port type
private Map<String, List<String>> ports;
- public Map<String,List<RequirementAssignmentData>> getVolumes() {
+ public Multimap<String, RequirementAssignmentData> getVolumes() {
return volumes;
}
- public void setVolumes(Map<String,List<RequirementAssignmentData>> volumes) {
+ public void setVolumes(Multimap<String, RequirementAssignmentData> volumes) {
this.volumes = volumes;
}
@@ -60,10 +65,9 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData {
public void addVolume(String requirementId, RequirementAssignment requirementAssignment) {
if (this.volumes == null) {
- this.volumes = new HashMap<>();
+ this.volumes = ArrayListMultimap.create();
}
- this.volumes.computeIfAbsent(requirementAssignment.getNode(), k -> new ArrayList<>())
- .add(new RequirementAssignmentData(requirementId,
+ this.volumes.put(requirementAssignment.getNode(), new RequirementAssignmentData(requirementId,
requirementAssignment));
}
@@ -80,4 +84,23 @@ public class ComputeTemplateConsolidationData extends EntityConsolidationData {
}
}
}
+
+ /**
+ * Is number of port from each compute type legal.
+ *
+ * @return the boolean
+ */
+ public boolean isNumberOfPortFromEachTypeLegal() {
+ Map<String, List<String>> currPortsMap = getPorts();
+ return MapUtils.isEmpty(currPortsMap) || currPortsMap.values().stream()
+ .allMatch(portList -> portList.size() == 1);
+ }
+
+ public Set<String> getPortsIds() {
+ return MapUtils.isEmpty(getPorts()) ? new HashSet<>() : getPorts().keySet();
+ }
+
+ public int getNumberOfPorts() {
+ return getPortsIds().size();
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
index 3987c54054..1c272770b3 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
@@ -16,6 +16,9 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -25,6 +28,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
@@ -41,11 +45,11 @@ public class EntityConsolidationData {
// key - node template id which has connection to this entity
// value - List of Requirement assignment data which connect to this entity
- private Map<String, List<RequirementAssignmentData>> nodesConnectedIn;
+ private Multimap<String, RequirementAssignmentData> nodesConnectedIn;
// key - node template id which connected from this entity
// List of Requirement assignment data which connect to the key node template id
- private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
+ private Multimap<String, RequirementAssignmentData> nodesConnectedOut;
//key - node template id which include get attribute function from this entity
//value - List of getAttr data
@@ -90,7 +94,7 @@ public class EntityConsolidationData {
*
* @param nodesConnectedIn the node connected to me
*/
- public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
+ public void setNodesConnectedIn(Multimap<String, RequirementAssignmentData> nodesConnectedIn) {
this.nodesConnectedIn = nodesConnectedIn;
}
@@ -105,10 +109,9 @@ public class EntityConsolidationData {
RequirementAssignment requirementAssignment) {
if (this.nodesConnectedIn == null) {
- this.nodesConnectedIn = new HashMap<>();
+ this.nodesConnectedIn = ArrayListMultimap.create();
}
- this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
this.nodesConnectedIn.get(nodeTemplateId).add(
new RequirementAssignmentData(requirementId, requirementAssignment));
}
@@ -118,7 +121,7 @@ public class EntityConsolidationData {
*
* @return the node connected to me
*/
- public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
+ public Multimap<String, RequirementAssignmentData> getNodesConnectedIn() {
return nodesConnectedIn;
}
@@ -128,7 +131,7 @@ public class EntityConsolidationData {
*
* @return the node connected from me
*/
- public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
+ public Multimap<String, RequirementAssignmentData> getNodesConnectedOut() {
return nodesConnectedOut;
}
@@ -137,7 +140,7 @@ public class EntityConsolidationData {
*
* @param nodesConnectedOut the node connected from me
*/
- public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
+ public void setNodesConnectedOut(Multimap<String, RequirementAssignmentData> nodesConnectedOut) {
this.nodesConnectedOut = nodesConnectedOut;
}
@@ -152,10 +155,9 @@ public class EntityConsolidationData {
RequirementAssignment requirementAssignment) {
if (this.nodesConnectedOut == null) {
- this.nodesConnectedOut = new HashMap<>();
+ this.nodesConnectedOut = ArrayListMultimap.create();
}
- this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
this.nodesConnectedOut.get(nodeTemplateId).add(
new RequirementAssignmentData(requirementId, requirementAssignment));
}
@@ -279,6 +281,11 @@ public class EntityConsolidationData {
*/
public boolean isGetAttrOutFromEntityLegal(Collection<? extends EntityConsolidationData>
entityConsolidationDataList, Map<String, List<String>> portTypeToIds) {
+ if (CollectionUtils.isEmpty(entityConsolidationDataList)
+ || MapUtils.isEmpty(portTypeToIds)) {
+ return true;
+ }
+
for (String portType : portTypeToIds.keySet()) {
Set<GetAttrFuncData> startingGetAttrFunc =
getEntityGetAttrFuncAsSet(portType);
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
index afad4a9b0f..1521d9d31e 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationData.java
@@ -18,6 +18,7 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
public class NestedConsolidationData {
@@ -62,4 +63,8 @@ public class NestedConsolidationData {
}
return consolidationData;
}
+
+ public boolean isNestedConsolidationDataExist(String nestedServiceTemplateName) {
+ return Objects.nonNull(getFileNestedConsolidationData(nestedServiceTemplateName));
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
index 62c0164d04..44f18afe4b 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
@@ -177,4 +177,8 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
return Objects.nonNull(nestedHeatFileName) && context.getAllTranslatedResourceIdsFromDiffNestedFiles(
nestedHeatFileName).contains(nestedNodeTemplateId);
}
+
+ public boolean isNestedConsolidationDataExist(String serviceTemplateName) {
+ return nestedConsolidationData.isNestedConsolidationDataExist(serviceTemplateName);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
index 7b99ec1514..09b97b26f6 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationData.java
@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
@@ -111,4 +112,29 @@ public class TypeComputeConsolidationData {
public boolean isNumberOfComputeConsolidationDataPerTypeLegal() {
return getAllComputeTemplateConsolidationData().size() == 1;
}
+
+ public boolean isThereMoreThanOneComputeTypeInstance() {
+ return getAllComputeNodeTemplateIds().size() > 1;
+ }
+
+ public boolean isNumberOfPortFromEachTypeLegal() {
+ return getAllComputeTemplateConsolidationData().stream().allMatch(
+ ComputeTemplateConsolidationData::isNumberOfPortFromEachTypeLegal);
+ }
+
+ public boolean isPortTypesEqualsBetweenComputeNodes() {
+ Set<String> startingPortTypes = getAllComputeTemplateConsolidationData().iterator().next().getPortsIds();
+
+ return getAllComputeTemplateConsolidationData()
+ .stream().allMatch(compute -> compute.getPortsIds().equals(startingPortTypes));
+ }
+
+ public boolean isNumberOfPortsEqualsBetweenComputeNodes() {
+ int startingNumberOfPorts =
+ getAllComputeTemplateConsolidationData().iterator().next().getNumberOfPorts();
+
+ return getAllComputeTemplateConsolidationData()
+ .stream().allMatch(compute -> compute.getNumberOfPorts() == startingNumberOfPorts);
+
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java
index 1000554975..45f12cea85 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationService.java
@@ -18,6 +18,7 @@ package org.openecomp.sdc.translator.services.heattotosca;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
@@ -39,6 +40,7 @@ import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaAnalyzerService;
@@ -56,7 +58,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FileNestedConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.GetAttrFuncData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationData;
+import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationDataHandler;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedTemplateConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.RequirementAssignmentData;
@@ -483,17 +485,16 @@ public class ConsolidationService {
secondEntity.getNodesConnectedOut());
}
- private boolean compareNodeConnectivity(
- Map<String, List<RequirementAssignmentData>> firstEntityMap,
- Map<String, List<RequirementAssignmentData>> secondEntityMap) {
+ private boolean compareNodeConnectivity(
+ Multimap<String, RequirementAssignmentData> firstEntityMap,
+ Multimap<String, RequirementAssignmentData> secondEntityMap) {
- if (MapUtils.isEmpty(firstEntityMap)
- && MapUtils.isEmpty(secondEntityMap)) {
- return true;
+ if (CommonUtil.isMultimapEmpty(firstEntityMap) && CommonUtil.isMultimapEmpty(secondEntityMap)) {
+ return true;
+ }
+ return !firstEntityMap.isEmpty() && !secondEntityMap.isEmpty()
+ && firstEntityMap.keySet().equals(secondEntityMap.keySet());
}
- return !MapUtils.isEmpty(firstEntityMap) && !MapUtils.isEmpty(secondEntityMap)
- && firstEntityMap.keySet().equals(secondEntityMap.keySet());
- }
private boolean checkGroupIdsRelations(EntityConsolidationData startingEntity,
EntityConsolidationData currentEntity) {
@@ -503,23 +504,23 @@ public class ConsolidationService {
}
- private boolean checkComputesRelationsToVolume(
- Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationEntities) {
- Iterator<ComputeTemplateConsolidationData> iterator =
- computeTemplateConsolidationEntities.iterator();
+ private boolean checkComputesRelationsToVolume(
+ Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationEntities) {
+ Iterator<ComputeTemplateConsolidationData> iterator =
+ computeTemplateConsolidationEntities.iterator();
- Map<String, List<RequirementAssignmentData>> startingVolumes =
- iterator.next().getVolumes();
+ Multimap<String, RequirementAssignmentData> startingVolumes =
+ iterator.next().getVolumes();
- for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationEntities) {
- Map<String, List<RequirementAssignmentData>> currentVolumes =
- compute.getVolumes();
- if (!compareNodeConnectivity(startingVolumes, currentVolumes)) {
- return false;
- }
+ for (ComputeTemplateConsolidationData compute : computeTemplateConsolidationEntities) {
+ Multimap<String, RequirementAssignmentData> currentVolumes =
+ compute.getVolumes();
+ if (!compareNodeConnectivity(startingVolumes, currentVolumes)) {
+ return false;
+ }
+ }
+ return true;
}
- return true;
- }
private boolean checkPortConsolidation(ServiceTemplate serviceTemplate,
@@ -804,58 +805,60 @@ public class ConsolidationService {
private boolean isThereMoreThanOneNestedLevel(ServiceTemplate nestedServiceTemplate,
TranslationContext context) {
- FileNestedConsolidationData fileNestedConsolidationData = null;
String nestedServiceTemplateName = ToscaUtil.getServiceTemplateFileName(nestedServiceTemplate);
if (Objects.isNull(nestedServiceTemplateName)) {
return false;
}
- NestedConsolidationData nestedConsolidationData = context.getConsolidationData().getNestedConsolidationData();
- if (Objects.nonNull(nestedConsolidationData)) {
- fileNestedConsolidationData =
- nestedConsolidationData.getFileNestedConsolidationData(nestedServiceTemplateName);
- }
+ NestedConsolidationDataHandler nestedConsolidationDataHandler = context.getNestedConsolidationDataHandler();
//Condition to check if there is nested file and if file contains only sub interfaces then
// return false
- return Objects.nonNull(fileNestedConsolidationData) && !ifNestedFileContainsOnlySubInterface(
- nestedServiceTemplate, context);
+ return nestedConsolidationDataHandler.isNestedConsolidationDataExist(nestedServiceTemplateName)
+ && !ifNestedFileContainsOnlySubInterface(nestedServiceTemplate, context);
}
- private boolean ifNestedFileContainsOnlySubInterface(ServiceTemplate serviceTemplate,
- TranslationContext context) {
- Map<String, NodeTemplate> nestedNodeTemplateMap =
- DataModelUtil.getNodeTemplates(serviceTemplate);
-
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- Set<Object> nestedHeatFileNames = nestedNodeTemplateMap.entrySet().stream()
- .filter(entry -> toscaAnalyzerService.isSubstitutableNodeTemplate(entry.getValue())
- && toscaAnalyzerService
- .getSubstituteServiceTemplateName(entry.getKey(), entry.getValue()).isPresent())
- .map(entry -> toscaAnalyzerService
- .getSubstituteServiceTemplateName(entry.getKey(), entry.getValue()).get())
- .collect(Collectors.toSet());
-
- if (CollectionUtils.isNotEmpty(nestedHeatFileNames)) {
- for (Object fileName : nestedHeatFileNames) {
- String heatFileName = context.getNestedHeatFileName().get(String.valueOf(fileName));
-
- if (Objects.nonNull(heatFileName)
- && !ifAllResourceAreSubInterface(context.getTranslatedServiceTemplates()
- .get(heatFileName).getTopology_template().getNode_templates().values())) {
- return false;
- }
- }
+ private boolean ifNestedFileContainsOnlySubInterface(ServiceTemplate serviceTemplate, TranslationContext context) {
+ Map<String, NodeTemplate> nestedNodeTemplateMap = DataModelUtil.getNodeTemplates(serviceTemplate);
+
+ Set<String> nestedHeatFileNames = getNestedHeatFileNames(nestedNodeTemplateMap);
+
+ return ifAllResourceAreSubInterface(nestedHeatFileNames, context);
}
- return true;
- }
+ private Set<String> getNestedHeatFileNames(Map<String, NodeTemplate> nestedNodeTemplateMap) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- // Method returns true if all of the resource are sub interface
- private boolean ifAllResourceAreSubInterface(Collection<NodeTemplate> nodeTemplates) {
- return nodeTemplates.stream().allMatch(nodeTemplate ->
- ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE.equals(nodeTemplate.getType()));
- }
+ return nestedNodeTemplateMap.entrySet().stream()
+ .filter(entry -> toscaAnalyzerService.isSubstitutableNodeTemplate(entry.getValue())
+ && toscaAnalyzerService.getSubstituteServiceTemplateName(
+ entry.getKey(), entry.getValue()).isPresent())
+ .map(entry -> toscaAnalyzerService.getSubstituteServiceTemplateName(
+ entry.getKey(), entry.getValue()).get())
+ .collect(Collectors.toSet());
+ }
+
+ // Method returns true if all of the resource are sub interface
+ private boolean ifAllResourceAreSubInterface(Set<String> nestedHeatFileNames,
+ TranslationContext context) {
+ if (nestedHeatFileNames.isEmpty()) {
+ return true;
+ }
+
+ for (String fileName : nestedHeatFileNames) {
+ String heatFileName = context.getNestedHeatFileName().get(fileName);
+
+ if (Objects.nonNull(heatFileName)
+ && !context.getTranslatedServiceTemplates().get(heatFileName).getTopology_template()
+ .getNode_templates().values().stream()
+ .allMatch(nodeTemplate -> ToscaNodeType.CONTRAILV2_VLAN_SUB_INTERFACE
+ .equals(nodeTemplate.getType()))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
private List<UnifiedCompositionData> createUnifiedCompositionDataList(
ServiceTemplate serviceTemplate,
@@ -960,10 +963,10 @@ public class ConsolidationService {
ConsolidationData consolidationData,
TypeComputeConsolidationData typeComputeConsolidationData) {
- return (isThereMoreThanOneComputeTypeInstance(typeComputeConsolidationData)
- && isNumberOfPortsEqualsBetweenComputeNodes(typeComputeConsolidationData)
- && isNumberOfPortFromEachTypeLegal(typeComputeConsolidationData)
- && isPortTypesEqualsBetweenComputeNodes(typeComputeConsolidationData)
+ return (typeComputeConsolidationData.isThereMoreThanOneComputeTypeInstance()
+ && typeComputeConsolidationData.isNumberOfPortsEqualsBetweenComputeNodes()
+ && typeComputeConsolidationData.isNumberOfPortFromEachTypeLegal()
+ && typeComputeConsolidationData.isPortTypesEqualsBetweenComputeNodes()
&& checkGetAttrBetweenConsolidationDataEntitiesNotFromSameType(serviceTemplate,
typeComputeConsolidationData, consolidationData)
&& checkSubInterfaceConsolidationPreCondition(serviceTemplate, consolidationData,
@@ -971,75 +974,6 @@ public class ConsolidationService {
}
- private boolean isThereMoreThanOneComputeTypeInstance(
- TypeComputeConsolidationData typeComputeConsolidationData) {
- return typeComputeConsolidationData.getAllComputeNodeTemplateIds().size() > 1;
- }
-
- private boolean isNumberOfPortsEqualsBetweenComputeNodes(
- TypeComputeConsolidationData typeComputeConsolidationData) {
- int startingNumberOfPorts =
- getNumberOfPortsPerCompute(typeComputeConsolidationData
- .getAllComputeTemplateConsolidationData().iterator().next());
-
- for (ComputeTemplateConsolidationData compute : typeComputeConsolidationData
- .getAllComputeTemplateConsolidationData()) {
- if (getNumberOfPortsPerCompute(compute) != startingNumberOfPorts) {
- return false;
- }
- }
-
- return true;
- }
-
-
- private boolean isNumberOfPortFromEachTypeLegal(
- TypeComputeConsolidationData typeComputeConsolidationData) {
-
- Collection<ComputeTemplateConsolidationData> computeTemplateConsolidationDataList =
- typeComputeConsolidationData.getAllComputeTemplateConsolidationData();
-
- for (ComputeTemplateConsolidationData computeTemplate : computeTemplateConsolidationDataList) {
- Map<String, List<String>> currPortsMap = computeTemplate.getPorts();
- if (MapUtils.isEmpty(currPortsMap)) {
- return true;
- }
- for (List<String> portList : currPortsMap.values()) {
- if (portList.size() > 1) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- private boolean isPortTypesEqualsBetweenComputeNodes(
- TypeComputeConsolidationData typeComputeConsolidationData) {
- Set<String> staringPortIds = getPortsIds(
- typeComputeConsolidationData.getAllComputeTemplateConsolidationData().iterator().next());
-
- for (ComputeTemplateConsolidationData compute : typeComputeConsolidationData
- .getAllComputeTemplateConsolidationData()) {
- Set<String> currentPortIds = getPortsIds(compute);
- if (!currentPortIds.equals(staringPortIds)) {
- return false;
- }
- }
- return true;
- }
-
- private int getNumberOfPortsPerCompute(
- ComputeTemplateConsolidationData computeTemplateConsolidationData) {
- return getPortsIds(computeTemplateConsolidationData).size();
- }
-
- private Set<String> getPortsIds(
- ComputeTemplateConsolidationData computeTemplateConsolidationData) {
- return MapUtils.isEmpty(computeTemplateConsolidationData.getPorts()) ? new HashSet<>()
- : computeTemplateConsolidationData.getPorts().keySet();
- }
-
List<String> getPropertiesWithIdenticalVal(UnifiedCompositionEntity entity) {
switch (entity) {
case COMPUTE:
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
index e0d12e7f79..7eec4e0c72 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionService.java
@@ -41,6 +41,7 @@ import static org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositi
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
@@ -80,6 +81,7 @@ import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
import org.onap.sdc.tosca.datatypes.model.heatextend.PropertyTypeExt;
import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
@@ -770,7 +772,7 @@ public class UnifiedCompositionService {
//Add requirements in the abstract node template for nodes connected out for computes
String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate,
computeTemplateConsolidationData.getNodeTemplateId());
- Map<String, List<RequirementAssignmentData>> computeNodesConnectedOut =
+ Multimap<String, RequirementAssignmentData> computeNodesConnectedOut =
computeTemplateConsolidationData.getNodesConnectedOut();
if (computeNodesConnectedOut != null) {
updateRequirementInAbstractNodeTemplate(serviceTemplate, computeTemplateConsolidationData,
@@ -785,7 +787,7 @@ public class UnifiedCompositionService {
portTemplateConsolidationDataList) {
String newPortNodeTemplateId = getNewPortNodeTemplateId(portTemplateConsolidationData
.getNodeTemplateId(), computeType, computeTemplateConsolidationData);
- Map<String, List<RequirementAssignmentData>> portNodesConnectedOut =
+ Multimap<String, RequirementAssignmentData> portNodesConnectedOut =
portTemplateConsolidationData.getNodesConnectedOut();
if (portNodesConnectedOut != null) {
updateRequirementInAbstractNodeTemplate(serviceTemplate, portTemplateConsolidationData,
@@ -810,7 +812,7 @@ public class UnifiedCompositionService {
subInterfaceTemplateConsolidationDataList) {
String newSubInterfaceNodeTemplateId = getNewSubInterfaceNodeTemplateId(serviceTemplate, computeType,
computeTemplateConsolidationData, subInterfaceTemplateConsolidationData, context);
- Map<String, List<RequirementAssignmentData>> subInterfaceNodesConnectedOut =
+ Multimap<String, RequirementAssignmentData> subInterfaceNodesConnectedOut =
subInterfaceTemplateConsolidationData.getNodesConnectedOut();
if (subInterfaceNodesConnectedOut != null) {
updateRequirementInAbstractNodeTemplate(serviceTemplate, subInterfaceTemplateConsolidationData,
@@ -825,8 +827,8 @@ public class UnifiedCompositionService {
TranslationContext context) {
NestedTemplateConsolidationData nestedTemplateConsolidationData =
unifiedCompositionData.getNestedTemplateConsolidationData();
- Map<String, List<RequirementAssignmentData>> nodesConnectedOut =
- Objects.isNull(nestedTemplateConsolidationData) ? new HashMap<>()
+ Multimap<String, RequirementAssignmentData> nodesConnectedOut =
+ Objects.isNull(nestedTemplateConsolidationData) ? ArrayListMultimap.create()
: nestedTemplateConsolidationData.getNodesConnectedOut();
FileComputeConsolidationData nestedFileComputeConsolidationData =
@@ -882,41 +884,41 @@ public class UnifiedCompositionService {
}
}
- private void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate,
- EntityConsolidationData entityConsolidationData,
- String newNodeTemplateId,
- TranslationContext context,
- boolean isNested) {
- Map<String, List<RequirementAssignmentData>> nodesConnectedIn =
- entityConsolidationData.getNodesConnectedIn();
- if (nodesConnectedIn == null) {
- //No nodes connected in info
- return;
- }
- for (Map.Entry<String, List<RequirementAssignmentData>> entry : nodesConnectedIn
- .entrySet()) {
- List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue();
- for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
- RequirementAssignment requirementAssignment = requirementAssignmentData
- .getRequirementAssignment();
- if (!requirementAssignment.getNode().equals(entityConsolidationData
- .getNodeTemplateId())) {
- //The requirement assignment target node should be the one which we are handling in the
- //consolidation object
- continue;
- }
- //Update the requirement assignment object in the original node template
- if (isNested) {
- updateRequirementForNestedCompositionNodesConnectedIn(serviceTemplate,
- requirementAssignmentData, newNodeTemplateId);
- } else {
- updateRequirementForNodesConnectedIn(serviceTemplate, requirementAssignmentData,
- entityConsolidationData, entry.getKey(), newNodeTemplateId, context);
+ private void updNodesConnectedInConnectivity(ServiceTemplate serviceTemplate,
+ EntityConsolidationData entityConsolidationData,
+ String newNodeTemplateId,
+ TranslationContext context,
+ boolean isNested) {
+ Multimap<String, RequirementAssignmentData> nodesConnectedIn =
+ entityConsolidationData.getNodesConnectedIn();
+ if (nodesConnectedIn == null) {
+ //No nodes connected in info
+ return;
}
- }
+ for (String key : nodesConnectedIn.keySet()) {
+ Collection<RequirementAssignmentData> requirementAssignmentDataList = nodesConnectedIn.get(key);
+ for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
+ RequirementAssignment requirementAssignment = requirementAssignmentData
+ .getRequirementAssignment();
+ if (!requirementAssignment.getNode().equals(entityConsolidationData
+ .getNodeTemplateId())) {
+ //The requirement assignment target node should be the one which we are handling in the
+ //consolidation object
+ continue;
+ }
+ //Update the requirement assignment object in the original node template
+ if (isNested) {
+ updateRequirementForNestedCompositionNodesConnectedIn(serviceTemplate,
+ requirementAssignmentData, newNodeTemplateId);
+ } else {
+ updateRequirementForNodesConnectedIn(serviceTemplate, requirementAssignmentData,
+ entityConsolidationData, key, newNodeTemplateId, context);
+ }
+
+ }
+ }
}
- }
private void updateSubInterfaceNodesConnectedIn(ServiceTemplate serviceTemplate,
UnifiedCompositionData unifiedCompositionData,
@@ -961,7 +963,7 @@ public class UnifiedCompositionService {
//Add requirements in the abstract node template for compute volumes
String newComputeNodeTemplateId = getNewComputeNodeTemplateId(serviceTemplate,
computeTemplateConsolidationData.getNodeTemplateId());
- Map<String, List<RequirementAssignmentData>> computeVolumes =
+ Multimap<String, RequirementAssignmentData> computeVolumes =
computeTemplateConsolidationData.getVolumes();
if (computeVolumes != null) {
updateRequirementInAbstractNodeTemplate(serviceTemplate, computeTemplateConsolidationData,
@@ -1271,84 +1273,81 @@ public class UnifiedCompositionService {
}
- private void updateRequirementInAbstractNodeTemplate(ServiceTemplate serviceTemplate,
- EntityConsolidationData
- entityConsolidationData,
- String newNodeTemplateId,
- Map<String, List<RequirementAssignmentData>>
- requirementAssignmentDataMap,
- TranslationContext context) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- for (Map.Entry<String, List<RequirementAssignmentData>> entry : requirementAssignmentDataMap
- .entrySet()) {
- String abstractNodeTemplateId = context.getUnifiedAbstractNodeTemplateId(
- serviceTemplate, entityConsolidationData.getNodeTemplateId());
- NodeTemplate abstractNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
- abstractNodeTemplateId);
- if (abstractNodeTemplate == null) {
- //The abstract node template is not found from id in the context
- return;
- }
- List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue();
- for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
- String oldRequirementId = requirementAssignmentData.getRequirementId();
- RequirementAssignment abstractRequirementAssignment = (RequirementAssignment)
- getClonedObject(requirementAssignmentData.getRequirementAssignment(),
- RequirementAssignment.class);
- String newRequirementId = oldRequirementId + "_" + newNodeTemplateId;
- //Check if the requirement is not already present in the list of requirements of the
- // abstract node template
- if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(abstractNodeTemplate,
- newRequirementId, abstractRequirementAssignment)) {
- DataModelUtil.addRequirementAssignment(abstractNodeTemplate, newRequirementId,
- abstractRequirementAssignment);
- //Update the volume relationship template if required
- updateVolumeRelationshipTemplate(serviceTemplate, abstractRequirementAssignment
- .getRelationship(), context);
+ private void updateRequirementInAbstractNodeTemplate(ServiceTemplate serviceTemplate,
+ EntityConsolidationData
+ entityConsolidationData,
+ String newNodeTemplateId,
+ Multimap<String, RequirementAssignmentData>
+ requirementAssignmentDataMap,
+ TranslationContext context) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ for (String key : requirementAssignmentDataMap.keySet()) {
+ String abstractNodeTemplateId = context.getUnifiedAbstractNodeTemplateId(
+ serviceTemplate, entityConsolidationData.getNodeTemplateId());
+ NodeTemplate abstractNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
+ abstractNodeTemplateId);
+ if (abstractNodeTemplate == null) {
+ //The abstract node template is not found from id in the context
+ return;
+ }
+ Collection<RequirementAssignmentData> requirementAssignmentDataList = requirementAssignmentDataMap.get(key);
+ for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
+ String oldRequirementId = requirementAssignmentData.getRequirementId();
+ RequirementAssignment abstractRequirementAssignment = (RequirementAssignment)
+ getClonedObject(requirementAssignmentData.getRequirementAssignment(),
+ RequirementAssignment.class);
+ String newRequirementId = oldRequirementId + "_" + newNodeTemplateId;
+ //Check if the requirement is not already present in the list of requirements of the
+ // abstract node template
+ if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(abstractNodeTemplate,
+ newRequirementId, abstractRequirementAssignment)) {
+ DataModelUtil.addRequirementAssignment(abstractNodeTemplate, newRequirementId,
+ abstractRequirementAssignment);
+ //Update the volume relationship template if required
+ updateVolumeRelationshipTemplate(serviceTemplate, abstractRequirementAssignment
+ .getRelationship(), context);
+ }
+ }
}
- }
}
- }
- private void updateRequirementInNestedNodeTemplate(ServiceTemplate serviceTemplate,
- EntityConsolidationData
- entityConsolidationData,
- String newNodeTemplateId,
- Map<String, List<RequirementAssignmentData>>
- requirementAssignmentDataMap) {
- ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
+ private void updateRequirementInNestedNodeTemplate(ServiceTemplate serviceTemplate,
+ EntityConsolidationData entityConsolidationData,
+ String newNodeTemplateId,
+ Multimap<String, RequirementAssignmentData>
+ requirementAssignmentDataMap) {
+ ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
- if (MapUtils.isEmpty(requirementAssignmentDataMap)) {
- return;
- }
+ if (CommonUtil.isMultimapEmpty(requirementAssignmentDataMap)) {
+ return;
+ }
- for (Map.Entry<String, List<RequirementAssignmentData>> entry : requirementAssignmentDataMap
- .entrySet()) {
- String nodeTemplateId = entityConsolidationData.getNodeTemplateId();
- NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, nodeTemplateId);
- if (nodeTemplate == null) {
- //The node template is not found from id in the context
- return;
- }
- List<RequirementAssignmentData> requirementAssignmentDataList = entry.getValue();
- for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
- String oldRequirementId = requirementAssignmentData.getRequirementId();
- RequirementAssignment clonedRequirementAssignment = (RequirementAssignment)
- getClonedObject(requirementAssignmentData.getRequirementAssignment(),
- RequirementAssignment.class);
- String newRequirementId = oldRequirementId + "_" + newNodeTemplateId;
- //Check if the requirement is not already present in the list of requirements of the
- // node template
- if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(nodeTemplate,
- newRequirementId, clonedRequirementAssignment)) {
- DataModelUtil.removeRequirementAssignment(nodeTemplate, oldRequirementId,
- requirementAssignmentData.getRequirementAssignment());
- DataModelUtil.addRequirementAssignment(nodeTemplate, newRequirementId,
- clonedRequirementAssignment);
+ for (String key : requirementAssignmentDataMap.keySet()) {
+ String nodeTemplateId = entityConsolidationData.getNodeTemplateId();
+ NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, nodeTemplateId);
+ if (nodeTemplate == null) {
+ //The node template is not found from id in the context
+ return;
+ }
+ Collection<RequirementAssignmentData> requirementAssignmentDataList = requirementAssignmentDataMap.get(key);
+ for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
+ String oldRequirementId = requirementAssignmentData.getRequirementId();
+ RequirementAssignment clonedRequirementAssignment = (RequirementAssignment)
+ getClonedObject(requirementAssignmentData.getRequirementAssignment(),
+ RequirementAssignment.class);
+ String newRequirementId = oldRequirementId + "_" + newNodeTemplateId;
+ //Check if the requirement is not already present in the list of requirements of the
+ // node template
+ if (!toscaAnalyzerService.isRequirementExistInNodeTemplate(nodeTemplate,
+ newRequirementId, clonedRequirementAssignment)) {
+ DataModelUtil.removeRequirementAssignment(nodeTemplate, oldRequirementId,
+ requirementAssignmentData.getRequirementAssignment());
+ DataModelUtil.addRequirementAssignment(nodeTemplate, newRequirementId,
+ clonedRequirementAssignment);
+ }
+ }
}
- }
}
- }
private void updNodeGetAttrInConnectivity(
ServiceTemplate serviceTemplate,
@@ -2725,42 +2724,40 @@ public class UnifiedCompositionService {
+ subInterfaceType + "_" + propertyId;
}
- private void removeConnectivityOut(EntityConsolidationData entityConsolidationData,
- NodeTemplate nodeTemplate) {
- if (MapUtils.isEmpty(entityConsolidationData.getNodesConnectedOut())) {
- return;
- }
+ private void removeConnectivityOut(EntityConsolidationData entityConsolidationData,
+ NodeTemplate nodeTemplate) {
- for (List<RequirementAssignmentData> requirementAssignmentDataList : entityConsolidationData
- .getNodesConnectedOut().values()) {
- for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
- DataModelUtil.removeRequirementsAssignment(nodeTemplate.getRequirements(),
- requirementAssignmentData.getRequirementId());
- }
- if (nodeTemplate.getRequirements().isEmpty()) {
- nodeTemplate.setRequirements(null);
- }
- }
- }
+ Multimap<String, RequirementAssignmentData> nodesConnectedOut = entityConsolidationData.getNodesConnectedOut();
- private void removeVolumeConnectivity(
- ComputeTemplateConsolidationData computeTemplateConsolidationData,
- NodeTemplate computeNodeTemplate) {
- if (MapUtils.isEmpty(computeTemplateConsolidationData.getVolumes())) {
- return;
- }
- Collection<List<RequirementAssignmentData>> volumeCollection =
- computeTemplateConsolidationData.getVolumes().values();
- for (List<RequirementAssignmentData> requirementAssignmentDataList : volumeCollection) {
- for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
- DataModelUtil.removeRequirementsAssignment(computeNodeTemplate.getRequirements(),
- requirementAssignmentData.getRequirementId());
- }
+ if (CommonUtil.isMultimapEmpty(nodesConnectedOut)) {
+ return;
+ }
+
+ nodesConnectedOut.values().forEach(requirementAssignmentData ->
+ DataModelUtil.removeRequirementsAssignment(nodeTemplate.getRequirements(),
+ requirementAssignmentData.getRequirementId())
+ );
+
+ if (nodeTemplate.getRequirements().isEmpty()) {
+ nodeTemplate.setRequirements(null);
+ }
}
- if (computeNodeTemplate.getRequirements().isEmpty()) {
- computeNodeTemplate.setRequirements(null);
+
+ private void removeVolumeConnectivity(ComputeTemplateConsolidationData computeTemplateConsolidationData,
+ NodeTemplate computeNodeTemplate) {
+ if (CommonUtil.isMultimapEmpty(computeTemplateConsolidationData.getVolumes())) {
+ return;
+ }
+
+ computeTemplateConsolidationData.getVolumes().values().forEach(requirementAssignmentData ->
+ DataModelUtil.removeRequirementsAssignment(computeNodeTemplate.getRequirements(),
+ requirementAssignmentData.getRequirementId())
+ );
+
+ if (computeNodeTemplate.getRequirements().isEmpty()) {
+ computeNodeTemplate.setRequirements(null);
+ }
}
- }
private void createIndexInputParameter(ServiceTemplate substitutionServiceTemplate) {
ParameterDefinition indexParameterDefinition =
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/TestUtils.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/TestUtils.java
index 95adef3a8c..0d981f320a 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/TestUtils.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/TestUtils.java
@@ -18,6 +18,9 @@ package org.openecomp.sdc.translator;
import static org.junit.Assert.assertEquals;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -355,7 +358,7 @@ public class TestUtils {
initComputeNodeTemplateIdInConsolidationData(serviceTemplateFileName, computeNodeTypeName,
computeNodeTemplateId, consolidationData);
- Map<String, List<RequirementAssignmentData>> volumes =
+ Multimap<String, RequirementAssignmentData> volumes =
consolidationData.getComputeConsolidationData().getFileComputeConsolidationData
(serviceTemplateFileName).getTypeComputeConsolidationData(computeNodeTypeName)
.getComputeTemplateConsolidationData(computeNodeTemplateId).getVolumes();
@@ -439,7 +442,7 @@ public class TestUtils {
public static ComputeTemplateConsolidationData createComputeTemplateConsolidationData(
String computeNodeTemplateId,
List<Pair<String, String>> portTypeToIdList,
- Map<String, List<RequirementAssignmentData>> volumes) {
+ Multimap<String, RequirementAssignmentData> volumes) {
ComputeTemplateConsolidationData compute = new ComputeTemplateConsolidationData();
compute.setNodeTemplateId(computeNodeTemplateId);
if (portTypeToIdList != null) {
@@ -525,9 +528,9 @@ public class TestUtils {
computeNodeTypeName, new TypeComputeConsolidationData());
}
- public static Map<String, List<RequirementAssignmentData>> getNodeConnectedOutList(
+ public static Multimap<String, RequirementAssignmentData> getNodeConnectedOutList(
NodeTemplate nodeTemplate, String requirementKey) {
- Map<String, List<RequirementAssignmentData>> requirementAssignmentDataMap = new HashMap<>();
+ Multimap<String, RequirementAssignmentData> requirementAssignmentDataMap = ArrayListMultimap.create();
Optional<List<RequirementAssignmentData>> requirementAssignmentDataList =
TestUtils.createRequirementAssignmentDataList(nodeTemplate, requirementKey);
if (requirementAssignmentDataList.isPresent()) {
@@ -535,9 +538,7 @@ public class TestUtils {
.get()) {
String connectedNodeTemplateId = requirementAssignmentData.getRequirementAssignment()
.getNode();
- requirementAssignmentDataMap
- .computeIfAbsent(connectedNodeTemplateId, k -> new ArrayList<>());
- requirementAssignmentDataMap.get(connectedNodeTemplateId).add(requirementAssignmentData);
+ requirementAssignmentDataMap.put(connectedNodeTemplateId, requirementAssignmentData);
}
}
return requirementAssignmentDataMap;
@@ -575,12 +576,12 @@ public class TestUtils {
}
}
- public static Map<String, List<RequirementAssignmentData>> getNodeConnectedInList(
+ public static Multimap<String, RequirementAssignmentData> getNodeConnectedInList(
String sourceNodeTemplateId,
ServiceTemplate serviceTemplate, String requirementKey) {
- Optional<List<RequirementAssignmentData>> requirementAssignmentDataList = Optional.empty();
+ Optional<List<RequirementAssignmentData>> requirementAssignmentDataList;
List<RequirementAssignmentData> assignmentDataList = new ArrayList<>();
- Map<String, List<RequirementAssignmentData>> requirementAssignmentDataMap = new HashMap<>();
+ Multimap<String, RequirementAssignmentData> requirementAssignmentDataMap = ArrayListMultimap.create();
Map<String, NodeTemplate> nodeTemplates = serviceTemplate.getTopology_template()
.getNode_templates();
for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
@@ -603,8 +604,7 @@ public class TestUtils {
if (requirementAssignmentDataList.isPresent()) {
for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList
.get()) {
- requirementAssignmentDataMap.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
- requirementAssignmentDataMap.get(nodeTemplateId).add(requirementAssignmentData);
+ requirementAssignmentDataMap.put(nodeTemplateId, requirementAssignmentData);
}
}
requirementAssignmentDataList = Optional.empty();
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/ComputeConsolidationDataHandlerTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java
index 6df781e375..e3d166f853 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java
@@ -47,6 +47,7 @@ public class ComputeConsolidationDataHandlerTest {
private static final String REQUIREMENT_ID = "requirementId";
private static final String SERVICE_FILE_NAME_PREFIX = "Main";
private static final String SERVICE_FILE_NAME = SERVICE_FILE_NAME_PREFIX + "ServiceTemplate.yaml";
+ private static final String MAIN_SERVICE_TEMPLATE = "MainServiceTemplate.yaml";
@Before
public void setUp() {
@@ -71,23 +72,23 @@ public class ComputeConsolidationDataHandlerTest {
@Test
public void testAddNodesConnectedOut() {
mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationDataHandler.addNodesConnectedOut(
- translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
- Mockito.verify(consolidationData).addNodesConnectedOut(
- COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ consolidationDataHandler
+ .addNodesConnectedOut(translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData)
+ .addNodesConnectedOut(COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
}
@Test
public void testAddNodesConnectedOut_consolidationDataNotExist() {
mockEntities_NullConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationDataHandler.addNodesConnectedOut(
- translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
- Mockito.verify(consolidationData, Mockito.times(0)).addNodesConnectedOut(
- Mockito.any(), Mockito.any(), Mockito.any());
+ consolidationDataHandler
+ .addNodesConnectedOut(translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData, Mockito.times(0))
+ .addNodesConnectedOut(Mockito.any(), Mockito.any(), Mockito.any());
}
@Test
@@ -95,73 +96,76 @@ public class ComputeConsolidationDataHandlerTest {
String sourceNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_1;
String dependentNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_2;
mockEntities(dependentNodeTemplateId);
- consolidationDataHandler.addNodesConnectedIn(translateTo, sourceNodeTemplateId,
- dependentNodeTemplateId, "targetResourceId", REQUIREMENT_ID, requirementAssignment);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
- Mockito.verify(consolidationData).addNodesConnectedIn(
- sourceNodeTemplateId, REQUIREMENT_ID, requirementAssignment);
+ consolidationDataHandler
+ .addNodesConnectedIn(translateTo, sourceNodeTemplateId, dependentNodeTemplateId, "targetResourceId",
+ REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
+ Mockito.verify(consolidationData)
+ .addNodesConnectedIn(sourceNodeTemplateId, REQUIREMENT_ID, requirementAssignment);
}
@Test
public void testAddNodesConnectedIn_consolidationDataNotExist() {
String dependentNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_2;
mockEntities_NullConsolidationData(dependentNodeTemplateId);
- consolidationDataHandler.addNodesConnectedIn(translateTo, COMPUTE_NODE_TEMPLATE_ID_1,
- dependentNodeTemplateId, "targetResourceId", REQUIREMENT_ID, requirementAssignment);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
- Mockito.verify(consolidationData, Mockito.times(0)).addNodesConnectedIn(
- Mockito.any(), Mockito.any(), Mockito.any());
+ consolidationDataHandler.addNodesConnectedIn(translateTo, COMPUTE_NODE_TEMPLATE_ID_1, dependentNodeTemplateId,
+ "targetResourceId", REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
+ Mockito.verify(consolidationData, Mockito.times(0))
+ .addNodesConnectedIn(Mockito.any(), Mockito.any(), Mockito.any());
}
@Test
public void testRemoveParamNameFromAttrFuncList() {
mockEntities(COMPUTE_NODE_TEMPLATE_ID_2);
- consolidationDataHandler.removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate,
- "paramName", COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ consolidationDataHandler
+ .removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate, "paramName",
+ COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
Mockito.verify(consolidationData).removeParamNameFromAttrFuncList("paramName");
}
@Test
public void testRemoveParamNameFromAttrFuncList_consolidationDataNotExist() {
mockEntities_NullConsolidationData(COMPUTE_NODE_TEMPLATE_ID_2);
- consolidationDataHandler.removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate,
- "paramName", COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
- Mockito.verify(consolidationData, Mockito.times(0))
- .removeParamNameFromAttrFuncList(Mockito.any());
+ consolidationDataHandler
+ .removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate, "paramName",
+ COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(consolidationData, Mockito.times(0)).removeParamNameFromAttrFuncList(Mockito.any());
}
@Test
public void testAddConsolidationData() {
- consolidationDataHandler.addConsolidationData(SERVICE_FILE_NAME,
- COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler
+ .addConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
}
@Test
public void testAddPortToConsolidationData() {
mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationDataHandler.addPortToConsolidationData(translateTo, COMPUTE_NODE_TYPE_1,
- COMPUTE_NODE_TEMPLATE_ID_1, PORT_NODE_TYPE_1, PORT_NODE_TEMPLATE_ID_1);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler
+ .addPortToConsolidationData(translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1,
+ PORT_NODE_TYPE_1, PORT_NODE_TEMPLATE_ID_1);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
Mockito.verify(consolidationData).addPort(PORT_NODE_TYPE_1, PORT_NODE_TEMPLATE_ID_1);
}
@Test
public void testAddVolumeToConsolidationData() {
mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationDataHandler.addVolumeToConsolidationData(
- translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1,
+ consolidationDataHandler
+ .addVolumeToConsolidationData(translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1,
REQUIREMENT_ID, requirementAssignment);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
Mockito.verify(consolidationData).addVolume(REQUIREMENT_ID, requirementAssignment);
}
@@ -169,10 +173,10 @@ public class ComputeConsolidationDataHandlerTest {
@Test
public void testAddGroupIdToConsolidationData() {
mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationDataHandler.addGroupIdToConsolidationData(
- translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1, GROUP_ID);
- Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
- SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler
+ .addGroupIdToConsolidationData(translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1, GROUP_ID);
+ Mockito.verify(computeConsolidationData)
+ .addComputeTemplateConsolidationData(SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
Mockito.verify(consolidationData).addGroupId(GROUP_ID);
}
@@ -204,8 +208,8 @@ public class ComputeConsolidationDataHandlerTest {
private void mockComputeConsolidationData() {
Mockito.when(computeConsolidationData
- .addComputeTemplateConsolidationData(Mockito.anyString(), Mockito.anyString(),
- Mockito.anyString())).thenReturn(consolidationData);
+ .addComputeTemplateConsolidationData(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(consolidationData);
}
private void mockNullConsolidationData() {
@@ -214,7 +218,7 @@ public class ComputeConsolidationDataHandlerTest {
Mockito.anyString())).thenReturn(null);
}
- private TopologyTemplate createTopologyTemplate(String nodeTemplateId) {
+ private TopologyTemplate createTopologyTemplate(String nodeTemplateId) {
TopologyTemplate topologyTemplate = new TopologyTemplate();
Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
NodeTemplate nodeTemplate = new NodeTemplate();
@@ -224,4 +228,13 @@ public class ComputeConsolidationDataHandlerTest {
return topologyTemplate;
}
+ @Test
+ public void isNumberOfComputeTypesLegalPositive() {
+ ComputeConsolidationDataHandler computeConsolidationDataHandler =
+ new ComputeConsolidationDataHandler(computeConsolidationData);
+
+ computeConsolidationDataHandler.isNumberOfComputeTypesLegal(MAIN_SERVICE_TEMPLATE);
+
+ Mockito.verify(computeConsolidationData).isNumberOfComputeTypesLegal(MAIN_SERVICE_TEMPLATE);
+ }
}
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/ComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java
index 32e9f0d30d..344fbd9b94 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java
@@ -32,6 +32,10 @@ public class ComputeConsolidationDataTest {
private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1";
private static final String COMPUTE_NODE_TYPE_2 = "computeNodeType2";
+ private static final String MAIN_SERVICE_TEMPLATE = "MainServiceTemplate.yaml";
+
+ @Mock
+ private FileComputeConsolidationData fileComputeConsolidationDataMock;
private final EnumMap<ServiceTemplateFileNameEnum, FileComputeConsolidationData> mockMap =
new EnumMap<>(ServiceTemplateFileNameEnum.class);
@@ -189,4 +193,20 @@ public class ComputeConsolidationDataTest {
return mock;
}
+ @Test
+ public void isNumberOfComputeTypesLegal() {
+ ComputeConsolidationData computeConsolidationData = new ComputeConsolidationData();
+ computeConsolidationData.setFileComputeConsolidationData(MAIN_SERVICE_TEMPLATE,
+ fileComputeConsolidationDataMock);
+
+ computeConsolidationData.isNumberOfComputeTypesLegal(MAIN_SERVICE_TEMPLATE);
+ Mockito.verify(fileComputeConsolidationDataMock).isNumberOfComputeTypesLegal();
+ }
+
+ @Test
+ public void isNumberOfComputeTypesLegalNegative() {
+ ComputeConsolidationData computeConsolidationData = new ComputeConsolidationData();
+
+ Assert.assertFalse(computeConsolidationData.isNumberOfComputeTypesLegal(MAIN_SERVICE_TEMPLATE));
+ }
}
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/ComputeTemplateConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java
index 9f32aec8aa..36a0b7ec72 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java
@@ -16,10 +16,17 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import com.google.common.collect.Multimap;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import org.junit.Assert;
import org.junit.Test;
@@ -36,59 +43,67 @@ public class ComputeTemplateConsolidationDataTest {
private static final String PORT_TYPE_2 = "portType2";
private static final String PORT_NODE_TEMPLATE_ID_1 = "portNodeTemplateId1";
private static final String PORT_NODE_TEMPLATE_ID_2 = "portNodeTemplateId2";
+ private static final String PORT_NEUTRON = "port_neutron";
+ private static final String PORT_NEUTRON_1 = "port_neutron_1";
+ private static final String PORT_NEUTRON_2 = "port_neutron_2";
+ private static final String PORT_NEUTRON_3 = "port_neutron_3";
+ private ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
+
+ private Map<String, List<String>> mapToBeModified = new HashMap<String, List<String>>() {
+ {
+ put(PORT_NEUTRON, new ArrayList<>(Collections.singletonList(PORT_NEUTRON_3)));
+ }
+ };
- private final ComputeTemplateConsolidationData consolidationData
- = new ComputeTemplateConsolidationData();
+ private final ComputeTemplateConsolidationData consolidationData = new ComputeTemplateConsolidationData();
@Test
public void testAddPort_SamePortType() {
Map<String, String[]> expectedPorts = new HashMap<>();
- expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1});
+ expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1});
addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_1, expectedPorts);
- expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_2});
+ expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_2});
addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_2, expectedPorts);
}
@Test
public void testAddPort_DiffPortType() {
Map<String, String[]> expectedPorts = new HashMap<>();
- expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1});
+ expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1});
addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_1, expectedPorts);
- expectedPorts.put(PORT_TYPE_2, new String[]{PORT_NODE_TEMPLATE_ID_2});
+ expectedPorts.put(PORT_TYPE_2, new String[] {PORT_NODE_TEMPLATE_ID_2});
addAndCheckPorts(PORT_TYPE_2, PORT_NODE_TEMPLATE_ID_2, expectedPorts);
}
@Test
public void testAddVolume_SameComputeNode() {
Map<String, String[]> expectedVolumes = new HashMap<>();
- expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1});
addAndCheckVolume(REQUIREMENT_ID_1, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes);
- expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2});
+ expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1, REQUIREMENT_ID_2});
addAndCheckVolume(REQUIREMENT_ID_2, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes);
}
@Test
public void testAddVolume_DiffComputeNode() {
Map<String, String[]> expectedVolumes = new HashMap<>();
- expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1});
+ expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1});
addAndCheckVolume(REQUIREMENT_ID_1, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes);
- expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2});
+ expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_2, new String[] {REQUIREMENT_ID_2});
addAndCheckVolume(REQUIREMENT_ID_2, COMPUTE_NODE_TEMPLATE_ID_2, expectedVolumes);
}
- private void addAndCheckPorts(String portType, String portNodeTemplateId,
- Map<String, String[]> expectedPorts) {
+ private void addAndCheckPorts(String portType, String portNodeTemplateId, Map<String, String[]> expectedPorts) {
consolidationData.addPort(portType, portNodeTemplateId);
checkPorts(consolidationData.getPorts(), expectedPorts);
}
- private void checkPorts(Map<String, List<String>> actualAllPorts,
- Map<String, String[]> expectedAllPorts) {
+ private void checkPorts(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts) {
Assert.assertNotNull(actualAllPorts);
expectedAllPorts.keySet().forEach(expectedPortType -> {
Assert.assertTrue(actualAllPorts.containsKey(expectedPortType));
@@ -97,39 +112,38 @@ public class ComputeTemplateConsolidationDataTest {
});
}
- private void checkPortsPerType(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts,
- String expectedPortType) {
+ private void checkPortsPerType(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts,
+ String expectedPortType) {
List<String> actualPorts = actualAllPorts.get(expectedPortType);
List<String> expectedPortList = Arrays.asList(expectedAllPorts.get(expectedPortType));
Assert.assertEquals(expectedPortList.size(), actualPorts.size());
- actualPorts.forEach(actualPort ->
- Assert.assertTrue(expectedPortList.contains(actualPort)));
+ actualPorts.forEach(actualPort -> Assert.assertTrue(expectedPortList.contains(actualPort)));
}
private void addAndCheckVolume(String requirementId, String computeNodeTemplateId,
- Map<String, String[]> expectedVolumes) {
+ Map<String, String[]> expectedVolumes) {
RequirementAssignment requirementAssignment1 = createRequirement(computeNodeTemplateId);
consolidationData.addVolume(requirementId, requirementAssignment1);
checkVolumes(consolidationData.getVolumes(), expectedVolumes);
}
- private void checkVolumes(Map<String, List<RequirementAssignmentData>> actualVolumes,
+ private void checkVolumes(Multimap<String, RequirementAssignmentData> actualVolumes,
Map<String, String[]> expectedVolumes) {
Assert.assertNotNull(actualVolumes);
expectedVolumes.keySet().forEach(nodeTemplateId -> {
Assert.assertTrue(actualVolumes.containsKey(nodeTemplateId));
- Assert.assertEquals(expectedVolumes.size(), actualVolumes.size());
+ Assert.assertEquals(expectedVolumes.size(), actualVolumes.keySet().size());
checkVolumesPerType(actualVolumes, expectedVolumes, nodeTemplateId);
});
}
- private void checkVolumesPerType(Map<String, List<RequirementAssignmentData>>
- actualVolumes, Map<String, String[]> expectedVolumes, String nodeTemplateId) {
- List<RequirementAssignmentData> actualRequirementAssignmentData = actualVolumes.get(nodeTemplateId);
+ private void checkVolumesPerType(Multimap<String, RequirementAssignmentData> actualVolumes,
+ Map<String, String[]> expectedVolumes, String nodeTemplateId) {
+ Collection<RequirementAssignmentData> actualRequirementAssignmentData = actualVolumes.get(nodeTemplateId);
List<String> requirementIds = Arrays.asList(expectedVolumes.get(nodeTemplateId));
Assert.assertEquals(requirementIds.size(), actualRequirementAssignmentData.size());
- actualRequirementAssignmentData.forEach(actualRequirementAssignment ->
- Assert.assertTrue(requirementIds.contains(actualRequirementAssignment.getRequirementId())));
+ actualRequirementAssignmentData.forEach(actualRequirementAssignment -> Assert.assertTrue(
+ requirementIds.contains(actualRequirementAssignment.getRequirementId())));
}
private RequirementAssignment createRequirement(String nodeTemplateId) {
@@ -137,4 +151,73 @@ public class ComputeTemplateConsolidationDataTest {
requirementAssignment.setNode(nodeTemplateId);
return requirementAssignment;
}
+
+ @Test
+ public void collectAllPortsOfEachTypeFromComputeKeyPresent() {
+ Map<String, List<String>> portMap = new HashMap<>();
+ portMap.put(PORT_NEUTRON, new ArrayList<>(Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2)));
+
+ computeTemplateConsolidationData.setPorts(portMap);
+
+ computeTemplateConsolidationData.collectAllPortsOfEachTypeFromCompute(mapToBeModified);
+
+ Assert.assertTrue(mapToBeModified.size() == 1 && mapToBeModified.get(PORT_NEUTRON).size() == 3);
+ Assert.assertTrue(mapToBeModified.get(PORT_NEUTRON).containsAll(
+ Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2, PORT_NEUTRON_3)));
+
+ }
+
+ @Test
+ public void collectAllPortsOfEachTypeFromComputeKeyAbsent() {
+ Map<String, List<String>> portMap = new HashMap<>();
+ portMap.put(PORT_NEUTRON, new ArrayList<>(Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2)));
+
+ computeTemplateConsolidationData.setPorts(portMap);
+
+ Map<String, List<String>> mapToBeModified = new HashMap<>();
+
+ computeTemplateConsolidationData.collectAllPortsOfEachTypeFromCompute(mapToBeModified);
+
+ Assert.assertTrue(mapToBeModified.size() == 1 && Objects.nonNull(mapToBeModified.get(PORT_NEUTRON))
+ && mapToBeModified.get(PORT_NEUTRON).size() == 2);
+ Assert.assertTrue(mapToBeModified.get(PORT_NEUTRON).containsAll(
+ Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2)));
+ }
+
+ @Test
+ public void isNumberOfPortFromEachTypeLegal_Empty() {
+ Assert.assertTrue(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal());
+ }
+
+ @Test
+ public void isNumberOfPortFromEachTypeLegal_OnePort() {
+ computeTemplateConsolidationData.setPorts(mapToBeModified);
+
+ Assert.assertTrue(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal());
+ }
+
+ @Test
+ public void isNumberOfPortFromEachTypeLegal_MultiplePorts() {
+ mapToBeModified.get(PORT_NEUTRON).addAll(Collections.singletonList("port_neutron_4"));
+ computeTemplateConsolidationData.setPorts(mapToBeModified);
+
+ Assert.assertFalse(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal());
+ }
+
+ @Test
+ public void getPortsIdsAndSizeEmpty() {
+ Assert.assertNotNull(computeTemplateConsolidationData.getPortsIds());
+ Assert.assertEquals(0, computeTemplateConsolidationData.getNumberOfPorts());
+ }
+
+ @Test
+ public void getPortsIdsWithData() {
+ computeTemplateConsolidationData.setPorts(mapToBeModified);
+ Map.Entry<String, String> entry = new AbstractMap.SimpleEntry<>("port_neutron", PORT_NEUTRON_3);
+
+ Assert.assertNotNull(computeTemplateConsolidationData.getPortsIds());
+ Assert.assertEquals(1, computeTemplateConsolidationData.getNumberOfPorts());
+ Assert.assertEquals("port_neutron",
+ computeTemplateConsolidationData.getPorts().entrySet().stream().findFirst().get().getKey());
+ }
}
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 447314c25f..e536647741 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
@@ -16,7 +16,10 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import com.google.common.collect.Multimap;
+
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -38,6 +41,12 @@ public class EntityConsolidationDataTest {
private static final String GROUP_ID_2 = "groupId2";
private static final String FIELD_1 = "field1";
private static final String FIELD_2 = "field2";
+ private static final String SERVER_NETWORKROLE_1_PORT = "server_networkrole_1_port";
+ private static final String SERVER_0_NETWORKROLE_1_PORT = "server_0_networkrole_1_port";
+ private static final String SERVER_0_NETWORKROLE_2_PORT = "server_0_networkrole_2_port";
+ private static final String VMAC_ADDRESS = "vmac_address";
+ private static final String ACCESS_IPV4 = "accessIPv4";
+ private static final String SERVER_1_NETWORKROLE_1_PORT = "server_1_networkrole_1_port";
private final EntityConsolidationData consolidationData = new EntityConsolidationData();
@@ -45,16 +54,16 @@ public class EntityConsolidationDataTest {
@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"));
+ 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");
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData(VMAC_ADDRESS, ACCESS_IPV4);
Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>();
- getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData));
+ getAttOutMap.put(SERVER_0_NETWORKROLE_1_PORT, Collections.singletonList(getAttrFuncData));
- GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4");
+ GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData(VMAC_ADDRESS, ACCESS_IPV4);
Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>();
- getAttOutMap1.put("server_1_networkrole_1_port", Collections.singletonList(getAttrFuncData1));
+ getAttOutMap1.put(SERVER_1_NETWORKROLE_1_PORT, Collections.singletonList(getAttrFuncData1));
EntityConsolidationData entityConsolidationData = new EntityConsolidationData();
@@ -71,12 +80,32 @@ public class EntityConsolidationDataTest {
}
@Test
- public void testIsGetAttrOutFromEntityLegalNegative() {
+ public void testIsGetAttrOutFromEntityLegal_EntityConsolidationDataListEmptyOrNull() {
+ EntityConsolidationData entityConsolidationData = new EntityConsolidationData();
+
+ Assert.assertTrue(entityConsolidationData.isGetAttrOutFromEntityLegal(null, null));
+ Assert.assertTrue(entityConsolidationData.isGetAttrOutFromEntityLegal(
+ Collections.emptyList(), Collections.emptyMap()));
+ }
+
+ @Test
+ public void testIsGetAttrOutFromEntityLegal_PortTypeToIdsEmptyOrNull() {
+ EntityConsolidationData entityConsolidationData = new EntityConsolidationData();
+
+ Assert.assertTrue(entityConsolidationData.isGetAttrOutFromEntityLegal(
+ Collections.singletonList(entityConsolidationData), null));
+
+ Assert.assertTrue(entityConsolidationData.isGetAttrOutFromEntityLegal(
+ Collections.singletonList(entityConsolidationData), Collections.emptyMap()));
+ }
+
+ @Test
+ public void testIsGetAttrOutFromEntityLegal_Negative() {
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"));
+ 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");
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData(VMAC_ADDRESS, ACCESS_IPV4);
Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>();
getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData));
@@ -97,22 +126,34 @@ public class EntityConsolidationDataTest {
}
@Test
- public void testIsGetAttrOutFromEntityLegalMultiplePortWithDiffAttr() {
+ public void testIsGetAttrOutFromEntityLegal_EmptyList() {
+ 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));
+
+ EntityConsolidationData entityConsolidationData = new EntityConsolidationData();
+
+ Assert.assertTrue(entityConsolidationData
+ .isGetAttrOutFromEntityLegal(Collections.emptyList(), ports));
+ }
+
+ @Test
+ public void testIsGetAttrOutFromEntityLegal_MultiplePortWithDiffAttr() {
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_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"));
+ Arrays.asList(SERVER_0_NETWORKROLE_2_PORT, "server_1_networkrole_2_port"));
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4");
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData(VMAC_ADDRESS, ACCESS_IPV4);
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));
+ 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");
+ GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData(VMAC_ADDRESS, ACCESS_IPV4);
Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>();
- getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData1));
+ getAttOutMap1.put(SERVER_0_NETWORKROLE_1_PORT, Collections.singletonList(getAttrFuncData1));
EntityConsolidationData entityConsolidationData = new EntityConsolidationData();
@@ -230,15 +271,15 @@ public class EntityConsolidationDataTest {
return getAttrFuncData;
}
- private void checkNodesConnected(Map<String, List<RequirementAssignmentData>> actualNodesConnected,
+ private void checkNodesConnected(Multimap<String, RequirementAssignmentData> actualNodesConnected,
Map<String, String[]> expectedNodesConnected) {
Assert.assertNotNull(actualNodesConnected);
expectedNodesConnected.keySet().forEach(expectedNodeTemplateId -> {
Assert.assertTrue(actualNodesConnected.containsKey(expectedNodeTemplateId));
- Assert.assertEquals(expectedNodesConnected.size(), actualNodesConnected.size());
+ Assert.assertEquals(expectedNodesConnected.size(), actualNodesConnected.keySet().size());
- List<RequirementAssignmentData> actualRequirementAssignmentData =
+ Collection<RequirementAssignmentData> actualRequirementAssignmentData =
actualNodesConnected.get(expectedNodeTemplateId);
List<String> expectedRequirementIdList =
Arrays.asList(expectedNodesConnected.get(expectedNodeTemplateId));
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/FileComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java
index 5d3d58e74c..aa71909c3c 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java
@@ -47,6 +47,9 @@ public class FileComputeConsolidationDataTest {
@Mock
private TypeComputeConsolidationData mockTypeComputeConsolidationData2;
+ @Mock
+ TypeComputeConsolidationData typeComputeConsolidationDataMock;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -122,6 +125,33 @@ public class FileComputeConsolidationDataTest {
addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_2);
}
+ @Test
+ public void isNumberOfComputeTypesLegalPositive() {
+ FileComputeConsolidationData fileComputeConsolidationData = new FileComputeConsolidationData();
+ fileComputeConsolidationData.setTypeComputeConsolidationData("server_oam",
+ typeComputeConsolidationDataMock);
+
+ Mockito.when(typeComputeConsolidationDataMock.isNumberOfComputeConsolidationDataPerTypeLegal())
+ .thenReturn(true);
+
+ Assert.assertTrue(fileComputeConsolidationData.isNumberOfComputeTypesLegal());
+ }
+
+ @Test
+ public void isNumberOfComputeTypesLegalNegative() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ "server_oam_1", new ComputeTemplateConsolidationData());
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ "server_oam_2", new ComputeTemplateConsolidationData());
+
+
+ FileComputeConsolidationData fileComputeConsolidationData = new FileComputeConsolidationData();
+ fileComputeConsolidationData.setTypeComputeConsolidationData("server_oam", typeComputeConsolidationData);
+
+ Assert.assertFalse(fileComputeConsolidationData.isNumberOfComputeTypesLegal());
+ }
+
private void checkComputeConsolidationData(FileComputeConsolidationData fileComputeConsolidationData,
String computeNodeType, Set<String> expectedComputeNodeTypes) {
TypeComputeConsolidationData typeComputeConsolidationData =
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/NestedConsolidationDataHandlerTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandlerTest.java
new file mode 100644
index 0000000000..09dd9f8fad
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandlerTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+public class NestedConsolidationDataHandlerTest {
+
+ private NestedConsolidationData nestedConsolidationData = new NestedConsolidationData();
+
+ @Mock
+ NestedConsolidationData nestedConsolidationDataMock;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void isNestedConsolidationDataExist() {
+ String nestedFileName = "nestedFileName";
+ NestedConsolidationDataHandler nestedConsolidationDataHandler =
+ new NestedConsolidationDataHandler(nestedConsolidationDataMock);
+
+ nestedConsolidationDataHandler.isNestedConsolidationDataExist(nestedFileName);
+
+ Mockito.verify(nestedConsolidationDataMock).isNestedConsolidationDataExist(nestedFileName);
+ }
+}
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/NestedConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataTest.java
new file mode 100644
index 0000000000..d10acb6bba
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NestedConsolidationDataTest {
+
+ @Test
+ public void isNestedConsolidationDataExistNotNull() {
+ String nestedFileName = "nestedFileName";
+
+ NestedConsolidationData nestedConsolidationData = new NestedConsolidationData();
+ nestedConsolidationData.setFileNestedConsolidationData(nestedFileName, new FileNestedConsolidationData());
+
+ Assert.assertTrue(nestedConsolidationData.isNestedConsolidationDataExist(nestedFileName));
+ }
+
+ @Test
+ public void isNestedConsolidationDataExistNull() {
+ NestedConsolidationData nestedConsolidationData = new NestedConsolidationData();
+
+ Assert.assertFalse(nestedConsolidationData.isNestedConsolidationDataExist(null));
+ }
+}
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 727dd5c43c..06fde3c506 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
@@ -18,6 +18,7 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolid
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -27,21 +28,52 @@ import java.util.Set;
import org.apache.commons.collections4.MapUtils;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
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_NETWORK_ROLE_1_PORT = "server_network_role_1_port";
- private static final String SERVER_NETWORK_ROLE_2_PORT = "server_network_role_2_port";
+ private static final String SERVER_NETWORK_ROLE_1_PORT = "server_networkrole_1_port";
+ private static final String SERVER_NETWORK_ROLE_2_PORT = "server_networkrole_2_port";
+ private static final String SERVER_NETWORK_ROLE_1_PORT1 = "server_networkrole_1_port";
+ private static final String SERVER_OAM = "server_oam";
+ private static final String SERVER_CMAUI = "server_cmaui";
+ private static final String SERVER_0_NETWORK_ROLE_1_PORT = "server_0_networkrole_1_port";
+ private static final String SERVER_1_NETWORK_ROLE_1_PORT = "server_1_networkrole_1_port";
+ private static final String SERVER_TYPE = "server_type";
+
+ @Mock
+ private ComputeTemplateConsolidationData computeTemplateConsolidationDataMock;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ private Map<String, List<String>> multipleNumberOfPortInEachTypeTypeMap = new HashMap<String, List<String>>() {
+ {
+ put("oam_untr_port", Arrays.asList("oam_1_untr_port_1", "oam_1_untr_port_2"));
+ put("cmaui_untr_port", Arrays.asList("cmaui_1_untr_port_1", "cmaui_1_untr_port_2"));
+ }
+ };
+
+ private Map<String, List<String>> singleNumberOfPortTypeMap = new HashMap<String, List<String>>() {
+ {
+ put("oam_untr_port", Collections.singletonList("oam_1_untr_port_1"));
+ }
+ };
private final TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
@Test
public void testCollectAllPortsOfEachTypeFromComputesNoPorts() {
ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
- consolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.setComputeTemplateConsolidationData(SERVER_TYPE,
computeTemplateConsolidationData);
Map<String, List<String>> stringListMap = consolidationData.collectAllPortsOfEachTypeFromComputes();
@@ -52,12 +84,12 @@ public class TypeComputeConsolidationDataTest {
public void testCollectAllPortsOfEachTypeFromComputes() {
Map<String, List<String>> ports = new HashMap<>();
ports.put(SERVER_NETWORK_ROLE_1_PORT,
- Arrays.asList("server_0_network_role_1_port", "server_1_network_role_1_port"));
+ Arrays.asList(SERVER_0_NETWORK_ROLE_1_PORT, SERVER_1_NETWORK_ROLE_1_PORT));
ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
computeTemplateConsolidationData.setPorts(ports);
- consolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.setComputeTemplateConsolidationData(SERVER_TYPE,
computeTemplateConsolidationData);
Map<String, List<String>> stringListMap = consolidationData.collectAllPortsOfEachTypeFromComputes();
@@ -81,19 +113,19 @@ public class TypeComputeConsolidationDataTest {
ComputeTemplateConsolidationData computeTemplateConsolidationData1 = new ComputeTemplateConsolidationData();
computeTemplateConsolidationData1.setPorts(ports1);
- consolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.setComputeTemplateConsolidationData(SERVER_TYPE,
computeTemplateConsolidationData);
consolidationData.setComputeTemplateConsolidationData("server_type1",
computeTemplateConsolidationData1);
Map<String, List<String>> stringListMap = consolidationData.collectAllPortsOfEachTypeFromComputes();
- Assert.assertTrue(stringListMap.size() == 2);
- Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).size() == 2);
+ Assert.assertEquals(2, stringListMap.size());
+ Assert.assertEquals(2, stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).size());
Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).contains("server_0_network_role_1_port_1")
&& stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).contains("server_1_network_role_1_port_2"));
- Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).size() == 2);
+ Assert.assertEquals(2, stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).size());
Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).contains("server_0_network_role_2_port_1")
&& stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).contains("server_1_network_role_2_port_2"));
}
@@ -136,6 +168,133 @@ public class TypeComputeConsolidationDataTest {
Assert.assertNotEquals(firstComputeTemplateConsolidationData, secondComputeTemplateConsolidationData);
}
+ @Test
+ public void isThereMoreThanOneComputeTypeInstancePositive() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ SERVER_OAM, new ComputeTemplateConsolidationData());
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ "server_mao", new ComputeTemplateConsolidationData());
+
+ Assert.assertTrue(typeComputeConsolidationData.isThereMoreThanOneComputeTypeInstance());
+ }
+
+ @Test
+ public void isThereMoreThanOneComputeTypeInstanceNegative() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ "server_mao", new ComputeTemplateConsolidationData());
+
+ Assert.assertFalse(typeComputeConsolidationData.isThereMoreThanOneComputeTypeInstance());
+ }
+
+ @Test
+ public void isThereMoreThanOneComputeTypeInstanceEmpty() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ Assert.assertFalse(typeComputeConsolidationData.isThereMoreThanOneComputeTypeInstance());
+ }
+
+ @Test
+ public void isNumberOfPortFromEachTypeLegal() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ SERVER_OAM, computeTemplateConsolidationDataMock);
+
+ typeComputeConsolidationData.isNumberOfPortFromEachTypeLegal();
+
+ Mockito.verify(computeTemplateConsolidationDataMock).isNumberOfPortFromEachTypeLegal();
+ }
+
+ @Test
+ public void isPortTypesAndNumberOfPortEqualsBetweenComputeNodesPositive() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+
+ ComputeTemplateConsolidationData firstComputeTemplate = new ComputeTemplateConsolidationData();
+ firstComputeTemplate.setPorts(singleNumberOfPortTypeMap);
+
+ ComputeTemplateConsolidationData secondComputeTemplate = new ComputeTemplateConsolidationData();
+ secondComputeTemplate.setPorts(singleNumberOfPortTypeMap);
+
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(SERVER_OAM, firstComputeTemplate);
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(SERVER_CMAUI, secondComputeTemplate);
+
+ Assert.assertTrue(typeComputeConsolidationData.isPortTypesEqualsBetweenComputeNodes());
+ Assert.assertTrue(typeComputeConsolidationData.isNumberOfPortsEqualsBetweenComputeNodes());
+ }
+
+ @Test
+ public void isPortTypesAndNumberOfPortEqualsBetweenComputeNodesNegative() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+
+ ComputeTemplateConsolidationData firstComputeTemplate = new ComputeTemplateConsolidationData();
+ firstComputeTemplate.setPorts(multipleNumberOfPortInEachTypeTypeMap);
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(SERVER_OAM, firstComputeTemplate);
+
+ ComputeTemplateConsolidationData secondComputeTemplate = new ComputeTemplateConsolidationData();
+ secondComputeTemplate.setPorts(singleNumberOfPortTypeMap);
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(SERVER_CMAUI, secondComputeTemplate);
+
+ Assert.assertFalse(typeComputeConsolidationData.isPortTypesEqualsBetweenComputeNodes());
+ Assert.assertFalse(typeComputeConsolidationData.isNumberOfPortsEqualsBetweenComputeNodes());
+ }
+
+ @Test
+ public void isNumberOfComputeConsolidationDataPerTypeLegalPositive() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ SERVER_CMAUI, new ComputeTemplateConsolidationData());
+
+ Assert.assertTrue(typeComputeConsolidationData.isNumberOfComputeConsolidationDataPerTypeLegal());
+ }
+
+ @Test
+ public void isNumberOfComputeConsolidationDataPerTypeLegalNegative() {
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ SERVER_CMAUI, new ComputeTemplateConsolidationData());
+ typeComputeConsolidationData.setComputeTemplateConsolidationData(
+ SERVER_OAM, new ComputeTemplateConsolidationData());
+
+ Assert.assertFalse(typeComputeConsolidationData.isNumberOfComputeConsolidationDataPerTypeLegal());
+ }
+
+ @Test
+ public void isGetAttrOutFromEntityLegal() {
+ Map<String, List<String>> ports = new HashMap<>();
+ ports.put(SERVER_NETWORK_ROLE_1_PORT1,
+ Arrays.asList(SERVER_0_NETWORK_ROLE_1_PORT, SERVER_1_NETWORK_ROLE_1_PORT));
+
+ Mockito.when(computeTemplateConsolidationDataMock.isGetAttrOutFromEntityLegal(Mockito.any(), Mockito.any()))
+ .thenReturn(true);
+
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData("server_oam_1", computeTemplateConsolidationDataMock);
+
+ Assert.assertTrue(typeComputeConsolidationData.isGetAttrOutFromEntityLegal(ports));
+ Mockito.verify(computeTemplateConsolidationDataMock, Mockito.times(1))
+ .isGetAttrOutFromEntityLegal(Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void testIsGetAttrOutFromEntityLegalNegative() {
+ Map<String, List<String>> ports = new HashMap<>();
+ ports.put(SERVER_NETWORK_ROLE_1_PORT1,
+ Arrays.asList(SERVER_0_NETWORK_ROLE_1_PORT, SERVER_1_NETWORK_ROLE_1_PORT));
+
+ TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
+ typeComputeConsolidationData.setComputeTemplateConsolidationData("server_oam_1",
+ computeTemplateConsolidationDataMock);
+
+ Mockito.when(computeTemplateConsolidationDataMock.isGetAttrOutFromEntityLegal(Mockito.any(), Mockito.any()))
+ .thenReturn(false);
+
+ Assert.assertFalse(typeComputeConsolidationData.isGetAttrOutFromEntityLegal(ports));
+
+ Mockito.verify(computeTemplateConsolidationDataMock, Mockito.times(1))
+ .isGetAttrOutFromEntityLegal(Mockito.any(), Mockito.any());
+
+ }
+
private void verifyComputeTemplateConsolidationData(TypeComputeConsolidationData typeComputeConsolidationData,
String computeNodeTemplateId, Set<String> expectedComputeNodeTemplateIds) {
ComputeTemplateConsolidationData computeTemplateConsolidationData =
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionServiceTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionServiceTest.java
index 4eeecea3d1..92faf85541 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionServiceTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionServiceTest.java
@@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
@@ -1046,7 +1049,7 @@ public class UnifiedCompositionServiceTest {
.put(MAIN_SERVICE_TEMPLATE_YAML, inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML));
context.addUnifiedNestedNodeTemplateId(MAIN_SERVICE_TEMPLATE_YAML, "server_pcm_001", "abstract_pcm_server_0");
- Map<String, List<RequirementAssignmentData>> nodeConnectedInList =
+ Multimap<String, RequirementAssignmentData> nodeConnectedInList =
TestUtils.getNodeConnectedInList("server_pcm_001", inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML),
DEPENDENCY);
UnifiedCompositionData unifiedComposition =
@@ -1080,7 +1083,7 @@ public class UnifiedCompositionServiceTest {
.put(MAIN_SERVICE_TEMPLATE_YAML, inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML));
context.addUnifiedNestedNodeTemplateId(MAIN_SERVICE_TEMPLATE_YAML, "server_pcm_001", "abstract_pcm_server_0");
- Map<String, List<RequirementAssignmentData>> nodeConnectedInList =
+ Multimap<String, RequirementAssignmentData> nodeConnectedInList =
TestUtils.getNodeConnectedInList("server_pcm_001", inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML),
DEPENDENCY);
UnifiedCompositionData unifiedComposition =
@@ -1118,7 +1121,7 @@ public class UnifiedCompositionServiceTest {
.put(MAIN_SERVICE_TEMPLATE_YAML, inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML));
context.addUnifiedNestedNodeTemplateId(MAIN_SERVICE_TEMPLATE_YAML, "server_pcm_001", "abstract_pcm_server_0");
- Map<String, List<RequirementAssignmentData>> nodeConnectedInList =
+ Multimap<String, RequirementAssignmentData> nodeConnectedInList =
TestUtils.getNodeConnectedInList("server_pcm_001", inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML),
DEPENDENCY);
UnifiedCompositionData unifiedComposition =
@@ -1317,7 +1320,7 @@ public class UnifiedCompositionServiceTest {
TestUtils.getRequirementAssignmentDataList(computeNodeTemplate, "local_storage");
List<RequirementAssignmentData> requirementAssignmentList =
(requirementAssignmentDataList.isPresent()) ? requirementAssignmentDataList.get() : null;
- Map<String, List<RequirementAssignmentData>> volume = null;
+ Multimap<String, RequirementAssignmentData> volume = null;
if (requirementAssignmentList != null) {
volume = getVolume(requirementAssignmentList);
}
@@ -1329,7 +1332,7 @@ public class UnifiedCompositionServiceTest {
NodeTemplate portNodeTemplate =
DataModelUtil.getNodeTemplate(inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML), port.getRight());
- Map<String, List<RequirementAssignmentData>> nodeConnectedOut =
+ Multimap<String, RequirementAssignmentData> nodeConnectedOut =
TestUtils.getNodeConnectedOutList(portNodeTemplate, "link");
PortTemplateConsolidationData portTemplateConsolidationData =
TestUtils.createPortTemplateConsolidationData(port.getRight());
@@ -1370,14 +1373,14 @@ public class UnifiedCompositionServiceTest {
DataModelUtil.getNodeTemplate(inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML), computeNodeTemplateId);
Optional<List<RequirementAssignmentData>> requirementAssignmentDataList =
TestUtils.getRequirementAssignmentDataList(computeNodeTemplate, "local_storage");
- Map<String, List<RequirementAssignmentData>> volume = null;
+ Multimap<String, RequirementAssignmentData> volume = null;
if (requirementAssignmentDataList.isPresent()) {
volume = getVolume(requirementAssignmentDataList.get());
}
UnifiedCompositionData data = new UnifiedCompositionData();
- Map<String, List<RequirementAssignmentData>> computeNodeConnectedOut =
+ Multimap<String, RequirementAssignmentData> computeNodeConnectedOut =
TestUtils.getNodeConnectedOutList(computeNodeTemplate, DEPENDENCY);
- Map<String, List<RequirementAssignmentData>> computeNodeConnectedIn =
+ Multimap<String, RequirementAssignmentData> computeNodeConnectedIn =
TestUtils
.getNodeConnectedInList(computeNodeTemplateId, inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML),
DEPENDENCY);
@@ -1415,14 +1418,14 @@ public class UnifiedCompositionServiceTest {
}
}
}
- Map<String, List<RequirementAssignmentData>> portNodeConnectedOut =
+ Multimap<String, RequirementAssignmentData> portNodeConnectedOut =
TestUtils.getNodeConnectedOutList(portNodeTemplate, "link");
PortTemplateConsolidationData portTemplateConsolidationData = TestUtils
.createPortTemplateConsolidationData(port.getRight());
portTemplateConsolidationData.setNodesConnectedOut(portNodeConnectedOut);
//Add node connected in info to test data
- Map<String, List<RequirementAssignmentData>> portNodeConnectedIn =
+ Multimap<String, RequirementAssignmentData> portNodeConnectedIn =
TestUtils.getNodeConnectedInList(port.getRight(), inputServiceTemplates.get(MAIN_SERVICE_TEMPLATE_YAML),
PORT);
portTemplateConsolidationData.setNodesConnectedIn(portNodeConnectedIn);
@@ -1438,13 +1441,12 @@ public class UnifiedCompositionServiceTest {
addGetAttrForPort(data);
}
- private Map<String, List<RequirementAssignmentData>> getVolume(
+ private Multimap<String, RequirementAssignmentData> getVolume(
List<RequirementAssignmentData> requirementAssignmentList) {
- Map<String, List<RequirementAssignmentData>> volume = new HashMap<>();
+ Multimap<String, RequirementAssignmentData> volume = ArrayListMultimap.create();
for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentList) {
String volumeNodeTemplateId = requirementAssignmentData.getRequirementAssignment().getNode();
- volume.computeIfAbsent(volumeNodeTemplateId, k -> new ArrayList<>());
- volume.get(volumeNodeTemplateId).add(requirementAssignmentData);
+ volume.put(volumeNodeTemplateId, requirementAssignmentData);
}
return volume;
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/buildconsolidationdata/ConsolidationDataTestUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/buildconsolidationdata/ConsolidationDataTestUtil.java
index 4381b37912..1fedc7b09c 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/buildconsolidationdata/ConsolidationDataTestUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/buildconsolidationdata/ConsolidationDataTestUtil.java
@@ -31,14 +31,19 @@ import static org.openecomp.sdc.translator.services.heattotosca.buildconsolidati
import static org.openecomp.sdc.translator.services.heattotosca.buildconsolidationdata.TestConstants.TEST_SINGLE_NESTED_RESOURCE;
import com.fasterxml.jackson.databind.ObjectMapper;
+ import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
import org.apache.commons.collections4.CollectionUtils;
import org.junit.Assert;
+import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
import org.onap.sdc.tosca.datatypes.model.GroupDefinition;
import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
import org.onap.sdc.tosca.datatypes.model.NodeType;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
import org.openecomp.sdc.tosca.services.DataModelUtil;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
@@ -55,6 +60,7 @@ import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -74,7 +80,7 @@ public class ConsolidationDataTestUtil {
String testName) {
Assert.assertNotNull(computeTemplateConsolidationData);
//Get the volume information from consolidation data
- Map<String, List<RequirementAssignmentData>> volumeConsolidationData =
+ Multimap<String, RequirementAssignmentData> volumeConsolidationData =
computeTemplateConsolidationData.getVolumes();
if(testName.equals("Negative")) {
@@ -111,20 +117,20 @@ public class ConsolidationDataTestUtil {
}
}
- private static void isVolumeComputeRequirement(List<String> computeVolumeRequirementsNodes,
- Map<String, List<RequirementAssignmentData>>
- volumeConsolidationData) {
- Assert.assertEquals(computeVolumeRequirementsNodes.size(), volumeConsolidationData.size());
- for(String volumeNodeTemplateId : computeVolumeRequirementsNodes) {
- Assert.assertNotNull(volumeConsolidationData.containsKey(volumeNodeTemplateId));
- List<RequirementAssignmentData> requirementAssignmentDataList = volumeConsolidationData.get
- (volumeNodeTemplateId);
- for(RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList){
- Assert.assertTrue(requirementAssignmentData.getRequirementId().equals(ToscaConstants
- .LOCAL_STORAGE_REQUIREMENT_ID));
- }
+ private static void isVolumeComputeRequirement(List<String> computeVolumeRequirementsNodes,
+ Multimap<String, RequirementAssignmentData>
+ volumeConsolidationData) {
+ Assert.assertEquals(computeVolumeRequirementsNodes.size(), volumeConsolidationData.size());
+ for (String volumeNodeTemplateId : computeVolumeRequirementsNodes) {
+ Assert.assertNotNull(volumeConsolidationData.containsKey(volumeNodeTemplateId));
+ Collection<RequirementAssignmentData> requirementAssignmentDataList = volumeConsolidationData.get
+ (volumeNodeTemplateId);
+ for (RequirementAssignmentData requirementAssignmentData : requirementAssignmentDataList) {
+ Assert.assertTrue(requirementAssignmentData.getRequirementId().equals(ToscaConstants
+ .LOCAL_STORAGE_REQUIREMENT_ID));
+ }
+ }
}
- }
public static void validatePortsInConsolidationData(String computeNodeTemplateId,
@@ -151,94 +157,95 @@ public class ConsolidationDataTestUtil {
}
}
- public static void validateDependsOnInConsolidationData(String computeNodeTemplateId,
- ComputeTemplateConsolidationData computeTemplateConsolidationData,
- ServiceTemplate outputServiceTemplate,
- String testName) {
- Map<String, NodeTemplate> outputNodeTemplates = outputServiceTemplate.getTopology_template()
- .getNode_templates();
- Map<String, List<RequirementAssignmentData>> nodesConnectedIn =
- computeTemplateConsolidationData.getNodesConnectedIn();
- Map<String, List<RequirementAssignmentData>> nodesConnectedOut =
- computeTemplateConsolidationData.getNodesConnectedOut();
-
- if(testName.equals(TEST_DEPENDS_ON_INVALID_DEPENDENCY_CANDIDATE) ||
- testName.equals(TEST_DEPENDS_ON_NO_DEPENDENCY)) {
- Assert.assertNull(nodesConnectedIn);
- Assert.assertNull(nodesConnectedOut);
- return;
- }
- //key - nodetemplate id , value - requirementassignment
- Map<String, List<RequirementAssignment>> outputDependsOnNodeRequirementMap = new HashMap<>();
- for(Map.Entry<String, NodeTemplate> entry : outputNodeTemplates.entrySet()) {
- NodeTemplate nodeTemplate = entry.getValue();
- List<Map<String, RequirementAssignment>> nodeRequirements = nodeTemplate.getRequirements();
- if(nodeRequirements != null){
- for(Map<String, RequirementAssignment> req : nodeRequirements) {
- Set<String> keySet = req.keySet();
- for(String key : keySet) {
- if(key.equals(ToscaConstants.DEPENDS_ON_REQUIREMENT_ID))
- //collect all dependency requirements in a map with key -> node template id
- outputDependsOnNodeRequirementMap.computeIfAbsent(entry.getKey(), k -> new ArrayList<>())
- .add(req.get(key));
- }
+ public static void validateDependsOnInConsolidationData(String computeNodeTemplateId,
+ ComputeTemplateConsolidationData
+ computeTemplateConsolidationData,
+ ServiceTemplate outputServiceTemplate,
+ String testName) {
+ Map<String, NodeTemplate> outputNodeTemplates = outputServiceTemplate.getTopology_template()
+ .getNode_templates();
+ Multimap<String, RequirementAssignmentData> nodesConnectedIn =
+ computeTemplateConsolidationData.getNodesConnectedIn();
+ Multimap<String, RequirementAssignmentData> nodesConnectedOut =
+ computeTemplateConsolidationData.getNodesConnectedOut();
+
+ if (testName.equals(TEST_DEPENDS_ON_INVALID_DEPENDENCY_CANDIDATE) ||
+ testName.equals(TEST_DEPENDS_ON_NO_DEPENDENCY)) {
+ Assert.assertNull(nodesConnectedIn);
+ Assert.assertNull(nodesConnectedOut);
+ return;
+ }
+ //key - nodetemplate id , value - requirementassignment
+ Multimap<String, RequirementAssignment> outputDependsOnNodeRequirementMap = ArrayListMultimap.create();
+ for (Map.Entry<String, NodeTemplate> entry : outputNodeTemplates.entrySet()) {
+ NodeTemplate nodeTemplate = entry.getValue();
+ List<Map<String, RequirementAssignment>> nodeRequirements = nodeTemplate.getRequirements();
+ if (nodeRequirements != null) {
+ for (Map<String, RequirementAssignment> req : nodeRequirements) {
+ Set<String> keySet = req.keySet();
+ for (String key : keySet) {
+ if (key.equals(ToscaConstants.DEPENDS_ON_REQUIREMENT_ID))
+ //collect all dependency requirements in a map with key -> node template id
+ {
+ outputDependsOnNodeRequirementMap.put(entry.getKey(), req.get(key));
+ }
+ }
+ }
+ }
}
- }
- }
- if(testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_OUT)){
- Assert.assertNull(nodesConnectedIn);
- validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
- outputDependsOnNodeRequirementMap, outputServiceTemplate);
- }
+ if (testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_OUT)) {
+ Assert.assertNull(nodesConnectedIn);
+ validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
+ outputDependsOnNodeRequirementMap, outputServiceTemplate);
+ }
- if(testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_IN)){
- Assert.assertNull(nodesConnectedOut);
- validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
- outputDependsOnNodeRequirementMap,
- outputServiceTemplate);
- }
+ if (testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_IN)) {
+ Assert.assertNull(nodesConnectedOut);
+ validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
+ outputDependsOnNodeRequirementMap,
+ outputServiceTemplate);
+ }
- if(testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_IN_AND_OUT)){
- Assert.assertNotNull(nodesConnectedIn);
- Assert.assertNotNull(nodesConnectedOut);
- validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
- outputDependsOnNodeRequirementMap,
- outputServiceTemplate);
- validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
- outputDependsOnNodeRequirementMap,
- outputServiceTemplate);
- }
+ if (testName.equals(TEST_DEPENDS_ON_NODES_CONNECTED_IN_AND_OUT)) {
+ Assert.assertNotNull(nodesConnectedIn);
+ Assert.assertNotNull(nodesConnectedOut);
+ validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
+ outputDependsOnNodeRequirementMap,
+ outputServiceTemplate);
+ validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
+ outputDependsOnNodeRequirementMap,
+ outputServiceTemplate);
+ }
- if(testName.equals(TEST_DEPENDS_ON_MULTIPLE_COMPUTE)){
- if(nodesConnectedOut != null)
- validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
- outputDependsOnNodeRequirementMap,
- outputServiceTemplate);
- if(nodesConnectedIn != null)
- validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
- outputDependsOnNodeRequirementMap,
- outputServiceTemplate);
- }
+ if (testName.equals(TEST_DEPENDS_ON_MULTIPLE_COMPUTE)) {
+ if (nodesConnectedOut != null) {
+ validateDependsOnNodesConnectedOut(computeNodeTemplateId, nodesConnectedOut,
+ outputDependsOnNodeRequirementMap,
+ outputServiceTemplate);
+ }
+ if (nodesConnectedIn != null) {
+ validateDependsOnNodesConnectedIn(computeNodeTemplateId, nodesConnectedIn,
+ outputDependsOnNodeRequirementMap,
+ outputServiceTemplate);
+ }
+ }
- }
+ }
private static void validateDependsOnNodesConnectedIn(String computeNodeTemplateId,
- Map<String,
- List<RequirementAssignmentData>>
+ Multimap<String, RequirementAssignmentData>
nodesConnectedIn,
- Map<String, List<RequirementAssignment>>
+ Multimap<String, RequirementAssignment>
outputDependsOnNodeRequirementMap,
ServiceTemplate outputServiceTemplate) {
ToscaAnalyzerServiceImpl analyzerService = new ToscaAnalyzerServiceImpl();
- for(Map.Entry<String, List<RequirementAssignment>> entry : outputDependsOnNodeRequirementMap
- .entrySet()) {
- String sourceNodeTemplateId = entry.getKey();
+ for(String sourceNodeTemplateId : outputDependsOnNodeRequirementMap.keySet()) {
Optional<NodeTemplate> sourceNodeTemplate = analyzerService.getNodeTemplateById
(outputServiceTemplate, sourceNodeTemplateId);
String sourceNodeType = sourceNodeTemplate.get().getType();
- for(Object obj : entry.getValue()){
+ for(Object obj : outputDependsOnNodeRequirementMap.get(sourceNodeTemplateId)){
RequirementAssignment req = new ObjectMapper().convertValue(obj, RequirementAssignment
.class);
String targetNodeTemplateId = req.getNode();
@@ -255,8 +262,8 @@ public class ConsolidationDataTestUtil {
if(isValidTargetForConnectedIn) {
//Should be present if target node is compute or port
- if(computeNodeTemplateId.equals(entry.getKey()))
- Assert.assertTrue(nodesConnectedIn.containsKey(entry.getKey()));
+ if(computeNodeTemplateId.equals(sourceNodeTemplateId))
+ Assert.assertTrue(nodesConnectedIn.containsKey(sourceNodeTemplateId));
}
if(sourceNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
@@ -310,59 +317,61 @@ public class ConsolidationDataTestUtil {
return false;
}
- private static void validateDependsOnNodesConnectedOut(String computeNodeTemplateId,
- Map<String,
- List<RequirementAssignmentData>>
- nodesConnectedOut,
- Map<String, List<RequirementAssignment>>
- outputDependsOnNodeRequirementMap,
- ServiceTemplate outputServiceTemplate) {
- ToscaAnalyzerServiceImpl analyzerService = new ToscaAnalyzerServiceImpl();
- //Iterating the map <nodeTemplateId, all the requirements of that node>
- for(Map.Entry<String, List<RequirementAssignment>> entry : outputDependsOnNodeRequirementMap
- .entrySet()) {
- String sourceNodeTemplateId = entry.getKey();
- Optional<NodeTemplate> sourceNodeTemplate = analyzerService.getNodeTemplateById
- (outputServiceTemplate, sourceNodeTemplateId);
- String sourceNodeType = sourceNodeTemplate.get().getType();
- boolean isValidSourceForConnectedOut = false;
- if(isComputeNodeType(outputServiceTemplate, sourceNodeType)) {
- isValidSourceForConnectedOut = true;
- } else if(isPortNodeType(outputServiceTemplate, sourceNodeType)) {
- isValidSourceForConnectedOut = true;
- }
- for(Object obj : entry.getValue()){
- RequirementAssignment req = new ObjectMapper().convertValue(obj, RequirementAssignment
- .class);
- String targetNodeTemplateId = req.getNode();
- Optional<NodeTemplate> targetNodeTemplate = analyzerService.getNodeTemplateById
- (outputServiceTemplate, targetNodeTemplateId);
- String targetNodeType = targetNodeTemplate.get().getType();
-
- if(isValidSourceForConnectedOut) {
- //Should be present if source node is compute or port
- if(computeNodeTemplateId.equals(entry.getKey()))
- Assert.assertTrue(nodesConnectedOut.containsKey(targetNodeTemplateId));
- }
-
- if(sourceNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
- && (targetNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
- || targetNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
- || targetNodeType.startsWith(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE))) {
- //Ignore Compute->Port, Compute->Compute, Compute->Volume relationship
- Assert.assertFalse(nodesConnectedOut.containsKey(targetNodeTemplateId));
+ private static void validateDependsOnNodesConnectedOut(String computeNodeTemplateId,
+ Multimap<String, RequirementAssignmentData>
+ nodesConnectedOut,
+ Multimap<String, RequirementAssignment>
+ outputDependsOnNodeRequirementMap,
+ ServiceTemplate outputServiceTemplate) {
+ ToscaAnalyzerServiceImpl analyzerService = new ToscaAnalyzerServiceImpl();
+ //Iterating the map <nodeTemplateId, all the requirements of that node>
+ /*for(Map.Entry<String, List<RequirementAssignment>> entry : outputDependsOnNodeRequirementMap
+ .entrySet()) {*/
+ for (String sourceNodeTemplateId : outputDependsOnNodeRequirementMap.keySet()) {
+ Optional<NodeTemplate> sourceNodeTemplate = analyzerService.getNodeTemplateById
+ (outputServiceTemplate, sourceNodeTemplateId);
+
+ String sourceNodeType = sourceNodeTemplate.get().getType();
+ boolean isValidSourceForConnectedOut = false;
+ if (isComputeNodeType(outputServiceTemplate, sourceNodeType)) {
+ isValidSourceForConnectedOut = true;
+ } else if (isPortNodeType(outputServiceTemplate, sourceNodeType)) {
+ isValidSourceForConnectedOut = true;
+ }
+ for (Object obj : outputDependsOnNodeRequirementMap.get(sourceNodeTemplateId)) {
+ RequirementAssignment req = new ObjectMapper().convertValue(obj, RequirementAssignment
+ .class);
+ String targetNodeTemplateId = req.getNode();
+ Optional<NodeTemplate> targetNodeTemplate = analyzerService.getNodeTemplateById
+ (outputServiceTemplate, targetNodeTemplateId);
+ String targetNodeType = targetNodeTemplate.get().getType();
+
+ if (isValidSourceForConnectedOut) {
+ //Should be present if source node is compute or port
+ if (computeNodeTemplateId.equals(sourceNodeTemplateId)) {
+ Assert.assertTrue(nodesConnectedOut.containsKey(targetNodeTemplateId));
+ }
+ }
+
+ if (sourceNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
+ && (targetNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
+ || targetNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
+ || targetNodeType.startsWith(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE))) {
+ //Ignore Compute->Port, Compute->Compute, Compute->Volume relationship
+ Assert.assertFalse(nodesConnectedOut.containsKey(targetNodeTemplateId));
+ }
+
+ if (sourceNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
+ && (targetNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
+ || targetNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
+ || targetNodeType.startsWith(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE))) {
+ //Ignore Port->Port, Port->Compute, Port->Volume relationship
+ Assert.assertFalse(nodesConnectedOut.containsKey(targetNodeTemplateId));
+ }
+ }
}
- if(sourceNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
- && (targetNodeType.startsWith(ToscaNodeType.NOVA_SERVER)
- || targetNodeType.startsWith(ToscaNodeType.NEUTRON_PORT)
- || targetNodeType.startsWith(ToscaNodeType.CONTRAILV2_VIRTUAL_MACHINE_INTERFACE))) {
- //Ignore Port->Port, Port->Compute, Port->Volume relationship
- Assert.assertFalse(nodesConnectedOut.containsKey(targetNodeTemplateId));
- }
- }
}
- }
private static Map<String,Map<String,List<String>>> getPortsInConsolidationData(ServiceTemplate
output){
@@ -453,180 +462,116 @@ public class ConsolidationDataTestUtil {
Set<String> nestedNodeTemplateIds =
fileNestedConsolidationData.getAllNestedNodeTemplateIds();
if (nestedNodeTemplateIds != null) {
- List<String> fileNestedNodeTemplateIds = new ArrayList<>();
- fileNestedNodeTemplateIds.addAll(nestedNodeTemplateIds);
+ List<String> fileNestedNodeTemplateIds = new ArrayList<>(nestedNodeTemplateIds);
nestedNodeTemplateIdMap.put(fileName, fileNestedNodeTemplateIds);
}
}
return nestedNodeTemplateIdMap;
}
- private static Map<String,List<String>> getSubstituteMapping(Map<String, ServiceTemplate>
- expectedServiceTemplateModels ){
- Map<String,List<String>> map = new LinkedHashMap<>();
- for(String key : expectedServiceTemplateModels.keySet()){
- ServiceTemplate serviceTemplate = expectedServiceTemplateModels.get(key);
- if(serviceTemplate.getTopology_template() != null && serviceTemplate
- .getTopology_template().getNode_templates() != null) {
- for (String key1 : serviceTemplate.getTopology_template().getNode_templates().keySet()) {
- NodeTemplate nodeTemplate = serviceTemplate.getTopology_template().getNode_templates()
- .get(key1);
- if (nodeTemplate.getType().contains(ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + "heat.")) {
-
- List<String> subNodeTempIdList = map.get(key);
- if (subNodeTempIdList == null) {
- subNodeTempIdList = new ArrayList<>();
- map.put(key, subNodeTempIdList);
+ private static Map<String, List<String>> getSubstituteMapping(Map<String, ServiceTemplate>
+ expectedServiceTemplateModels) {
+ Map<String, List<String>> map = new LinkedHashMap<>();
+ for (String key : expectedServiceTemplateModels.keySet()) {
+ ServiceTemplate serviceTemplate = expectedServiceTemplateModels.get(key);
+ if (serviceTemplate.getTopology_template() != null && serviceTemplate
+ .getTopology_template().getNode_templates() != null) {
+ for (String key1 : serviceTemplate.getTopology_template().getNode_templates().keySet()) {
+ NodeTemplate nodeTemplate = serviceTemplate.getTopology_template().getNode_templates()
+ .get(key1);
+ if (nodeTemplate.getType().contains(ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + "heat.")) {
+ List<String> subNodeTempIdList = map.computeIfAbsent(key, k -> new ArrayList<>());
+ subNodeTempIdList.add(key1);
+ }
+ }
}
- subNodeTempIdList.add(key1);
- }
}
- }
+ return map;
}
- return map;
- }
- public static void validateComputeConnectivityIn(ComputeTemplateConsolidationData
- computeTemplateConsolidationData,
- ServiceTemplate expectedServiceTemplate){
- Map<String,List<RequirementAssignmentData>> nodesConnectedIn = computeTemplateConsolidationData.
- getNodesConnectedIn();
- if(nodesConnectedIn==null){
- return;
- }
- boolean found = false;
- for(String nodeIdConnTo : nodesConnectedIn.keySet()){
- List<RequirementAssignmentData> connectToList = nodesConnectedIn.get(nodeIdConnTo);
- List<Map<String, RequirementAssignment>> requirementsList = expectedServiceTemplate
- .getTopology_template().getNode_templates().get(nodeIdConnTo).getRequirements();
- for(RequirementAssignmentData requirementAssignmentData : connectToList) {
- for (Map<String, RequirementAssignment> requirementAssignmentMap : requirementsList) {
- RequirementAssignment requirementAssignment =
- new ObjectMapper().convertValue(requirementAssignmentMap.values().iterator().next(),
- RequirementAssignment.class);
- if (requirementAssignment.getNode().equals(requirementAssignmentData.getRequirementAssignment().getNode())) {
- Assert.assertEquals(requirementAssignment.getCapability(),requirementAssignmentData.getRequirementAssignment().getCapability());
- Assert.assertEquals(requirementAssignment.getNode(),requirementAssignmentData.getRequirementAssignment().getNode());
- Assert.assertEquals(requirementAssignment.getRelationship(),requirementAssignmentData.getRequirementAssignment()
- .getRelationship());
- found = true;
- }
- }
- if (!found) {
- Assert.fail();
+ public static void validateComputeConnectivityIn(ComputeTemplateConsolidationData
+ computeTemplateConsolidationData,
+ ServiceTemplate expectedServiceTemplate) {
+ Multimap<String, RequirementAssignmentData> nodesConnectedIn =
+ computeTemplateConsolidationData.getNodesConnectedIn();
+ if (nodesConnectedIn == null) {
+ return;
}
- found = false;
- }
- }
- }
- public static void validateComputeConnectivityOut(String computeNodeTemplateId,
- ComputeTemplateConsolidationData
- computeTemplateConsolidationData,
- ServiceTemplate expectedServiceTemplate){
- Map<String,List<RequirementAssignmentData>> nodesConnectedOut = computeTemplateConsolidationData.
- getNodesConnectedOut();
- if(nodesConnectedOut==null){
- return;
+ validateConnectivity(null, nodesConnectedIn, expectedServiceTemplate);
}
- boolean found = false;
- for(String nodeIdConnFrom : nodesConnectedOut.keySet()){
- List<RequirementAssignmentData> connectToList = nodesConnectedOut.get(nodeIdConnFrom);
- List<Map<String, RequirementAssignment>> requirementsList = expectedServiceTemplate
- .getTopology_template().getNode_templates().get(computeNodeTemplateId).getRequirements();
- for(RequirementAssignmentData requirementAssignmentData : connectToList) {
- for (Map<String, RequirementAssignment> requirementAssignmentMap : requirementsList) {
- RequirementAssignment requirementAssignment =
- new ObjectMapper().convertValue(requirementAssignmentMap.values().iterator().next(),
- RequirementAssignment.class);
- if (requirementAssignment.getNode().equals(requirementAssignmentData.getRequirementAssignment().getNode())) {
- Assert.assertEquals(requirementAssignment.getCapability(),requirementAssignmentData.getRequirementAssignment().getCapability());
- Assert.assertEquals(requirementAssignment.getNode(),requirementAssignmentData.getRequirementAssignment().getNode());
- Assert.assertEquals(requirementAssignment.getRelationship(),requirementAssignmentData.getRequirementAssignment()
- .getRelationship());
- found = true;
- }
- }
- if (!found) {
- Assert.fail();
+
+ public static void validateComputeConnectivityOut(String computeNodeTemplateId,
+ ComputeTemplateConsolidationData computeTemplateConsolidationData,
+ ServiceTemplate expectedServiceTemplate) {
+ Multimap<String, RequirementAssignmentData> nodesConnectedOut =
+ computeTemplateConsolidationData.getNodesConnectedOut();
+ if (nodesConnectedOut == null) {
+ return;
}
- found = false;
- }
- }
- }
- public static void validatePortConnectivityIn(PortTemplateConsolidationData
- portTemplateConsolidationData,
- ServiceTemplate expectedServiceTemplate){
- Map<String,List<RequirementAssignmentData>> nodesConnectedIn = portTemplateConsolidationData.
- getNodesConnectedIn();
- if(nodesConnectedIn==null){
- return;
+ validateConnectivity(computeNodeTemplateId, nodesConnectedOut, expectedServiceTemplate);
}
- boolean found = false;
- for(String nodeIdConnTo : nodesConnectedIn.keySet()){
- List<RequirementAssignmentData> connectToList = nodesConnectedIn.get(nodeIdConnTo);
- List<Map<String, RequirementAssignment>> requirementsList = expectedServiceTemplate
- .getTopology_template().getNode_templates().get(nodeIdConnTo).getRequirements();
- for(RequirementAssignmentData requirementAssignmentData : connectToList) {
- for (Map<String, RequirementAssignment> requirementAssignmentMap : requirementsList) {
- RequirementAssignment requirementAssignment =
- new ObjectMapper().convertValue(requirementAssignmentMap.values().iterator().next(),
- RequirementAssignment.class);
- if (requirementAssignment.getNode().equals(requirementAssignmentData.getRequirementAssignment().getNode())) {
- Assert.assertEquals(requirementAssignment.getCapability(),requirementAssignmentData.getRequirementAssignment().getCapability());
- Assert.assertEquals(requirementAssignment.getNode(),requirementAssignmentData.getRequirementAssignment().getNode());
- Assert.assertEquals(requirementAssignment.getRelationship(),requirementAssignmentData.getRequirementAssignment()
- .getRelationship());
- found = true;
- }
- }
- if (!found) {
- Assert.fail();
+
+ public static void validatePortConnectivityIn(PortTemplateConsolidationData portTemplateConsolidationData,
+ ServiceTemplate expectedServiceTemplate) {
+ Multimap<String, RequirementAssignmentData> nodesConnectedIn =
+ portTemplateConsolidationData.getNodesConnectedIn();
+ if (nodesConnectedIn == null) {
+ return;
}
- found = false;
- }
- }
- }
- public static void validatePortConnectivityOut(String portNodeTemplateId,
- PortTemplateConsolidationData
- portTemplateConsolidationData,
- ServiceTemplate expectedServiceTemplate){
- Map<String, List<RequirementAssignmentData>> nodesConnectedOut =
- portTemplateConsolidationData.getNodesConnectedOut();
- if(nodesConnectedOut==null){
- return;
+ validateConnectivity(null, nodesConnectedIn, expectedServiceTemplate);
}
- boolean found = false;
- for(String nodeIdConnFrom : nodesConnectedOut.keySet()){
- List<RequirementAssignmentData> connectToList = nodesConnectedOut.get(nodeIdConnFrom);
- List<Map<String, RequirementAssignment>> requirementsList = expectedServiceTemplate
- .getTopology_template().getNode_templates().get(portNodeTemplateId).getRequirements();
- for(RequirementAssignmentData requirementAssignmentData : connectToList) {
- for (Map<String, RequirementAssignment> requirementAssignmentMap : requirementsList) {
- RequirementAssignment requirementAssignment =
- new ObjectMapper().convertValue(requirementAssignmentMap.values().iterator().next(),
- RequirementAssignment.class);
- if (requirementAssignment.getNode().equals(requirementAssignmentData.getRequirementAssignment().getNode())) {
- Assert.assertEquals(requirementAssignment.getCapability(),requirementAssignmentData.getRequirementAssignment().getCapability());
- Assert.assertEquals(requirementAssignment.getNode(),requirementAssignmentData.getRequirementAssignment().getNode());
- Assert.assertEquals(requirementAssignment.getRelationship(),requirementAssignmentData.getRequirementAssignment()
- .getRelationship());
- found = true;
- }
+
+ public static void validatePortConnectivityOut(String portNodeTemplateId,
+ PortTemplateConsolidationData portTemplateConsolidationData,
+ ServiceTemplate expectedServiceTemplate) {
+ Multimap<String, RequirementAssignmentData> nodesConnectedOut =
+ portTemplateConsolidationData.getNodesConnectedOut();
+ if (nodesConnectedOut == null) {
+ return;
}
- if (!found) {
- Assert.fail();
+
+ validateConnectivity(portNodeTemplateId, nodesConnectedOut, expectedServiceTemplate);
+ }
+
+ private static void validateConnectivity(String nodeTemplateId,
+ Multimap<String, RequirementAssignmentData> nodesConnected,
+ ServiceTemplate expectedServiceTemplate) {
+ boolean found = false;
+ for (String nodeIdConnTo : nodesConnected.keySet()) {
+ Collection<RequirementAssignmentData> connectToList = nodesConnected.get(nodeIdConnTo);
+ List<Map<String, RequirementAssignment>> requirementsList = expectedServiceTemplate
+ .getTopology_template().getNode_templates()
+ .get(nodeTemplateId != null ? nodeTemplateId : nodeIdConnTo).getRequirements();
+
+ for (RequirementAssignmentData requirementAssignmentData : connectToList) {
+ for (Map<String, RequirementAssignment> requirementAssignmentMap : requirementsList) {
+ RequirementAssignment requirementAssignment =
+ new ObjectMapper().convertValue(requirementAssignmentMap.values().iterator().next(),
+ RequirementAssignment.class);
+ if (requirementAssignment.getNode()
+ .equals(requirementAssignmentData.getRequirementAssignment().getNode())) {
+ Assert.assertEquals(requirementAssignment.getCapability(),
+ requirementAssignmentData.getRequirementAssignment().getCapability());
+ Assert.assertEquals(requirementAssignment.getNode(),
+ requirementAssignmentData.getRequirementAssignment().getNode());
+ Assert.assertEquals(requirementAssignment.getRelationship(),
+ requirementAssignmentData.getRequirementAssignment()
+ .getRelationship());
+ found = true;
+ }
+ }
+ if (!found) {
+ Assert.fail();
+ }
+ found = false;
+ }
}
- found = false;
- }
}
- }
- public static void validateGetAttr(TranslationContext translationContext, Map<String,
- ServiceTemplate>
- expectedServiceTemplateModels,String testName){
+ public static void validateGetAttr(TranslationContext translationContext, String testName){
ConsolidationData consolidationData = translationContext.getConsolidationData();
Assert.assertNotNull(consolidationData);
if(TestConstants.TEST_GET_ATTR_FOR_MORE_THAN_ONE_ATTR_IN_ATTR_LIST.equals(testName)){
@@ -788,328 +733,317 @@ public class ConsolidationDataTestUtil {
}
}
- public static void validateNestedConsolidationData(TranslationContext context,
- String testName) {
- ConsolidationData consolidationData = context.getConsolidationData();
- if (testName.equals(TEST_SINGLE_NESTED_RESOURCE)) {
- String nestedNodeTemplateId = "server_pcm_001";
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
- //Validate nodes connected in (will only be populated for dependsOn relationships)
- Map<String, List<RequirementAssignmentData>> nodesConnectedIn =
- nestedTemplateConsolidationData.getNodesConnectedIn();
- List<String> dependentNodes = new LinkedList<>();
- dependentNodes.add("packet_mirror_network");
-
- //Validate get attribute in
- Map<String, List<GetAttrFuncData>> nodesGetAttrIn =
- nestedTemplateConsolidationData.getNodesGetAttrIn();
- String getAttrNodeTemplateId = "server_compute_get_attr_test";
- List<GetAttrFuncData> getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
- Assert.assertNotNull(getAttrFuncData);
- Assert.assertEquals(getAttrFuncData.size(), 2);
- Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
- Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "server_pcm_id");
- Assert.assertEquals(getAttrFuncData.get(1).getFieldName(), "user_data_format");
- Assert.assertEquals(getAttrFuncData.get(1).getAttributeName(), "oam_net_gw");
-
- //Validate output parameter get attribute in
- List<GetAttrFuncData> outputParametersGetAttrIn =
- nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
- Assert.assertNotNull(outputParametersGetAttrIn);
- Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_1");
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "pcm_vol");
-
- } else if (testName.equals(TEST_MULTIPLE_NESTED_RESOURCE)) {
- List<String> nestedNodeTemplateIds = new ArrayList<>();
- nestedNodeTemplateIds.add("server_pcm_001");
- nestedNodeTemplateIds.add("server_pcm_002");
- nestedNodeTemplateIds.add("server_pcm_003");
-
- for (String nestedNodeTemplateId : nestedNodeTemplateIds) {
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
- nestedNodeTemplateId);
- if (nestedNodeTemplateId.equals("server_pcm_001")) {
- //Validate nodes connected in (will only be populated for dependsOn relationships)
- Map<String, List<RequirementAssignmentData>> nodesConnectedIn =
- nestedTemplateConsolidationData.getNodesConnectedIn();
- List<String> dependentNodes = new LinkedList<>();
- dependentNodes.add("packet_mirror_network");
- } else {
- Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedIn());
+ public static void validateNestedConsolidationData(TranslationContext context,
+ String testName) {
+ ConsolidationData consolidationData = context.getConsolidationData();
+ if (testName.equals(TEST_SINGLE_NESTED_RESOURCE)) {
+ String nestedNodeTemplateId = "server_pcm_001";
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
+ //Validate nodes connected in (will only be populated for dependsOn relationships)
+ List<String> dependentNodes = new LinkedList<>();
+ dependentNodes.add("packet_mirror_network");
+
+ //Validate get attribute in
+ Map<String, List<GetAttrFuncData>> nodesGetAttrIn =
+ nestedTemplateConsolidationData.getNodesGetAttrIn();
+ String getAttrNodeTemplateId = "server_compute_get_attr_test";
+ List<GetAttrFuncData> getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
+ Assert.assertNotNull(getAttrFuncData);
+ Assert.assertEquals(getAttrFuncData.size(), 2);
+ Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
+ Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "server_pcm_id");
+ Assert.assertEquals(getAttrFuncData.get(1).getFieldName(), "user_data_format");
+ Assert.assertEquals(getAttrFuncData.get(1).getAttributeName(), "oam_net_gw");
+
+ //Validate output parameter get attribute in
+ List<GetAttrFuncData> outputParametersGetAttrIn =
+ nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
+ Assert.assertNotNull(outputParametersGetAttrIn);
+ Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_1");
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "pcm_vol");
+
+ } else if (testName.equals(TEST_MULTIPLE_NESTED_RESOURCE)) {
+ List<String> nestedNodeTemplateIds = new ArrayList<>();
+ nestedNodeTemplateIds.add("server_pcm_001");
+ nestedNodeTemplateIds.add("server_pcm_002");
+ nestedNodeTemplateIds.add("server_pcm_003");
+
+ for (String nestedNodeTemplateId : nestedNodeTemplateIds) {
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
+ nestedNodeTemplateId);
+ if (!nestedNodeTemplateId.equals("server_pcm_001")) {
+ Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedIn());
+ }
+ }
+ String nestedNodeTemplateId = "server_pcm_001";
+
+ //Validate get attribute in
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData("server_pcm_002");
+ Map<String, List<GetAttrFuncData>> nodesGetAttrIn =
+ nestedTemplateConsolidationData.getNodesGetAttrIn();
+ String getAttrNodeTemplateId = "server_pcm_001";
+ List<GetAttrFuncData> getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
+ Assert.assertNotNull(getAttrFuncData);
+ Assert.assertEquals(getAttrFuncData.size(), 1);
+ Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "user_data_format");
+ Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "pcm_vol");
+ //Validate output parameter get attribute in
+ List<GetAttrFuncData> outputParametersGetAttrIn =
+ nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
+ Assert.assertNotNull(outputParametersGetAttrIn);
+ Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_2");
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "oam_net_ip");
+
+
+ nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData("server_pcm_001");
+ nodesGetAttrIn = nestedTemplateConsolidationData.getNodesGetAttrIn();
+ getAttrNodeTemplateId = "server_pcm_002";
+ getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
+ Assert.assertNotNull(getAttrFuncData);
+ Assert.assertEquals(getAttrFuncData.size(), 1);
+ Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
+ Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "server_pcm_id");
+ //Validate output parameter get attribute in
+ outputParametersGetAttrIn = nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
+ Assert.assertNotNull(outputParametersGetAttrIn);
+ Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_1");
+ Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "pcm_vol");
+
+ nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData("server_pcm_003");
+ Assert.assertNull(nestedTemplateConsolidationData.getNodesGetAttrIn());
+ Assert.assertNull(nestedTemplateConsolidationData.getOutputParametersGetAttrIn());
+
+ } else if (testName.equals(TEST_MULTIPLE_MULTI_LEVEL_NESTED_RESOURCE)) {
+ String nestedNodeTemplateId = "test_nested";
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
+ nestedNodeTemplateId);
+ //Validate nodes connected in (will only be populated for dependsOn relationships)
+ Multimap<String, RequirementAssignmentData> nodesConnectedIn =
+ nestedTemplateConsolidationData.getNodesConnectedIn();
+ List<String> dependentNodes = new LinkedList<>();
+ dependentNodes.add("packet_mirror_network");
+ //Validate output parameter get attribute in
+ List<GetAttrFuncData> getAttrFuncData =
+ nestedTemplateConsolidationData.getNodesGetAttrIn().get("packet_mirror_network");
+ Assert.assertNotNull(getAttrFuncData);
+ Assert.assertEquals(getAttrFuncData.size(), 1);
+ Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "shared");
+ Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "output_attr_1");
+ Assert.assertNull(nestedTemplateConsolidationData.getOutputParametersGetAttrIn());
+
+ nestedNodeTemplateId = "test_nested2";
+ nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nestedServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
+ nestedNodeTemplateId);
+ Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedIn());
+ //Validate output parameter get attribute in
+ getAttrFuncData = nestedTemplateConsolidationData.getNodesGetAttrIn().get("server_cmaui_1");
+ Assert.assertNotNull(getAttrFuncData);
+ Assert.assertEquals(getAttrFuncData.size(), 1);
+ Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
+ Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "availability_zone_0");
+
+ List<GetAttrFuncData> outputParametersGetAttrIn1 =
+ nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
+ Assert.assertNotNull(outputParametersGetAttrIn1);
+ Assert.assertEquals(outputParametersGetAttrIn1.size(), 1);
+ Assert.assertEquals(outputParametersGetAttrIn1.get(0).getFieldName(), "output_attr_1");
+ Assert.assertEquals(outputParametersGetAttrIn1.get(0).getAttributeName(), "availability_zone_0");
}
- }
- String nestedNodeTemplateId = "server_pcm_001";
-
- //Validate get attribute in
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData("server_pcm_002");
- Map<String, List<GetAttrFuncData>> nodesGetAttrIn =
- nestedTemplateConsolidationData.getNodesGetAttrIn();
- String getAttrNodeTemplateId = "server_pcm_001";
- List<GetAttrFuncData> getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
- Assert.assertNotNull(getAttrFuncData);
- Assert.assertEquals(getAttrFuncData.size(), 1);
- Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "user_data_format");
- Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "pcm_vol");
- //Validate output parameter get attribute in
- List<GetAttrFuncData> outputParametersGetAttrIn =
- nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
- Assert.assertNotNull(outputParametersGetAttrIn);
- Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_2");
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "oam_net_ip");
-
-
- nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData("server_pcm_001");
- nodesGetAttrIn = nestedTemplateConsolidationData.getNodesGetAttrIn();
- getAttrNodeTemplateId = "server_pcm_002";
- getAttrFuncData = nodesGetAttrIn.get(getAttrNodeTemplateId);
- Assert.assertNotNull(getAttrFuncData);
- Assert.assertEquals(getAttrFuncData.size(), 1);
- Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
- Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "server_pcm_id");
- //Validate output parameter get attribute in
- outputParametersGetAttrIn = nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
- Assert.assertNotNull(outputParametersGetAttrIn);
- Assert.assertEquals(outputParametersGetAttrIn.size(), 1);
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getFieldName(), "output_attr_1");
- Assert.assertEquals(outputParametersGetAttrIn.get(0).getAttributeName(), "pcm_vol");
-
- nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData("server_pcm_003");
- Assert.assertNull(nestedTemplateConsolidationData.getNodesGetAttrIn());
- Assert.assertNull(nestedTemplateConsolidationData.getOutputParametersGetAttrIn());
-
- } else if (testName.equals(TEST_MULTIPLE_MULTI_LEVEL_NESTED_RESOURCE)) {
- String nestedNodeTemplateId = "test_nested";
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
- nestedNodeTemplateId);
- //Validate nodes connected in (will only be populated for dependsOn relationships)
- Map<String, List<RequirementAssignmentData>> nodesConnectedIn =
- nestedTemplateConsolidationData.getNodesConnectedIn();
- List<String> dependentNodes = new LinkedList<>();
- dependentNodes.add("packet_mirror_network");
- //Validate output parameter get attribute in
- List<GetAttrFuncData> getAttrFuncData =
- nestedTemplateConsolidationData.getNodesGetAttrIn().get("packet_mirror_network");
- Assert.assertNotNull(getAttrFuncData);
- Assert.assertEquals(getAttrFuncData.size(), 1);
- Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "shared");
- Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "output_attr_1");
- Assert.assertNull(nestedTemplateConsolidationData.getOutputParametersGetAttrIn());
-
- nestedNodeTemplateId = "test_nested2";
- nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nestedServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert.assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(),
- nestedNodeTemplateId);
- Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedIn());
- //Validate output parameter get attribute in
- getAttrFuncData = nestedTemplateConsolidationData.getNodesGetAttrIn().get("server_cmaui_1");
- Assert.assertNotNull(getAttrFuncData);
- Assert.assertEquals(getAttrFuncData.size(), 1);
- Assert.assertEquals(getAttrFuncData.get(0).getFieldName(), "metadata");
- Assert.assertEquals(getAttrFuncData.get(0).getAttributeName(), "availability_zone_0");
-
- List<GetAttrFuncData> outputParametersGetAttrIn1 =
- nestedTemplateConsolidationData.getOutputParametersGetAttrIn();
- Assert.assertNotNull(outputParametersGetAttrIn1);
- Assert.assertEquals(outputParametersGetAttrIn1.size(), 1);
- Assert.assertEquals(outputParametersGetAttrIn1.get(0).getFieldName(), "output_attr_1");
- Assert.assertEquals(outputParametersGetAttrIn1.get(0).getAttributeName(), "availability_zone_0");
}
- }
- private static void validateBasicNestedConsolidationData(NestedTemplateConsolidationData
- nestedTemplateConsolidationData) {
- Assert.assertNull(nestedTemplateConsolidationData.getGroupIds());
- Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedOut());
- }
+ private static void validateBasicNestedConsolidationData(NestedTemplateConsolidationData
+ nestedTemplateConsolidationData) {
+ Assert.assertNull(nestedTemplateConsolidationData.getGroupIds());
+ Assert.assertNull(nestedTemplateConsolidationData.getNodesConnectedOut());
+ }
- public static void validateNestedNodesConnectedInSecurityRuleToPort(String testName,
- TranslationContext context) {
- ConsolidationData consolidationData = context.getConsolidationData();
- if (testName.equals(TEST_SECURITY_RULE_PORT_NESTED_CONNECTION) ||
- testName.equals(TestConstants.TEST_SECURITY_RULE_PORT_NESTED_SHARED_PORT)) {
- String nestedNodeTemplateId = "test_nested";
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert
- .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
- String securityRuleNodeTemplateId = "jsa_security_group1";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
- securityRuleNodeTemplateId = "jsa_security_group2";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
- if (testName.equals(TestConstants.TEST_SECURITY_RULE_PORT_NESTED_SHARED_PORT)) {
- nestedNodeTemplateId = "test_nestedArrayParam";
- Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
- Assert.assertNull(consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
- }
- } else if (testName.equals(TEST_SECURITY_RULE_PORT_MULTI_LEVEL_NESTED_CONNECTION) ||
- testName.equals(TEST_SECURITY_RULE_PORT_MULTI_LEVEL_NESTED_SHARED_PORT)) {
- String nestedNodeTemplateId = "test_nested2Level";
- Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested1ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
- Assert.assertNull(consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested1ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
- nestedNodeTemplateId = "test_nested3Level";
- Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested2ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
- Assert.assertNull(consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested2ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
- nestedNodeTemplateId = "test_nested4Level";
- Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested3ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
- Assert.assertNull(consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData("nested3ServiceTemplate.yaml")
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
-
- //Validate main service template
-
- nestedNodeTemplateId = "test_nested1Level";
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert
- .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
- String securityRuleNodeTemplateId = "jsa_security_group1";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
- securityRuleNodeTemplateId = "jsa_security_group2";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
-
- nestedNodeTemplateId = "test_resourceGroup";
- nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId);
- //Validate basic null attributes
- validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
- //Validate nodeTemplateId
- Assert
- .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
- securityRuleNodeTemplateId = "jsa_security_group2";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
- securityRuleNodeTemplateId = "jsa_security_group2";
- validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
- .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
- nestedNodeTemplateId, securityRuleNodeTemplateId,
- nestedTemplateConsolidationData);
-
- nestedNodeTemplateId = "test_nestedInvalidConnectionToNova";
- Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
- Assert.assertNull(consolidationData.getNestedConsolidationData()
- .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
- .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+ public static void validateNestedNodesConnectedInSecurityRuleToPort(String testName, TranslationContext context) {
+ ConsolidationData consolidationData = context.getConsolidationData();
+ if (testName.equals(TEST_SECURITY_RULE_PORT_NESTED_CONNECTION) ||
+ testName.equals(TestConstants.TEST_SECURITY_RULE_PORT_NESTED_SHARED_PORT)) {
+ String nestedNodeTemplateId = "test_nested";
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert
+ .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
+ String securityRuleNodeTemplateId = "jsa_security_group1";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+ securityRuleNodeTemplateId = "jsa_security_group2";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+ if (testName.equals(TestConstants.TEST_SECURITY_RULE_PORT_NESTED_SHARED_PORT)) {
+ nestedNodeTemplateId = "test_nestedArrayParam";
+ Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
+ Assert.assertNull(consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+ }
+ } else if (testName.equals(TEST_SECURITY_RULE_PORT_MULTI_LEVEL_NESTED_CONNECTION) ||
+ testName.equals(TEST_SECURITY_RULE_PORT_MULTI_LEVEL_NESTED_SHARED_PORT)) {
+ String nestedNodeTemplateId = "test_nested2Level";
+ Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested1ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
+ Assert.assertNull(consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested1ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+ nestedNodeTemplateId = "test_nested3Level";
+ Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested2ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
+ Assert.assertNull(consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested2ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+ nestedNodeTemplateId = "test_nested4Level";
+ Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested3ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
+ Assert.assertNull(consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData("nested3ServiceTemplate.yaml")
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+
+ //Validate main service template
+
+ nestedNodeTemplateId = "test_nested1Level";
+ NestedTemplateConsolidationData nestedTemplateConsolidationData =
+ consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert
+ .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
+ String securityRuleNodeTemplateId = "jsa_security_group1";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+ securityRuleNodeTemplateId = "jsa_security_group2";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+
+ nestedNodeTemplateId = "test_resourceGroup";
+ nestedTemplateConsolidationData = consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId);
+ //Validate basic null attributes
+ validateBasicNestedConsolidationData(nestedTemplateConsolidationData);
+ //Validate nodeTemplateId
+ Assert
+ .assertEquals(nestedTemplateConsolidationData.getNodeTemplateId(), nestedNodeTemplateId);
+ securityRuleNodeTemplateId = "jsa_security_group2";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+ securityRuleNodeTemplateId = "jsa_security_group2";
+ validateNestedNodesConnectedInSecurityRuleToPort(HeatToToscaUtil
+ .getServiceTemplateFromContext(MAIN_SERVICE_TEMPLATE, context).get(),
+ nestedNodeTemplateId, securityRuleNodeTemplateId,
+ nestedTemplateConsolidationData);
+
+ nestedNodeTemplateId = "test_nestedInvalidConnectionToNova";
+ Assert.assertEquals(nestedNodeTemplateId, consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodeTemplateId());
+ Assert.assertNull(consolidationData.getNestedConsolidationData()
+ .getFileNestedConsolidationData(MAIN_SERVICE_TEMPLATE)
+ .getNestedTemplateConsolidationData(nestedNodeTemplateId).getNodesConnectedIn());
+ }
}
- }
- private static void validateNestedNodesConnectedInSecurityRuleToPort(ServiceTemplate
- serviceTemplate,
- String nestedNodeTemplateId,
- String
- securityRuleNodeTemplateId,
- NestedTemplateConsolidationData nestedTemplateConsolidationData) {
- Map<String, List<RequirementAssignmentData>> consolidationDataNodesConnectedIn =
- nestedTemplateConsolidationData.getNodesConnectedIn();
- Assert.assertNotNull(consolidationDataNodesConnectedIn);
- NodeTemplate securityRuleNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
- securityRuleNodeTemplateId);
- List<Map<String, RequirementAssignment>> securityRuleNodeTemplateRequirements =
- securityRuleNodeTemplate.getRequirements();
- for (Map<String, RequirementAssignment> req : securityRuleNodeTemplateRequirements) {
- String requirementId = req.keySet().toArray()[0].toString();
- if (requirementId.equals(ToscaConstants.PORT_REQUIREMENT_ID)) {
- RequirementAssignment requirementAssignment = req.get(requirementId);
- if (requirementAssignment.getNode().equals(nestedNodeTemplateId)) {
- validateSecurityRulePortNestedConsolidationData(requirementAssignment,
- securityRuleNodeTemplateId, consolidationDataNodesConnectedIn);
+ private static void validateNestedNodesConnectedInSecurityRuleToPort(ServiceTemplate serviceTemplate,
+ String nestedNodeTemplateId,
+ String securityRuleNodeTemplateId,
+ NestedTemplateConsolidationData
+ nestedTemplateConsolidationData) {
+ Multimap<String, RequirementAssignmentData> consolidationDataNodesConnectedIn =
+ nestedTemplateConsolidationData.getNodesConnectedIn();
+ Assert.assertNotNull(consolidationDataNodesConnectedIn);
+ NodeTemplate securityRuleNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
+ securityRuleNodeTemplateId);
+ List<Map<String, RequirementAssignment>> securityRuleNodeTemplateRequirements =
+ securityRuleNodeTemplate.getRequirements();
+ for (Map<String, RequirementAssignment> req : securityRuleNodeTemplateRequirements) {
+ String requirementId = req.keySet().toArray()[0].toString();
+ if (requirementId.equals(ToscaConstants.PORT_REQUIREMENT_ID)) {
+ RequirementAssignment requirementAssignment = req.get(requirementId);
+ if (requirementAssignment.getNode().equals(nestedNodeTemplateId)) {
+ validateSecurityRulePortNestedConsolidationData(requirementAssignment,
+ securityRuleNodeTemplateId, consolidationDataNodesConnectedIn);
+ }
+ }
}
- }
}
- }
- private static void validateSecurityRulePortNestedConsolidationData(RequirementAssignment
- requirementAssignment,
- String securityRuleNodeTemplateId,
- Map<String,
- List<RequirementAssignmentData>> consolidationDataNodesConnectedIn) {
- List<RequirementAssignmentData> requirementAssignmentDataList =
- consolidationDataNodesConnectedIn.get(securityRuleNodeTemplateId);
- Assert.assertNotNull(requirementAssignmentDataList);
- boolean result = false;
- for (RequirementAssignmentData data : requirementAssignmentDataList) {
- RequirementAssignment dataRequirementAssignment = data.getRequirementAssignment();
- result = DataModelUtil
- .compareRequirementAssignment(requirementAssignment, dataRequirementAssignment);
- if (result) {
- break;
- }
+ private static void validateSecurityRulePortNestedConsolidationData(RequirementAssignment requirementAssignment,
+ String securityRuleNodeTemplateId,
+ Multimap<String, RequirementAssignmentData>
+ consolidationDataNodesConnectedIn) {
+ Collection<RequirementAssignmentData> requirementAssignmentDataList =
+ consolidationDataNodesConnectedIn.get(securityRuleNodeTemplateId);
+ Assert.assertNotNull(requirementAssignmentDataList);
+ boolean result = false;
+ for (RequirementAssignmentData data : requirementAssignmentDataList) {
+ RequirementAssignment dataRequirementAssignment = data.getRequirementAssignment();
+ result = DataModelUtil
+ .compareRequirementAssignment(requirementAssignment, dataRequirementAssignment);
+ if (result) {
+ break;
+ }
+ }
+ Assert.assertTrue(result);
}
- Assert.assertTrue(result);
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceTranslationTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceTranslationTest.java
index f399cc15e0..56d0b2da9f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceTranslationTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceTranslationTest.java
@@ -260,8 +260,8 @@ public class BaseResourceTranslationTest {
case VALIDATE_CONNECTIVITY:
validateComputeConnectivityIn(computeTemplateConsolidationData,
expectedServiceTemplate);
- validateComputeConnectivityOut(computeNodeTemplateId,computeTemplateConsolidationData,
- expectedServiceTemplate);
+ validateComputeConnectivityOut(computeNodeTemplateId, computeTemplateConsolidationData,
+ expectedServiceTemplate);
break;
case VALIDATE_DEPENDS_ON:
validateDependsOnInConsolidationData(computeNodeTemplateId,
@@ -274,11 +274,9 @@ public class BaseResourceTranslationTest {
}
}
- protected void validateGetAttribute(String testName){
- Map<String, ServiceTemplate> expectedServiceTemplateModels = TestUtils.getServiceTemplates
- (expectedResultMap);
- validateGetAttr(translationContext,expectedServiceTemplateModels,testName);
- }
+ protected void validateGetAttribute(String testName) {
+ validateGetAttr(translationContext, testName);
+ }
protected void validateNestedTemplateConsolidationData(String testName){
validateNestedConsolidationData(translationContext, testName);
@@ -311,8 +309,7 @@ public class BaseResourceTranslationTest {
switch(ConsolidationDataValidationType.VALIDATE_CONNECTIVITY){
case VALIDATE_CONNECTIVITY:
validatePortConnectivityIn(portTemplateConsolidationData,expectedServiceTemplate);
- validatePortConnectivityOut(portNodeTemplateId, portTemplateConsolidationData,
- expectedServiceTemplate);
+ validatePortConnectivityOut(portNodeTemplateId, portTemplateConsolidationData, expectedServiceTemplate);
break;
}
}