From cf1033dd4f9e0863f408314ba411fa0dc3150aae Mon Sep 17 00:00:00 2001 From: shrek2000 Date: Tue, 12 Sep 2017 14:28:40 +0300 Subject: Create new VSP, onboard from TOSCA file - UI Issue-ID: SDC-230 Change-Id: I99db84eeef6e795f81d25fac31d17594d0071e69 Signed-off-by: shrek2000 --- .../impl/GlobalSubstitutionServiceTemplate.java | 32 ++++++++++++++++++++-- .../openecomp/core/impl/ToscaConverterImpl.java | 11 ++++++-- .../impl/ToscaConvertorDefinitionsTest.java | 8 +----- 3 files changed, 39 insertions(+), 12 deletions(-) (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib') diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java index 2d33748e26..778445c513 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java @@ -1,23 +1,30 @@ package org.openecomp.core.impl; +import org.apache.commons.collections4.MapUtils; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.model.Import; import org.openecomp.sdc.tosca.datatypes.model.NodeType; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { private static final Logger logger = LoggerFactory.getLogger(ServiceTemplate.class); - public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = "GlobalSubstitutionServiceTemplate.yaml"; + public static final String GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME = + "GlobalSubstitutionTypesServiceTemplate.yaml"; public static final String TEMPLATE_NAME_PROPERTY = "template_name"; public static final String DEFININTION_VERSION = "tosca_simple_yaml_1_0_0"; public static final String HEAT_INDEX = "openecomp_heat_index"; + private static final Map globalServiceTemplates = + GlobalTypesGenerator.getGlobalTypesServiceTemplate(); public GlobalSubstitutionServiceTemplate() { super(); @@ -26,7 +33,10 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { public void appendNodes(Map nodes) { - getNode_types().putAll(nodes); + Optional> nodeTypesToAdd = + removeExistingGlobalTypes(nodes); + + nodeTypesToAdd.ifPresent(nodeTypes -> getNode_types().putAll(nodeTypes)); } public void init() { @@ -56,4 +66,22 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate { private void writeDefinitionSection() { setTosca_definitions_version(DEFININTION_VERSION); } + + public Optional> removeExistingGlobalTypes(Map nodes){ + Map nodeTypesToAdd = new HashMap<>(); + ServiceTemplate serviceTemplate = globalServiceTemplates.get("openecomp/nodes.yml"); + + if(Objects.isNull(serviceTemplate) || MapUtils.isEmpty(serviceTemplate.getNode_types())){ + return Optional.of(nodes); + } + + Map globalNodeTypes = serviceTemplate.getNode_types(); + for(Map.Entry nodeTypeEntry : nodes.entrySet()){ + if(!globalNodeTypes.containsKey(nodeTypeEntry.getKey())){ + nodeTypesToAdd.put(nodeTypeEntry.getKey(), nodeTypeEntry.getValue()); + } + } + + return Optional.of(nodeTypesToAdd); + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java index c4ed6f9c5f..69fa33aae7 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java @@ -70,7 +70,7 @@ public class ToscaConverterImpl implements ToscaConverter { private void handleMetadataFile(Map csarFiles) { byte[] bytes = csarFiles.remove(metadataFile); if (bytes != null) { - csarFiles.put(metadataFile + ".old", bytes); + csarFiles.put(metadataFile + ".original", bytes); } } @@ -102,11 +102,16 @@ public class ToscaConverterImpl implements ToscaConverter { Collection globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate().values(); addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates); - serviceTemplates.put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate); toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName); toscaServiceModel.setServiceTemplates(serviceTemplates); - externalFilesHandler.addFile(metadataFile + ".old", csarFiles.get(metadataFile + ".old")); + externalFilesHandler.addFile(metadataFile + ".original", + csarFiles.get(metadataFile + ".original")); toscaServiceModel.setArtifactFiles(externalFilesHandler); + + if(MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) { + serviceTemplates + .put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate); + } } private void addGlobalServiceTemplates(Collection globalServiceTemplates, diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java index 9f7071e9e7..1ee8f6c05f 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java @@ -47,15 +47,9 @@ public class ToscaConvertorDefinitionsTest { assertNotNull(serviceTemplate.getNode_types()); - assertEquals(7, serviceTemplate.getNode_types().size()); + assertEquals(1, serviceTemplate.getNode_types().size()); Set keys = serviceTemplate.getNode_types().keySet(); - assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VDU")); - assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.CP")); assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF.vCSCF")); - assertTrue(keys.contains("tosca.nodes.nfv.ext.ImageFile")); - assertTrue(keys.contains("tosca.nodes.nfv.ext.LocalStorage")); - assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF")); - assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VL")); } -- cgit 1.2.3-korg