This operation was not exposed at the binding layer when these
utilities were conceived and thus is lacking here, even when they
are available as part of MDSAL-389.
The MD-SAL version of TypedReadTransaction has been updated back
then, this patch backports these changes to legacy Genius APIs.
Also converts a few callers to use this capability, potentially
improving performance.
JIRA: MDSAL-389
Change-Id: Ieb870a49c8239ee74e697d7d36dea431b24362ae
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
7144e4db6a02daf37f8ba055745a359d0a80c21e)
NodeId nodeID = IfmUtil.getNodeIdFromNodeConnectorId(nodeConnectorId);
InstanceIdentifier<Node> nodeInstanceIdentifier = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, new NodeKey(nodeID)).build();
- return tx.read(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier).checkedGet().isPresent();
+ return tx.exists(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier).checkedGet();
}
public static InstanceIdentifier<Interface> getInterfaceIdentifier(InterfaceKey interfaceKey) {
throws ExecutionException, InterruptedException {
InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class)
.child(ExternalTunnel.class, ItmUtils.getExternalTunnelKey(dstDpnOrNode, srcDpnOrNode, tunType));
- return tx.read(path).get().isPresent();
+ return tx.exists(path).get();
}
}
private void initializeTZNode() {
InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION, tx -> {
- FluentFuture<Optional<TransportZones>> tzones = tx.read(path);
- if (!tzones.get().isPresent()) {
+ FluentFuture<Boolean> tzones = tx.exists(path);
+ if (!tzones.get()) {
TransportZonesBuilder tzb = new TransportZonesBuilder();
tx.put(path, tzb.build());
}
doReturn(FluentFutures.immediateFluentFuture(optionalTransportZone))
.when(typedReadWriteTransaction).read(transportZoneIdentifier);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels))
- .when(typedReadWriteTransaction).read(externalTunnelIdentifier1);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels))
- .when(typedReadWriteTransaction).read(externalTunnelIdentifier2);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels)).when(typedReadWriteTransaction)
- .read(externalTunnelIdentifier3);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels)).when(typedReadWriteTransaction)
- .read(externalTunnelIdentifier4);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels)).when(typedReadWriteTransaction)
- .read(externalTunnelIdentifier5);
- doReturn(FluentFutures.immediateFluentFuture(exTunnels)).when(typedReadWriteTransaction)
- .read(externalTunnelIdentifier6);
+ doReturn(FluentFutures.immediateTrueFluentFuture())
+ .when(typedReadWriteTransaction).exists(externalTunnelIdentifier1);
+ doReturn(FluentFutures.immediateTrueFluentFuture())
+ .when(typedReadWriteTransaction).exists(externalTunnelIdentifier2);
+ doReturn(FluentFutures.immediateTrueFluentFuture()).when(typedReadWriteTransaction)
+ .exists(externalTunnelIdentifier3);
+ doReturn(FluentFutures.immediateTrueFluentFuture()).when(typedReadWriteTransaction)
+ .exists(externalTunnelIdentifier4);
+ doReturn(FluentFutures.immediateTrueFluentFuture()).when(typedReadWriteTransaction)
+ .exists(externalTunnelIdentifier5);
+ doReturn(FluentFutures.immediateTrueFluentFuture()).when(typedReadWriteTransaction)
+ .exists(externalTunnelIdentifier6);
+
try {
ItmExternalTunnelDeleteWorker
.deleteHwVtepsTunnels(dpnTepsList, cfgdHwVtepsList, transportZone, typedReadWriteTransaction,
private ListenableFuture<Void> unlock(final String lockName,
final InstanceIdentifier<Lock> lockInstanceIdentifier, final int retry) {
ListenableFuture<Void> future = txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> {
- Optional<Lock> result = tx.read(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier).get();
- if (!result.isPresent()) {
+ Boolean result = tx.exists(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier).get();
+ if (!result) {
LOG.debug("unlock ignored, as unnecessary; lock is already unlocked: {}", lockName);
} else {
tx.delete(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier);
return Futures.makeChecked(delegate.read(path),
e -> new ReadFailedException("Error reading from the datastore", e));
}
+
+ @Override
+ public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
+ InstanceIdentifier<?> path) {
+ checkStore(store);
+ return Futures.makeChecked(delegate.exists(path),
+ e -> new ReadFailedException("Error reading from the datastore", e));
+ }
}
}
* @return A future providing access to the result of the read, when it’s available, or any error encountered.
*/
<T extends DataObject> FluentFuture<Optional<T>> read(InstanceIdentifier<T> path);
+
+ /**
+ * Determines if an object exists at the given path.
+ *
+ * @see ReadTransaction#exists(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType,
+ * InstanceIdentifier)
+ *
+ * @param path The path to read from.
+ * @return A future providing access to the result of the check, when it’s available, or any error encountered.
+ */
+ FluentFuture<Boolean> exists(InstanceIdentifier<?> path);
}
return FluentFuture.from(delegate.read(getDatastoreType(), path));
}
+ @Override
+ public FluentFuture<Boolean> exists(InstanceIdentifier<?> path) {
+ return FluentFuture.from(delegate.exists(getDatastoreType(), path));
+ }
+
@Override
public Object getIdentifier() {
return delegate.getIdentifier();
public <T extends DataObject> FluentFuture<Optional<T>> read(InstanceIdentifier<T> path) {
return FluentFuture.from(delegate.read(getDatastoreType(), path));
}
+
+ @Override
+ public FluentFuture<Boolean> exists(InstanceIdentifier<?> path) {
+ return FluentFuture.from(delegate.exists(getDatastoreType(), path));
+ }
}
InstanceIdentifier<T> path) {
return ((ReadWriteTransaction) delegate()).read(store, path);
}
+
+ @Override
+ public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
+ InstanceIdentifier<?> path) {
+ return ((ReadWriteTransaction) delegate()).exists(store, path);
+ }
}
private static boolean groupExists(TypedReadTransaction<Configuration> tx, Node nodeDpn, long groupId)
throws ExecutionException, InterruptedException {
- return tx.read(buildGroupInstanceIdentifier(groupId, nodeDpn)).get().isPresent();
+ return tx.exists(buildGroupInstanceIdentifier(groupId, nodeDpn)).get();
}
private static InstanceIdentifier<Group> buildGroupInstanceIdentifier(long groupId, Node nodeDpn) {