diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-11-22 18:52:02 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2017-11-23 06:42:21 +0000 |
commit | 49f1676efc2efe8d9e153a61afa692607cb526d3 (patch) | |
tree | f53856957023e3de5f2f13cec4c520fa859bdc67 /openecomp-be/lib/openecomp-sdc-validation-lib | |
parent | 7bc86774af4b54478aa00e3554b1a6c868d983dc (diff) |
NovaServerResourceValidator
This task is about updating error messages with error codes for NovaServerResourceValidator
Change-Id: I90638b7c736b75b8cdadd440dbaafed146eec140
Issue-ID: SDC-572
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib')
2 files changed, 34 insertions, 31 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java index d05f2813ff..9c9f4bcdc0 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidator.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.sdc.validation.ResourceValidator; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; @@ -24,14 +25,16 @@ import java.util.Map; */ public class NovaServerResourceValidator implements ResourceValidator { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final ErrorMessageCode ERROR_CODE_HNS1 = new ErrorMessageCode("HNS1"); + private static final ErrorMessageCode ERROR_CODE_HNS2 = new ErrorMessageCode("HNS2"); public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext, ValidationContext validationContext) { HeatResourceValidationContext heatResourceValidationContext = (HeatResourceValidationContext) - validationContext; + validationContext; validateNovaServerResourceType - (fileName, resourceEntry, heatResourceValidationContext, globalContext); + (fileName, resourceEntry, heatResourceValidationContext, globalContext); } private static void validateNovaServerResourceType(String fileName, @@ -43,8 +46,8 @@ public class NovaServerResourceValidator implements ResourceValidator { validateAssignedValueForImageOrFlavorFromNova(fileName, resourceEntry, globalContext); validateAllServerGroupsPointedByServerExistAndDefined - (fileName, resourceEntry, - heatResourceValidationContext.getHeatOrchestrationTemplate(), globalContext); + (fileName, resourceEntry, + heatResourceValidationContext.getHeatOrchestrationTemplate(), globalContext); mdcDataDebugMessage.debugExitMessage("file", fileName); @@ -52,21 +55,21 @@ public class NovaServerResourceValidator implements ResourceValidator { private static void validateAssignedValueForImageOrFlavorFromNova(String fileName, Map.Entry<String, Resource> - resourceEntry, + resourceEntry, GlobalValidationContext - globalContext) { + globalContext) { mdcDataDebugMessage.debugEntryMessage("file", fileName); Resource resource = resourceEntry.getValue(); Map<String, Object> propertiesMap = resource.getProperties(); if (propertiesMap.get(PropertiesMapKeyTypes.IMAGE.getKeyMap()) == null - && propertiesMap.get(PropertiesMapKeyTypes.FLAVOR.getKeyMap()) == null) { + && propertiesMap.get(PropertiesMapKeyTypes.FLAVOR.getKeyMap()) == null) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_IMAGE_AND_FLAVOR.getErrorMessage(), - resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_ASSIGNED_VALUES_FOR_NOVA_IMAGE_FLAVOR, - LoggerErrorDescription.MISSING_NOVA_PROPERTIES); + .getErrorWithParameters(ERROR_CODE_HNS1, Messages.MISSING_IMAGE_AND_FLAVOR.getErrorMessage(), + resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_ASSIGNED_VALUES_FOR_NOVA_IMAGE_FLAVOR, + LoggerErrorDescription.MISSING_NOVA_PROPERTIES); } mdcDataDebugMessage.debugExitMessage("file", fileName); @@ -83,8 +86,8 @@ public class NovaServerResourceValidator implements ResourceValidator { Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources(); Map<String, Object> resourceProperties = resourceEntry.getValue().getProperties(); Map<String, Object> schedulerHintsMap = - resourceProperties == null ? null : (Map<String, Object>) resourceProperties.get( - ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction()); + resourceProperties == null ? null : (Map<String, Object>) resourceProperties.get( + ResourceReferenceFunctions.SCHEDULER_HINTS.getFunction()); if (MapUtils.isEmpty(schedulerHintsMap)) { return; @@ -99,16 +102,16 @@ public class NovaServerResourceValidator implements ResourceValidator { String serverResourceName = (String) currentServerMap .get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()); Resource serverResource = - serverResourceName == null || resourcesMap == null ? null - : resourcesMap.get(serverResourceName); + serverResourceName == null || resourcesMap == null ? null + : resourcesMap.get(serverResourceName); if (serverResource != null && !serverResource.getType() - .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())) { + .equals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.SERVER_NOT_DEFINED_FROM_NOVA.getErrorMessage(), - serverResourceName, resourceEntry.getKey()), - LoggerTragetServiceName.VALIDATE_SERVER_GROUP_EXISTENCE, - LoggerErrorDescription.SERVER_NOT_DEFINED_NOVA); + .getErrorWithParameters(ERROR_CODE_HNS2, Messages.SERVER_NOT_DEFINED_FROM_NOVA.getErrorMessage(), + serverResourceName, resourceEntry.getKey()), + LoggerTragetServiceName.VALIDATE_SERVER_GROUP_EXISTENCE, + LoggerErrorDescription.SERVER_NOT_DEFINED_NOVA); } } } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidatorTest.java index 94bdf1e52f..1022270a8f 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/heatresource/NovaServerResourceValidatorTest.java @@ -17,37 +17,37 @@ public class NovaServerResourceValidatorTest { HeatResourceValidator baseValidator = new HeatResourceValidator(); NovaServerResourceValidator resourceValidator = new NovaServerResourceValidator(); - + private static final String PATH = "/org/openecomp/validation/validators/heat_validator/"; @Test public void testNovaPropertiesHasAssignedValue() throws IOException { Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator, - resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), - "/org/openecomp/validation/validators/heat_validator/nova_properties_has_assigned_value/negative_test/input"); + resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), + PATH + "nova_properties_has_assigned_value/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( - messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Missing both Image and Flavor in NOVA Server, Resource ID [nova_server_resource_missing_both]"); + messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), + "ERROR: [HNS1]: Missing both Image and Flavor in NOVA Server, Resource ID [nova_server_resource_missing_both]"); } @Test public void testServerGroupsPointedByServersDefinedCorrectly() throws IOException { Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator, - resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), - "/org/openecomp/validation/validators/heat_validator/server_groups_defined_correctly/negative_test/input"); + resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), + PATH + "server_groups_defined_correctly/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2); Assert.assertEquals( - messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Missing server group definition - BE_Affinity_2, nova_server_1"); + messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), + "ERROR: [HNS2]: Missing server group definition - BE_Affinity_2, nova_server_1"); Assert.assertEquals( - messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), - "ERROR: Missing server group definition - BE_Affinity_2, nova_server_2"); + messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), + "ERROR: [HNS2]: Missing server group definition - BE_Affinity_2, nova_server_2"); } } |