From b0319352df2a57ae1d3fe4c1e8fb4619e33fb728 Mon Sep 17 00:00:00 2001 From: talio Date: Mon, 13 Nov 2017 15:29:29 +0200 Subject: port validator fixing neutron port validator to recognize ports that are not connected to any nova server Issue-Id : SDC-654 Change-Id: I5607b0046bb2debe67119b62566b5283f4afeae6 Signed-off-by: talio --- .../heatresource/NeutronPortResourceValidator.java | 45 +++++++++++----------- 1 file changed, 23 insertions(+), 22 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 09afec3faf..bb749079f5 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 @@ -17,6 +17,7 @@ import org.openecomp.sdc.validation.ResourceValidator; import org.openecomp.sdc.validation.ValidationContext; import org.openecomp.sdc.validation.type.HeatResourceValidationContext; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -34,7 +35,7 @@ public class NeutronPortResourceValidator implements ResourceValidator { GlobalValidationContext globalContext, ValidationContext validationContext) { validateNovaServerPortBinding - (fileName, resourceEntry, (HeatResourceValidationContext)validationContext, globalContext); + (fileName, resourceEntry, (HeatResourceValidationContext) validationContext, globalContext); } @@ -50,44 +51,43 @@ public class NeutronPortResourceValidator implements ResourceValidator { heatResourceValidationContext.getFileLevelResourceDependencies() .get(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()); - if(MapUtils.isEmpty(portIdToPointingResources)){ + String portResourceId = resourceEntry.getKey(); + if (MapUtils.isEmpty(portIdToPointingResources)) { globalContext .addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder .getErrorWithParameters( Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), - resourceEntry.getKey()), LoggerTragetServiceName.CHECK_FOR_ORPHAN_PORTS, + portResourceId), LoggerTragetServiceName.CHECK_FOR_ORPHAN_PORTS, LoggerErrorDescription.NO_BIND_FROM_PORT_TO_NOVA); return; } - for (Map.Entry>> portEntry : - portIdToPointingResources.entrySet()) { - checkPortBindingFromMap(fileName, portEntry, globalContext); - } + Map> pointingResourcesToCurrPort = + portIdToPointingResources.get(portResourceId); + checkPortBindingFromMap( + fileName, portResourceId, pointingResourcesToCurrPort, globalContext); mdcDataDebugMessage.debugExitMessage("file", fileName); } private static void checkPortBindingFromMap(String fileName, - Map.Entry>> portEntry, + String portResourceId, + Map> resourcesPointingToCurrPort, GlobalValidationContext globalContext) { - Map> pointingResourcesToCurrPort = portEntry.getValue(); - List pointingNovaServers = pointingResourcesToCurrPort - .get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()); - - if (CollectionUtils.isEmpty(pointingNovaServers)) { - return; - } + List pointingNovaServers = + MapUtils.isEmpty(resourcesPointingToCurrPort) ? new ArrayList<>() + : resourcesPointingToCurrPort.get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()); - handleErrorEventsForPortBinding(fileName, portEntry, globalContext, pointingNovaServers); + handleErrorEventsForPortBinding( + fileName, portResourceId, globalContext, pointingNovaServers); } private static void handleErrorEventsForPortBinding(String fileName, - Map.Entry>> portEntry, + String portResourceId, GlobalValidationContext globalContext, List pointingNovaServers) { if (isThereMoreThanOneBindFromNovaToPort(pointingNovaServers)) { @@ -96,28 +96,29 @@ public class NeutronPortResourceValidator implements ResourceValidator { ErrorMessagesFormatBuilder .getErrorWithParameters( Messages.MORE_THAN_ONE_BIND_FROM_NOVA_TO_PORT.getErrorMessage(), - portEntry.getKey()), + portResourceId), LoggerTragetServiceName.VALIDATE_NOVA_SERVER_PORT_BINDING, LoggerErrorDescription.PORT_BINDS_MORE_THAN_ONE_NOVA); } - if(isNoNovaPointingToPort(pointingNovaServers)){ + if (isNoNovaPointingToPort(pointingNovaServers)) { globalContext .addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder .getErrorWithParameters( Messages.PORT_NO_BIND_TO_ANY_NOVA_SERVER.getErrorMessage(), - portEntry.getKey()), LoggerTragetServiceName.CHECK_FOR_ORPHAN_PORTS, + portResourceId), LoggerTragetServiceName.CHECK_FOR_ORPHAN_PORTS, LoggerErrorDescription.NO_BIND_FROM_PORT_TO_NOVA); } } private static boolean isNoNovaPointingToPort(List pointingNovaServers) { - return pointingNovaServers.size() == 0; + return CollectionUtils.isEmpty(pointingNovaServers); } private static boolean isThereMoreThanOneBindFromNovaToPort(List pointingNovaServers) { - return pointingNovaServers.size() > 1; + return CollectionUtils.isNotEmpty(pointingNovaServers) + && pointingNovaServers.size() > 1; } @SuppressWarnings("unchecked") -- cgit 1.2.3-korg