From 6914f938afd9cec84d6bb2b044cef74f4e997ab1 Mon Sep 17 00:00:00 2001
From: sebdet <sebastien.determe@intl.att.com>
Date: Tue, 12 Feb 2019 21:34:58 +0100
Subject: support multiple CL

Support multiple CL CSAR deployment per service/vnf

Issue-ID: CLAMP-289
Change-Id: I6e52da07b393bffeff18e16a5afa78ef14162935
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
---
 .../clds/sdc/controller/installer/CsarHandler.java |  3 +-
 .../controller/installer/CsarInstallerImpl.java    | 32 +++++++++++-----------
 2 files changed, 17 insertions(+), 18 deletions(-)

(limited to 'src/main')

diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
index 1b7cb28c2..1a99919ee 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
@@ -138,8 +138,7 @@ public class CsarHandler {
                     blueprintArtifact.setResourceAttached(searchForResourceByInstanceName(entry.getName().substring(
                         entry.getName().indexOf(RESOURCE_INSTANCE_NAME_PREFIX) + RESOURCE_INSTANCE_NAME_PREFIX.length(),
                         entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX))));
-                    this.mapOfBlueprints.put(blueprintArtifact.getResourceAttached().getResourceInstanceName(),
-                        blueprintArtifact);
+                    this.mapOfBlueprints.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact);
                     logger.info("Found a blueprint entry in the CSAR " + blueprintArtifact.getBlueprintArtifactName()
                         + " for resource instance Name "
                         + blueprintArtifact.getResourceAttached().getResourceInstanceName());
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index 50090920e..bfda6924d 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -25,8 +25,8 @@ package org.onap.clamp.clds.sdc.controller.installer;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-
 import com.google.gson.JsonObject;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -59,8 +59,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.yaml.snakeyaml.Yaml;
 
 /**
- * This class will be instantiated by spring config, and used by Sdc Controller. There is no state kept by the bean.
- * It's used to deploy the csar/notification received from SDC in DB.
+ * This class will be instantiated by spring config, and used by Sdc Controller.
+ * There is no state kept by the bean. It's used to deploy the csar/notification
+ * received from SDC in DB.
  */
 public class CsarInstallerImpl implements CsarInstaller {
 
@@ -101,15 +102,14 @@ public class CsarInstallerImpl implements CsarInstaller {
         boolean alreadyInstalled = true;
         for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {
             alreadyInstalled = alreadyInstalled
-                && (CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getKey()), true).getId() != null) ? true
-                : false;
+                && CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getValue()), true).getId() != null;
         }
         return alreadyInstalled;
     }
 
-    public static String buildModelName(CsarHandler csar, String resourceInstanceName)
+    public static String buildModelName(CsarHandler csar, BlueprintArtifact artifact)
         throws SdcArtifactInstallerException {
-        String policyScopePrefix = searchForPolicyScopePrefix(csar.getMapOfBlueprints().get(resourceInstanceName));
+        String policyScopePrefix = searchForPolicyScopePrefix(artifact);
         if (policyScopePrefix.contains("*")) {
             // This is policy_filter type
             policyScopePrefix = policyScopePrefix.replaceAll("\\*", "");
@@ -117,9 +117,10 @@ public class CsarInstallerImpl implements CsarInstaller {
             // This is normally the get_input case
             policyScopePrefix = MODEL_NAME_PREFIX;
         }
-        return policyScopePrefix + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v"
-            + csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_"
-            + resourceInstanceName.replaceAll(" ", "");
+        return (policyScopePrefix + "_" + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v"
+            + csar.getSdcNotification().getServiceVersion() + "_"
+            + artifact.getResourceAttached().getResourceInstanceName().replaceAll(" ", "") + "_"
+            + artifact.getBlueprintArtifactName().replace(".yaml", "")).replace('.', '_');
     }
 
     @Override
@@ -214,8 +215,8 @@ public class CsarInstallerImpl implements CsarInstaller {
     }
 
     /**
-     * This call must be done when deploying the SDC notification as this call get the latest version of the artifact
-     * (version can be specified to DCAE call)
+     * This call must be done when deploying the SDC notification as this call get
+     * the latest version of the artifact (version can be specified to DCAE call)
      *
      * @return The DcaeInventoryResponse object containing the dcae values
      */
@@ -236,8 +237,7 @@ public class CsarInstallerImpl implements CsarInstaller {
             "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}");
         template
             .setImageText(IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream()));
-        template.setName(TEMPLATE_NAME_PREFIX
-            + buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName()));
+        template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar, blueprintArtifact));
         template.save(cldsDao, null);
         logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName()
             + " with name " + template.getName());
@@ -246,14 +246,14 @@ public class CsarInstallerImpl implements CsarInstaller {
 
     private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact,
         CldsTemplate cldsTemplate, DcaeInventoryResponse dcaeInventoryResponse) throws SdcArtifactInstallerException {
-        
+
         if (dcaeInventoryResponse == null) {
             throw new SdcArtifactInstallerException(
                 "DCAE inventory response is NULL, query to DCAE fail to be answered properly, this is required to deploy CSAR properly !!!");
         }
         try {
             CldsModel cldsModel = new CldsModel();
-            cldsModel.setName(buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName()));
+            cldsModel.setName(buildModelName(csar, blueprintArtifact));
             cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint());
             cldsModel.setTemplateName(cldsTemplate.getName());
             cldsModel.setTemplateId(cldsTemplate.getId());
-- 
cgit