diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src')
2 files changed, 70 insertions, 49 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; } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java index 8207c7c589..97ba7828c0 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java @@ -33,6 +33,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.onap.logging.filter.base.ErrorCode; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.adapters.vdu.CloudInfo; import org.onap.so.adapters.vdu.PluginAction; @@ -45,14 +46,11 @@ import org.onap.so.adapters.vdu.VduPlugin; import org.onap.so.adapters.vdu.VduStateType; import org.onap.so.adapters.vdu.VduStatus; import org.onap.so.cloud.authentication.KeystoneAuthHolder; -import org.onap.so.db.catalog.beans.CloudIdentity; -import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.HeatTemplateParam; import org.onap.so.db.request.beans.CloudApiRequests; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; -import org.onap.logging.filter.base.ErrorCode; import org.onap.so.logger.MessageEnum; import org.onap.so.openstack.beans.CreateStackRequest; import org.onap.so.openstack.beans.HeatStatus; @@ -70,6 +68,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Strings; @@ -1191,7 +1190,11 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin { InfraActiveRequests request = new InfraActiveRequests(); request.setRequestId(requestId); request.setResourceStatusMessage(resourceStatusMessage); - requestDBClient.patchInfraActiveRequests(request); + try { + requestDBClient.patchInfraActiveRequests(request); + } catch (HttpClientErrorException e) { + logger.warn("Unable to update active request resource status"); + } } } |