Migrate elanmanager to use LoggingFutures
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / utils / StaleVlanBindingsCleaner.java
index 4bd8aebbebd37d6070b9bc29b40f2d2d9402e581..ea8e50cbf22a7a1ed15fe82826987352583d5127 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.utils;
 
-import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -29,7 +29,7 @@ import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.mdsalutil.MDSALUtil;
 import org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
 import org.opendaylight.netvirt.elan.cache.ElanInstanceCache;
 import org.opendaylight.netvirt.elan.utils.Scheduler;
 import org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache;
@@ -62,8 +62,8 @@ public class StaleVlanBindingsCleaner {
         (validNetworks, logicalSwitch) -> !validNetworks.contains(logicalSwitch);
 
     private static Predicate<TerminationPoint> CONTAINS_VLANBINDINGS = (port) ->
-            port.getAugmentation(HwvtepPhysicalPortAugmentation.class) != null
-                    && port.getAugmentation(HwvtepPhysicalPortAugmentation.class).getVlanBindings() != null;
+            port.augmentation(HwvtepPhysicalPortAugmentation.class) != null
+                    && port.augmentation(HwvtepPhysicalPortAugmentation.class).getVlanBindings() != null;
 
 
     private final DataBroker broker;
@@ -108,9 +108,10 @@ public class StaleVlanBindingsCleaner {
                 () -> {
                     L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
                     NodeId globalNodeId = globalNodeIid.firstKeyOf(Node.class).getNodeId();
-                    Node configNode = MDSALUtil.read(broker, CONFIGURATION, globalNodeIid)
+                    Node configNode = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, globalNodeIid)
                             .or(defaultNode(globalNodeId));
-                    Node configPsNode = MDSALUtil.read(broker, CONFIGURATION, psNodeIid).or(defaultNode(psNodeId));
+                    Node configPsNode =
+                        MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, psNodeIid).or(defaultNode(psNodeId));
                     cleanupStaleLogicalSwitches(l2GwDevice, configNode, configPsNode);
                     cleanupTasks.remove(psNodeIid.firstKeyOf(Node.class).getNodeId());
                 }, getCleanupDelay(), TimeUnit.SECONDS);
@@ -157,11 +158,9 @@ public class StaleVlanBindingsCleaner {
         Map<String, List<InstanceIdentifier<VlanBindings>>> vlans = new HashMap<>();
         ports.stream()
                 .filter(CONTAINS_VLANBINDINGS)
-                .forEach((port) -> {
-                    port.getAugmentation(HwvtepPhysicalPortAugmentation.class)
-                            .getVlanBindings()
-                            .forEach((binding) -> putVlanBindingVsLogicalSwitch(configPsNode, vlans, port, binding));
-                });
+                .forEach((port) -> port.augmentation(HwvtepPhysicalPortAugmentation.class)
+                        .getVlanBindings()
+                        .forEach((binding) -> putVlanBindingVsLogicalSwitch(configPsNode, vlans, port, binding)));
         return vlans;
     }
 
@@ -178,9 +177,9 @@ public class StaleVlanBindingsCleaner {
                                                            final TerminationPoint tp,
                                                            final VlanBindings vlanBinding) {
         return HwvtepSouthboundUtils.createInstanceIdentifier(nodeId)
-                .child(TerminationPoint.class, tp.getKey())
+                .child(TerminationPoint.class, tp.key())
                 .augmentation(HwvtepPhysicalPortAugmentation.class)
-                .child(VlanBindings.class, vlanBinding.getKey());
+                .child(VlanBindings.class, vlanBinding.key());
     }
 
     private void cleanupStaleBindings(final String globalNodeId,
@@ -188,11 +187,10 @@ public class StaleVlanBindingsCleaner {
                                       final String staleLogicalSwitch) {
 
         LOG.trace("CleanupStaleBindings for logical switch {}", staleLogicalSwitch);
-        ListenableFutures.addErrorLogging(
-            txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
+        LoggingFutures.addErrorLogging(
+            txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                 if (vlans.containsKey(staleLogicalSwitch)) {
-                    vlans.get(staleLogicalSwitch)
-                            .forEach((vlanIid) -> tx.delete(LogicalDatastoreType.CONFIGURATION, vlanIid));
+                    vlans.get(staleLogicalSwitch).forEach((vlanIid) -> tx.delete(vlanIid));
                 }
             }),
             LOG, "Failed to delete stale vlan bindings from node {}", globalNodeId);
@@ -200,7 +198,7 @@ public class StaleVlanBindingsCleaner {
     }
 
     private List<String> getLogicalSwitchesOnDevice(final Node globalConfigNode) {
-        HwvtepGlobalAugmentation augmentation = globalConfigNode.getAugmentation(HwvtepGlobalAugmentation.class);
+        HwvtepGlobalAugmentation augmentation = globalConfigNode.augmentation(HwvtepGlobalAugmentation.class);
         if (augmentation == null || augmentation.getLogicalSwitches() == null) {
             return Collections.emptyList();
         }