aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java32
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java11
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java8
3 files changed, 39 insertions, 12 deletions
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<String, ServiceTemplate> globalServiceTemplates =
+ GlobalTypesGenerator.getGlobalTypesServiceTemplate();
public GlobalSubstitutionServiceTemplate() {
super();
@@ -26,7 +33,10 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
public void appendNodes(Map<String, NodeType> nodes) {
- getNode_types().putAll(nodes);
+ Optional<Map<String, NodeType>> 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<Map<String, NodeType>> removeExistingGlobalTypes(Map<String, NodeType> nodes){
+ Map<String, NodeType> nodeTypesToAdd = new HashMap<>();
+ ServiceTemplate serviceTemplate = globalServiceTemplates.get("openecomp/nodes.yml");
+
+ if(Objects.isNull(serviceTemplate) || MapUtils.isEmpty(serviceTemplate.getNode_types())){
+ return Optional.of(nodes);
+ }
+
+ Map<String, NodeType> globalNodeTypes = serviceTemplate.getNode_types();
+ for(Map.Entry<String, NodeType> 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<String, byte[]> 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<ServiceTemplate> 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<ServiceTemplate> 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<String> 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"));
}