import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, path);
+ Optional<Node> optional = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, path);
if (optional != null && optional.isPresent()) {
HwvtepGlobalAugmentation hwvtepNode = null;
Node node = optional.get();
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.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+ Optional<Node> readNode = new MdsalUtils(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 ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
+ Optional<Node> readNode = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL,
entry.getKey());
//add related globalNode or physicalSwitchNode to operationalNodes map
//for example, when creating physical port, logical switch is needed
InstanceIdentifier<Node> psNodeIid =
(InstanceIdentifier<Node>) pswitch.getSwitchRef().getValue();
Optional<Node> psNode =
- new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, psNodeIid);
+ new MdsalUtils(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 ControllerMdsalUtils(db).readOptional(
+ Optional<Node> hgNode = new MdsalUtils(db).readOptional(
LogicalDatastoreType.OPERATIONAL, hgNodeIid);
if (hgNode.isPresent()) {
operationalNodes.put(hgNodeIid, hgNode.get());
}
public Optional<LogicalSwitches> getLogicalSwitches(final InstanceIdentifier<LogicalSwitches> iid) {
- return new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+ return new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
}
public Optional<Tunnels> getTunnels(final InstanceIdentifier<?> iid, final TunnelsKey tunnelsKey) {
}
public Optional<Tunnels> getTunnels(final InstanceIdentifier<Tunnels> iid) {
- Optional<Tunnels> tunnels = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+ Optional<Tunnels> tunnels = new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
return tunnels;
}
public Optional<HwvtepPhysicalLocatorAugmentation>
getPhysicalLocatorAugmentation(final InstanceIdentifier<TerminationPoint> iid) {
Optional<TerminationPoint> tp =
- new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+ new MdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
if (tp.isPresent()) {
return Optional.ofNullable(tp.get().augmentation(HwvtepPhysicalLocatorAugmentation.class));
}
}
public Optional<Acls> getAcls(final InstanceIdentifier<Acls> iid) {
- Optional<Acls> acl = new ControllerMdsalUtils(db).readOptional(LogicalDatastoreType.OPERATIONAL, iid);
+ Optional<Acls> acl = new MdsalUtils(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.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils(getOperationalState().getDataBroker())
+ Optional<TerminationPoint> confLocOptional = new MdsalUtils(getOperationalState().getDataBroker())
.readOptional(LogicalDatastoreType.CONFIGURATION, iid);
if (confLocOptional.isPresent()) {
locatorUUID = TransactUtils.createPhysicalLocator(transaction, getOperationalState(), iid);
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
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;
return null;
}
LogicalSwitchUpdateCommand cmd = new LogicalSwitchUpdateCommand(operationalState, Collections.emptyList());
- ControllerMdsalUtils mdsalUtils = new ControllerMdsalUtils(operationalState.getDataBroker());
+ MdsalUtils mdsalUtils = new MdsalUtils(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.notation.UUID;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils(
+ Optional<TerminationPoint> configLocatorOptional = new MdsalUtils(
getOperationalState().getDataBroker()).readOptional(LogicalDatastoreType.CONFIGURATION, iid);
if (configLocatorOptional.isPresent()) {
HwvtepPhysicalLocatorAugmentation locatorAugmentation =
import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType;
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.l2.types.rev130827.VlanId;
private final Map<UUID, PhysicalPort> oldPPRows;
private final Map<UUID, PhysicalSwitch> switchUpdatedRows;
private final Set<UUID> skipReconciliationPorts;
- private final ControllerMdsalUtils mdsalUtils;
+ private final MdsalUtils mdsalUtils;
public HwvtepPhysicalPortUpdateCommand(final HwvtepConnectionInstance key, final TableUpdates updates,
final DatabaseSchema dbSchema) {
oldPPRows = TyperUtils.extractRowsOld(PhysicalPort.class, getUpdates(), getDbSchema());
switchUpdatedRows = TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(), getDbSchema());
skipReconciliationPorts = new HashSet<>();
- mdsalUtils = new ControllerMdsalUtils(key.getDataBroker());
+ mdsalUtils = new MdsalUtils(key.getDataBroker());
for (Entry<UUID, PhysicalPort> portUpdateEntry : updatedPPRows.entrySet()) {
Optional<InstanceIdentifier<Node>> switchIid = getTerminationPointSwitch(portUpdateEntry.getKey());
if (switchIid.isPresent()) {
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.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils mdsalUtils = null;
+ private static MdsalUtils mdsalUtils = null;
private static boolean setup = false;
private static int testMethodsRemaining;
private static String addressStr;
}
}
- mdsalUtils = new ControllerMdsalUtils(dataBroker);
+ mdsalUtils = new MdsalUtils(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.ControllerMdsalUtils;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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 ControllerMdsalUtils mdsalUtils = null;
+ private static MdsalUtils mdsalUtils = null;
private static Node ovsdbNode;
private static int testMethodsRemaining;
private static Version schemaVersion;
}
}
- mdsalUtils = new ControllerMdsalUtils(dataBroker);
+ mdsalUtils = new MdsalUtils(dataBroker);
assertTrue("Did not find " + SouthboundUtils.OVSDB_TOPOLOGY_ID.getValue(), getOvsdbTopology());
final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
+++ /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.util.concurrent.FluentFuture;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
-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;
-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.mdsal.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);
- FluentFuture<? extends @NonNull CommitInfo> future = transaction.commit();
- try {
- future.get();
- result = true;
- } catch (InterruptedException | ExecutionException 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.mergeParentStructureMerge(logicalDatastoreType, path, data);
- FluentFuture<? extends @NonNull CommitInfo> future = transaction.commit();
- try {
- future.get();
- result = true;
- } catch (InterruptedException | ExecutionException 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.mergeParentStructurePut(logicalDatastoreType, path, data);
- FluentFuture<? extends @NonNull CommitInfo> future = transaction.commit();
- try {
- future.get();
- result = true;
- } catch (InterruptedException | ExecutionException 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;
- ReadTransaction transaction = databroker.newReadOnlyTransaction();
- do {
- try {
- Optional<D> result = transaction.read(store, (InstanceIdentifier<D>)path).get();
- transaction.close();
- return result;
- } catch (InterruptedException | ExecutionException 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.empty();
- }
-
- 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.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
-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;
-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 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 FluentFuture} object to which you can assign a
- * callback
- */
- public <D extends DataObject> FluentFuture<? extends @NonNull CommitInfo> delete(
- final LogicalDatastoreType store,
- final InstanceIdentifier<D> path) {
- final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
- transaction.delete(store, path);
- return transaction.commit();
- }
-
- /**
- * 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 FluentFuture} object to which you can assign a
- * callback
- */
- public <D extends DataObject> FluentFuture<? extends @NonNull CommitInfo> put(
- final LogicalDatastoreType logicalDatastoreType,
- final InstanceIdentifier<D> path,
- final D data) {
- final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
- transaction.mergeParentStructurePut(logicalDatastoreType, path, data);
- return transaction.commit();
- }
-
- /**
- * 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 FluentFuture} object to which you can assign a
- * callback
- */
- // FIXME: eliminate the boolean flag here to separate out the distinct code paths
- public <D extends DataObject> FluentFuture<? extends @NonNull CommitInfo> merge(
- final LogicalDatastoreType logicalDatastoreType,
- final InstanceIdentifier<D> path,
- final D data,
- final boolean withParent) {
- final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
- if (withParent) {
- transaction.mergeParentStructureMerge(logicalDatastoreType, path, data);
- } else {
- transaction.merge(logicalDatastoreType, path, data);
- }
- return transaction.commit();
- }
-
- /**
- * 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.
- */
- // FIXME: eliminate the boolean flag here to separate out the distinct code paths
- 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 FluentFuture} object to which you can assign a
- * callback
- */
- public <D extends DataObject> FluentFuture<Optional<D>> read(
- final LogicalDatastoreType store,
- final InstanceIdentifier<D> 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) {
- transaction.close();
- }
-
- @Override
- public void onFailure(final Throwable ex) {
- transaction.close();
- }
- };
- future.addCallback(closeTransactionCallback, MoreExecutors.directExecutor());
- return future;
- }
-
- /**
- * Assign a default callback to a {@link FluentFuture}. 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 FluentFuture<? extends @NonNull CommitInfo> transactionFuture,
- final String operationDesc) {
- transactionFuture.addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo 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.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;
-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(DataTreeIdentifier.create(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;
- }
-}
}
/**
- * Create a new ControllerNotifyingDataChangeListener.
+ * Create a new NotifyingDataChangeListener.
*
* @param type DataStore type
* @param iid of the md-sal object we're waiting for
}
/**
- * Completely reset the state of this ControllerNotifyingDataChangeListener.
+ * Completely reset the state of this NotifyingDataChangeListener.
*
* @param newType DataStore type
* @param newIid of the md-sal object we're waiting for
+++ /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.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.MoreExecutors;
-import java.util.Collections;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-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;
-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 FluentFuture<? extends @NonNull CommitInfo> fut = mdsalUtilsAsync.put(
- LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
- fut.addCallback(new FutureCallback<CommitInfo>() {
-
- @Override
- public void onSuccess(final CommitInfo result) {
- final FluentFuture<? extends @NonNull CommitInfo> future =
- mdsalUtilsAsync.delete(LogicalDatastoreType.CONFIGURATION, TEST_IID);
- future.addCallback(new FutureCallback<CommitInfo>() {
-
- @Override
- public void onSuccess(final CommitInfo 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 FluentFuture<? extends @NonNull CommitInfo> future = mdsalUtilsAsync.put(
- LogicalDatastoreType.CONFIGURATION, TEST_IID, data2);
- future.addCallback(new FutureCallback<CommitInfo>() {
-
- @Override
- public void onSuccess(final CommitInfo 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 FluentFuture<? extends @NonNull CommitInfo> future =
- mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data2, true);
- future.addCallback(new FutureCallback<CommitInfo>() {
-
- @Override
- public void onSuccess(final CommitInfo result) {
- assertEquals(2, readDS().getSupportingNode().size());
- }
-
- @Override
- public void onFailure(final Throwable ex) {
- fail(ex.getMessage());
- }
- }, MoreExecutors.directExecutor());
- }
-
- @Test
- public void testRead() {
- final FluentFuture<? extends @NonNull CommitInfo> fut =
- mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, DATA);
-
- fut.addCallback(new FutureCallback<CommitInfo>() {
- @Override
- public void onSuccess(final CommitInfo result) {
- final FluentFuture<Optional<Node>> 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.ArgumentMatchers.any;
-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.util.concurrent.FluentFuture;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-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;
-
-/**
- * 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);
- FluentFuture<? extends @NonNull CommitInfo> future = mock(FluentFuture.class);
- Mockito.when(writeTransaction.commit()).thenReturn(FluentFutures.immediateNullFluentFuture());
-
- boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, mock(InstanceIdentifier.class));
-
- verify(writeTransaction, times(1)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
- verify(writeTransaction, times(1)).commit();
-
- assertTrue("Error, the delete transaction failed", result);
- }
-
- @Test
- public void testMerge() {
- WriteTransaction writeTransaction = mock(WriteTransaction.class);
- when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
- FluentFuture<? extends @NonNull CommitInfo> future = mock(FluentFuture.class);
- Mockito.when(writeTransaction.commit()).thenReturn(FluentFutures.immediateNullFluentFuture());
-
- boolean result = mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION,
- mock(InstanceIdentifier.class), mock(DataObject.class));
-
- verify(writeTransaction, times(1)).mergeParentStructureMerge(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class), any(DataObject.class));
- verify(writeTransaction, times(1)).commit();
-
- assertTrue("Error, the merge transaction failed", result);
- }
-
- @Test
- public void testPut() {
- WriteTransaction writeTransaction = mock(WriteTransaction.class);
- when(databroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
- FluentFuture<? extends @NonNull CommitInfo> future = mock(FluentFuture.class);
- Mockito.when(writeTransaction.commit()).thenReturn(FluentFutures.immediateNullFluentFuture());
-
- boolean result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
- mock(InstanceIdentifier.class), mock(DataObject.class));
-
- verify(writeTransaction, times(1)).mergeParentStructurePut(any(LogicalDatastoreType.class),
- any(InstanceIdentifier.class), any(DataObject.class));
- verify(writeTransaction, times(1)).commit();
-
- assertTrue("Error, the put transaction failed", result);
- }
-
- @Test
- public void testRead() throws InterruptedException, ExecutionException {
- ReadTransaction readOnlyTransaction = mock(ReadTransaction.class);
- when(databroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
- FluentFuture<Optional> future = mock(FluentFuture.class);
- DataObject obj = mock(DataObject.class);
- Optional opt = Optional.of(obj);
- when(future.get()).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 java.util.List;
import org.opendaylight.mdsal.common.api.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 ControllerNotifyingDataChangeListener ovsdbWaiter;
- private ControllerNotifyingDataChangeListener bridgeWaiter;
- private final List<ControllerNotifyingDataChangeListener> waitList;
+ private NotifyingDataChangeListener ovsdbWaiter;
+ private NotifyingDataChangeListener bridgeWaiter;
+ private final List<NotifyingDataChangeListener> waitList;
private final OvsdbItUtils itUtils;
/**
* @param waitList for tracking outstanding md-sal events
*/
NodeInfo(ConnectionInfo connectionInfo, OvsdbItUtils itUtils,
- List<ControllerNotifyingDataChangeListener> waitList) {
+ List<NotifyingDataChangeListener> waitList) {
this.connectionInfo = connectionInfo;
this.itUtils = itUtils;
this.waitList = waitList;
}
private void addWaiters() {
- ovsdbWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- ControllerNotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList);
+ ovsdbWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ NotifyingDataChangeListener.BIT_CREATE, ovsdbIid, waitList);
ovsdbWaiter.registerDataChangeListener(itUtils.dataBroker);
- bridgeWaiter = new ControllerNotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- ControllerNotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList);
+ bridgeWaiter = new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ NotifyingDataChangeListener.BIT_CREATE, bridgeIid, waitList);
bridgeWaiter.registerDataChangeListener(itUtils.dataBroker);
}
import java.util.List;
import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerNotifyingDataChangeListener;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+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.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);
- ControllerMdsalUtils mdsalUtils;
+ MdsalUtils mdsalUtils;
SouthboundUtils southboundUtils;
DataBroker dataBroker;
*/
public OvsdbItUtils(DataBroker dataBroker) {
this.dataBroker = dataBroker;
- mdsalUtils = new ControllerMdsalUtils(dataBroker);
+ mdsalUtils = new MdsalUtils(dataBroker);
southboundUtils = new SouthboundUtils(mdsalUtils);
}
* @return a new NodeInfo object
*/
public NodeInfo createNodeInfo(ConnectionInfo connectionInfo,
- List<ControllerNotifyingDataChangeListener> waitList) {
+ List<NotifyingDataChangeListener> waitList) {
return new NodeInfo(connectionInfo, this, waitList);
}
import java.util.stream.Collectors;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.ovsdb.utils.config.ConfigProperties;
-import org.opendaylight.ovsdb.utils.mdsal.utils.ControllerMdsalUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
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;
abstract <T extends DataObject> boolean merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data);
}
- @Deprecated
- private static final class ControllerUtilsProvider extends UtilsProvider {
- private final ControllerMdsalUtils mdsalUtils;
-
- ControllerUtilsProvider(final ControllerMdsalUtils mdsalUtils) {
- this.mdsalUtils = requireNonNull(mdsalUtils);
- }
-
- @Override
- <T extends DataObject> T read(LogicalDatastoreType store, InstanceIdentifier<T> path) {
- return mdsalUtils.read(store, path);
- }
-
- @Override
- <T extends DataObject> boolean put(LogicalDatastoreType store,
- InstanceIdentifier<T> path, T data) {
- return mdsalUtils.put(store, path, data);
- }
-
- @Override
- boolean delete(LogicalDatastoreType store, InstanceIdentifier<?> path) {
- return mdsalUtils.delete(store, path);
- }
-
- @Override
- <T extends DataObject> boolean merge(LogicalDatastoreType store, InstanceIdentifier<T> path, T data) {
- return mdsalUtils.merge(store, path, data);
- }
- }
-
private static final class MdsalUtilsProvider extends UtilsProvider {
private final MdsalUtils mdsalUtils;
private final UtilsProvider provider;
- @Deprecated
- public SouthboundUtils(ControllerMdsalUtils mdsalUtils) {
- provider = new ControllerUtilsProvider(mdsalUtils);
- }
-
public SouthboundUtils(MdsalUtils mdsalUtils) {
provider = new MdsalUtilsProvider(mdsalUtils);
}