diff options
author | talio <tali.orenbach@amdocs.com> | 2017-11-13 15:29:29 +0200 |
---|---|---|
committer | talio <tali.orenbach@amdocs.com> | 2017-11-13 16:08:11 +0200 |
commit | b0319352df2a57ae1d3fe4c1e8fb4619e33fb728 (patch) | |
tree | db9b5b2477b152ac28b658a068bc2eeb05a5212a /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java | |
parent | ce113865c2fafa11ef20f56201e2004013bc1169 (diff) |
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 <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/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 | 45 |
1 files 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<String, Map<String, List<String>>> portEntry : - portIdToPointingResources.entrySet()) { - checkPortBindingFromMap(fileName, portEntry, globalContext); - } + Map<String, List<String>> pointingResourcesToCurrPort = + portIdToPointingResources.get(portResourceId); + checkPortBindingFromMap( + fileName, portResourceId, pointingResourcesToCurrPort, globalContext); mdcDataDebugMessage.debugExitMessage("file", fileName); } private static void checkPortBindingFromMap(String fileName, - Map.Entry<String, Map<String, List<String>>> portEntry, + String portResourceId, + Map<String, List<String>> resourcesPointingToCurrPort, GlobalValidationContext globalContext) { - Map<String, List<String>> pointingResourcesToCurrPort = portEntry.getValue(); - List<String> pointingNovaServers = pointingResourcesToCurrPort - .get(HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource()); - - if (CollectionUtils.isEmpty(pointingNovaServers)) { - return; - } + List<String> 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<String, Map<String, List<String>>> portEntry, + String portResourceId, GlobalValidationContext globalContext, List<String> 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<String> pointingNovaServers) { - return pointingNovaServers.size() == 0; + return CollectionUtils.isEmpty(pointingNovaServers); } private static boolean isThereMoreThanOneBindFromNovaToPort(List<String> pointingNovaServers) { - return pointingNovaServers.size() > 1; + return CollectionUtils.isNotEmpty(pointingNovaServers) + && pointingNovaServers.size() > 1; } @SuppressWarnings("unchecked") |