Check to make sure Heat records do not exist. 41/86541/1
authorMerkel, Jeff <jeff.merkel@att.com>
Mon, 29 Apr 2019 14:48:13 +0000 (10:48 -0400)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Mon, 29 Apr 2019 14:48:23 +0000 (10:48 -0400)
- Replaced index assert statements with stream().
- Updated the UT to retrieve from the service object for the assert
statements.
- Added check to make sure Heat records don't already exist.

Change-Id: Ife02303e7b3f5c7d132fb9c1baebaa3787a18494
Issue-ID: SO-1818
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java [new file with mode: 0644]

index 85943ed..4e97b5f 100644 (file)
@@ -112,6 +112,8 @@ import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomization
 import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
+import org.onap.so.db.catalog.data.repository.HeatEnvironmentRepository;
+import org.onap.so.db.catalog.data.repository.HeatFilesRepository;
 import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
@@ -226,6 +228,12 @@ public class ToscaResourceInstaller {
     @Autowired
     protected HeatTemplateRepository heatRepo;
 
+    @Autowired
+    protected HeatEnvironmentRepository heatEnvRepo;
+
+    @Autowired
+    protected HeatFilesRepository heatFilesRepo;
+
     @Autowired
     protected NetworkResourceCustomizationRepository networkCustomizationRepo;
 
@@ -1137,77 +1145,95 @@ public class ToscaResourceInstaller {
 
     protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure,
             ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) {
-        HeatTemplate heatTemplate = new HeatTemplate();
-        List<String> typeList = new ArrayList<>();
-        typeList.add(ASDCConfiguration.HEAT_NESTED);
-        typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
 
-        heatTemplate.setTemplateBody(
-                verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
-        heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+        HeatTemplate existingHeatTemplate =
+                heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
 
-        if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
-            heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
-        } else {
-            heatTemplate.setTimeoutMinutes(240);
-        }
+        if (existingHeatTemplate == null) {
+            HeatTemplate heatTemplate = new HeatTemplate();
+            List<String> typeList = new ArrayList<>();
+            typeList.add(ASDCConfiguration.HEAT_NESTED);
+            typeList.add(ASDCConfiguration.HEAT_ARTIFACT);
 
-        heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
-        heatTemplate.setVersion(BigDecimalVersion
-                .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
-        heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+            heatTemplate.setTemplateBody(
+                    verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
+            heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName());
 
-        if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
-            heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
-        } else {
-            heatTemplate.setArtifactChecksum(MANUAL_RECORD);
-        }
+            if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) {
+                heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout());
+            } else {
+                heatTemplate.setTimeoutMinutes(240);
+            }
+
+            heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+            heatTemplate.setVersion(BigDecimalVersion
+                    .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+            heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+            if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+                heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+            } else {
+                heatTemplate.setArtifactChecksum(MANUAL_RECORD);
+            }
 
-        Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
-                vfModuleArtifact.getArtifactInfo().getArtifactUUID());
-        heatTemplate.setParameters(heatParam);
-        vfModuleArtifact.setHeatTemplate(heatTemplate);
+            Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(),
+                    vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+            heatTemplate.setParameters(heatParam);
+            vfModuleArtifact.setHeatTemplate(heatTemplate);
+        }
     }
 
     protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure,
             VfModuleArtifact vfModuleArtifact) {
-        HeatEnvironment heatEnvironment = new HeatEnvironment();
-        heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
-        List<String> typeList = new ArrayList<>();
-        typeList.add(ASDCConfiguration.HEAT);
-        typeList.add(ASDCConfiguration.HEAT_VOL);
-        heatEnvironment.setEnvironment(
-                verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
-        heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
-        heatEnvironment.setVersion(BigDecimalVersion
-                .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
-        heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
-
-        if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
-            heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
-        } else {
-            heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
+
+        HeatEnvironment existingHeatEnvironment =
+                heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+        if (existingHeatEnvironment == null) {
+            HeatEnvironment heatEnvironment = new HeatEnvironment();
+            heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+            List<String> typeList = new ArrayList<>();
+            typeList.add(ASDCConfiguration.HEAT);
+            typeList.add(ASDCConfiguration.HEAT_VOL);
+            heatEnvironment.setEnvironment(
+                    verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList));
+            heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+            heatEnvironment.setVersion(BigDecimalVersion
+                    .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+            heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+            if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+                heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+            } else {
+                heatEnvironment.setArtifactChecksum(MANUAL_RECORD);
+            }
+            vfModuleArtifact.setHeatEnvironment(heatEnvironment);
         }
-        vfModuleArtifact.setHeatEnvironment(heatEnvironment);
     }
 
     protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure,
             VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) {
 
-        HeatFiles heatFile = new HeatFiles();
-        heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
-        heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
-        heatFile.setFileBody(vfModuleArtifact.getResult());
-        heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
-        heatFile.setVersion(BigDecimalVersion
-                .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
-        toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
-        if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
-            heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
-        } else {
-            heatFile.setArtifactChecksum(MANUAL_RECORD);
+        HeatFiles existingHeatFiles =
+                heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+
+        if (existingHeatFiles == null) {
+            HeatFiles heatFile = new HeatFiles();
+            heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+            heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription());
+            heatFile.setFileBody(vfModuleArtifact.getResult());
+            heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName());
+            heatFile.setVersion(BigDecimalVersion
+                    .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion()));
+            toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID());
+            if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) {
+                heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum());
+            } else {
+                heatFile.setArtifactChecksum(MANUAL_RECORD);
+            }
+            vfModuleArtifact.setHeatFiles(heatFile);
+
         }
-        vfModuleArtifact.setHeatFiles(heatFile);
     }
 
     protected Service createService(ToscaResourceStructure toscaResourceStructure,
@@ -2153,10 +2179,12 @@ public class ToscaResourceInstaller {
             vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment());
             vfModuleArtifact.incrementDeployedInDB();
         } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) {
-            if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
-                vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
-            } else {
-                vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
+            if (vfModuleArtifact.getHeatEnvironment() != null) {
+                if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) {
+                    vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment());
+                } else {
+                    vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment());
+                }
             }
             vfModuleArtifact.incrementDeployedInDB();
         } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) {
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/HeatFilesRepository.java
new file mode 100644 (file)
index 0000000..acefb75
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.db.catalog.data.repository;
+
+import org.onap.so.db.catalog.beans.HeatFiles;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
+
+@RepositoryRestResource(collectionResourceRel = "heatFiles", path = "heatFiles")
+public interface HeatFilesRepository extends JpaRepository<HeatFiles, String> {
+    HeatFiles findByArtifactUuid(String artifactUUID);
+}