From 63ab11e3a5c635d69056d6f79156ce1d114fa1be Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Mon, 25 May 2020 17:08:23 +0100 Subject: Support the substitution_mappings in the VNFD Signed-off-by: MichaelMorris Issue-ID: SDC-2957 Change-Id: I8a385b02568b3bf3d83a250cbe36a7e7f61e710c --- .../openecomp/sdc/be/components/csar/CsarInfo.java | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'catalog-be/src/main/java/org/openecomp') 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 nodeTypesInfo, List> globalSubstitutes, Map.Entry 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 mappedToscaTemplate = (Map) new Yaml().load(new String(entry.getValue())); findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP) .right() .on(sub->handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map)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 nodeTypesInfo, Map.Entry entry, Map mappedToscaTemplate, Map substitutionMappings) { - if (substitutionMappings.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName())) { + final Set 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 findNodeTypesDefinedInTemplate(final Map mappedToscaTemplate) { + final Either nodeTypesEither = findToscaElement(mappedToscaTemplate, + TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + if (nodeTypesEither.isLeft()) { + final Map nodeTypes = (Map) nodeTypesEither.left().value(); + return nodeTypes.keySet(); + } + return Collections.emptySet(); + } private boolean isGlobalSubstitute(String fileName) { return fileName.equalsIgnoreCase(Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE) -- cgit 1.2.3-korg