MRI version bumpup for Aluminium
[netvirt.git] / qosservice / impl / src / main / java / org / opendaylight / netvirt / qosservice / QosNeutronUtils.java
index 9ec3309f32438720fb04639981e5d348ac3066f4..50b6f97c5b1c8cf4fcba45c074c304ac762b1f4b 100644 (file)
@@ -10,12 +10,12 @@ 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;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -25,8 +25,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.genius.infra.Datastore;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
@@ -46,6 +45,8 @@ import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
 import org.opendaylight.genius.utils.ServiceIndex;
 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
@@ -484,11 +485,11 @@ public class QosNeutronUtils {
         tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
         try {
             if (writeConfigTxn != null) {
-                writeConfigTxn.merge(InstanceIdentifier
+                writeConfigTxn.mergeParentStructureMerge(InstanceIdentifier
                         .create(NetworkTopology.class)
                         .child(Topology.class, new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID))
                         .child(Node.class, bridgeNode.get().key())
-                        .child(TerminationPoint.class, new TerminationPointKey(tp.key())), tpBuilder.build(), true);
+                        .child(TerminationPoint.class, new TerminationPointKey(tp.key())), tpBuilder.build());
             } else {
                 MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
                         .create(NetworkTopology.class)
@@ -643,12 +644,13 @@ public class QosNeutronUtils {
 
     @Nullable
     private BridgeEntry getBridgeEntryFromConfigDS(InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier) {
-        return MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, dataBroker).orNull();
+        return MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, dataBroker)
+                .orElse(null);
     }
 
     @Nullable
     private BridgeRefEntry getBridgeRefEntryFromOperDS(InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid) {
-        return MDSALUtil.read(LogicalDatastoreType.OPERATIONAL, dpnBridgeEntryIid, dataBroker).orNull();
+        return MDSALUtil.read(LogicalDatastoreType.OPERATIONAL, dpnBridgeEntryIid, dataBroker).orElse(null);
     }
 
     @Nullable
@@ -728,8 +730,14 @@ public class QosNeutronUtils {
 
     public org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
             .@Nullable Interface getInterfaceStateFromOperDS(String interfaceName) {
-        return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL,
-                createInterfaceStateInstanceIdentifier(interfaceName)).orNull();
+        try {
+            return SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL,
+                    createInterfaceStateInstanceIdentifier(interfaceName)).orElse(null);
+        } catch (ExecutionException | InterruptedException e) {
+            LOG.error("getInterfaceStateFromOperDS: Exception while reading interface DS for the interface {}",
+                    interfaceName, e);
+        }
+        return null;
     }
 
     @NonNull
@@ -808,7 +816,7 @@ public class QosNeutronUtils {
         } else {
             Network network = neutronVpnManager.getNeutronNetwork(port.getNetworkId());
 
-            if (network.augmentation(QosNetworkExtension.class) != null) {
+            if (network != null && network.augmentation(QosNetworkExtension.class) != null) {
                 qosUuid = network.augmentation(QosNetworkExtension.class).getQosPolicyId();
             }
         }
@@ -875,7 +883,7 @@ public class QosNeutronUtils {
 
     public int getIpVersions(Port port) {
         int versions = 0;
-        for (FixedIps fixedIp: port.getFixedIps()) {
+        for (FixedIps fixedIp: port.getFixedIps().values()) {
             if (fixedIp.getIpAddress().getIpv4Address() != null) {
                 versions |= (1 << QosConstants.IPV4_ADDR_MASK_BIT);
             } else if (fixedIp.getIpAddress().getIpv6Address() != null) {