Create new VSP, onboard from TOSCA file - UI 45/11945/2
authorshrek2000 <orenkle@amdocs.com>
Tue, 12 Sep 2017 11:28:40 +0000 (14:28 +0300)
committershrek2000 <orenkle@amdocs.com>
Tue, 12 Sep 2017 11:59:18 +0000 (14:59 +0300)
Issue-ID: SDC-230
Change-Id: I99db84eeef6e795f81d25fac31d17594d0071e69
Signed-off-by: shrek2000 <orenkle@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java

index 4c6cdaa..07cef57 100644 (file)
@@ -3,7 +3,6 @@ package org.openecomp.sdcrests.vsp.rest.services;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
-import org.openecomp.core.utilities.file.FileUtils;
 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
 import org.openecomp.sdc.common.errors.Messages;
 import org.openecomp.sdc.logging.api.Logger;
@@ -34,7 +33,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Optional;
-import static org.openecomp.core.utilities.file.FileUtils.*;
+
+import static org.openecomp.core.utilities.file.FileUtils.getFileExtension;
+import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName;
 
 @Named
 @Service("orchestrationTemplateCandidate")
@@ -55,7 +56,7 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
     UploadFileResponse uploadFileResponse = candidateManager
         .upload(vspId, resolveVspVersion(vspId, null, user, VersionableEntityAction
             .Write), fileToUpload.getObject(InputStream.class), user, getFileExtension(filename),
-            FileUtils.getNetworkPackageName(filename));
+            getNetworkPackageName(filename));
     UploadFileResponseDto uploadFileResponseDto = new MapUploadFileResponseToUploadFileResponseDto()
         .applyMapping(uploadFileResponse, UploadFileResponseDto.class);
 
index 104da69..85f9266 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_Impl_Key;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY;
 
 public class OrchestrationUploadFactory {
     private static Map<String, ImplementationConfiguration> fileHanlders;
@@ -17,7 +17,7 @@ public class OrchestrationUploadFactory {
     static {
         Configuration config = ConfigurationManager.lookup();
         fileHanlders = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE,
-                ORCHESTRATION_Impl_Key, ImplementationConfiguration.class));
+                ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class));
 
     }
 
index 5d14477..9d7421f 100644 (file)
@@ -59,7 +59,7 @@ import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConst
 public class OrchestrationUtil {
 
     public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration";
-    public static final String ORCHESTRATION_Impl_Key = "orchestration_impl";
+    public static final String ORCHESTRATION_IMPL_KEY = "orchestration_impl";
 
 
     private static VendorSoftwareProductDao vendorSoftwareProductDao =
index 5e217d4..85c6fcb 100644 (file)
@@ -1,6 +1,6 @@
 package org.openecomp.sdc.vendorsoftwareproduct.types;
 
 public class ConfigConstants {
-  public static final String namespace = "Orchestration";
-  public static final String processImplKey =  "process_impl";
+  public static final String NAMESPACE = "Orchestration";
+  public static final String PROCESS_IMPL_KEY =  "process_impl";
 }
index 2d33748..778445c 100644 (file)
@@ -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);
+    }
 }
index c4ed6f9..69fa33a 100644 (file)
@@ -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,
index 9f7071e..1ee8f6c 100644 (file)
@@ -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"));
     }