port validator 49/23349/3
authortalio <tali.orenbach@amdocs.com>
Mon, 13 Nov 2017 13:29:29 +0000 (15:29 +0200)
committertalio <tali.orenbach@amdocs.com>
Mon, 13 Nov 2017 14:08:11 +0000 (16:08 +0200)
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>
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/heatresource/NeutronPortResourceValidator.java

index 09afec3..bb74907 100644 (file)
@@ -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")