diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java | 122 |
1 files changed, 44 insertions, 78 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/NeutronPortResourceValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java index a21173a6b2..08177a158e 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.validation.impl.validators.heatresource; import java.util.ArrayList; @@ -33,90 +32,57 @@ import org.openecomp.sdc.validation.ValidationContext; import org.openecomp.sdc.validation.type.HeatResourceValidationContext; public class NeutronPortResourceValidator implements ResourceValidator { - private static final ErrorMessageCode ERROR_HPRODE_HPR1 = new ErrorMessageCode("HPR1"); - private static final ErrorMessageCode ERROR_HPRODE_HPR2 = new ErrorMessageCode("HPR2"); - private static final ErrorMessageCode ERROR_HPRODE_HPR3 = new ErrorMessageCode("HPR3"); - - @Override - public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, - GlobalValidationContext globalContext, ValidationContext validationContext) { - - validateNovaServerPortBinding(fileName, - resourceEntry, (HeatResourceValidationContext) validationContext, globalContext); - } - - @SuppressWarnings("unchecked") - private static void validateNovaServerPortBinding(String fileName, - Map.Entry<String, Resource> resourceEntry, - HeatResourceValidationContext heatResourceValidationContext, - GlobalValidationContext globalContext) { - Map<String, Map<String, List<String>>> portIdToPointingResources = - heatResourceValidationContext.getFileLevelResourceDependencies() - .get(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()); - - String portResourceId = resourceEntry.getKey(); - if (MapUtils.isEmpty(portIdToPointingResources)) { - globalContext - .addMessage(fileName, ErrorLevel.WARNING, - ErrorMessagesFormatBuilder - .getErrorWithParameters( - ERROR_HPRODE_HPR1, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), - portResourceId)); - - return; + private static final ErrorMessageCode ERROR_HPRODE_HPR1 = new ErrorMessageCode("HPR1"); + private static final ErrorMessageCode ERROR_HPRODE_HPR2 = new ErrorMessageCode("HPR2"); + private static final ErrorMessageCode ERROR_HPRODE_HPR3 = new ErrorMessageCode("HPR3"); + + @SuppressWarnings("unchecked") + private static void validateNovaServerPortBinding(String fileName, Map.Entry<String, Resource> resourceEntry, + HeatResourceValidationContext heatResourceValidationContext, + GlobalValidationContext globalContext) { + Map<String, Map<String, List<String>>> portIdToPointingResources = heatResourceValidationContext.getFileLevelResourceDependencies() + .get(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()); + String portResourceId = resourceEntry.getKey(); + if (MapUtils.isEmpty(portIdToPointingResources)) { + globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_HPRODE_HPR1, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), portResourceId)); + return; + } + Map<String, List<String>> pointingResourcesToCurrPort = portIdToPointingResources.get(portResourceId); + checkPortBindingFromMap(fileName, portResourceId, pointingResourcesToCurrPort, globalContext); } - Map<String, List<String>> pointingResourcesToCurrPort = - portIdToPointingResources.get(portResourceId); - checkPortBindingFromMap( - fileName, portResourceId, pointingResourcesToCurrPort, globalContext); - } - - private static void checkPortBindingFromMap(String fileName, - String portResourceId, - Map<String, List<String>> resourcesPointingToCurrPort, - GlobalValidationContext globalContext) { - List<String> pointingNovaServers = - MapUtils.isEmpty(resourcesPointingToCurrPort) ? new ArrayList<>() - : resourcesPointingToCurrPort.get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()); - - handleErrorEventsForPortBinding( - fileName, portResourceId, globalContext, pointingNovaServers); - - - } + private static void checkPortBindingFromMap(String fileName, String portResourceId, Map<String, List<String>> resourcesPointingToCurrPort, + GlobalValidationContext globalContext) { + List<String> pointingNovaServers = MapUtils.isEmpty(resourcesPointingToCurrPort) ? new ArrayList<>() + : resourcesPointingToCurrPort.get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()); + handleErrorEventsForPortBinding(fileName, portResourceId, globalContext, pointingNovaServers); + } - private static void handleErrorEventsForPortBinding(String fileName, - String portResourceId, - GlobalValidationContext globalContext, - List<String> pointingNovaServers) { - if (isThereMoreThanOneBindFromNovaToPort(pointingNovaServers)) { - globalContext - .addMessage(fileName, ErrorLevel.ERROR, - ErrorMessagesFormatBuilder - .getErrorWithParameters( - ERROR_HPRODE_HPR2, - Messages.MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT.getErrorMessage(), - portResourceId)); + private static void handleErrorEventsForPortBinding(String fileName, String portResourceId, GlobalValidationContext globalContext, + List<String> pointingNovaServers) { + if (isThereMoreThanOneBindFromNovaToPort(pointingNovaServers)) { + globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_HPRODE_HPR2, Messages.MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT.getErrorMessage(), portResourceId)); + } + if (isNoNovaPointingToPort(pointingNovaServers)) { + globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_HPRODE_HPR3, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), portResourceId)); + } } - if (isNoNovaPointingToPort(pointingNovaServers)) { - globalContext - .addMessage(fileName, ErrorLevel.WARNING, - ErrorMessagesFormatBuilder - .getErrorWithParameters( - ERROR_HPRODE_HPR3, Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), - portResourceId)); + private static boolean isNoNovaPointingToPort(List<String> pointingNovaServers) { + return CollectionUtils.isEmpty(pointingNovaServers); } - } - private static boolean isNoNovaPointingToPort(List<String> pointingNovaServers) { - return CollectionUtils.isEmpty(pointingNovaServers); - } + private static boolean isThereMoreThanOneBindFromNovaToPort(List<String> pointingNovaServers) { + return CollectionUtils.isNotEmpty(pointingNovaServers) && pointingNovaServers.size() > 1; + } - private static boolean isThereMoreThanOneBindFromNovaToPort(List<String> pointingNovaServers) { - return CollectionUtils.isNotEmpty(pointingNovaServers) - && pointingNovaServers.size() > 1; - } + @Override + public void validate(String fileName, Map.Entry<String, Resource> resourceEntry, GlobalValidationContext globalContext, + ValidationContext validationContext) { + validateNovaServerPortBinding(fileName, resourceEntry, (HeatResourceValidationContext) validationContext, globalContext); + } } |