utils: migrate to the mdsal DataBroker 93/79993/2
authorStephen Kitt <skitt@redhat.com>
Tue, 29 Jan 2019 14:56:45 +0000 (15:56 +0100)
committerSam Hague <shague@redhat.com>
Tue, 29 Jan 2019 20:25:02 +0000 (20:25 +0000)
This duplicates controller-based classes temporarily, so that we can
migrate hwvtepsouthbound and southbound separately.

Change-Id: I1ed7c137423deb149320df86f0abc090e1182df5
Signed-off-by: Stephen Kitt <skitt@redhat.com>
24 files changed:
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/reconciliation/configuration/HwvtepReconciliationTask.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/HwvtepOperationalState.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalSwitchUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactUtils.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsLocalUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UnMetDependencyGetter.java
hwvtepsouthbound/hwvtepsouthbound-it/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/it/HwvtepSouthboundIT.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java
utils/mdsal-utils/pom.xml
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtils.java [new file with mode: 0644]
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsync.java [new file with mode: 0644]
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerNotifyingDataChangeListener.java [new file with mode: 0644]
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtils.java
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsync.java
utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/NotifyingDataChangeListener.java
utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsyncTest.java [new file with mode: 0644]
utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsTest.java [new file with mode: 0644]
utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java
utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsTest.java
utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/NodeInfo.java
utils/ovsdb-it-utils/src/main/java/org/opendaylight/ovsdb/utils/ovsdb/it/utils/OvsdbItUtils.java
utils/southbound-utils/src/main/java/org/opendaylight/ovsdb/utils/southbound/utils/SouthboundUtils.java

index 415fce8eac08f3fba3c7df504980af9f4c4f7c9c..d4463b447ef94d9b7bc4c8ecd0cf9712a7c536c4 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchAttributes;
@@ -103,7 +103,7 @@ public final class HwvtepSouthboundUtil {
             // below
             InstanceIdentifier<Node> path = (InstanceIdentifier<Node>) ref.getValue();
 
-            Optional<Node> optional = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, path);
+            Optional<Node> optional = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, path);
             if (optional != null && optional.isPresent()) {
                 HwvtepGlobalAugmentation hwvtepNode = null;
                 Node node = optional.get();
index ab94f6bc0437743cdf7c34733fbc4238dcd8df2c..69ca66e4c1fd512aae1c6ca52ca0c043de4e7751 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationMana
 import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationTask;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState;
 import org.opendaylight.ovsdb.hwvtepsouthbound.transact.TransactCommandAggregator;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
@@ -31,7 +31,7 @@ public class HwvtepReconciliationTask extends ReconciliationTask {
     private final HwvtepConnectionInstance connectionInstance;
     private final DataBroker db;
     private final Node psNode;
-    private final MdsalUtils mdsalUtils;
+    private final ControllerMdsalUtils mdsalUtils;
 
     public HwvtepReconciliationTask(ReconciliationManager reconciliationManager,
                                     HwvtepConnectionManager connectionManager,
@@ -43,7 +43,7 @@ public class HwvtepReconciliationTask extends ReconciliationTask {
         this.db = db;
         this.psNode = psNode;
         this.connectionInstance = connectionInstance;
-        this.mdsalUtils = new MdsalUtils(db);
+        this.mdsalUtils = new ControllerMdsalUtils(db);
     }
 
     private void transactChangesToDevice(final Collection<DataTreeModification<Node>> changes,
index 122117d5f9adadabcddbab37b0b9ba1ce32ac658..def91f73b6d4b1014d00efd97b3f00642f44e057 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
 import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
@@ -155,7 +155,7 @@ public abstract class AbstractTransactCommand<T extends Identifiable, A extends
                     //data would have got deleted by , push the data only if it is still in configds
                     hwvtepOperationalState = operationalState;
                     deviceTransaction = transactionBuilder;
-                    T data = (T) new MdsalUtils(operationalState.getDataBroker()).read(
+                    T data = (T) new ControllerMdsalUtils(operationalState.getDataBroker()).read(
                             LogicalDatastoreType.CONFIGURATION, key);
                     if (data != null) {
                         onConfigUpdate(transactionBuilder, nodeIid, data, key, extraData);
index 0ac3b65190a5ff42f39b2e849b14e718fd76bb6c..652f35e831c31f150ad92734ff2187d8dada1bf7 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
 import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
@@ -100,7 +100,7 @@ public class HwvtepOperationalState {
         this.db = connectionInstance.getDataBroker();
         this.changes = null;
         transaction = connectionInstance.getDataBroker().newReadWriteTransaction();
-        Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+        Optional<Node> readNode = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
                 connectionInstance.getInstanceIdentifier());
         if (readNode.isPresent()) {
             operationalNodes.put(connectionInstance.getInstanceIdentifier(), readNode.get());
@@ -137,7 +137,7 @@ public class HwvtepOperationalState {
         if (nodeCreateOrUpdate != null) {
             transaction = db.newReadWriteTransaction();
             for (Entry<InstanceIdentifier<Node>, Node> entry: nodeCreateOrUpdate.entrySet()) {
-                Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+                Optional<Node> readNode = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
                         entry.getKey());
                 //add related globalNode or physicalSwitchNode to operationalNodes map
                 //for example, when creating physical port, logical switch is needed
@@ -153,8 +153,8 @@ public class HwvtepOperationalState {
                             @SuppressWarnings("unchecked")
                             InstanceIdentifier<Node> psNodeIid =
                                     (InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
-                            Optional<Node> psNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
-                                    psNodeIid);
+                            Optional<Node> psNode =
+                                new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, psNodeIid);
                             if (psNode.isPresent()) {
                                 operationalNodes.put(psNodeIid, psNode.get());
                             }
@@ -164,7 +164,7 @@ public class HwvtepOperationalState {
                         @SuppressWarnings("unchecked")
                         InstanceIdentifier<Node> hgNodeIid =
                                 (InstanceIdentifier<Node>) psAugmentation.getManagedBy().getValue();
-                        Optional<Node> hgNode = new MdsalUtils(db).readOptional(
+                        Optional<Node> hgNode = new ControllerMdsalUtils(db).readOptional(
                                 LogicalDatastoreType.OPERATIONAL, hgNodeIid);
                         if (hgNode.isPresent()) {
                             operationalNodes.put(hgNodeIid, hgNode.get());
@@ -229,8 +229,7 @@ public class HwvtepOperationalState {
     }
 
     public Optional<LogicalSwitches> getLogicalSwitches(InstanceIdentifier<LogicalSwitches> iid) {
-        Optional<LogicalSwitches> lswitch = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
-        return lswitch;
+        return new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
     }
 
     public Optional<Tunnels> getTunnels(InstanceIdentifier<?> iid, TunnelsKey tunnelsKey) {
@@ -254,7 +253,7 @@ public class HwvtepOperationalState {
     }
 
     public Optional<Tunnels> getTunnels(InstanceIdentifier<Tunnels> iid) {
-        Optional<Tunnels> tunnels = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        Optional<Tunnels> tunnels = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
         return tunnels;
     }
 
@@ -295,7 +294,8 @@ public class HwvtepOperationalState {
 
     public Optional<HwvtepPhysicalLocatorAugmentation>
             getPhysicalLocatorAugmentation(InstanceIdentifier<TerminationPoint> iid) {
-        Optional<TerminationPoint> tp = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        Optional<TerminationPoint> tp =
+            new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
         if (tp.isPresent()) {
             return Optional.fromNullable(tp.get().augmentation(HwvtepPhysicalLocatorAugmentation.class));
         }
@@ -400,7 +400,7 @@ public class HwvtepOperationalState {
     }
 
     public Optional<Acls> getAcls(InstanceIdentifier<Acls> iid) {
-        Optional<Acls> acl = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+        Optional<Acls> acl = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
         return acl;
     }
 
index 1e8f0b0c13267fb301aa1301e543635afc5b109c..81297bf2407e220b6161efdb1ca5e1dd836d20df 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.hardwarevtep.Global;
 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
 import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.ManagementIps;
@@ -285,7 +285,7 @@ public class PhysicalSwitchUpdateCommand extends AbstractTransactCommand {
         } else {
             // TODO/FIXME: Not in operational, do we create a new one?
             LOG.warn("Trying to create tunnel without creating physical locators first");
-            Optional<TerminationPoint> confLocOptional = new MdsalUtils(getOperationalState().getDataBroker())
+            Optional<TerminationPoint> confLocOptional = new ControllerMdsalUtils(getOperationalState().getDataBroker())
                     .readOptional(LogicalDatastoreType.CONFIGURATION, iid);
             if (confLocOptional.isPresent()) {
                 locatorUUID = TransactUtils.createPhysicalLocator(transaction, getOperationalState(), iid);
index dd357ea2fd69d372930393f19bc28079a5501e4e..a87d86c9bb3ca86bae642feb273784d7d4a8c31a 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeVxlanOverIpv4;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
@@ -231,7 +231,7 @@ public final class TransactUtils {
             return null;
         }
         LogicalSwitchUpdateCommand cmd = new LogicalSwitchUpdateCommand(operationalState, Collections.emptyList());
-        MdsalUtils mdsalUtils = new MdsalUtils(operationalState.getDataBroker());
+        ControllerMdsalUtils mdsalUtils = new ControllerMdsalUtils(operationalState.getDataBroker());
         LogicalSwitches ls = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, lswitchIid);
         if (ls != null) {
             cmd.updateLogicalSwitch(transaction, lswitchIid.firstIdentifierOf(Node.class), Lists.newArrayList(ls));
index 52b20d5b6ffe83d207b4fb25f8b16898ba8b4ba2..7016423735fbc729207966f41474a1debedcaf7c 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
@@ -121,7 +121,7 @@ public class UcastMacsLocalUpdateCommand extends AbstractTransactCommand<LocalUc
                 locatorUuid = new UUID(locatorAugmentation.getPhysicalLocatorUuid().getValue());
             } else {
                 //if no, get it from config DS and create id
-                Optional<TerminationPoint> configLocatorOptional = new MdsalUtils(
+                Optional<TerminationPoint> configLocatorOptional = new ControllerMdsalUtils(
                         getOperationalState().getDataBroker()).readOptional(LogicalDatastoreType.CONFIGURATION, iid);
                 if (configLocatorOptional.isPresent()) {
                     HwvtepPhysicalLocatorAugmentation locatorAugmentation =
index 3222def8b2e39b3d74ddf123f2bb1ce4033effbc..88dc54585a72d142e86b8407f99a9f626a01dcf8 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Map.Entry;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepDeviceInfo;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -105,7 +105,7 @@ public abstract class UnMetDependencyGetter<T extends Identifiable> {
 
         boolean isConfigDataAvailable(HwvtepOperationalState opState, InstanceIdentifier<? extends DataObject> key) {
             DataBroker db = opState.getConnectionInstance().getDataBroker();
-            MdsalUtils mdsalUtils = new MdsalUtils(db);
+            ControllerMdsalUtils mdsalUtils = new ControllerMdsalUtils(db);
             return mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, key) != null;
         }
     }
index 32282999ab9109c681eada74d7a84450a92437da..be219f4b61e5b8c3d5a4e8d927aeac37002577ac 100644 (file)
@@ -42,7 +42,7 @@ import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
 import org.opendaylight.ovsdb.utils.hwvtepsouthbound.utils.HwvtepSouthboundUtils;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
@@ -96,7 +96,7 @@ public class HwvtepSouthboundIT extends AbstractMdsalTestBase {
     private static final int OVSDB_UPDATE_TIMEOUT = 1000;
     private static final int OVSDB_ROUNDTRIP_TIMEOUT = 10000;
 
-    private static MdsalUtils mdsalUtils = null;
+    private static ControllerMdsalUtils mdsalUtils = null;
     private static boolean setup = false;
     private static int testMethodsRemaining;
     private static String addressStr;
@@ -268,7 +268,7 @@ public class HwvtepSouthboundIT extends AbstractMdsalTestBase {
             }
         }
 
-        mdsalUtils = new MdsalUtils(dataBroker);
+        mdsalUtils = new ControllerMdsalUtils(dataBroker);
         assertTrue("Did not find " + HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue(), getHwvtepTopology());
         final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
         final InstanceIdentifier<Node> iid = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo);
index bf98ea9ae1058fdc59fb5073d0f8b8f5025c1f96..19a794ada3715c2cc455ec8ba5cd8a3f5a670b8d 100644 (file)
@@ -53,7 +53,7 @@ import org.opendaylight.ovsdb.lib.notation.Version;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
@@ -174,7 +174,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
     private static int portNumber;
     private static String connectionType;
     private static boolean setup = false;
-    private static MdsalUtils mdsalUtils = null;
+    private static ControllerMdsalUtils mdsalUtils = null;
     private static Node ovsdbNode;
     private static int testMethodsRemaining;
     private static Version schemaVersion;
@@ -422,7 +422,7 @@ public class SouthboundIT extends AbstractMdsalTestBase {
             }
         }
 
-        mdsalUtils = new MdsalUtils(dataBroker);
+        mdsalUtils = new ControllerMdsalUtils(dataBroker);
         assertTrue("Did not find " + SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), getOvsdbTopology());
         final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
         final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
index 9d2dc4cecc90a932a7dee2f27d74ecf4841d296f..cd8313b739a83c75ee983e962990acdd9f5f33c6 100644 (file)
@@ -57,6 +57,17 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal</groupId>
+      <artifactId>mdsal-binding-dom-adapter</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.mdsal</groupId>
+      <artifactId>mdsal-binding-dom-adapter</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 
diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtils.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtils.java
new file mode 100644 (file)
index 0000000..7abbce5
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.utils.mdsal.utils;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Deprecated
+public class ControllerMdsalUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(ControllerMdsalUtils.class);
+    private static int MDSAL_MAX_READ_TRIALS = Integer.getInteger("mdsalutil.max.tries", 30);
+    private static int MDSAL_READ_SLEEP_INTERVAL_MS = Integer.getInteger("mdsalutil.sleep.between.mdsal.reads", 1000);
+
+    private final DataBroker databroker;
+
+    /**
+     * Class constructor setting the data broker.
+     *
+     * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
+     */
+    public ControllerMdsalUtils(DataBroker dataBroker) {
+        this.databroker = dataBroker;
+    }
+
+    /**
+     * Executes delete as a blocking transaction.
+     *
+     * @param store {@link LogicalDatastoreType} which should be modified
+     * @param path {@link InstanceIdentifier} to read from
+     * @param <D> the data object type
+     * @return the result of the request
+     */
+    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
+            final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
+        boolean result = false;
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.delete(store, path);
+        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        try {
+            future.checkedGet();
+            result = true;
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Failed to delete {} ", path, e);
+        }
+        return result;
+    }
+
+    /**
+     * Executes merge as a blocking transaction.
+     *
+     * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
+     * @param path {@link InstanceIdentifier} for path to read
+     * @param <D> the data object type
+     * @return the result of the request
+     */
+    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
+            final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
+        boolean result = false;
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.merge(logicalDatastoreType, path, data, true);
+        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        try {
+            future.checkedGet();
+            result = true;
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Failed to merge {} ", path, e);
+        }
+        return result;
+    }
+
+    /**
+     * Executes put as a blocking transaction.
+     *
+     * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
+     * @param path {@link InstanceIdentifier} for path to read
+     * @param <D> the data object type
+     * @return the result of the request
+     */
+    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
+            final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
+        boolean result = false;
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.put(logicalDatastoreType, path, data, true);
+        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        try {
+            future.checkedGet();
+            result = true;
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Failed to put {} ", path, e);
+        }
+        return result;
+    }
+
+    /**
+     * Executes read as a blocking transaction.
+     *
+     * @param store {@link LogicalDatastoreType} to read
+     * @param path {@link InstanceIdentifier} for path to read
+     * @param <D> the data object type
+     * @return the result as the data object requested
+     */
+    public <D extends DataObject> D read(
+            final LogicalDatastoreType store, final InstanceIdentifier<? extends DataObject> path) {
+        Optional<D> optionalDataObject = readOptional(store, path);
+        if (optionalDataObject.isPresent()) {
+            return optionalDataObject.get();
+        }
+        LOG.debug("{}: Failed to read {}",
+                Thread.currentThread().getStackTrace()[1], path);
+        return null;
+    }
+
+    public <D extends DataObject> Optional<D> readOptional(
+            final LogicalDatastoreType store, final InstanceIdentifier<? extends DataObject> path)  {
+        int trialNo = 0;
+        ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
+        do {
+            try {
+                Optional<D> result = transaction.read(store, (InstanceIdentifier<D>)path).checkedGet();
+                transaction.close();
+                return result;
+            } catch (ReadFailedException e) {
+                if (trialNo == 0) {
+                    logReadFailureError(path, " mdsal Read failed exception retrying the read after sleep");
+                }
+                try {
+                    transaction.close();
+                    Thread.sleep(MDSAL_READ_SLEEP_INTERVAL_MS);
+                    transaction = databroker.newReadOnlyTransaction();
+                } catch (InterruptedException e1) {
+                    logReadFailureError(path, " Sleep interrupted");
+                }
+            }
+        } while (trialNo++ < MDSAL_MAX_READ_TRIALS);
+        logReadFailureError(path, " All read trials exceeded");
+        return Optional.absent();
+    }
+
+    private <D extends org.opendaylight.yangtools.yang.binding.DataObject> void logReadFailureError(
+            InstanceIdentifier<D> path, String cause) {
+        LOG.error("{}: Failed to read {} Cause : {}", Thread.currentThread().getStackTrace()[2], path, cause);
+
+    }
+}
diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsync.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsync.java
new file mode 100644 (file)
index 0000000..e57b727
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.utils.mdsal.utils;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Deprecated
+public class ControllerMdsalUtilsAsync {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ControllerMdsalUtilsAsync.class);
+    private final DataBroker databroker;
+
+    /**
+     * Class constructor setting the data broker.
+     *
+     * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
+     */
+    public ControllerMdsalUtilsAsync(final DataBroker dataBroker) {
+        this.databroker = dataBroker;
+    }
+
+    /**
+     * Executes delete as a non blocking transaction and returns the future.
+     *
+     * @param store
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} to read from
+     * @return The {@link CheckedFuture} object to which you can assign a
+     *         callback
+     */
+    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> delete(
+                                    final LogicalDatastoreType store,
+                                    final InstanceIdentifier<D> path)  {
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.delete(store, path);
+        return transaction.submit();
+    }
+
+    /**
+     * Executes delete as a non blocking transaction and assign a default callback.
+     *
+     * @param store
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} to read from
+     * @param operationDesc
+     *            A brief description of the operation to perform
+     */
+    public <D extends DataObject> void delete(
+                                    final LogicalDatastoreType store,
+                                    final InstanceIdentifier<D> path,
+                                    final String operationDesc)  {
+        assignDefaultCallback(delete(store, path), operationDesc);
+    }
+
+    /**
+     * Executes put as non blocking transaction and return the future.
+     *
+     * @param logicalDatastoreType
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} for path to read
+     * @param <D>
+     *            The data object type
+     * @return The {@link CheckedFuture} object to which you can assign a
+     *         callback
+     */
+    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> put(
+                                        final LogicalDatastoreType logicalDatastoreType,
+                                        final InstanceIdentifier<D> path,
+                                        final D data)  {
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.put(logicalDatastoreType, path, data, true);
+        return transaction.submit();
+    }
+
+    /**
+     * Executes put as non blocking transaction and assign default callback.
+     *
+     * @param logicalDatastoreType
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} for path to read
+     * @param <D>
+     *            The data object type
+     * @param operationDesc
+     *            A brief description of the operation to perform
+     */
+    public <D extends DataObject> void put(
+                                        final LogicalDatastoreType logicalDatastoreType,
+                                        final InstanceIdentifier<D> path,
+                                        final D data,
+                                        final String operationDesc)  {
+        assignDefaultCallback(put(logicalDatastoreType, path, data), operationDesc);
+    }
+
+    /**
+     * Executes merge as non blocking transaction and return the future.
+     *
+     * @param logicalDatastoreType
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} for path to read
+     * @param <D>
+     *            The data object type
+     * @param withParent
+     *            Whether or not to create missing parent.
+     * @return The {@link CheckedFuture} object to which you can assign a
+     *         callback
+     */
+    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> merge(
+                                        final LogicalDatastoreType logicalDatastoreType,
+                                        final InstanceIdentifier<D> path,
+                                        final D data,
+                                        final boolean withParent)  {
+        final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
+        transaction.merge(logicalDatastoreType, path, data, withParent);
+        return transaction.submit();
+    }
+
+    /**
+     * Executes merge as non blocking transaction and assign default callback.
+     *
+     * @param logicalDatastoreType
+     *            {@link LogicalDatastoreType} which should be modified
+     * @param path
+     *            {@link InstanceIdentifier} for path to read
+     * @param <D>
+     *            The data object type
+     * @param operationDesc
+     *            A brief description of the operation to perform
+     * @param withParent
+     *            Whether or not to create missing parent.
+     */
+    public <D extends DataObject> void merge(
+                                        final LogicalDatastoreType logicalDatastoreType,
+                                        final InstanceIdentifier<D> path,
+                                        final D data,
+                                        final String operationDesc,
+                                        final boolean withParent)  {
+        assignDefaultCallback(merge(logicalDatastoreType, path, data, withParent), operationDesc);
+    }
+
+    /**
+     * Executes read as non blocking transaction and assign a default callback
+     * to close the transaction.
+     *
+     * @param store
+     *            {@link LogicalDatastoreType} to read
+     * @param path
+     *            {@link InstanceIdentifier} for path to read
+     * @param <D>
+     *            The data object type
+     * @return The {@link CheckedFuture} object to which you can assign a
+     *         callback
+     */
+    public <D extends DataObject> CheckedFuture<Optional<D>, ReadFailedException> read(
+                                        final LogicalDatastoreType store,
+                                        final InstanceIdentifier<D> path)  {
+        final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
+        final CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
+        final FutureCallback<Optional<D>> closeTransactionCallback = new FutureCallback<Optional<D>>() {
+            @Override
+            public void onSuccess(final Optional<D> result) {
+                transaction.close();
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                transaction.close();
+            }
+        };
+        Futures.addCallback(future, closeTransactionCallback);
+        return future;
+    }
+
+    /**
+     * Assign a default callback to a {@link CheckedFuture}. It will either log
+     * a message at DEBUG level if the transaction succeed, or will log at ERROR
+     * level and throw an {@link IllegalStateException} if the transaction
+     * failed.
+     *
+     * @param transaction
+     *            The transaction to commit.
+     * @param operationDesc
+     *            A description of the transaction to commit.
+     */
+    void assignDefaultCallback(final CheckedFuture<Void, TransactionCommitFailedException> transactionFuture,
+            final String operationDesc) {
+        Futures.addCallback(transactionFuture, new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(final Void result) {
+                LOG.debug("Transaction({}) SUCCESSFUL", operationDesc);
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                LOG.error("Transaction({}) FAILED!", operationDesc, ex);
+                throw new IllegalStateException("  Transaction(" + operationDesc + ") not committed correctly", ex);
+            }
+        }, MoreExecutors.directExecutor());
+    }
+}
diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerNotifyingDataChangeListener.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerNotifyingDataChangeListener.java
new file mode 100644 (file)
index 0000000..111f9a0
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.utils.mdsal.utils;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class provides methods for checking or waiting for various md-sal operations to complete.
+ * Once an instance is created one must invoke the registerDataChangeListener method
+ * with a DataBroker.
+ */
+@Deprecated
+public class ControllerNotifyingDataChangeListener implements AutoCloseable, DataTreeChangeListener<DataObject> {
+    private static final Logger LOG = LoggerFactory.getLogger(ControllerNotifyingDataChangeListener.class);
+    private static final int RETRY_WAIT = 100;
+    private static final int MDSAL_TIMEOUT_OPERATIONAL = 10000;
+    private static final int MDSAL_TIMEOUT_CONFIG = 1000;
+
+    public static final int BIT_CREATE = 1;
+    public static final int BIT_UPDATE = 2;
+    public static final int BIT_DELETE = 4;
+    public static final int BIT_ALL = 7;
+
+    private final Set<InstanceIdentifier<?>> createdIids = ConcurrentHashMap.newKeySet();
+    private final Set<InstanceIdentifier<?>> removedIids = ConcurrentHashMap.newKeySet();
+    private final Set<InstanceIdentifier<?>> updatedIids = ConcurrentHashMap.newKeySet();
+    private final List<ControllerNotifyingDataChangeListener> waitList;
+    private ListenerRegistration<?> listenerRegistration;
+    private int mdsalTimeout = MDSAL_TIMEOUT_OPERATIONAL;
+    private volatile InstanceIdentifier<?> iid;
+    private volatile  LogicalDatastoreType type;
+    private volatile boolean listen;
+    private volatile int mask;
+
+    public ControllerNotifyingDataChangeListener(LogicalDatastoreType type, int mask, InstanceIdentifier<?> iid,
+                                                 List<ControllerNotifyingDataChangeListener> waitList) {
+        this(type, iid, waitList);
+        this.mask = mask;
+    }
+
+    /**
+     * Create a new ControllerNotifyingDataChangeListener.
+     *
+     * @param type DataStore type
+     * @param iid of the md-sal object we're waiting for
+     * @param waitList for tracking outstanding changes
+     */
+    public ControllerNotifyingDataChangeListener(LogicalDatastoreType type, InstanceIdentifier<?> iid,
+                                                 List<ControllerNotifyingDataChangeListener> waitList) {
+        this.type = type;
+        this.iid = iid;
+        this.waitList = waitList;
+        if (this.waitList != null) {
+            this.waitList.add(this);
+        }
+
+        mdsalTimeout = MDSAL_TIMEOUT_OPERATIONAL;
+        if (type == LogicalDatastoreType.CONFIGURATION) {
+            mdsalTimeout = MDSAL_TIMEOUT_CONFIG;
+        }
+        listen = true;
+        mask = BIT_ALL;
+    }
+
+    /**
+     * Completely reset the state of this ControllerNotifyingDataChangeListener.
+     *
+     * @param newType DataStore type
+     * @param newIid of the md-sal object we're waiting for
+     */
+    public void modify(LogicalDatastoreType newType, InstanceIdentifier<?> newIid) {
+        this.close();
+        this.clear();
+        this.type = newType;
+        this.iid = newIid;
+    }
+
+    public void setlisten(boolean value) {
+        this.listen = value;
+    }
+
+    public void setMask(int mask) {
+        this.mask = mask;
+    }
+
+    @Override
+    @SuppressFBWarnings("NN_NAKED_NOTIFY")
+    public void onDataTreeChanged(Collection<DataTreeModification<DataObject>> changes) {
+        if (!listen) {
+            return;
+        }
+
+        for (DataTreeModification<DataObject> change: changes) {
+            DataObjectModification<DataObject> rootNode = change.getRootNode();
+            final InstanceIdentifier<DataObject> identifier = change.getRootPath().getRootIdentifier();
+            switch (rootNode.getModificationType()) {
+                case SUBTREE_MODIFIED:
+                case WRITE:
+                    if (rootNode.getDataBefore() == null) {
+                        if ((mask & BIT_CREATE) == BIT_CREATE) {
+                            LOG.info("{} DataTreeChanged: created {}", type, identifier);
+                            createdIids.add(identifier);
+                        }
+                    } else if ((mask & BIT_UPDATE) == BIT_UPDATE) {
+                        LOG.info("{} DataTreeChanged: updated {}", type, identifier);
+                        updatedIids.add(identifier);
+                    }
+                    break;
+                case DELETE:
+                    if ((mask & BIT_DELETE) == BIT_DELETE) {
+                        LOG.info("{} DataTreeChanged: removed {}", type, identifier);
+                        removedIids.add(identifier);
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        synchronized (this) {
+            notifyAll();
+        }
+    }
+
+    public boolean isCreated(InstanceIdentifier<?> path) {
+        return createdIids.remove(path);
+    }
+
+    public boolean isUpdated(InstanceIdentifier<?> path) {
+        return updatedIids.remove(path);
+    }
+
+    public boolean isRemoved(InstanceIdentifier<?> path) {
+        return removedIids.remove(path);
+    }
+
+    public void clear() {
+        createdIids.clear();
+        updatedIids.clear();
+        removedIids.clear();
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public void registerDataChangeListener(DataBroker dataBroker) {
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(type,
+                (InstanceIdentifier)iid), this);
+    }
+
+    public void waitForCreation() throws InterruptedException {
+        waitForCreation(mdsalTimeout);
+    }
+
+    public void waitForCreation(long timeout) throws InterruptedException {
+        synchronized (this) {
+            long start = System.currentTimeMillis();
+            LOG.info("Waiting for {} DataChanged creation on {}", type, iid);
+            while (!isCreated(iid) && System.currentTimeMillis() - start < timeout) {
+                wait(RETRY_WAIT);
+            }
+            LOG.info("Woke up, waited {}ms for creation of {}", System.currentTimeMillis() - start, iid);
+        }
+    }
+
+    public void waitForUpdate() throws InterruptedException {
+        waitForUpdate(mdsalTimeout);
+    }
+
+    public void waitForUpdate(long timeout) throws InterruptedException {
+        synchronized (this) {
+            long start = System.currentTimeMillis();
+            LOG.info("Waiting for {} DataChanged update on {}", type, iid);
+            while (!isUpdated(iid) && System.currentTimeMillis() - start < timeout) {
+                wait(RETRY_WAIT);
+            }
+            LOG.info("Woke up, waited {}ms for update of {}", System.currentTimeMillis() - start, iid);
+        }
+    }
+
+    public void waitForDeletion() throws InterruptedException {
+        waitForDeletion(mdsalTimeout);
+    }
+
+    public void waitForDeletion(long timeout) throws InterruptedException {
+        synchronized (this) {
+            long start = System.currentTimeMillis();
+            LOG.info("Waiting for {} DataChanged deletion on {}", type, iid);
+            while (!isRemoved(iid) && System.currentTimeMillis() - start < timeout) {
+                wait(RETRY_WAIT);
+            }
+            LOG.info("Woke up, waited {}ms for deletion of {}", System.currentTimeMillis() - start, iid);
+        }
+    }
+
+    @Override
+    public void close() {
+        if (listenerRegistration != null) {
+            listenerRegistration.close();
+        }
+
+        if (waitList != null) {
+            waitList.remove(this);
+        }
+
+        listenerRegistration = null;
+    }
+}
index 50f833e09025053e4d629dbe0ca890616dec71a3..b0569ef91ed428d6598d84fd4df0bd063d709f35 100644 (file)
@@ -7,14 +7,14 @@
  */
 package org.opendaylight.ovsdb.utils.mdsal.utils;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import com.google.common.util.concurrent.FluentFuture;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -30,7 +30,7 @@ public class MdsalUtils {
     /**
      * Class constructor setting the data broker.
      *
-     * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
+     * @param dataBroker the {@link DataBroker}
      */
     public MdsalUtils(DataBroker dataBroker) {
         this.databroker = dataBroker;
@@ -44,16 +44,16 @@ public class MdsalUtils {
      * @param <D> the data object type
      * @return the result of the request
      */
-    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
+    public <D extends DataObject> boolean delete(
             final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
         boolean result = false;
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.delete(store, path);
-        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        FluentFuture<? extends CommitInfo> future = transaction.commit();
         try {
-            future.checkedGet();
+            future.get();
             result = true;
-        } catch (TransactionCommitFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Failed to delete {} ", path, e);
         }
         return result;
@@ -67,16 +67,16 @@ public class MdsalUtils {
      * @param <D> the data object type
      * @return the result of the request
      */
-    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
+    public <D extends DataObject> boolean merge(
             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
         boolean result = false;
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.merge(logicalDatastoreType, path, data, true);
-        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        FluentFuture<? extends CommitInfo> future = transaction.commit();
         try {
-            future.checkedGet();
+            future.get();
             result = true;
-        } catch (TransactionCommitFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Failed to merge {} ", path, e);
         }
         return result;
@@ -90,16 +90,16 @@ public class MdsalUtils {
      * @param <D> the data object type
      * @return the result of the request
      */
-    public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
+    public <D extends DataObject> boolean put(
             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
         boolean result = false;
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.put(logicalDatastoreType, path, data, true);
-        CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+        FluentFuture<? extends CommitInfo> future = transaction.commit();
         try {
-            future.checkedGet();
+            future.get();
             result = true;
-        } catch (TransactionCommitFailedException e) {
+        } catch (InterruptedException | ExecutionException e) {
             LOG.warn("Failed to put {} ", path, e);
         }
         return result;
@@ -127,13 +127,13 @@ public class MdsalUtils {
     public <D extends DataObject> Optional<D> readOptional(
             final LogicalDatastoreType store, final InstanceIdentifier<? extends DataObject> path)  {
         int trialNo = 0;
-        ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
+        ReadTransaction transaction = databroker.newReadOnlyTransaction();
         do {
             try {
-                Optional<D> result = transaction.read(store, (InstanceIdentifier<D>)path).checkedGet();
+                Optional<D> result = transaction.read(store, (InstanceIdentifier<D>)path).get();
                 transaction.close();
                 return result;
-            } catch (ReadFailedException e) {
+            } catch (InterruptedException | ExecutionException e) {
                 if (trialNo == 0) {
                     logReadFailureError(path, " mdsal Read failed exception retrying the read after sleep");
                 }
@@ -147,10 +147,10 @@ public class MdsalUtils {
             }
         } while (trialNo++ < MDSAL_MAX_READ_TRIALS);
         logReadFailureError(path, " All read trials exceeded");
-        return Optional.absent();
+        return Optional.empty();
     }
 
-    private <D extends org.opendaylight.yangtools.yang.binding.DataObject> void logReadFailureError(
+    private <D extends DataObject> void logReadFailureError(
             InstanceIdentifier<D> path, String cause) {
         LOG.error("{}: Failed to read {} Cause : {}", Thread.currentThread().getStackTrace()[2], path, cause);
 
index e8ddeb92859f68b66a38ecd19ff8cb0d66f8e808..0cb0388f5b5ac058519da5d9f30b89d092e4073a 100644 (file)
@@ -8,17 +8,17 @@
 
 package org.opendaylight.ovsdb.utils.mdsal.utils;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import java.util.Optional;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -32,7 +32,7 @@ public class MdsalUtilsAsync {
     /**
      * Class constructor setting the data broker.
      *
-     * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
+     * @param dataBroker the {@link DataBroker}
      */
     public MdsalUtilsAsync(final DataBroker dataBroker) {
         this.databroker = dataBroker;
@@ -45,15 +45,15 @@ public class MdsalUtilsAsync {
      *            {@link LogicalDatastoreType} which should be modified
      * @param path
      *            {@link InstanceIdentifier} to read from
-     * @return The {@link CheckedFuture} object to which you can assign a
+     * @return The {@link FluentFuture} object to which you can assign a
      *         callback
      */
-    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> delete(
+    public <D extends DataObject> FluentFuture<? extends CommitInfo> delete(
                                     final LogicalDatastoreType store,
                                     final InstanceIdentifier<D> path)  {
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.delete(store, path);
-        return transaction.submit();
+        return transaction.commit();
     }
 
     /**
@@ -82,16 +82,16 @@ public class MdsalUtilsAsync {
      *            {@link InstanceIdentifier} for path to read
      * @param <D>
      *            The data object type
-     * @return The {@link CheckedFuture} object to which you can assign a
+     * @return The {@link FluentFuture} object to which you can assign a
      *         callback
      */
-    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> put(
+    public <D extends DataObject> FluentFuture<? extends CommitInfo> put(
                                         final LogicalDatastoreType logicalDatastoreType,
                                         final InstanceIdentifier<D> path,
                                         final D data)  {
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.put(logicalDatastoreType, path, data, true);
-        return transaction.submit();
+        return transaction.commit();
     }
 
     /**
@@ -125,17 +125,17 @@ public class MdsalUtilsAsync {
      *            The data object type
      * @param withParent
      *            Whether or not to create missing parent.
-     * @return The {@link CheckedFuture} object to which you can assign a
+     * @return The {@link FluentFuture} object to which you can assign a
      *         callback
      */
-    public <D extends DataObject> CheckedFuture<Void, TransactionCommitFailedException> merge(
+    public <D extends DataObject> FluentFuture<? extends CommitInfo> merge(
                                         final LogicalDatastoreType logicalDatastoreType,
                                         final InstanceIdentifier<D> path,
                                         final D data,
                                         final boolean withParent)  {
         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
         transaction.merge(logicalDatastoreType, path, data, withParent);
-        return transaction.submit();
+        return transaction.commit();
     }
 
     /**
@@ -171,14 +171,14 @@ public class MdsalUtilsAsync {
      *            {@link InstanceIdentifier} for path to read
      * @param <D>
      *            The data object type
-     * @return The {@link CheckedFuture} object to which you can assign a
+     * @return The {@link FluentFuture} object to which you can assign a
      *         callback
      */
-    public <D extends DataObject> CheckedFuture<Optional<D>, ReadFailedException> read(
+    public <D extends DataObject> FluentFuture<Optional<D>> read(
                                         final LogicalDatastoreType store,
                                         final InstanceIdentifier<D> path)  {
-        final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
-        final CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
+        final ReadTransaction transaction = databroker.newReadOnlyTransaction();
+        final FluentFuture<Optional<D>> future = transaction.read(store, path);
         final FutureCallback<Optional<D>> closeTransactionCallback = new FutureCallback<Optional<D>>() {
             @Override
             public void onSuccess(final Optional<D> result) {
@@ -200,16 +200,16 @@ public class MdsalUtilsAsync {
      * level and throw an {@link IllegalStateException} if the transaction
      * failed.
      *
-     * @param transaction
+     * @param transactionFuture
      *            The transaction to commit.
      * @param operationDesc
      *            A description of the transaction to commit.
      */
-    void assignDefaultCallback(final CheckedFuture<Void, TransactionCommitFailedException> transactionFuture,
+    void assignDefaultCallback(final FluentFuture<? extends CommitInfo> transactionFuture,
             final String operationDesc) {
-        Futures.addCallback(transactionFuture, new FutureCallback<Void>() {
+        Futures.addCallback(transactionFuture, new FutureCallback<CommitInfo>() {
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final CommitInfo result) {
                 LOG.debug("Transaction({}) SUCCESSFUL", operationDesc);
             }
 
index 853ffee9f1b1f0201b8c1f0335f34abc3d3740e6..298662151eaa1a26ee85b7ca64af08c5f68a07c7 100644 (file)
@@ -12,12 +12,12 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -47,7 +47,7 @@ public class NotifyingDataChangeListener implements AutoCloseable, DataTreeChang
     private ListenerRegistration<?> listenerRegistration;
     private int mdsalTimeout = MDSAL_TIMEOUT_OPERATIONAL;
     private volatile InstanceIdentifier<?> iid;
-    private volatile  LogicalDatastoreType type;
+    private volatile LogicalDatastoreType type;
     private volatile boolean listen;
     private volatile int mask;
 
@@ -58,7 +58,7 @@ public class NotifyingDataChangeListener implements AutoCloseable, DataTreeChang
     }
 
     /**
-     * Create a new NotifyingDataChangeListener.
+     * Create a new ControllerNotifyingDataChangeListener.
      *
      * @param type DataStore type
      * @param iid of the md-sal object we're waiting for
@@ -82,13 +82,12 @@ public class NotifyingDataChangeListener implements AutoCloseable, DataTreeChang
     }
 
     /**
-     * Completely reset the state of this NotifyingDataChangeListener.
+     * Completely reset the state of this ControllerNotifyingDataChangeListener.
      *
      * @param newType DataStore type
      * @param newIid of the md-sal object we're waiting for
-     * @throws Exception on failure
      */
-    public void modify(LogicalDatastoreType newType, InstanceIdentifier<?> newIid) throws Exception {
+    public void modify(LogicalDatastoreType newType, InstanceIdentifier<?> newIid) {
         this.close();
         this.clear();
         this.type = newType;
@@ -162,7 +161,7 @@ public class NotifyingDataChangeListener implements AutoCloseable, DataTreeChang
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public void registerDataChangeListener(DataBroker dataBroker) {
-        listenerRegistration = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(type,
+        listenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(type,
                 (InstanceIdentifier)iid), this);
     }
 
diff --git a/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsyncTest.java b/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsAsyncTest.java
new file mode 100644 (file)
index 0000000..37d30d7
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright Â© 2016, 2017 Inocybe and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.utils.mdsal.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNode;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.node.attributes.SupportingNodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ControllerMdsalUtilsAsyncTest extends AbstractDataBrokerTest {
+
+    private ControllerMdsalUtilsAsync mdsalUtilsAsync;
+    private DataBroker databroker;
+
+    private static final TopologyId TOPOLOGY_TEST = new TopologyId("test:1");
+
+    private static final NodeId NODE_ID = new NodeId("test");
+    private static final NodeKey NODE_KEY =  new NodeKey(NODE_ID);
+    private static final Node DATA = new NodeBuilder().withKey(NODE_KEY).setNodeId(NODE_ID).build();
+
+    private static final InstanceIdentifier<Node> TEST_IID = InstanceIdentifier
+            .create(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(TOPOLOGY_TEST))
+            .child(Node.class, NODE_KEY);
+
+    @Before
+    public void setUp() {
+        databroker = getDataBroker();
+        mdsalUtilsAsync = Mockito.spy(new ControllerMdsalUtilsAsync(databroker));
+    }
+
+    @Test
+    public void testDelete() {
+        final CheckedFuture<Void, TransactionCommitFailedException> fut = mdsalUtilsAsync.put(
+                LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
+        Futures.addCallback(fut, new FutureCallback<Void>() {
+
+            @Override
+            public void onSuccess(final Void result) {
+                final CheckedFuture<Void, TransactionCommitFailedException> future =
+                        mdsalUtilsAsync.delete(LogicalDatastoreType.CONFIGURATION, TEST_IID);
+                Futures.addCallback(future, new FutureCallback<Void>() {
+
+                    @Override
+                    public void onSuccess(final Void result) {
+                        assertNull(readDS());
+                    }
+
+                    @Override
+                    public void onFailure(final Throwable ex) {
+                        fail(ex.getMessage());
+                    }
+                }, MoreExecutors.directExecutor());
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                fail(ex.getMessage());
+            }
+        }, MoreExecutors.directExecutor());
+    }
+
+    @Test
+    public void testPutWithoutCallback() {
+        final String operationDesc = "testPut";
+        final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().withKey(
+                new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build();
+        final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().withKey(
+                new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build();
+
+        final Node data1 = new NodeBuilder(DATA).setSupportingNode(
+                Collections.singletonList(supportingNodeBuilder1)).build();
+        final Node data2 = new NodeBuilder(DATA).setSupportingNode(
+                Collections.singletonList(supportingNodeBuilder2)).build();
+
+        mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc);
+        assertEquals(data1, readDS());
+
+        final CheckedFuture<Void, TransactionCommitFailedException> future = mdsalUtilsAsync.put(
+                LogicalDatastoreType.CONFIGURATION, TEST_IID, data2);
+        Futures.addCallback(future, new FutureCallback<Void>() {
+
+            @Override
+            public void onSuccess(final Void result) {
+                assertEquals(1, readDS().getSupportingNode().size());
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                fail(ex.getMessage());
+            }
+        }, MoreExecutors.directExecutor());
+    }
+
+    @Test
+    public void testMerge() {
+        final String operationDesc = "testMerge";
+        final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().withKey(
+                new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build();
+        final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().withKey(
+                new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build();
+
+        final Node data1 = new NodeBuilder(DATA).setSupportingNode(
+                Collections.singletonList(supportingNodeBuilder1)).build();
+        final Node data2 = new NodeBuilder(DATA).setSupportingNode(
+                Collections.singletonList(supportingNodeBuilder2)).build();
+
+        mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc, true);
+        assertEquals(data1, readDS());
+
+        final CheckedFuture<Void, TransactionCommitFailedException> future =
+                mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data2, true);
+        Futures.addCallback(future, new FutureCallback<Void>() {
+
+            @Override
+            public void onSuccess(final Void result) {
+                assertEquals(2, readDS().getSupportingNode().size());
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                fail(ex.getMessage());
+            }
+        }, MoreExecutors.directExecutor());
+    }
+
+    @Test
+    public void testRead() {
+        final CheckedFuture<Void, TransactionCommitFailedException> fut =
+                mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
+
+        Futures.addCallback(fut, new FutureCallback<Void>() {
+            @Override
+            public void onSuccess(final Void result) {
+                final CheckedFuture<Optional<Node>, ReadFailedException> future =
+                        mdsalUtilsAsync.read(LogicalDatastoreType.CONFIGURATION, TEST_IID);
+                Optional<Node> optNode;
+                try {
+                    optNode = future.get();
+                    if (optNode.isPresent()) {
+                        assertEquals(DATA, optNode.get());
+                    } else {
+                        fail("Couldn't read node");
+                    }
+                } catch (InterruptedException | ExecutionException e) {
+                    fail(e.getMessage());
+                }
+            }
+
+            @Override
+            public void onFailure(final Throwable ex) {
+                fail(ex.getMessage());
+            }
+        }, MoreExecutors.directExecutor());
+    }
+
+    private Node readDS() {
+        try {
+            final Optional<Node> result = databroker.newReadOnlyTransaction().read(
+                    LogicalDatastoreType.CONFIGURATION, TEST_IID).get();
+            if (result.isPresent()) {
+                return result.get();
+            }
+        } catch (InterruptedException | ExecutionException e) {
+            fail(e.getMessage());
+        }
+        return null;
+    }
+}
diff --git a/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsTest.java b/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/ControllerMdsalUtilsTest.java
new file mode 100644 (file)
index 0000000..9662ee6
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015 Inocybe and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.utils.mdsal.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Unit test for class {@link ControllerMdsalUtils}.
+ */
+@RunWith(MockitoJUnitRunner.class)
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public class ControllerMdsalUtilsTest {
+
+    @InjectMocks private ControllerMdsalUtils mdsalUtils;
+
+    @Mock private DataBroker databroker;
+
+    @Test
+    public void testDelete() {
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
+        when(writeTransaction.submit()).thenReturn(future);
+
+        boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, mock(InstanceIdentifier.class));
+
+        verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(writeTransaction, times(1)).submit();
+
+        assertTrue("Error, the delete transaction failed", result);
+    }
+
+    @Test
+    public void testMerge() {
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
+        when(writeTransaction.submit()).thenReturn(future);
+
+        boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
+                mock(InstanceIdentifier.class), mock(DataObject.class));
+
+        verify(writeTransaction, times(1)).merge(any(LogicalDatastoreType.class),
+                any(InstanceIdentifier.class), any(DataObject.class), anyBoolean());
+        verify(writeTransaction, times(1)).submit();
+
+        assertTrue("Error, the merge transaction failed", result);
+    }
+
+    @Test
+    public void testPut() {
+        WriteTransaction writeTransaction = mock(WriteTransaction.class);
+        when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
+        when(writeTransaction.submit()).thenReturn(future);
+
+        boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
+                mock(InstanceIdentifier.class), mock(DataObject.class));
+
+        verify(writeTransaction, times(1)).put(any(LogicalDatastoreType.class),
+                any(InstanceIdentifier.class), any(DataObject.class), anyBoolean());
+        verify(writeTransaction, times(1)).submit();
+
+        assertTrue("Error, the put transaction failed", result);
+    }
+
+    @Test
+    public void testRead() throws ReadFailedException {
+        ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+        when(databroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        CheckedFuture<Optional, ReadFailedException> future = mock(CheckedFuture.class);
+        DataObject obj = mock(DataObject.class);
+        Optional opt = Optional.of(obj);
+        when(future.checkedGet()).thenReturn(opt);
+        when(readOnlyTransaction.read(any(LogicalDatastoreType.class),
+                any(InstanceIdentifier.class))).thenReturn(future);
+
+        DataObject result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, mock(InstanceIdentifier.class));
+
+        verify(readOnlyTransaction, times(1)).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(readOnlyTransaction, times(1)).close();
+
+        assertEquals("Error, the read transaction failed", obj, result);
+    }
+}
index 5c5f4c06e5b451b76f3c08b1ba192e0633e6d93e..05c55f8a7b854e65fe120007807fc36454d901d5 100644 (file)
@@ -12,23 +12,22 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collections;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
@@ -67,18 +66,18 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest {
 
     @Test
     public void testDelete() {
-        final CheckedFuture<Void, TransactionCommitFailedException> fut = mdsalUtilsAsync.put(
+        final FluentFuture<? extends CommitInfo> fut = mdsalUtilsAsync.put(
                 LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
-        Futures.addCallback(fut, new FutureCallback<Void>() {
+        Futures.addCallback(fut, new FutureCallback<CommitInfo>() {
 
             @Override
-            public void onSuccess(final Void result) {
-                final CheckedFuture<Void, TransactionCommitFailedException> future =
+            public void onSuccess(final CommitInfo result) {
+                final FluentFuture<? extends CommitInfo> future =
                         mdsalUtilsAsync.delete(LogicalDatastoreType.CONFIGURATION, TEST_IID);
-                Futures.addCallback(future, new FutureCallback<Void>() {
+                Futures.addCallback(future, new FutureCallback<CommitInfo>() {
 
                     @Override
-                    public void onSuccess(final Void result) {
+                    public void onSuccess(final CommitInfo result) {
                         assertNull(readDS());
                     }
 
@@ -112,12 +111,12 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest {
         mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc);
         assertEquals(data1, readDS());
 
-        final CheckedFuture<Void, TransactionCommitFailedException> future = mdsalUtilsAsync.put(
+        final FluentFuture<? extends CommitInfo> future = mdsalUtilsAsync.put(
                 LogicalDatastoreType.CONFIGURATION, TEST_IID, data2);
-        Futures.addCallback(future, new FutureCallback<Void>() {
+        Futures.addCallback(future, new FutureCallback<CommitInfo>() {
 
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final CommitInfo result) {
                 assertEquals(1, readDS().getSupportingNode().size());
             }
 
@@ -144,12 +143,12 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest {
         mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc, true);
         assertEquals(data1, readDS());
 
-        final CheckedFuture<Void, TransactionCommitFailedException> future =
+        final FluentFuture<? extends CommitInfo> future =
                 mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data2, true);
-        Futures.addCallback(future, new FutureCallback<Void>() {
+        Futures.addCallback(future, new FutureCallback<CommitInfo>() {
 
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final CommitInfo result) {
                 assertEquals(2, readDS().getSupportingNode().size());
             }
 
@@ -162,13 +161,13 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest {
 
     @Test
     public void testRead() {
-        final CheckedFuture<Void, TransactionCommitFailedException> fut =
+        final FluentFuture<? extends CommitInfo> fut =
                 mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
 
-        Futures.addCallback(fut, new FutureCallback<Void>() {
+        Futures.addCallback(fut, new FutureCallback<CommitInfo>() {
             @Override
-            public void onSuccess(final Void result) {
-                final CheckedFuture<Optional<Node>, ReadFailedException> future =
+            public void onSuccess(final CommitInfo result) {
+                final FluentFuture<Optional<Node>> future =
                         mdsalUtilsAsync.read(LogicalDatastoreType.CONFIGURATION, TEST_IID);
                 Optional<Node> optNode;
                 try {
index c88e25a9307624cead7262e463ff24b51217b8c8..1a0854da4b2d661074e14b67610360d9b296dce7 100644 (file)
@@ -11,24 +11,24 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import java.util.Optional;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -47,13 +47,12 @@ public class MdsalUtilsTest {
     public void testDelete() {
         WriteTransaction writeTransaction = mock(WriteTransaction.class);
         when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
-        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
-        when(writeTransaction.submit()).thenReturn(future);
+        doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
 
         boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, mock(InstanceIdentifier.class));
 
         verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(writeTransaction, times(1)).submit();
+        verify(writeTransaction, times(1)).commit();
 
         assertTrue("Error, the delete transaction failed", result);
     }
@@ -62,15 +61,14 @@ public class MdsalUtilsTest {
     public void testMerge() {
         WriteTransaction writeTransaction = mock(WriteTransaction.class);
         when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
-        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
-        when(writeTransaction.submit()).thenReturn(future);
+        doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
 
         boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
                 mock(InstanceIdentifier.class), mock(DataObject.class));
 
         verify(writeTransaction, times(1)).merge(any(LogicalDatastoreType.class),
                 any(InstanceIdentifier.class), any(DataObject.class), anyBoolean());
-        verify(writeTransaction, times(1)).submit();
+        verify(writeTransaction, times(1)).commit();
 
         assertTrue("Error, the merge transaction failed", result);
     }
@@ -79,34 +77,29 @@ public class MdsalUtilsTest {
     public void testPut() {
         WriteTransaction writeTransaction = mock(WriteTransaction.class);
         when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
-        CheckedFuture<Void, TransactionCommitFailedException> future = mock(CheckedFuture.class);
-        when(writeTransaction.submit()).thenReturn(future);
+        doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
 
         boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
                 mock(InstanceIdentifier.class), mock(DataObject.class));
 
         verify(writeTransaction, times(1)).put(any(LogicalDatastoreType.class),
                 any(InstanceIdentifier.class), any(DataObject.class), anyBoolean());
-        verify(writeTransaction, times(1)).submit();
+        verify(writeTransaction, times(1)).commit();
 
         assertTrue("Error, the put transaction failed", result);
     }
 
     @Test
-    public void testRead() throws ReadFailedException {
-        ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
-        when(databroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
-        CheckedFuture<Optional, ReadFailedException> future = mock(CheckedFuture.class);
+    public void testRead() {
+        ReadTransaction readTransaction = mock(ReadTransaction.class);
+        doReturn(readTransaction).when(databroker).newReadOnlyTransaction();
         DataObject obj = mock(DataObject.class);
-        Optional opt = Optional.of(obj);
-        when(future.checkedGet()).thenReturn(opt);
-        when(readOnlyTransaction.read(any(LogicalDatastoreType.class),
-                any(InstanceIdentifier.class))).thenReturn(future);
-
+        doReturn(FluentFutures.immediateFluentFuture(Optional.of(obj))).when(readTransaction).read(
+            any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
         DataObject result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, mock(InstanceIdentifier.class));
 
-        verify(readOnlyTransaction, times(1)).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
-        verify(readOnlyTransaction, times(1)).close();
+        verify(readTransaction, times(1)).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        verify(readTransaction, times(1)).close();
 
         assertEquals("Error, the read transaction failed", obj, result);
     }
index 0950fe6da8a35c2739fadddaa7e2f772e9c95da7..b5d69c3cdaa4ca33c31d62a9b3414afa5c455026 100644 (file)
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener;
 import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
@@ -37,9 +38,9 @@ public class NodeInfo {
     public long datapathId;
     public Node ovsdbNode;
     public Node bridgeNode;
-    private NotifyingDataChangeListener ovsdbWaiter;
-    private NotifyingDataChangeListener bridgeWaiter;
-    private final List<NotifyingDataChangeListener> waitList;
+    private ControllerNotifyingDataChangeListener ovsdbWaiter;
+    private ControllerNotifyingDataChangeListener bridgeWaiter;
+    private final List<ControllerNotifyingDataChangeListener> waitList;
     private final OvsdbItUtils itUtils;
 
     /**
@@ -48,7 +49,8 @@ public class NodeInfo {
      * @param itUtils OvsdbItUtils instance
      * @param waitList for tracking outstanding md-sal events
      */
-    NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils, List<NotifyingDataChangeListener> waitList) {
+    NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils,
+            List<ControllerNotifyingDataChangeListener> waitList) {
         this.connectionInfo = connectionInfo;
         this.itUtils = itUtils;
         this.waitList = waitList;
@@ -57,11 +59,11 @@ public class NodeInfo {
     }
 
     private void addWaiters() {
-        ovsdbWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                NotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList);
+        ovsdbWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                ControllerNotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList);
         ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker);
-        bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                NotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList);
+        bridgeWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+                ControllerNotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList);
         bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
     }
 
index 0b3a914eb2aa4a5f7bcaa17d83a948fd7abb9382..eb7d3d3564b33b2634a6b0cbcee114e471d25ff7 100644 (file)
@@ -12,10 +12,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.List;
-
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
-import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener;
 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
@@ -29,7 +28,7 @@ import org.slf4j.LoggerFactory;
  */
 public class OvsdbItUtils {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbItUtils.class);
-    MdsalUtils mdsalUtils;
+    ControllerMdsalUtils mdsalUtils;
     SouthboundUtils southboundUtils;
     DataBroker dataBroker;
 
@@ -39,7 +38,7 @@ public class OvsdbItUtils {
      */
     public OvsdbItUtils(DataBroker dataBroker) {
         this.dataBroker = dataBroker;
-        mdsalUtils = new MdsalUtils(dataBroker);
+        mdsalUtils = new ControllerMdsalUtils(dataBroker);
         southboundUtils = new SouthboundUtils(mdsalUtils);
     }
 
@@ -49,7 +48,8 @@ public class OvsdbItUtils {
      * @param waitList For tracking outstanding md-sal events notifications
      * @return a new NodeInfo object
      */
-    public NodeInfo createNodeInfo(ConnectionInfo connectionInfo, List<NotifyingDataChangeListener> waitList) {
+    public NodeInfo createNodeInfo(ConnectionInfo connectionInfo,
+            List<ControllerNotifyingDataChangeListener> waitList) {
         return new NodeInfo(connectionInfo, this, waitList);
     }
 
index b4434d2825adde56389a650666c1b4baea715ee1..d7da4fb09317cee0ad0efca939be97d334222b14 100644 (file)
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
-import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
@@ -114,7 +114,7 @@ public class SouthboundUtils {
     private static final Logger LOG = LoggerFactory.getLogger(SouthboundUtils.class);
     private static final int OVSDB_UPDATE_TIMEOUT = 1000;
     public static final TopologyId OVSDB_TOPOLOGY_ID = new TopologyId(new Uri("ovsdb:1"));
-    private final MdsalUtils mdsalUtils;
+    private final ControllerMdsalUtils mdsalUtils;
     public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
     public static final String OPENFLOW_SECURE_PROTOCOL = "ssl";
     public static final short OPENFLOW_PORT = 6653;
@@ -129,7 +129,7 @@ public class SouthboundUtils {
     private static final Pattern PATTERN = Pattern.compile(FORMAT);
 
 
-    public SouthboundUtils(MdsalUtils mdsalUtils) {
+    public SouthboundUtils(ControllerMdsalUtils mdsalUtils) {
         this.mdsalUtils = mdsalUtils;
     }