Handle nullable lists in qosservice 55/77255/2
authorStephen Kitt <skitt@redhat.com>
Wed, 24 Oct 2018 14:27:42 +0000 (16:27 +0200)
committerSam Hague <shague@redhat.com>
Thu, 25 Oct 2018 22:46:05 +0000 (22:46 +0000)
Following YANGTOOLS-585, lists can be null (which is correctly
indicated with an @Nullable annotation). This patch deals with the
fallout.

Change-Id: Id613950a2c9e0ffb376d8c45b75edbd51cb385bb
Signed-off-by: Stephen Kitt <skitt@redhat.com>
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertEnableCLI.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertPollIntervalCLI.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertThresholdCLI.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronNetworkChangeListener.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronPortChangeListener.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosPolicyChangeListener.java
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosTerminationPointListener.java

index 9e012bb4466c9fcd4117bf9fa171194f987e9a77..5ccf35583435305bc69754325fb0b1616846e328 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -33,6 +34,7 @@ public class QosAlertEnableCLI extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("Setting poll enable in qos alert manager:{}", value);
         qosAlertManager.setEnable(Boolean.parseBoolean(value));
index 998b860172e6f7558f57473814b5c470ded16965..0de3fa07c392f8ce057f12507283ef02fdaa44b0 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -31,6 +32,7 @@ public class QosAlertPollIntervalCLI extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("setting threshold in qos alert manager:{}", interval);
         qosAlertManager.setPollInterval(Integer.parseInt(interval));
index ac59670e05156ae4cfd943f4480beeb631f7db45..dceed36b2d0587530f01eefa60167ae857eff1a7 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import javax.annotation.Nullable;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -31,6 +32,7 @@ public class QosAlertThresholdCLI extends OsgiCommandSupport {
     }
 
     @Override
+    @Nullable
     protected Object doExecute() {
         LOG.debug("setting threshold in qos alert manager:{}", threshold);
         qosAlertManager.setThreshold(Short.parseShort(threshold));
index 8b4b855ee4b583e523e5816dc1b8599471e6db2f..54ffb1558586f0638fa6209d46dd3c5a6c0b96d7 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.qosservice;
 
+import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -81,7 +82,7 @@ public class QosNeutronNetworkChangeListener extends AsyncClusteredDataTreeChang
             qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
             qosNeutronUtils.handleNeutronNetworkQosUpdate(update, updateQos.getQosPolicyId());
         } else if (originalQos != null && updateQos != null
-                && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
+                && !Objects.equals(originalQos.getQosPolicyId(), updateQos.getQosPolicyId())) {
             // qosservice policy update
             qosNeutronUtils.removeFromQosNetworksCache(originalQos.getQosPolicyId(), original);
             qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
index 6925d044a07a93bdc503f3322b22ef0e81edf7b8..62c60fb77ed81cbc3e9515cda10522dcaff97886 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.qosservice;
 
 import java.math.BigInteger;
 import java.util.Collections;
+import java.util.Objects;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -98,7 +99,7 @@ public class QosNeutronPortChangeListener extends AsyncClusteredDataTreeChangeLi
             qosNeutronUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
             qosNeutronUtils.handleNeutronPortQosAdd(update, updateQos.getQosPolicyId());
         } else if (originalQos != null && updateQos != null
-                && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
+                && !Objects.equals(originalQos.getQosPolicyId(), updateQos.getQosPolicyId())) {
 
             // qosservice policy update
             qosNeutronUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
index c48a28a296d0640a99d32e75d512afdc02d98403..01d5001dd42fa6c1f7793201ba9b7a20f42ca126 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netvirt.qosservice;
 
+import static java.util.Collections.emptyList;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import com.google.common.base.Optional;
@@ -150,7 +151,7 @@ public class QosNeutronUtils {
 
     public Collection<Port> getQosPorts(Uuid qosUuid) {
         final ConcurrentMap<Uuid, Port> portMap = qosPortsMap.get(qosUuid);
-        return portMap != null ? portMap.values() : Collections.emptyList();
+        return portMap != null ? portMap.values() : emptyList();
     }
 
     public void addToQosPortsCache(Uuid qosUuid, Port port) {
@@ -177,7 +178,7 @@ public class QosNeutronUtils {
     @Nonnull
     public Collection<Network> getQosNetworks(Uuid qosUuid) {
         final ConcurrentMap<Uuid, Network> networkMap = qosNetworksMap.get(qosUuid);
-        return networkMap != null ? networkMap.values() : Collections.emptyList();
+        return networkMap != null ? networkMap.values() : emptyList();
     }
 
     @Nonnull
@@ -186,7 +187,7 @@ public class QosNeutronUtils {
                 .child(NetworkMap.class, new NetworkMapKey(networkId)).build();
         Optional<NetworkMap> optionalNetworkMap = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION,
                 networkMapId, dataBroker);
-        return optionalNetworkMap.isPresent() ? optionalNetworkMap.get().getSubnetIdList() : Collections.emptyList();
+        return optionalNetworkMap.isPresent() ? nullToEmpty(optionalNetworkMap.get().getSubnetIdList()) : emptyList();
     }
 
     @Nonnull
@@ -196,7 +197,7 @@ public class QosNeutronUtils {
                 .child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
         Optional<Subnetmap> optionalSubnetmap = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION,
                 subnetMapId,dataBroker);
-        return optionalSubnetmap.isPresent() ? optionalSubnetmap.get().getPortList() : Collections.emptyList();
+        return optionalSubnetmap.isPresent() ? nullToEmpty(optionalSubnetmap.get().getPortList()) : emptyList();
     }
 
     public void handleNeutronPortQosAdd(Port port, Uuid qosUuid) {
@@ -232,7 +233,7 @@ public class QosNeutronUtils {
                     && !qosPolicy.getDscpmarkingRules().isEmpty()) {
                 setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0));
             }
-            return Collections.emptyList();
+            return emptyList();
         });
     }
 
@@ -314,7 +315,7 @@ public class QosNeutronUtils {
                     && !qosPolicy.getDscpmarkingRules().isEmpty()) {
                 unsetPortDscpMark(port);
             }
-            return Collections.emptyList();
+            return emptyList();
         });
     }
 
@@ -328,7 +329,7 @@ public class QosNeutronUtils {
                     && !qosPolicy.getDscpmarkingRules().isEmpty()) {
                 unsetPortDscpMark(port, intrf);
             }
-            return Collections.emptyList();
+            return emptyList();
         });
     }
 
@@ -430,7 +431,7 @@ public class QosNeutronUtils {
                         || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) {
                     jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), () -> {
                         unsetPortDscpMark(port);
-                        return Collections.emptyList();
+                        return emptyList();
                     });
                 }
             }
@@ -842,6 +843,7 @@ public class QosNeutronUtils {
         return neutronNetworkMap.get(networkUuid);
     }
 
+    @Nullable
     public static BigInteger getDpnIdFromLowerLayerIf(String lowerLayerIf) {
         try {
             return new BigInteger(lowerLayerIf.substring(lowerLayerIf.indexOf(":") + 1, lowerLayerIf.lastIndexOf(":")));
@@ -850,6 +852,7 @@ public class QosNeutronUtils {
         }
     }
 
+    @Nullable
     public static String getPortNumberFromLowerLayerIf(String lowerLayerIf) {
         try {
             return (lowerLayerIf.substring(lowerLayerIf.lastIndexOf(":") + 1));
@@ -871,16 +874,16 @@ public class QosNeutronUtils {
     }
 
     public boolean hasIpv4Addr(int versions) {
-        if ((versions & (1 << QosConstants.IPV4_ADDR_MASK_BIT)) != 0) {
-            return true;
-        }
-        return false;
+        return (versions & (1 << QosConstants.IPV4_ADDR_MASK_BIT)) != 0;
     }
 
     public boolean hasIpv6Addr(int versions) {
-        if ((versions & (1 << QosConstants.IPV6_ADDR_MASK_BIT)) != 0) {
-            return true;
-        }
-        return false;
+        return (versions & (1 << QosConstants.IPV6_ADDR_MASK_BIT)) != 0;
+    }
+
+    // TODO Replace this with mdsal's DataObjectUtils.nullToEmpty when upgrading to mdsal 3
+    @Nonnull
+    public static <T> List<T> nullToEmpty(final @Nullable List<T> input) {
+        return input != null ? input : emptyList();
     }
 }
index 8f35f718e0906d99677ece4cf2e9b07e6ab24c9a..8a89f922f9194df5614789d3d0de82dfd67ac8cf 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.netvirt.qosservice;
 
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.netvirt.qosservice.QosNeutronUtils.nullToEmpty;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -251,13 +252,13 @@ public class QosPolicyChangeListener extends AsyncClusteredDataTreeChangeListene
             return;
         }
 
-        if (!qosNeutronUtils.getQosPolicyMap().get(policyUuid).getBandwidthLimitRules().isEmpty()) {
+        if (!nullToEmpty(qosNeutronUtils.getQosPolicyMap().get(policyUuid).getBandwidthLimitRules()).isEmpty()) {
             BandwidthLimitRules bandwidthLimitRules =
                     qosNeutronUtils.getQosPolicyMap().get(policyUuid).getBandwidthLimitRules().get(0);
             update(policyUuid, bandwidthLimitRules);
         }
 
-        if (!qosNeutronUtils.getQosPolicyMap().get(policyUuid).getDscpmarkingRules().isEmpty()) {
+        if (!nullToEmpty(qosNeutronUtils.getQosPolicyMap().get(policyUuid).getDscpmarkingRules()).isEmpty()) {
             DscpmarkingRules dscpmarkingRules =
                     qosNeutronUtils.getQosPolicyMap().get(policyUuid).getDscpmarkingRules().get(0);
             update(policyUuid, dscpmarkingRules);
index 07f0c6290f5efd7671756289b56862a30db3372a..f6337bdf33c68c0670fdceb3ed49f5551a465276 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.netvirt.qosservice;
 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import java.util.Collections;
+import javax.annotation.Nullable;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -196,10 +197,11 @@ public class QosTerminationPointListener extends
                 })));
     }
 
+    @Nullable
     private String getIfaceId(OvsdbTerminationPointAugmentation tpAugmentation) {
         if (tpAugmentation.getInterfaceExternalIds() != null) {
             for (InterfaceExternalIds entry: tpAugmentation.getInterfaceExternalIds()) {
-                if (entry.getExternalIdKey().equals(EXTERNAL_ID_INTERFACE_ID)) {
+                if (EXTERNAL_ID_INTERFACE_ID.equals(entry.getExternalIdKey())) {
                     return entry.getExternalIdValue();
                 }
             }