Added isAlreadyDeployed check at the Service level. 18/84918/1
authorBenjamin, Max (mb388a) <mb388a@us.att.com>
Wed, 10 Apr 2019 17:47:15 +0000 (13:47 -0400)
committerBenjamin, Max (mb388a) <mb388a@us.att.com>
Wed, 10 Apr 2019 17:53:45 +0000 (13:53 -0400)
- Committed changes for tabs verse spaces.
- Added isAlreadyDeployed check at the Service level.

Change-Id: I1f735830820f84745ed1fb9f5a9e76146ee23d3b
Issue-ID: SO-1764
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java
asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java

index 92326b1..57e9c17 100644 (file)
@@ -1,5 +1,5 @@
 /*-
-d * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
@@ -250,9 +250,11 @@ public class ASDCController {
         this.changeControllerStatus(ASDCControllerStatus.STOPPED);
     }
 
-    private boolean checkResourceAlreadyDeployed(VfResourceStructure resource) throws ArtifactInstallerException {
+    protected boolean checkResourceAlreadyDeployed(ResourceStructure resource, boolean serviceDeployed)
+            throws ArtifactInstallerException {
 
-        if (toscaInstaller.isResourceAlreadyDeployed(resource)) {
+
+        if (toscaInstaller.isResourceAlreadyDeployed(resource, serviceDeployed)) {
             logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST.toString(),
                     resource.getResourceInstance().getResourceInstanceName(),
                     resource.getResourceInstance().getResourceUUID(), resource.getResourceInstance().getResourceName());
@@ -656,6 +658,7 @@ public class ASDCController {
         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
         boolean deploySuccessful = true;
         String errorMessage = null;
+        boolean serviceDeployed = false;
 
         try {
             this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
@@ -686,12 +689,45 @@ public class ASDCController {
                     resourceStructure.setResourceType(ResourceType.OTHER);
                 }
 
-                for (IArtifactInfo artifact : resource.getArtifacts()) {
-                    IDistributionClientDownloadResult resultArtifact =
-                            this.downloadTheArtifact(artifact, iNotif.getDistributionID());
-                    if (resultArtifact != null) {
-                        resourceStructure.addArtifactToStructure(distributionClient, artifact, resultArtifact);
+                try {
+
+                    if (!this.checkResourceAlreadyDeployed(resourceStructure, serviceDeployed)) {
+
+                        logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: "
+                                + resourceStructure.getResourceInstance().getResourceUUID());
+
+                        if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) {
+
+                            for (IArtifactInfo artifact : resource.getArtifacts()) {
+                                IDistributionClientDownloadResult resultArtifact =
+                                        this.downloadTheArtifact(artifact, iNotif.getDistributionID());
+                                if (resultArtifact != null) {
+
+                                    if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
+                                        logger.debug("VF_MODULE_ARTIFACT: "
+                                                + new String(resultArtifact.getArtifactPayload(), "UTF-8"));
+                                        logger.debug(ASDCNotificationLogging
+                                                .dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure)
+                                                        .decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
+                                    }
+                                    resourceStructure.addArtifactToStructure(distributionClient, artifact,
+                                            resultArtifact);
+                                }
+                            }
+
+                            // Deploy VF resource and artifacts
+                            logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
+
+
+                            this.deployResourceStructure(resourceStructure, toscaResourceStructure);
+                            serviceDeployed = true;
+                        }
                     }
+
+                } catch (ArtifactInstallerException e) {
+                    deploySuccessful = false;
+                    errorMessage = e.getMessage();
+                    logger.error("Exception occurred", e);
                 }
 
                 // Deploy VF resource and artifacts
index 0e30b77..e61aafa 100644 (file)
@@ -249,9 +249,10 @@ public class ToscaResourceInstaller {
 
     protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
 
-    public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
+    public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed)
+            throws ArtifactInstallerException {
         boolean status = false;
-        VfResourceStructure vfResourceStructure = vfResourceStruct;
+        ResourceStructure vfResourceStructure = vfResourceStruct;
         try {
             status = vfResourceStructure.isDeployedSuccessfully();
         } catch (RuntimeException e) {
@@ -260,7 +261,7 @@ public class ToscaResourceInstaller {
         try {
             Service existingService =
                     serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
-            if (existingService != null)
+            if (existingService != null && serviceDeployed == false)
                 status = true;
             if (status) {
                 logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(),
index 99833da..d3c0bde 100644 (file)
@@ -131,7 +131,7 @@ public class ToscaResourceInstallerTest extends BaseTest {
         doReturn("resourceCustomizationUUID").when(resourceInstance).getResourceCustomizationUUID();
         doReturn("resourceName").when(resourceInstance).getResourceName();
 
-        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure);
+        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure, false);
 
         WatchdogComponentDistributionStatus actualWatchdogComponentDistributionStatus = getWatchdogCDStatusWithName(
                 watchdogCDStatusRepository.findByDistributionId(notificationData.getDistributionID()), MSO);
@@ -156,7 +156,7 @@ public class ToscaResourceInstallerTest extends BaseTest {
         doReturn("resourceCustomizationUUID").when(resourceInstance).getResourceCustomizationUUID();
         doReturn("resourceName").when(resourceInstance).getResourceName();
 
-        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure);
+        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure, false);
 
         verify(vfResourceStructure, times(3)).getResourceInstance();
         verify(vfResourceStructure, times(4)).getNotification();
@@ -166,7 +166,7 @@ public class ToscaResourceInstallerTest extends BaseTest {
     public void isResourceAlreadyDeployedExceptionTest() throws ArtifactInstallerException {
         expectedException.expect(ArtifactInstallerException.class);
 
-        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure);
+        toscaInstaller.isResourceAlreadyDeployed(vfResourceStructure, false);
     }
 
     @Test