Merge "Rename the default recipe for VFC NS"
[so.git] / adapters / mso-adapter-utils / src / main / java / org / openecomp / mso / openstack / utils / MsoHeatUtilsWithUpdate.java
index 5f46549..75bb003 100644 (file)
@@ -1,8 +1,9 @@
 /*-
  * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
+ * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +21,6 @@
 
 package org.openecomp.mso.openstack.utils;
 
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -159,7 +159,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
      * @param tenantId The Openstack ID of the tenant in which to create the Stack
      * @param cloudSiteId The cloud identifier (may be a region) in which to create the tenant.
      * @param stackName The name of the stack to update
-     * @param stackTemplate The Heat template
+     * @param heatTemplate The Heat template
      * @param stackInputs A map of key/value inputs
      * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client
      * @param environment An optional yaml-format string to specify environmental parameters
@@ -193,10 +193,8 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
         }
 
         // Obtain the cloud site information where we will create the stack
-        CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId);
-        if (cloudSite == null) {
-            throw new MsoCloudSiteNotFound (cloudSiteId);
-        }
+        CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+                () -> new MsoCloudSiteNotFound(cloudSiteId));
         // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
         // This could throw MsoTenantNotFound or MsoOpenstackException (both propagated)
         Heat heatClient = getHeatClient (cloudSite, tenantId);
@@ -232,7 +230,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
         if (haveFiles && haveHeatFiles) {
             // Let's do this here - not in the bean
             LOGGER.debug ("Found files AND heatFiles - combine and add!");
-            Map <String, Object> combinedFiles = new HashMap <String, Object> ();
+            Map <String, Object> combinedFiles = new HashMap<>();
             for (String keyString : files.keySet ()) {
                 combinedFiles.put (keyString, files.get (keyString));
             }
@@ -281,7 +279,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                     try {
                        LOGGER.debug("Current stack " + this.getOutputsAsStringBuilder(heatStack).toString());
                     } catch (Exception e) {
-                       LOGGER.debug("an error occurred trying to print out the current outputs of the stack");
+                       LOGGER.debug("an error occurred trying to print out the current outputs of the stack", e);
                     }
 
 
@@ -360,24 +358,25 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                        sb.append("(outputs is empty)");
                        return sb;
                }
-               Map<String, Object> outputs = new HashMap<String,Object>();
+               Map<String, Object> outputs = new HashMap<>();
                for (Output outputItem : outputList) {
                        outputs.put(outputItem.getOutputKey(), outputItem.getOutputValue());
                }
                int counter = 0;
                sb.append("OUTPUTS:\n");
                for (String key : outputs.keySet()) {
-                       sb.append("outputs[" + counter++ + "]: " + key + "=");
+                       sb.append("outputs[").append(counter++).append("]: ").append(key).append("=");
                        Object obj = outputs.get(key);
                        if (obj instanceof String) {
-                               sb.append((String)obj +" (a string)");
+                               sb.append((String) obj).append(" (a string)");
                        } else if (obj instanceof JsonNode) {
-                               sb.append(this.convertNode((JsonNode)obj) + " (a JsonNode)");
+                               sb.append(this.convertNode((JsonNode) obj)).append(" (a JsonNode)");
                        } else if (obj instanceof java.util.LinkedHashMap) {
                                try {
                                        String str = JSON_MAPPER.writeValueAsString(obj);
-                                       sb.append(str + " (a java.util.LinkedHashMap)");
+                                       sb.append(str).append(" (a java.util.LinkedHashMap)");
                                } catch (Exception e) {
+                                       LOGGER.debug("Exception :", e);
                                        sb.append("(a LinkedHashMap value that would not convert nicely)");
                                }                               
                        } else if (obj instanceof Integer) {
@@ -385,6 +384,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                                try {
                                        str = obj.toString() + " (an Integer)\n";
                                } catch (Exception e) {
+                                       LOGGER.debug("Exception :", e);
                                        str = "(an Integer unable to call .toString() on)";
                                }
                                sb.append(str);
@@ -393,6 +393,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                                try {
                                        str = obj.toString() + " (an ArrayList)";
                                } catch (Exception e) {
+                                       LOGGER.debug("Exception :", e);
                                        str = "(an ArrayList unable to call .toString() on?)";
                                }
                                sb.append(str);
@@ -401,6 +402,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                                try {
                                        str = obj.toString() + " (a Boolean)";
                                } catch (Exception e) {
+                                       LOGGER.debug("Exception :", e);
                                        str = "(an Boolean unable to call .toString() on?)";
                                }
                                sb.append(str);
@@ -410,6 +412,7 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                                try {
                                        str = obj.toString() + " (unknown Object type)";
                                } catch (Exception e) {
+                                       LOGGER.debug("Exception :", e);
                                        str = "(a value unable to call .toString() on?)";
                                }
                                sb.append(str);
@@ -425,10 +428,8 @@ public class MsoHeatUtilsWithUpdate extends MsoHeatUtils {
                        final Object obj = JSON_MAPPER.treeToValue(node, Object.class);
                        final String json = JSON_MAPPER.writeValueAsString(obj);
                        return json;
-               } catch (JsonParseException jpe) {
-                       LOGGER.debug("Error converting json to string " + jpe.getMessage());
                } catch (Exception e) {
-                       LOGGER.debug("Error converting json to string " + e.getMessage());
+                       LOGGER.debug("Error converting json to string " + e.getMessage(), e);
                }
                return "[Error converting json to string]";
        }