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;
// 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();
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;
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,
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,
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;
//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);
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;
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());
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
@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());
}
@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());
}
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) {
}
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;
}
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));
}
}
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;
}
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;
} 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);
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;
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));
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;
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 =
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;
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;
}
}
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;
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;
}
}
- 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);
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;
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;
}
}
- 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);
<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>
--- /dev/null
+/*
+ * 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);
+
+ }
+}
--- /dev/null
+/*
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
*/
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;
/**
* 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;
* @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;
* @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;
* @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;
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");
}
}
} 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);
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;
/**
* 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;
* {@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();
}
/**
* {@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();
}
/**
* 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();
}
/**
* {@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) {
* 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);
}
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;
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;
}
/**
- * Create a new NotifyingDataChangeListener.
+ * Create a new ControllerNotifyingDataChangeListener.
*
* @param type DataStore type
* @param iid of the md-sal object we're waiting for
}
/**
- * 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;
@SuppressWarnings({ "rawtypes", "unchecked" })
public void registerDataChangeListener(DataBroker dataBroker) {
- listenerRegistration = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(type,
+ listenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(type,
(InstanceIdentifier)iid), this);
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
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;
@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());
}
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());
}
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());
}
@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 {
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;
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);
}
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);
}
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);
}
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;
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;
/**
* @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;
}
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);
}
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;
*/
public class OvsdbItUtils {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbItUtils.class);
- MdsalUtils mdsalUtils;
+ ControllerMdsalUtils mdsalUtils;
SouthboundUtils southboundUtils;
DataBroker dataBroker;
*/
public OvsdbItUtils(DataBroker dataBroker) {
this.dataBroker = dataBroker;
- mdsalUtils = new MdsalUtils(dataBroker);
+ mdsalUtils = new ControllerMdsalUtils(dataBroker);
southboundUtils = new SouthboundUtils(mdsalUtils);
}
* @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);
}
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;
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;
private static final Pattern PATTERN = Pattern.compile(FORMAT);
- public SouthboundUtils(MdsalUtils mdsalUtils) {
+ public SouthboundUtils(ControllerMdsalUtils mdsalUtils) {
this.mdsalUtils = mdsalUtils;
}