repeat distribution transaction error
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / heat / ToscaResourceInstaller.java
index 23c31f3..85943ed 100644 (file)
@@ -121,6 +121,7 @@ import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.ServiceRepository;
 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
+import org.onap.so.db.catalog.data.repository.ToscaCsarRepository;
 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
@@ -241,6 +242,9 @@ public class ToscaResourceInstaller {
     @Autowired
     protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
 
+    @Autowired
+    protected ToscaCsarRepository toscaCsarRepo;
+
     @Autowired
     protected PnfResourceRepository pnfResourceRepository;
 
@@ -252,6 +256,31 @@ public class ToscaResourceInstaller {
 
     protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
 
+    public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure)
+            throws ArtifactInstallerException {
+        boolean deployed = false;
+        if (toscaResourceStructure == null) {
+            return deployed;
+        }
+
+        IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
+        String checkSum = inputToscaCsar.getArtifactChecksum();
+        String artifactUuid = inputToscaCsar.getArtifactUUID();
+
+        Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
+        if (toscaCsarObj.isPresent()) {
+            ToscaCsar toscaCsar = toscaCsarObj.get();
+            if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
+                String errorMessage =
+                        String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
+                throw new ArtifactInstallerException(errorMessage);
+            } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
+                deployed = true;
+            }
+        }
+        return deployed;
+    }
+
     public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed)
             throws ArtifactInstallerException {
         boolean status = false;