diff options
author | Abhai Singh <Abhai.Singh@amdocs.com> | 2017-11-20 18:27:50 +0530 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-11-20 16:17:18 +0000 |
commit | 66ed5840294585b55bc632944f19b859d389b3d2 (patch) | |
tree | 1e870df0ce3985b3287d053abf620ebee99e18f6 /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main | |
parent | 746d3c490eaf8c92ca6125be97371720f4c8f7c9 (diff) |
Adding error codes to HEAT Validator
Added error code to SharedResourceGuideLineValidator
Issue-Id :SDC-572
Change-Id: I20c014a1aeb488788bc1faeb05a89ff920258275
Signed-off-by: Abhai Singh <Abhai.Singh@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java | 63 |
1 files changed, 55 insertions, 8 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java index 04771e023e..424f8d3517 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/SharedResourceGuideLineValidator.java @@ -1,6 +1,9 @@ package org.openecomp.sdc.validation.impl.validators; import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.validation.ErrorMessageCode; +import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.validation.Validator; @@ -30,6 +33,12 @@ import java.util.Set; public class SharedResourceGuideLineValidator implements Validator { public static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); + private static final ErrorMessageCode ERROR_CODE_SRG_1 = new ErrorMessageCode("SRG1"); + private static final ErrorMessageCode ERROR_CODE_SRG_2 = new ErrorMessageCode("SRG2"); + private static final ErrorMessageCode ERROR_CODE_SRG_3 = new ErrorMessageCode("SRG3"); + private static final ErrorMessageCode ERROR_CODE_SRG_4 = new ErrorMessageCode("SRG4"); + private static final ErrorMessageCode ERROR_CODE_SRG_5 = new ErrorMessageCode("SRG5"); + private static final ErrorMessageCode ERROR_CODE_SRG_6 = new ErrorMessageCode("SRG6"); @Override public void validate(GlobalValidationContext globalContext) { @@ -41,7 +50,7 @@ public class SharedResourceGuideLineValidator implements Validator { return; } - Set<String> baseFiles = ValidationUtil.validateManifest(manifestContent, globalContext); + Set<String> baseFiles = validateManifest(manifestContent, globalContext); Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent); Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent); @@ -55,10 +64,47 @@ public class SharedResourceGuideLineValidator implements Validator { } + private Set<String> validateManifest(ManifestContent manifestContent, + GlobalValidationContext globalContext) { + mdcDataDebugMessage.debugEntryMessage("file", SdcCommon.MANIFEST_NAME); + Set<String> baseFiles = ManifestUtil.getBaseFiles(manifestContent); + if (baseFiles == null || baseFiles.size() == 0) { + globalContext.addMessage( + SdcCommon.MANIFEST_NAME, + ErrorLevel.WARNING, + ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_CODE_SRG_3,Messages + .MISSIN_BASE_HEAT_FILE.getErrorMessage()), + LoggerTragetServiceName.VALIDATE_BASE_FILE, + LoggerErrorDescription.MISSING_BASE_HEAT); + } else if (baseFiles.size() > 1) { + String baseFileList = getElementListAsString(baseFiles); + globalContext.addMessage( + SdcCommon.MANIFEST_NAME, + ErrorLevel.WARNING, + ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_CODE_SRG_4,Messages + .MULTI_BASE_HEAT_FILE.getErrorMessage(), + baseFileList), + LoggerTragetServiceName.VALIDATE_BASE_FILE, + LoggerErrorDescription.MULTI_BASE_HEAT); + } + mdcDataDebugMessage.debugExitMessage("file", SdcCommon.MANIFEST_NAME); + return baseFiles; + } + + private static String getElementListAsString(Set<String> elementCollection) { + return "[" + + CommonMethods.collectionToCommaSeparatedString(elementCollection) + + "]"; + } + private void validate(String fileName, String envFileName, Map<String, FileData.Type> fileTypeMap, Set<String> baseFiles, GlobalValidationContext globalContext) { + globalContext.setMessageCode(ERROR_CODE_SRG_5); HeatOrchestrationTemplate - heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext); + heatOrchestrationTemplate = ValidationUtil + .checkHeatOrchestrationPreCondition(fileName, globalContext); if (heatOrchestrationTemplate == null) { return; } @@ -88,15 +134,15 @@ public class SharedResourceGuideLineValidator implements Validator { } Set<String> expectedExposedResources = new HashSet<>(); - Set<String> actualExposedResources = new HashSet<>(); heatOrchestrationTemplate.getResources() .entrySet() .stream() .filter(entry -> ValidationUtil.isExpectedToBeExposed(entry.getValue().getType())) .forEach(entry -> expectedExposedResources.add(entry.getKey())); + Set<String> actualExposedResources = new HashSet<>(); if (heatOrchestrationTemplate.getOutputs() != null) { - + globalContext.setMessageCode(ERROR_CODE_SRG_6); heatOrchestrationTemplate.getOutputs().entrySet() .stream() .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(), @@ -105,7 +151,6 @@ public class SharedResourceGuideLineValidator implements Validator { getResourceIdFromPropertyValue(fileName, entry.getValue().getValue(), globalContext))); } - ValidationUtil.removeExposedResourcesCalledByGetResource(fileName, actualExposedResources, heatOrchestrationTemplate, globalContext); @@ -117,7 +162,8 @@ public class SharedResourceGuideLineValidator implements Validator { .forEach(name -> globalContext.addMessage( fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.RESOURCE_NOT_DEFINED_IN_OUTPUT.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_SRG_1,Messages + .RESOURCE_NOT_DEFINED_IN_OUTPUT.getErrorMessage(), name), LoggerTragetServiceName.VALIDATE_BASE_FILE, LoggerErrorDescription.RESOURCE_NOT_DEFINED_AS_OUTPUT)); @@ -156,7 +202,7 @@ public class SharedResourceGuideLineValidator implements Validator { .forEach(entry -> expectedExposedResources.add(entry.getKey())); if (heatOrchestrationTemplate.getOutputs() != null) { - + globalContext.setMessageCode(ERROR_CODE_SRG_6); heatOrchestrationTemplate.getOutputs().entrySet() .stream() .filter(entry -> isPropertyValueGetResource(fileName, entry.getValue().getValue(), @@ -174,7 +220,8 @@ public class SharedResourceGuideLineValidator implements Validator { .forEach(name -> globalContext.addMessage( fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.VOLUME_HEAT_NOT_EXPOSED.getErrorMessage(), name), + .getErrorWithParameters(ERROR_CODE_SRG_2,Messages + .VOLUME_HEAT_NOT_EXPOSED.getErrorMessage(), name), LoggerTragetServiceName.VALIDATE_VOLUME_FILE, LoggerErrorDescription.VOLUME_FILE_NOT_EXPOSED)); } |