diff options
author | Ester Rotstein <er767y@att.com> | 2017-07-20 09:14:38 +0300 |
---|---|---|
committer | Ester Rotstein <er767y@att.com> | 2017-07-20 09:15:29 +0300 |
commit | fc5eb8622019f06498a05b8dadef7f0a7bb3ab4b (patch) | |
tree | f019354f3ec4ebdd6cf7357e3ee532851aeba494 /src | |
parent | 3b2a4a9f36d21c0d5519e83551fde633945eb3a7 (diff) |
[SDC-142] support nested node templates
Change-Id: I04b61547decd93b2a2e2941d77f077f515ac1daf
Signed-off-by: Ester Rotstein <er767y@att.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java | 7 | ||||
-rw-r--r-- | src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 36 | ||||
-rw-r--r-- | src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java | 52 | ||||
-rw-r--r-- | src/test/resources/csars/service-nested-vfc-csar.csar | bin | 47592 -> 47690 bytes |
4 files changed, 87 insertions, 8 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java index bb5bd25..06a66c6 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -387,4 +387,11 @@ public interface ISdcCsarHelper { * @return true if node template has topology template, false if not. */ public boolean hasTopology(NodeTemplate nodeTemplate); + + /** + * Get children node templates for node template. + * @param nodeTemplate - Node Template to get its children + * @return return list of children node templates for node template. + */ + public List<NodeTemplate> getNodeTemplateChildren(NodeTemplate nodeTemplate); } diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index c927817..9b40416 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -22,9 +22,7 @@ package org.openecomp.sdc.tosca.parser.impl; import java.util.*; import java.util.Map.Entry; -import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -41,7 +39,6 @@ import org.openecomp.sdc.toscaparser.api.ToscaTemplate; import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.functions.Function; -import org.openecomp.sdc.toscaparser.api.functions.GetInput; import org.openecomp.sdc.toscaparser.api.parameters.Input; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -625,13 +622,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { if (sdcType.equals(SdcTypes.VFC) && isVNF) { return nodeTemplates.stream() .filter(x -> (x.getMetaData() != null && - sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && (x.getType().endsWith("VnfConfiguration"))) + sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && isVNFType(x)) .collect(Collectors.toList()); } else { return nodeTemplates.stream() .filter(x -> (x.getMetaData() != null && - sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !(x.getType().endsWith("VnfConfiguration"))) + sdcType.toString().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !isVNFType(x)) .collect(Collectors.toList()); } } @@ -705,7 +702,36 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return false; } + @Override + public List<NodeTemplate> getNodeTemplateChildren(NodeTemplate nodeTemplate) { + if (nodeTemplate == null) { + log.error("getNodeTemplateChildren - nodeTemplate - is null"); + return new ArrayList<>(); + } + + SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate(); + if (substitutionMappings != null) { + List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates(); + if (nodeTemplates != null && nodeTemplates.size() > 0) { + + return nodeTemplates.stream() + .filter(x -> !isVNFType(x)) + .collect(Collectors.toList()); + } + else { + log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist"); + } + } else + log.debug("getNodeTemplateChildren - SubstitutionMappings not exist"); + + return new ArrayList<>(); + } + /************************************* helper functions ***********************************/ + private boolean isVNFType(NodeTemplate nt) { + return nt.getType().endsWith("VnfConfiguration"); + } + private Map<String, String> filterProperties(Object property, String path, FilterType filterType, String pattern, Map<String, String> filterMap) { if (property instanceof Map) { diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index 9818a89..4ab9af3 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -7,6 +7,7 @@ import static org.testng.Assert.assertTrue; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -555,8 +556,9 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { public void testNestedVfcByExistCvfc() { List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); assertNotNull(vfcList); - assertEquals(1, vfcList.size()); - assertEquals("VF_VNF", vfcList.get(0).getName()); + assertEquals(vfcList.size(), 2); + assertEquals("VFC1 DUMMY", vfcList.get(0).getName()); + assertEquals("VF_VNF", vfcList.get(1).getName()); } @Test @@ -585,7 +587,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { @Test public void testHasTopologyByCVFC() { List<NodeTemplate> vfcList = nestedVfcCsarHlper.getVfcListByVf("71389f8b-8671-4a43-a991-59fb621d3615"); - boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(0)); + boolean hasTopology = nestedVfcCsarHlper.hasTopology(vfcList.get(1)); assertEquals(true, hasTopology); } @@ -603,4 +605,48 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { } //endregion + //region getNodeTemplateChildren + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVF() { + List<NodeTemplate> vfList = fdntCsarHelper.getServiceVfList(); + List<NodeTemplate> children = fdntCsarHelper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(children); + assertEquals(3, children.size()); + + children.sort(Comparator.comparing(NodeTemplate::getName)); + + assertEquals("DNT_FW_RSG_SI_1", children.get(1).getName()); + assertEquals("VFC", children.get(1).getMetaData().getValue("type")); + assertEquals("DNT_PORT", children.get(2).getName()); + assertEquals("CP", children.get(2).getMetaData().getValue("type")); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByVFC() { + List<NodeTemplate> vfList = nestedVfcCsarHlper.getServiceVfList(); + List<NodeTemplate> vfChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfList.get(0)); + assertNotNull(vfChildren); + assertEquals(vfChildren.size(), 2); + vfChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("VFC1 DUMMY", vfChildren.get(0).getName()); + assertEquals("VF_VNF", vfChildren.get(1).getName()); + assertEquals("CVFC", vfChildren.get(1).getMetaData().getValue("type")); + + + List<NodeTemplate> vfcChildren = nestedVfcCsarHlper.getNodeTemplateChildren(vfChildren.get(1)); + assertNotNull(vfcChildren); + assertEquals(vfcChildren.size(), 3); + vfcChildren.sort(Comparator.comparing(NodeTemplate::getName)); + assertEquals("Test NIC 02_wan_port", vfcChildren.get(0).getName()); + assertEquals("Test NIC_wan_port", vfcChildren.get(1).getName()); + assertEquals("VF", vfcChildren.get(2).getName()); + } + + @Test + public void testGetNodeTemplatesListOfNodeTemplateByNull() { + List<NodeTemplate> children = fdntCsarHelper.getNodeTemplateChildren(null); + assertNotNull(children); + assertEquals(0, children.size()); + } + //endregion } diff --git a/src/test/resources/csars/service-nested-vfc-csar.csar b/src/test/resources/csars/service-nested-vfc-csar.csar Binary files differindex b141fe2..0275520 100644 --- a/src/test/resources/csars/service-nested-vfc-csar.csar +++ b/src/test/resources/csars/service-nested-vfc-csar.csar |