summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2017-11-22 18:02:49 +0530
committermojahidi <mojahidul.islam@amdocs.com>2017-11-22 18:03:04 +0530
commit5650c6a9b50287d572e8e040085d0ce2100a82a1 (patch)
tree2a91990a512eb857b9493521a1818e2d664baee1 /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java
parent683b6a8e84dfe3f205dcc2ef55e1d170579f8831 (diff)
Heat Validator
This task is about updating error messages with error codes for HeatValidator Change-Id: I80d918e4ae0541c194634e744545d705907d8e15 Issue-ID: SDC-572 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java184
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java233
2 files changed, 217 insertions, 200 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
index 39362c7e10..d59d0a8def 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.validation.impl.util;
import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.tosca.services.YamlUtil;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
@@ -30,11 +29,8 @@ import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes;
import org.openecomp.sdc.heat.datatypes.model.Environment;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.heat.datatypes.model.Output;
import org.openecomp.sdc.heat.datatypes.model.Parameter;
import org.openecomp.sdc.heat.datatypes.model.Resource;
-import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
-import org.openecomp.sdc.heat.services.HeatStructureUtil;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
@@ -57,6 +53,7 @@ import java.util.Set;
public class HeatValidationService {
private static final Logger logger = (Logger) LoggerFactory.getLogger(HeatValidator.class);
+ private static final String NESTED_FILE = "nested file";
private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
/**
@@ -77,8 +74,9 @@ public class HeatValidationService {
.forEach(artifactName -> {
globalContext.addMessage(fileName,
ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_ARTIFACT.getErrorMessage(),
- artifactName), LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE,
+ .getErrorWithParameters(globalContext.getMessageCode(),Messages.MISSING_ARTIFACT.getErrorMessage()
+ ,artifactName),
+ LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE,
LoggerErrorDescription.MISSING_FILE);
});
@@ -86,86 +84,6 @@ public class HeatValidationService {
}
/**
- * Check resource existence from resources map.
- *
- * @param fileName the file name
- * @param resourcesNames the resources names
- * @param valuesToSearchIn the values to search in
- * @param globalContext the global context
- */
- public static void checkResourceExistenceFromResourcesMap(String fileName,
- Set<String> resourcesNames,
- Collection<?> valuesToSearchIn,
- GlobalValidationContext globalContext) {
-
-
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
-
- if (CollectionUtils.isNotEmpty(valuesToSearchIn)) {
- for (Object value : valuesToSearchIn) {
- if (value instanceof Resource) {
- Resource resource = (Resource) value;
-
- Collection<Object> resourcePropertiesValues =
- resource.getProperties() == null ? null : resource.getProperties().values();
- if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) {
- for (Object propertyValue : resourcePropertiesValues) {
- handleReferencedResources(fileName, propertyValue, resourcesNames, globalContext);
- }
- }
- } else if (value instanceof Output) {
- Output output = (Output) value;
- Object outputsValue = output.getValue();
- handleReferencedResources(fileName, outputsValue, resourcesNames, globalContext);
- }
- }
- }
-
- mdcDataDebugMessage.debugExitMessage("file", fileName);
- }
-
- private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn,
- Set<String> resourcesNames,
- GlobalValidationContext globalContext) {
-
-
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
-
- Set<String> referencedResourcesNames = HeatStructureUtil
- .getReferencedValuesByFunctionName(fileName,
- ResourceReferenceFunctions.GET_RESOURCE.getFunction(), valueToSearchReferencesIn,
- globalContext);
- if (CollectionUtils.isNotEmpty(referencedResourcesNames)) {
- checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames,
- globalContext);
- }
-
- mdcDataDebugMessage.debugExitMessage("file", fileName);
- }
-
- private static void checkIfResourceReferenceExist(String fileName,
- Set<String> referencedResourcesNames,
- Set<String> referencedResources,
- GlobalValidationContext globalContext) {
-
-
- mdcDataDebugMessage.debugEntryMessage("file", fileName);
-
- referencedResources.stream()
- .filter(referencedResource -> !referencedResourcesNames.contains(referencedResource))
- .forEach(referencedResource -> {
- globalContext.addMessage(fileName,
- ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(),
- referencedResource),
- LoggerTragetServiceName.VALIDATE_RESOURCE_REFERENCE_EXISTENCE,
- LoggerErrorDescription.RESOURCE_NOT_FOUND);
- });
-
- mdcDataDebugMessage.debugExitMessage("file", fileName);
- }
-
- /**
* Draw files loop string.
*
* @param filesInPath the files in path
@@ -267,7 +185,7 @@ public class HeatValidationService {
Set<String> nestedParametersNames,
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
if (CollectionUtils.isNotEmpty(nestedParametersNames)) {
resourceFileProperties
@@ -282,7 +200,7 @@ public class HeatValidationService {
LoggerErrorDescription.MISSING_PARAMETER_IN_NESTED));
}
- mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
}
@@ -295,7 +213,7 @@ public class HeatValidationService {
GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
Map<String, Object> properties = resource.getProperties();
for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
@@ -314,7 +232,7 @@ public class HeatValidationService {
}
}
- mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
}
private static void validateStaticValueForNestedInputParameter(String parentFileName,
@@ -327,7 +245,7 @@ public class HeatValidationService {
globalContext) {
- mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName);
if (parameterInNested == null) {
return;
@@ -342,7 +260,7 @@ public class HeatValidationService {
LoggerErrorDescription.WRONG_VALUE_ASSIGNED_NESTED_PARAMETER);
}
- mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName);
+ mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName);
}
@@ -403,92 +321,10 @@ public class HeatValidationService {
return false;
}
-
- /**
- * Loop over output map and validate get attr from nested.
- *
- * @param fileName the file name
- * @param outputMap the output map
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param globalContext the global context
- */
- @SuppressWarnings("unchecked")
- public static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName,
- Map<String, Output> outputMap,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate,
- GlobalValidationContext
- globalContext) {
- for (Output output : outputMap.values()) {
- Object outputValue = output.getValue();
- if (outputValue != null && outputValue instanceof Map) {
- Map<String, Object> outputValueMap = (Map<String, Object>) outputValue;
- List<String> getAttrValue =
- (List<String>) outputValueMap.get(ResourceReferenceFunctions.GET_ATTR.getFunction());
- if (!CollectionUtils.isEmpty(getAttrValue)) {
- String resourceName = getAttrValue.get(0);
- Object attNameObject = getAttrValue.get(1);
- if (!(attNameObject instanceof String)) {
- return;
- }
- String attName = getAttrValue.get(1);
- String resourceType =
- getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate);
-
- if (Objects.nonNull(resourceType)
- && isNestedResource(resourceType)) {
- handleGetAttrNestedResource(fileName, globalContext, resourceName, attName,
- resourceType);
- }
- }
- }
- }
- }
-
- private static void handleGetAttrNestedResource(String fileName,
- GlobalValidationContext globalContext,
- String resourceName, String attName,
- String resourceType) {
- Map<String, Output> nestedOutputMap;
- HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
- try {
- Optional<InputStream> fileContent = globalContext.getFileContent(resourceType);
- if (fileContent.isPresent()) {
- nestedHeatOrchestrationTemplate =
- new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
- } else {
- MdcDataErrorMessage
- .createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
- LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED,
- ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(),
- LoggerErrorDescription.EMPTY_FILE);
- throw new Exception("The file '" + resourceType + "' has no content");
- }
- } catch (Exception exception) {
- logger.debug("",exception);
- return;
- }
- nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs();
-
- if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) {
- globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.GET_ATTR_NOT_FOUND.getErrorMessage(),
- attName, resourceName),
- LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED,
- LoggerErrorDescription.GET_ATTR_NOT_FOUND);
- }
- }
-
public static boolean isNestedResource(String resourceType) {
return resourceType.contains(".yaml") || resourceType.contains(".yml");
}
- private static String getResourceTypeFromResourcesMap(String resourceName,
- HeatOrchestrationTemplate
- heatOrchestrationTemplate) {
- return heatOrchestrationTemplate.getResources().get(resourceName).getType();
- }
-
/**
* Validate env content environment.
*
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
index 5297453369..da87a13eb4 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java
@@ -22,6 +22,11 @@ package org.openecomp.sdc.validation.impl.validators;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.validation.ErrorMessageCode;
+import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
+import org.openecomp.sdc.logging.types.LoggerConstants;
+import org.openecomp.sdc.logging.types.LoggerErrorCode;
+import org.openecomp.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.validation.Validator;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
@@ -48,15 +53,29 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
import org.openecomp.sdc.validation.impl.util.HeatValidationService;
import org.openecomp.sdc.validation.util.ValidationUtil;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.io.InputStream;
+import java.util.*;
public class HeatValidator implements Validator {
public static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
protected static Logger logger = (Logger) LoggerFactory.getLogger(HeatValidator.class);
+ private static final ErrorMessageCode ERROR_CODE_HOT_1 = new ErrorMessageCode("HOT1");
+ private static final ErrorMessageCode ERROR_CODE_HOT_2 = new ErrorMessageCode("HOT2");
+ private static final ErrorMessageCode ERROR_CODE_HOT_3 = new ErrorMessageCode("HOT3");
+ private static final ErrorMessageCode ERROR_CODE_HOT_4 = new ErrorMessageCode("HOT4");
+ private static final ErrorMessageCode ERROR_CODE_HOT_5 = new ErrorMessageCode("HOT5");
+ private static final ErrorMessageCode ERROR_CODE_HOT_6 = new ErrorMessageCode("HOT6");
+ private static final ErrorMessageCode ERROR_CODE_HOT_7 = new ErrorMessageCode("HOT7");
+ private static final ErrorMessageCode ERROR_CODE_HOT_8 = new ErrorMessageCode("HOT8");
+ private static final ErrorMessageCode ERROR_CODE_HOT_9 = new ErrorMessageCode("HOT9");
+ private static final ErrorMessageCode ERROR_CODE_HOT_10 = new ErrorMessageCode("HOT10");
+ private static final ErrorMessageCode ERROR_CODE_HOT_11 = new ErrorMessageCode("HOT11");
+ private static final ErrorMessageCode ERROR_CODE_HOT_12 = new ErrorMessageCode("HOT12");
+ private static final ErrorMessageCode ERROR_CODE_HOT_13 = new ErrorMessageCode("HOT13");
+ private static final ErrorMessageCode ERROR_CODE_HOT_14 = new ErrorMessageCode("HOT14");
+ private static final ErrorMessageCode ERROR_CODE_HOT_15 = new ErrorMessageCode("HOT15");
+ private static final ErrorMessageCode ERROR_CODE_HOT_16 = new ErrorMessageCode("HOT16");
+ private static final ErrorMessageCode ERROR_CODE_HOT_17 = new ErrorMessageCode("HOT17");
private static void validateAllRequiredArtifactsExist(String fileName,
HeatOrchestrationTemplate
@@ -76,10 +95,12 @@ public class HeatValidator implements Validator {
if (CollectionUtils.isNotEmpty(properties)) {
for (Object property : properties) {
if (property instanceof Map) {
+ globalContext.setMessageCode(ERROR_CODE_HOT_14);
Set<String> artifactNames = HeatStructureUtil
.getReferencedValuesByFunctionName(fileName,
ResourceReferenceFunctions.GET_FILE.getFunction(), property, globalContext);
artifacts.addAll(artifactNames);
+ globalContext.setMessageCode(ERROR_CODE_HOT_15);
HeatValidationService.checkArtifactsExistence(fileName, artifactNames, globalContext);
}
}
@@ -105,18 +126,92 @@ public class HeatValidator implements Validator {
: heatOrchestrationTemplate.getResources().values();
Collection<Output> outputsValues = heatOrchestrationTemplate.getOutputs() == null ? null
: heatOrchestrationTemplate.getOutputs().values();
-
- HeatValidationService
- .checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues,
+ checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues,
globalContext);
- HeatValidationService
- .checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues,
+ checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues,
globalContext);
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
+ private static void checkResourceExistenceFromResourcesMap(String fileName,
+ Set<String> resourcesNames,
+ Collection<?> valuesToSearchIn,
+ GlobalValidationContext globalContext) {
+
+ mdcDataDebugMessage.debugEntryMessage("file", fileName);
+
+ if (CollectionUtils.isNotEmpty(valuesToSearchIn)) {
+ for (Object value : valuesToSearchIn) {
+ if (value instanceof Resource) {
+ extractResourceProperty(fileName, resourcesNames, globalContext, (Resource) value);
+ } else if (value instanceof Output) {
+ Output output = (Output) value;
+ Object outputsValue = output.getValue();
+ handleReferencedResources(fileName, outputsValue, resourcesNames,
+ globalContext);
+ }
+ }
+ }
+ }
+
+ private static void extractResourceProperty(String fileName, Set<String> resourcesNames,
+ GlobalValidationContext globalContext,
+ Resource value) {
+ Resource resource = value;
+ Collection<Object> resourcePropertiesValues =
+ resource.getProperties() == null ? null : resource.getProperties()
+ .values();
+ if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) {
+ for (Object propertyValue : resourcePropertiesValues) {
+ handleReferencedResources(fileName, propertyValue, resourcesNames,
+ globalContext);
+ }
+ }
+ }
+
+ private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn,
+ Set<String> resourcesNames,
+ GlobalValidationContext globalContext) {
+
+
+ mdcDataDebugMessage.debugEntryMessage("file", fileName);
+ globalContext.setMessageCode(ERROR_CODE_HOT_13);
+ Set<String> referencedResourcesNames = HeatStructureUtil
+ .getReferencedValuesByFunctionName(fileName,
+ ResourceReferenceFunctions.GET_RESOURCE.getFunction(),
+ valueToSearchReferencesIn, globalContext);
+ if (CollectionUtils.isNotEmpty(referencedResourcesNames)) {
+ checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames,
+ globalContext);
+ }
+
+ mdcDataDebugMessage.debugExitMessage("file", fileName);
+ }
+
+ private static void checkIfResourceReferenceExist(String fileName,
+ Set<String> referencedResourcesNames,
+ Set<String> referencedResources,
+ GlobalValidationContext globalContext) {
+
+
+ mdcDataDebugMessage.debugEntryMessage("file", fileName);
+
+ referencedResources.stream()
+ .filter(referencedResource -> !referencedResourcesNames.contains(referencedResource))
+ .forEach(referencedResource -> {
+ globalContext.addMessage(fileName,
+ ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_16,Messages
+ .REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(), referencedResource),
+ LoggerTragetServiceName.VALIDATE_RESOURCE_REFERENCE_EXISTENCE,
+ LoggerErrorDescription.RESOURCE_NOT_FOUND);
+ });
+
+ mdcDataDebugMessage.debugExitMessage("file", fileName);
+ }
+
/* validation 16 */
private static void validateGetParamPointToParameter(String fileName,
@@ -153,7 +248,6 @@ public class HeatValidator implements Validator {
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
-
private static void validateReferenceParams(String fileName, String resourceName,
Set<String> parametersNamesFromFile,
Set<String> referencedParametersNames,
@@ -166,7 +260,8 @@ public class HeatValidator implements Validator {
if (!isHeatPseudoParameter(parameterName)
&& !parametersNamesFromFile.contains(parameterName)) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(),
+ .getErrorWithParameters(ERROR_CODE_HOT_1,Messages.
+ REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(),
parameterName, resourceName),
LoggerTragetServiceName.VALIDATE_PARAMETER_REFERENCE_EXITENCE,
LoggerErrorDescription.PARAMETER_NOT_FOUND);
@@ -192,13 +287,87 @@ public class HeatValidator implements Validator {
outputMap = heatOrchestrationTemplate.getOutputs();
if (MapUtils.isNotEmpty(outputMap)) {
- HeatValidationService.loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap,
+ loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap,
heatOrchestrationTemplate, globalContext);
}
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
+ private static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName,
+ Map<String, Output> outputMap,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate,
+ GlobalValidationContext
+ globalContext) {
+ for (Output output : outputMap.values()) {
+ Object outputValue = output.getValue();
+ if (outputValue != null && outputValue instanceof Map) {
+ Map<String, Object> outputValueMap = (Map<String, Object>) outputValue;
+ List<String> getAttrValue =
+ (List<String>) outputValueMap.get(
+ ResourceReferenceFunctions.GET_ATTR.getFunction());
+ if (!CollectionUtils.isEmpty(getAttrValue)) {
+ String resourceName = getAttrValue.get(0);
+ Object attNameObject = getAttrValue.get(1);
+ if (!(attNameObject instanceof String)) {
+ return;
+ }
+ String attName = getAttrValue.get(1);
+ String resourceType =
+ getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate);
+
+ if (Objects.nonNull(resourceType)
+ && HeatValidationService.isNestedResource(resourceType)) {
+ handleGetAttrNestedResource(fileName, globalContext, resourceName, attName,
+ resourceType);
+ }
+ }
+ }
+ }
+ }
+
+ private static void handleGetAttrNestedResource(String fileName,
+ GlobalValidationContext globalContext,
+ String resourceName, String attName,
+ String resourceType) {
+ Map<String, Output> nestedOutputMap;
+ HeatOrchestrationTemplate nestedHeatOrchestrationTemplate;
+ try {
+ Optional<InputStream> fileContent = globalContext.getFileContent(resourceType);
+ if (fileContent.isPresent()) {
+ nestedHeatOrchestrationTemplate =
+ new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class);
+ } else {
+ MdcDataErrorMessage
+ .createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
+ LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED,
+ ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(),
+ LoggerErrorDescription.EMPTY_FILE);
+ throw new Exception("The file '" + resourceType + "' has no content");
+ }
+ } catch (Exception exception) {
+ logger.debug("",exception);
+ return;
+ }
+ nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs();
+
+ if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) {
+ globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_17,Messages.
+ GET_ATTR_NOT_FOUND.getErrorMessage(),
+ attName, resourceName),
+ LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED,
+ LoggerErrorDescription.GET_ATTR_NOT_FOUND);
+ }
+ }
+
+ private static String getResourceTypeFromResourcesMap(String resourceName,
+ HeatOrchestrationTemplate
+ heatOrchestrationTemplate) {
+ return heatOrchestrationTemplate.getResources().get(resourceName).getType();
+ }
+
/* validation 17 + */
private static void validateEnvFile(String fileName, String envFileName,
HeatOrchestrationTemplate heatOrchestrationTemplate,
@@ -211,7 +380,7 @@ public class HeatValidator implements Validator {
if (!envFileName.contains(".env")) {
globalContext.addMessage(envFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages
+ .getErrorWithParameters(ERROR_CODE_HOT_2,Messages
.WRONG_ENV_FILE_EXTENSION.getErrorMessage(), envFileName),
LoggerTragetServiceName.VALIDATE_ENV_FILE, LoggerErrorDescription.WRONG_FILE_EXTENSION);
}
@@ -247,7 +416,8 @@ public class HeatValidator implements Validator {
if (parametersNames != null && !parametersNames.contains(envParameter)) {
globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
.getErrorWithParameters(
- Messages.ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile,
+ ERROR_CODE_HOT_3,Messages.
+ ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile,
envParameter), LoggerTragetServiceName.VALIDATE_ENV_FILE,
LoggerErrorDescription.ENV_PARAMETER_NOT_IN_HEAT);
}
@@ -255,7 +425,7 @@ public class HeatValidator implements Validator {
} else {
for (Map.Entry<String, Object> envEntry : envContent.getParameters().entrySet()) {
globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages
+ .getErrorWithParameters(ERROR_CODE_HOT_3,Messages
.ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(),
envFile, envEntry.getKey()), LoggerTragetServiceName.VALIDATE_ENV_FILE,
LoggerErrorDescription.ENV_PARAMETER_NOT_IN_HEAT);
@@ -289,7 +459,8 @@ public class HeatValidator implements Validator {
if (!isValueMatchDefault) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
.getErrorWithParameters(
- Messages.PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
+ ERROR_CODE_HOT_4,Messages.
+ PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
parameterEntry.getKey(), parameterType),
LoggerTragetServiceName.VALIDATE_PARAMTER_DEFAULT_MATCH_TYPE,
LoggerErrorDescription.PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE);
@@ -324,7 +495,8 @@ public class HeatValidator implements Validator {
.isValueIsFromGivenType(parameterEnvValue, parameterType)) {
globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
.getErrorWithParameters(
- Messages.PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
+ ERROR_CODE_HOT_5,Messages.
+ PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(),
parameterName), LoggerTragetServiceName.VALIDATE_ENV_PARAMETER_MATCH_TYPE,
LoggerErrorDescription.PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE);
}
@@ -374,7 +546,9 @@ public class HeatValidator implements Validator {
.filter(fileName -> isManifestArtifact(manifestArtifacts, fileName) &&
isNotArtifact(artifacts, fileName))
.forEach(fileName -> globalContext.addMessage(fileName, ErrorLevel.WARNING,
- Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage(),
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_HOT_11,
+ Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage()),
LoggerTragetServiceName.CHECK_FOR_ORPHAN_ARTIFACTS,
LoggerErrorDescription.ARTIFACT_NOT_REFERENCED));
@@ -393,14 +567,16 @@ public class HeatValidator implements Validator {
private void validate(String fileName, String envFileName, String baseFileName,
Set<String> artifacts, Set<String> securityGroupsNamesFromBaseFileOutputs,
GlobalValidationContext globalContext) {
+ globalContext.setMessageCode(ERROR_CODE_HOT_12);
HeatOrchestrationTemplate
- heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+ heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(
+ fileName, globalContext);
if (heatOrchestrationTemplate != null) {
if (!(fileName.contains(".yaml") || fileName.contains(".yml"))) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages
+ .getErrorWithParameters(ERROR_CODE_HOT_6,Messages
.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(), fileName),
LoggerTragetServiceName.CHECK_FOR_VALID_FILE_EXTENTION,
LoggerErrorDescription.WRONG_FILE_EXTENSION);
@@ -432,7 +608,8 @@ public class HeatValidator implements Validator {
Set<String> resourcesNames = resourcesMap.keySet();
resourcesMap.entrySet().stream()
- .forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(), resourcesNames, globalContext));
+ .forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(),
+ resourcesNames, globalContext));
}
@SuppressWarnings("unchecked")
@@ -450,13 +627,15 @@ public class HeatValidator implements Validator {
.filter(resource_id -> !resourcesNames.contains(resource_id))
.forEach(resource_id -> globalContext.addMessage(fileName, ErrorLevel.ERROR,
ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(),
+ .getErrorWithParameters(ERROR_CODE_HOT_7,Messages.
+ MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(),
(String) resource_id), LoggerTragetServiceName.CHECK_RESOURCE_DEPENDS_ON,
LoggerErrorDescription.MISSING_RESOURCE_DEPENDS_ON));
} else if (dependencies instanceof String) {
if (!resourcesNames.contains(dependencies)) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(),
+ .getErrorWithParameters(ERROR_CODE_HOT_8,Messages.
+ MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(),
(String) dependencies), LoggerTragetServiceName.CHECK_RESOURCE_DEPENDS_ON,
LoggerErrorDescription.MISSING_RESOURCE_DEPENDS_ON);
}
@@ -475,14 +654,16 @@ public class HeatValidator implements Validator {
if (heatOrchestrationTemplate.getHeat_template_version() == null) {
globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
+ .getErrorWithParameters(ERROR_CODE_HOT_9,Messages.
+ INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
"missing template version"), LoggerTragetServiceName.VALIDATE_HEAT_FORMAT,
LoggerErrorDescription.INVALID_HEAT_FORMAT);
}
if (heatOrchestrationTemplate.getResources() == null
|| heatOrchestrationTemplate.getResources().size() == 0) {
globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
+ .getErrorWithParameters(ERROR_CODE_HOT_10,Messages.
+ INVALID_HEAT_FORMAT_REASON.getErrorMessage(),
"The heat file does not contain any resources"),
LoggerTragetServiceName.VALIDATE_HEAT_FORMAT, LoggerErrorDescription.INVALID_HEAT_FORMAT);
}