Fix Sdc Controller 31/47231/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 11 May 2018 16:28:24 +0000 (18:28 +0200)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Fri, 11 May 2018 16:28:24 +0000 (18:28 +0200)
Remove artifact types that clamp does not need so that it's correct in
SDC UI + add notifications for all artifact types

Issue-ID: CLAMP-151
Change-Id: Iada581cdb2b17b355dd3a607cbe6930bba7a6931
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java
src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java

index 2afc3d9..ca756aa 100644 (file)
@@ -81,7 +81,7 @@ public class SdcSingleControllerConfiguration implements IConfiguration {
     public static final String TOSCA_CSAR = "TOSCA_CSAR";
     public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
     private static final String[] SUPPORTED_ARTIFACT_TYPES = {
-            HEAT, HEAT_ARTIFACT, HEAT_ENV, HEAT_NESTED, HEAT_NET, HEAT_VOL, OTHER, TOSCA_CSAR, VF_MODULES_METADATA
+            TOSCA_CSAR, VF_MODULES_METADATA
     };
     public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST = Collections
             .unmodifiableList(Arrays.asList(SUPPORTED_ARTIFACT_TYPES));
index c9bbd06..3421ee9 100644 (file)
@@ -27,6 +27,7 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 \r
 import java.util.Date;\r
+import java.util.Map.Entry;\r
 import java.util.concurrent.ThreadLocalRandom;\r
 \r
 import org.onap.clamp.clds.config.ClampProperties;\r
@@ -36,6 +37,7 @@ import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerExceptio
 import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;\r
 import org.onap.clamp.clds.exception.sdc.controller.SdcDownloadException;\r
 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;\r
+import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;\r
 import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;\r
 import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
@@ -191,6 +193,29 @@ public class SdcSingleController {
         this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);\r
     }\r
 \r
+    private void sendAllNotificationForCsarHandler(INotificationData iNotif, CsarHandler csar,\r
+            NotificationType notificationType, DistributionStatusEnum distributionStatus, String errorMessage) {\r
+        if (csar != null) {\r
+            // Notify for the CSAR\r
+            this.sendSdcNotification(notificationType, csar.getArtifactElement().getArtifactURL(),\r
+                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
+                    System.currentTimeMillis());\r
+            // Notify for all VF resources found\r
+            for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {\r
+                // Normally always 1 artifact in resource for Clamp as we\r
+                // specified\r
+                // only VF_METADATA type\r
+                this.sendSdcNotification(notificationType,\r
+                        blueprint.getValue().getResourceAttached().getArtifacts().get(0).getArtifactURL(),\r
+                        sdcConfig.getConsumerID(), iNotif.getDistributionID(), distributionStatus, errorMessage,\r
+                        System.currentTimeMillis());\r
+            }\r
+        } else {\r
+            this.sendSdcNotification(notificationType, null, sdcConfig.getConsumerID(), iNotif.getDistributionID(),\r
+                    distributionStatus, errorMessage, System.currentTimeMillis());\r
+        }\r
+    }\r
+\r
     /**\r
      * This method processes the notification received from Sdc.\r
      * \r
@@ -202,54 +227,41 @@ public class SdcSingleController {
         try {\r
             // wait for a random time, so that 2 running Clamp will not treat\r
             // the same Notification at the same time\r
-            long i = ThreadLocalRandom.current().nextInt(1, 5);\r
-            Thread.sleep(i * 1000L);\r
+            Thread.sleep(ThreadLocalRandom.current().nextInt(1, 10) * 1000L);\r
             logger.info("Notification received for service UUID:" + iNotif.getServiceUUID());\r
             this.changeControllerStatus(SdcSingleControllerStatus.BUSY);\r
             csar = new CsarHandler(iNotif, this.sdcConfig.getSdcControllerName(),\r
                     refProp.getStringValue(CONFIG_SDC_FOLDER));\r
             csar.save(downloadTheArtifact(csar.getArtifactElement()));\r
             if (csarInstaller.isCsarAlreadyDeployed(csar)) {\r
-                this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
-                        sdcConfig.getConsumerID(), iNotif.getDistributionID(),\r
-                        DistributionStatusEnum.ALREADY_DOWNLOADED, null, System.currentTimeMillis());\r
-                this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
-                        sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.ALREADY_DEPLOYED,\r
-                        null, System.currentTimeMillis());\r
+                sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
+                        DistributionStatusEnum.ALREADY_DOWNLOADED, null);\r
+                sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+                        DistributionStatusEnum.ALREADY_DEPLOYED, null);\r
             } else {\r
-                this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
-                        sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_OK, null,\r
-                        System.currentTimeMillis());\r
+                sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
+                        DistributionStatusEnum.DOWNLOAD_OK, null);\r
                 csarInstaller.installTheCsar(csar);\r
-                this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
-                        sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null,\r
-                        System.currentTimeMillis());\r
+                sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+                        DistributionStatusEnum.DEPLOY_OK, null);\r
             }\r
-        } catch (SdcArtifactInstallerException e) {\r
+        } catch (SdcArtifactInstallerException | SdcToscaParserException e) {\r
             logger.error("SdcArtifactInstallerException exception caught during the notification processing", e);\r
-            this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
-                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,\r
-                    e.getMessage(), System.currentTimeMillis());\r
-        } catch (SdcDownloadException e) {\r
+            sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+                    DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
+        } catch (SdcDownloadException | CsarHandlerException e) {\r
             logger.error("SdcDownloadException exception caught during the notification processing", e);\r
-            this.sendSdcNotification(NotificationType.DOWNLOAD, csar.getArtifactElement().getArtifactURL(),\r
-                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR,\r
-                    e.getMessage(), System.currentTimeMillis());\r
-        } catch (CsarHandlerException e) {\r
-            logger.error("CsarHandlerException exception caught during the notification processing", e);\r
-            this.sendSdcNotification(NotificationType.DOWNLOAD, null, sdcConfig.getConsumerID(),\r
-                    iNotif.getDistributionID(), DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(),\r
-                    System.currentTimeMillis());\r
-        } catch (SdcToscaParserException e) {\r
-            logger.error("SdcToscaParserException exception caught during the notification processing", e);\r
-            this.sendSdcNotification(NotificationType.DEPLOY, csar.getArtifactElement().getArtifactURL(),\r
-                    sdcConfig.getConsumerID(), iNotif.getDistributionID(), DistributionStatusEnum.DEPLOY_ERROR,\r
-                    e.getMessage(), System.currentTimeMillis());\r
+            sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,\r
+                    DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage());\r
         } catch (InterruptedException e) {\r
             logger.error("Interrupt exception caught during the notification processing", e);\r
+            sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+                    DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
             Thread.currentThread().interrupt();\r
         } catch (RuntimeException e) {\r
             logger.error("Unexpected exception caught during the notification processing", e);\r
+            sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,\r
+                    DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());\r
         } finally {\r
             this.changeControllerStatus(SdcSingleControllerStatus.IDLE);\r
         }\r