Merge "Reorder modifiers"
[so.git] / adapters / mso-vnf-adapter / src / main / java / org / openecomp / mso / adapters / vnf / MsoVnfAdapterImpl.java
index 2fec3f8..48e0a56 100644 (file)
@@ -668,15 +668,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
 
         LOGGER.debug("requestTypeString = " + requestTypeString + ", nestedStackId = " + nestedStackId + ", nestedBaseStackId = " + nestedBaseStackId);
 
-        // TODO(sshank): Figure out the body format to be sent from Groovy.
-        String hpaEnviromnentString = "";
-        // Something similar to the following:
-        /*
-            if requestTypeString.substring(?) != "" {
-                hpaEnviromnentString = requestTypeString.substring(?)
-            }
-         */
-
         // Will capture execution time for metrics
         long startTime = System.currentTimeMillis();
 
@@ -1052,6 +1043,18 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                 LOGGER.debug("no environment parameter found for this Type " + vfModuleType);
             }
 
+            // Replace flavors in environment with those returned by OOF
+            Map<String, Object> returnMap = updateFlavorsFromOof(heatEnvironmentString, inputs);
+            heatEnvironmentString = returnMap.get("heatEnvironmentString").toString();
+            LOGGER.debug("After OOF Update Heat Env String is: " + heatEnvironmentString);
+            if (returnMap.get("inputs") instanceof Map) {
+                inputs = (Map<String, String>) returnMap.get("inputs");
+                LOGGER.debug("After OOF Update inputs are: " + inputs.toString());
+            } else {
+                LOGGER.debug("inputs is not an instance of a Map: " + returnMap.get("inputs"));
+                throw new VnfException("Updating inputs using OOF info failed.", MsoExceptionCategory.INTERNAL);
+            }
+
             // 1510 - Add the files: for nested templates *if* there are any
             LOGGER.debug("In MsoVnfAdapterImpl, createVfModule about to call db.getNestedTemplates avec templateId="
                     + heatTemplate.getArtifactUuid());
@@ -1170,12 +1173,6 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
                 //LOGGER.debug("About to create MHEE with " + sb);
                 mhee = new MsoHeatEnvironmentEntry(sb);
 
-                // sshank: hpaEnviromnentString is obtained from requestTypeString above.
-                if (hpaEnviromnentString != null && hpaEnviromnentString.contains("parameters:")) {
-                    StringBuilder hpasb = new StringBuilder(hpaEnviromnentString);
-                    mhee.setHPAParameters(hpasb);
-                }
-
                 StringBuilder sb2 = new StringBuilder("\nHeat Template Parameters:\n");
                 for (HeatTemplateParam parm : heatTemplate.getParameters()) {
                     sb2.append("\t" + parm.getParamName() + ", required=" + parm.isRequired());
@@ -1888,7 +1885,7 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
             // Also new in 1510 - don't flag missing parameters if there's an environment - because they might be there.
             // And also new - add parameter to turn off checking all together if we find we're blocking orders we
             // shouldn't
-            boolean haveEnvironmentParameters = false;
+//            boolean haveEnvironmentParameters = false;
             boolean checkRequiredParameters = true;
             try {
                 String propertyString = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_VNF_ADAPTER)
@@ -2163,4 +2160,17 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
         return CatalogDatabase.getInstance();
     }
 
+    private Map<String, Object> updateFlavorsFromOof(String heatEnvironmentString, Map<String, String> inputs) {
+        Map<String, Object> returnMap = new HashMap<>();
+        for (Map.Entry<String, String> input : inputs.entrySet()){
+            if (heatEnvironmentString.contains("label_" + input.getKey())){
+            heatEnvironmentString = heatEnvironmentString.replace("label_" + input.getKey(),
+            input.getValue());
+            inputs.remove("label_" + input.getKey());
+            }
+        }
+        returnMap.put("heatEnvironmentString", heatEnvironmentString);
+        returnMap.put("inputs", inputs);
+        return returnMap;
+    }
 }