Port QosService to Datastore-constrained txes 63/73763/2
authorVishal Thapar <vthapar@redhat.com>
Thu, 5 Jul 2018 03:32:00 +0000 (09:02 +0530)
committerVishal Thapar <vthapar@redhat.com>
Thu, 5 Jul 2018 05:17:06 +0000 (10:47 +0530)
JIRA: NETVIRT-1343
Change-Id: I3e80d5dd6139b2cdc6c73a9162c9612650525a17
Signed-off-by: Vishal Thapar <vthapar@redhat.com>
qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertManager.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 f2d0ed6d2aaa29224c79847a6872678a514e1c2e..4f2ddca82ec1d19c3bc5ad084d660f8b0f14ee8f 100644 (file)
@@ -8,6 +8,9 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import java.math.BigInteger;
 import java.util.List;
 import java.util.Map.Entry;
@@ -22,8 +25,6 @@ import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.genius.interfacemanager.globals.IfmConstants;
@@ -279,9 +280,9 @@ public final class QosAlertManager implements Runnable {
                 .setQosAlertPollInterval(alertPollInterval)
                 .build();
 
-        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
-            tx -> tx.put(LogicalDatastoreType.CONFIGURATION, path, qosAlertConfig,
-                    WriteTransaction.CREATE_MISSING_PARENTS)), LOG, "Error writing to the config data store");
+        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+            tx -> tx.put(path, qosAlertConfig,
+                    CREATE_MISSING_PARENTS)), LOG, "Error writing to the config data store");
     }
 
     private void pollDirectStatisticsForAllNodes() {
index a1a77424f9306e697f53408821162966d5aeb082..c48a28a296d0640a99d32e75d512afdc02d98403 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.qosservice;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import com.google.common.base.Optional;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -24,10 +26,11 @@ import javax.annotation.Nullable;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.infra.Datastore;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.genius.infra.TypedWriteTransaction;
 import org.opendaylight.genius.mdsalutil.ActionInfo;
 import org.opendaylight.genius.mdsalutil.FlowEntity;
 import org.opendaylight.genius.mdsalutil.InstructionInfo;
@@ -203,7 +206,7 @@ public class QosNeutronUtils {
         QosPolicy qosPolicy = qosPolicyMap.get(qosUuid);
 
         jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                 // handle Bandwidth Limit Rules update
                 if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null
                         && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
@@ -241,7 +244,7 @@ public class QosNeutronUtils {
         QosPolicy qosPolicyOld = qosPolicyMap.get(qosUuidOld);
 
         jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(),
-            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+            () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                 // handle Bandwidth Limit Rules update
                 if (qosPolicyNew != null && qosPolicyNew.getBandwidthLimitRules() != null
                         && !qosPolicyNew.getBandwidthLimitRules().isEmpty()) {
@@ -282,7 +285,7 @@ public class QosNeutronUtils {
             QosPolicy qosPolicy = qosPolicyMap.get(qosUuid);
 
             jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(),
-                () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                     // handle Bandwidth Limit Rules removal
                     if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null
                             && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
@@ -347,16 +350,17 @@ public class QosNeutronUtils {
                 if (port != null && (port.augmentation(QosPortExtension.class) == null
                         || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) {
                     jobCoordinator.enqueueJob("QosPort-" + portId.getValue(),
-                        () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
-                            if (qosPolicy.getBandwidthLimitRules() != null
-                                    && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
-                                setPortBandwidthLimits(port, qosPolicy.getBandwidthLimitRules().get(0), tx);
-                            }
-                            if (qosPolicy.getDscpmarkingRules() != null
-                                    && !qosPolicy.getDscpmarkingRules().isEmpty()) {
-                                setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0));
-                            }
-                        })));
+                        () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            CONFIGURATION, tx -> {
+                                if (qosPolicy.getBandwidthLimitRules() != null
+                                        && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
+                                    setPortBandwidthLimits(port, qosPolicy.getBandwidthLimitRules().get(0), tx);
+                                }
+                                if (qosPolicy.getDscpmarkingRules() != null
+                                        && !qosPolicy.getDscpmarkingRules().isEmpty()) {
+                                    setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0));
+                                }
+                            })));
                 }
             }
         }
@@ -375,19 +379,20 @@ public class QosNeutronUtils {
                 if (port != null && (port.augmentation(QosPortExtension.class) == null
                         || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) {
                     jobCoordinator.enqueueJob("QosPort-" + portId.getValue(),
-                        () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
-                            if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null
-                                    && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
-                                BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder();
-                                setPortBandwidthLimits(port, bwLimitBuilder
-                                        .setMaxBurstKbps(BigInteger.ZERO)
-                                        .setMaxKbps(BigInteger.ZERO).build(), tx);
-                            }
-                            if (qosPolicy != null && qosPolicy.getDscpmarkingRules() != null
-                                    && !qosPolicy.getDscpmarkingRules().isEmpty()) {
-                                unsetPortDscpMark(port);
-                            }
-                        })));
+                        () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            CONFIGURATION, tx -> {
+                                if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null
+                                        && !qosPolicy.getBandwidthLimitRules().isEmpty()) {
+                                    BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder();
+                                    setPortBandwidthLimits(port, bwLimitBuilder
+                                            .setMaxBurstKbps(BigInteger.ZERO)
+                                            .setMaxKbps(BigInteger.ZERO).build(), tx);
+                                }
+                                if (qosPolicy != null && qosPolicy.getDscpmarkingRules() != null
+                                        && !qosPolicy.getDscpmarkingRules().isEmpty()) {
+                                    unsetPortDscpMark(port);
+                                }
+                            })));
                 }
             }
         }
@@ -405,7 +410,7 @@ public class QosNeutronUtils {
                 if (port != null && (port.augmentation(QosPortExtension.class) == null
                         || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) {
                     jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), () -> Collections.singletonList(
-                            txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                            txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                                 tx -> setPortBandwidthLimits(port, zeroBwLimitRule, tx))));
                 }
             }
@@ -434,7 +439,8 @@ public class QosNeutronUtils {
 
     // TODO Clean up the exception handling
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public void setPortBandwidthLimits(Port port, BandwidthLimitRules bwLimit, WriteTransaction writeConfigTxn) {
+    public void setPortBandwidthLimits(Port port, BandwidthLimitRules bwLimit,
+                                       TypedWriteTransaction<Datastore.Configuration> writeConfigTxn) {
         if (!qosEosHandler.isQosClusterOwner()) {
             LOG.debug("Not Qos Cluster Owner. Ignoring setting bandwidth limits");
             return;
@@ -475,7 +481,7 @@ public class QosNeutronUtils {
         tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
         try {
             if (writeConfigTxn != null) {
-                writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier
+                writeConfigTxn.merge(InstanceIdentifier
                         .create(NetworkTopology.class)
                         .child(Topology.class, new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID))
                         .child(Node.class, bridgeNode.get().key())
index 05a97236d418b5258700528fd8e88bcd80204239..8f35f718e0906d99677ece4cf2e9b07e6ab24c9a 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.netvirt.qosservice;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -173,7 +176,7 @@ public class QosPolicyChangeListener extends AsyncClusteredDataTreeChangeListene
 
         for (Port port : qosNeutronUtils.getQosPorts(qosUuid)) {
             jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), () -> Collections.singletonList(
-                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                         tx -> qosNeutronUtils.setPortBandwidthLimits(port, input, tx))));
         }
     }
@@ -218,7 +221,7 @@ public class QosPolicyChangeListener extends AsyncClusteredDataTreeChangeListene
 
         for (Port port : qosNeutronUtils.getQosPorts(qosUuid)) {
             jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), () -> Collections.singletonList(
-                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                         tx -> qosNeutronUtils.setPortBandwidthLimits(port, zeroBwLimitRule, tx))));
         }
     }
@@ -284,7 +287,7 @@ public class QosPolicyChangeListener extends AsyncClusteredDataTreeChangeListene
 
         for (Port port : qosNeutronUtils.getQosPorts(qosUuid)) {
             jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), () -> Collections.singletonList(
-                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(
+                    txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
                         tx -> qosNeutronUtils.setPortBandwidthLimits(port, update, tx))));
         }
     }
@@ -319,9 +322,9 @@ public class QosPolicyChangeListener extends AsyncClusteredDataTreeChangeListene
 
         qrtBuilder.setRuleTypes(value);
 
-        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+        ListenableFutures.addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
             InstanceIdentifier instanceIdentifier = InstanceIdentifier.create(Neutron.class).child(QosRuleTypes.class);
-            tx.merge(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, qrtBuilder.build());
+            tx.merge(instanceIdentifier, qrtBuilder.build());
         }), LOG, "Error setting up supported QoS rule types");
     }
 
index 6058e8ddb501ebd736dc036fff6f02d0d95130b6..07f0c6290f5efd7671756289b56862a30db3372a 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
+
 import java.util.Collections;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -176,7 +178,7 @@ public class QosTerminationPointListener extends
                 port.getUuid(), update.getName(), qosPolicy.getName());
 
         jobCoordinator.enqueueJob("QosPort-" + port.getUuid(), () ->
-                Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
+                Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
                     BandwidthLimitRules bwRule = qosPolicy.getBandwidthLimitRules().get(0);
                     OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
                             new OvsdbTerminationPointAugmentationBuilder();
@@ -184,7 +186,7 @@ public class QosTerminationPointListener extends
                     tpAugmentationBuilder.setIngressPolicingRate(bwRule.getMaxKbps().longValue());
                     tpAugmentationBuilder.setIngressPolicingBurst(bwRule.getMaxBurstKbps().longValue());
 
-                    tx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(NetworkTopology.class)
+                    tx.merge(InstanceIdentifier.create(NetworkTopology.class)
                             .child(Topology.class, new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID))
                             .child(Node.class, identifier.firstKeyOf(Node.class))
                             .child(TerminationPoint.class, identifier.firstKeyOf(TerminationPoint.class))