diff options
author | Steve Smokowski <ss835w@att.com> | 2020-03-16 20:01:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-16 20:01:51 +0000 |
commit | b29c12d739290137a60a37803d1abb1df33e9806 (patch) | |
tree | 240105e10385d20ce0b55760d9f076d4f451934a /adapters/mso-adapter-utils/src/main | |
parent | 0514d12f76335aa3bf3cfccaef3864fd91a54444 (diff) | |
parent | 5f6afc61e09eaeda51d6e6834ab0646b00047bcf (diff) |
Merge "Fix Critical & Major issues in adapters"
Diffstat (limited to 'adapters/mso-adapter-utils/src/main')
-rw-r--r-- | adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java index 0a3c6acd84..50ebcc66ee 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java @@ -198,7 +198,9 @@ public class MsoCommonUtils { // Generate an alarm for 5XX and higher errors. if (re.getStatus() >= 500) { - + logger.error("{} {} OpenStackResponseException with response code {} on {}: ", + MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), re.getStatus(), context, + e); } } else if (e instanceof OpenStackConnectException) { OpenStackConnectException ce = (OpenStackConnectException) e; @@ -281,7 +283,9 @@ public class MsoCommonUtils { // Generate an alarm for 5XX and higher errors. if (re.getStatus() >= 500) { - + logger.error("{} {} OpenStackBaseException with response code {} on {}: ", + MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), re.getStatus(), context, + e); } } else if (e instanceof OpenStackConnectException) { OpenStackConnectException ce = (OpenStackConnectException) e; @@ -334,32 +338,6 @@ public class MsoCommonUtils { protected CreateStackParam createStackParam(String stackName, String heatTemplate, Map<String, ?> stackInputs, int timeoutMinutes, String environment, Map<String, Object> files, Map<String, Object> heatFiles) { - // Create local variables checking to see if we have an environment, nested, get_files - // Could later add some checks to see if it's valid. - boolean haveEnvtVariable = true; - if (environment == null || "".equalsIgnoreCase(environment.trim())) { - haveEnvtVariable = false; - logger.debug("createStackParam called with no environment variable"); - } else { - logger.debug("createStackParam called with an environment variable: {}", environment); - } - - boolean haveFiles = true; - if (files == null || files.isEmpty()) { - haveFiles = false; - logger.debug("createStackParam called with no files / child template ids"); - } else { - logger.debug("createStackParam called with {} files / child template ids", files.size()); - } - - boolean haveHeatFiles = true; - if (heatFiles == null || heatFiles.isEmpty()) { - haveHeatFiles = false; - logger.debug("createStackParam called with no heatFiles"); - } else { - logger.debug("createStackParam called with {} heatFiles", heatFiles.size()); - } - // force entire stackInput object to generic Map<String, Object> for openstack compatibility ObjectMapper mapper = new ObjectMapper(); Map<String, Object> normalized = new HashMap<>(); @@ -370,6 +348,28 @@ public class MsoCommonUtils { logger.debug("could not map json", e1); } + CreateStackParam stack = + createStack(stackName, heatTemplate, timeoutMinutes, environment, files, heatFiles, normalized); + + // 1802 - attempt to add better formatted printout of request to openstack + try { + Map<String, Object> inputs = new HashMap<>(); + for (Entry<String, ?> entry : stackInputs.entrySet()) { + if (entry.getValue() != null) { + inputs.put(entry.getKey(), entry.getValue()); + } + } + logger.debug("stack request: {}", stack); + } catch (Exception e) { + // that's okay - this is a nice-to-have + logger.debug("(had an issue printing nicely formatted request to debuglog) {}", e); + } + + return stack; + } + + private CreateStackParam createStack(String stackName, String heatTemplate, int timeoutMinutes, String environment, + Map<String, Object> files, Map<String, Object> heatFiles, Map<String, Object> normalized) { // Build up the stack to create // Disable auto-rollback, because error reason is lost. Always rollback in the code. CreateStackParam stack = new CreateStackParam(); @@ -379,13 +379,13 @@ public class MsoCommonUtils { stack.setTemplate(heatTemplate); stack.setDisableRollback(true); // TJM New for PO Adapter - add envt variable - if (haveEnvtVariable) { + if (isEnvVariablePresent(environment)) { logger.debug("Found an environment variable - value: {}", environment); stack.setEnvironment(environment); } // Now handle nested templates or get_files - have to combine if we have both // as they're both treated as "files:" on the stack. - if (haveFiles && haveHeatFiles) { + if (isFilesPresent(files) && isHeatFilesPresent(heatFiles)) { // Let's do this here - not in the bean logger.debug("Found files AND heatFiles - combine and add!"); Map<String, Object> combinedFiles = new HashMap<>(); @@ -398,32 +398,50 @@ public class MsoCommonUtils { stack.setFiles(combinedFiles); } else { // Handle if we only have one or neither: - if (haveFiles) { + if (isFilesPresent(files)) { logger.debug("Found files - adding to stack"); stack.setFiles(files); } - if (haveHeatFiles) { + if (isHeatFilesPresent(heatFiles)) { logger.debug("Found heatFiles - adding to stack"); // the setFiles was modified to handle adding the entries stack.setFiles(heatFiles); } } + return stack; + } - // 1802 - attempt to add better formatted printout of request to openstack - try { - Map<String, Object> inputs = new HashMap<>(); - for (Entry<String, ?> entry : stackInputs.entrySet()) { - if (entry.getValue() != null) { - inputs.put(entry.getKey(), entry.getValue()); - } - } - logger.debug("stack request: {}", stack.toString()); - } catch (Exception e) { - // that's okay - this is a nice-to-have - logger.debug("(had an issue printing nicely formatted request to debuglog) {}", e.getMessage()); + private boolean isEnvVariablePresent(String environment) { + boolean haveEnvVariable = true; + if (environment == null || "".equalsIgnoreCase(environment.trim())) { + haveEnvVariable = false; + logger.debug("createStackParam called with no environment variable"); + } else { + logger.debug("createStackParam called with an environment variable: {}", environment); } + return haveEnvVariable; + } - return stack; + private boolean isFilesPresent(Map<String, Object> files) { + boolean haveFile = true; + if (files == null || files.isEmpty()) { + haveFile = false; + logger.debug("createStackParam called with no files / child template ids"); + } else { + logger.debug("createStackParam called with {} files / child template ids", files.size()); + } + return haveFile; + } + + private boolean isHeatFilesPresent(Map<String, Object> heatFiles) { + boolean haveHeatFile = true; + if (heatFiles == null || heatFiles.isEmpty()) { + haveHeatFile = false; + logger.debug("createStackParam called with no heatFiles"); + } else { + logger.debug("createStackParam called with {} heatFiles", heatFiles.size()); + } + return haveHeatFile; } |