From 7bc86774af4b54478aa00e3554b1a6c868d983dc Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 22 Nov 2017 18:46:42 +0530 Subject: NovaServerGroupResourceValidator This task is about updating error messages with error codes for NovaServerGroupResourceValidator Change-Id: I72efa7954e846a094268dbda4399bea9c841305d Issue-ID: SDC-572 Signed-off-by: mojahidi --- .../NovaServerGroupResourceValidator.java | 74 ++++++++++++---------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java index f56d941ba4..a9cbbe565e 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerGroupResourceValidator.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.validation.impl.validators.heatresource; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.validation.ErrorMessageCode; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; import org.openecomp.sdc.common.errors.Messages; @@ -25,12 +26,15 @@ import java.util.Objects; */ public class NovaServerGroupResourceValidator implements ResourceValidator { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final ErrorMessageCode ERROR_CODE_HNG1 = new ErrorMessageCode("HNG1"); + private static final ErrorMessageCode ERROR_CODE_HNG2 = new ErrorMessageCode("HNG2"); + private static final ErrorMessageCode ERROR_CODE_HNG3 = new ErrorMessageCode("HNG3"); public void validate(String fileName, Map.Entry resourceEntry, GlobalValidationContext globalContext, ValidationContext validationContext) { validateNovaServerGroupPolicy(fileName, resourceEntry, globalContext); - validateServerGroupIsUsed - (fileName, resourceEntry, globalContext, (HeatResourceValidationContext) validationContext); + validateServerGroupIsUsed(fileName, resourceEntry, globalContext, + (HeatResourceValidationContext) validationContext); } @SuppressWarnings("unchecked") @@ -42,7 +46,7 @@ public class NovaServerGroupResourceValidator implements ResourceValidator { Resource resource = resourceEntry.getValue(); Object policies = - resource.getProperties() == null ? null : resource.getProperties().get("policies"); + resource.getProperties() == null ? null : resource.getProperties().get("policies"); if (Objects.nonNull(policies) && policies instanceof List) { List policiesList = (List) policies; @@ -50,17 +54,19 @@ public class NovaServerGroupResourceValidator implements ResourceValidator { Object policy = policiesList.get(0); if (!isGivenPolicyValid(policy)) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), - resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_NOVA_SEVER_GROUP_POLICY, - LoggerErrorDescription.WRONG_POLICY_SERVER_GROUP); + .getErrorWithParameters( + ERROR_CODE_HNG1, Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_NOVA_SEVER_GROUP_POLICY, + LoggerErrorDescription.WRONG_POLICY_SERVER_GROUP); } } else { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), - resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_NOVA_SEVER_GROUP_POLICY, - LoggerErrorDescription.WRONG_POLICY_SERVER_GROUP); + .getErrorWithParameters(ERROR_CODE_HNG1, + Messages.WRONG_POLICY_IN_SERVER_GROUP.getErrorMessage(), + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_NOVA_SEVER_GROUP_POLICY, + LoggerErrorDescription.WRONG_POLICY_SERVER_GROUP); } } @@ -83,45 +89,43 @@ public class NovaServerGroupResourceValidator implements ResourceValidator { HeatResourceValidationContext validationContext) { Map>> pointedServerGroups = - validationContext.getFileLevelResourceDependencies().get(HeatResourcesTypes - .NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource()); + validationContext.getFileLevelResourceDependencies().get(HeatResourcesTypes + .NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource()); if (MapUtils.isEmpty(pointedServerGroups)) { globalContext - .addMessage( - fileName, - ErrorLevel.WARNING, - ErrorMessagesFormatBuilder - .getErrorWithParameters( - Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), - ValidatorConstants.Server_Group, resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE, - LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE); + .addMessage( + fileName, + ErrorLevel.WARNING, + ErrorMessagesFormatBuilder + .getErrorWithParameters( + ERROR_CODE_HNG2, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), + ValidatorConstants.Server_Group, resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE, + LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE); return; } handleServerGroupReferences(fileName, resourceEntry, pointedServerGroups, globalContext); - - } private void handleServerGroupReferences(String fileName, Map.Entry - resourceEntry, Map>> pointedServerGroups, + resourceEntry, Map>> pointedServerGroups, GlobalValidationContext globalContext) { Map> resourcesPointingToCurrServerGroup = - pointedServerGroups.get(resourceEntry.getKey()); + pointedServerGroups.get(resourceEntry.getKey()); if (MapUtils.isEmpty(resourcesPointingToCurrServerGroup)) { globalContext - .addMessage( - fileName, - ErrorLevel.WARNING, - ErrorMessagesFormatBuilder - .getErrorWithParameters( - Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), - ValidatorConstants.Server_Group, resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE, - LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE); + .addMessage( + fileName, + ErrorLevel.WARNING, + ErrorMessagesFormatBuilder + .getErrorWithParameters( + ERROR_CODE_HNG3, Messages.RESOURCE_NOT_IN_USE.getErrorMessage(), + ValidatorConstants.Server_Group, resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_ALL_SERVER_GROUP_OR_SECURITY_GROUP_IN_USE, + LoggerErrorDescription.SERVER_GROUP_SECURITY_GROUP_NOT_IN_USE); } } -- cgit 1.2.3-korg