aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java26
-rw-r--r--catalog-be/src/test/resources/etsi_vnf.csarbin0 -> 14280 bytes
3 files changed, 44 insertions, 10 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index ce6d60bd3c..58beecbf20 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -43,12 +43,14 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.yaml.snakeyaml.Yaml;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Queue;
+import java.util.Set;
import java.util.regex.Pattern;
import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
@@ -144,20 +146,25 @@ public class CsarInfo {
@SuppressWarnings("unchecked")
private void extractNodeTypeInfo(Map<String, NodeTypeInfo> nodeTypesInfo,
List<Map.Entry<String, byte[]>> globalSubstitutes, Map.Entry<String, byte[]> entry) {
- if (Pattern.compile(CsarUtils.SERVICE_TEMPLATE_PATH_PATTERN).matcher(entry.getKey()).matches()) {
- if (!isGlobalSubstitute(entry.getKey())) {
+ if (isAServiceTemplate(entry.getKey())) {
+ if (isGlobalSubstitute(entry.getKey())) {
+ globalSubstitutes.add(entry);
+ } else {
Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(new String(entry.getValue()));
findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP)
.right()
.on(sub->handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map<String, Object>)sub));
- }else {
- globalSubstitutes.add(entry);
}
}
}
+
+ private boolean isAServiceTemplate(final String filePath) {
+ return Pattern.compile(CsarUtils.SERVICE_TEMPLATE_PATH_PATTERN).matcher(filePath).matches();
+ }
private ResultStatusEnum handleSubstitutionMappings(Map<String, NodeTypeInfo> nodeTypesInfo, Map.Entry<String, byte[]> entry, Map<String, Object> mappedToscaTemplate, Map<String, Object> substitutionMappings) {
- if (substitutionMappings.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName())) {
+ final Set<String> nodeTypesDefinedInTemplate = findNodeTypesDefinedInTemplate(mappedToscaTemplate);
+ if (substitutionMappings.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName()) && !nodeTypesDefinedInTemplate.contains(substitutionMappings.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName()))) {
NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
nodeTypeInfo.setSubstitutionMapping(true);
nodeTypeInfo.setType(
@@ -168,6 +175,17 @@ public class CsarInfo {
}
return ResultStatusEnum.OK;
}
+
+ @SuppressWarnings("unchecked")
+ private Set<String> findNodeTypesDefinedInTemplate(final Map<String, Object> mappedToscaTemplate) {
+ final Either<Object, ResultStatusEnum> nodeTypesEither = findToscaElement(mappedToscaTemplate,
+ TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP);
+ if (nodeTypesEither.isLeft()) {
+ final Map<String, Object> nodeTypes = (Map<String, Object>) nodeTypesEither.left().value();
+ return nodeTypes.keySet();
+ }
+ return Collections.emptySet();
+ }
private boolean isGlobalSubstitute(String fileName) {
return fileName.equalsIgnoreCase(Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE)
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
index 62fd3f9e78..a28e2efcdb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java
@@ -75,14 +75,19 @@ public class CsarInfoTest {
@Before
public void setup() throws ZipException, URISyntaxException {
// given
- final File csarFile = new File(CsarInfoTest.class.getClassLoader().getResource(PAYLOAD_NAME).toURI());
- final Map<String, byte[]> payload = ZipUtils.readZip(csarFile, false);
- String mainTemplateContent = new String(payload.get(MAIN_TEMPLATE_NAME));
+ csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME);
- csarInfo = new CsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME,
- MAIN_TEMPLATE_NAME, mainTemplateContent, true);
new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
}
+
+ private CsarInfo createCsarInfo(final String csarFileName, final String mainTemplateName) throws URISyntaxException, ZipException {
+ final File csarFile = new File(CsarInfoTest.class.getClassLoader().getResource(csarFileName).toURI());
+ final Map<String, byte[]> payload = ZipUtils.readZip(csarFile, false);
+ String mainTemplateContent = new String(payload.get(mainTemplateName));
+
+ return new CsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME,
+ mainTemplateName, mainTemplateContent, true);
+ }
@Test
public void add2TimesTheSameNodeTest() {
@@ -151,4 +156,15 @@ public class CsarInfoTest {
final Optional<String> softwareInformationPath = csarInfo.getSoftwareInformationPath();
assertThat("The software information yaml path should not be present", softwareInformationPath.isPresent(), is(false));
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCreateCsarInfoEtsiVnf() throws URISyntaxException, ZipException {
+ final CsarInfo csarInfo = createCsarInfo("etsi_vnf.csar", "Definitions/MainServiceTemplate.yaml");
+
+ final String nodeTypeInSubstitutionMapping = (String) ((Map<String, Object>)((Map<String, Object>)csarInfo.getMappedToscaMainTemplate().get("topology_template")).get("substitution_mappings")).get("node_type");
+ assertTrue(((Map<String, Object>) csarInfo.getMappedToscaMainTemplate().get("node_types")).containsKey(nodeTypeInSubstitutionMapping));
+
+ assertTrue(csarInfo.extractNodeTypesInfo().isEmpty());
+ }
}
diff --git a/catalog-be/src/test/resources/etsi_vnf.csar b/catalog-be/src/test/resources/etsi_vnf.csar
new file mode 100644
index 0000000000..93e62bc20e
--- /dev/null
+++ b/catalog-be/src/test/resources/etsi_vnf.csar
Binary files differ