com.google.common.util.concurrent.CheckedFuture is deprecated.
Netconf switched to new MD-SAL APIs that rely now on FluentFuture.
https://git.opendaylight.org/gerrit/c/netconf/+/78424
https://git.opendaylight.org/gerrit/c/netconf/+/78425
https://git.opendaylight.org/gerrit/c/controller/+/80412
- switch to FluentFuture or ListenableFuture when possible.
- ReadFailedException removed since not managed by ListenableFuture.
- When mocking MD-SAL APIs, switch to FluentFuture and doReturn().when()
since when().thenReturn() raises an error with FluentFuture.
- checkGet catched by TransactionCommitFailedException replaced by
(Future.)get catched by InterruptedException and ExecutionException
- improve by the way common.network.RequestProcessor logs syntax
TODO: remove makeChecked use from Junit DeviceTransactionManagerTest
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I138268e9a117306107f5a7c30093b7b3132fa9c9
package org.opendaylight.transportpce.common.device;
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.ListenableFuture;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
LOG.debug("Device transaction created. Lock: {}", deviceLock);
}
- public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store,
+ public <T extends DataObject> ListenableFuture<Optional<T>> read(LogicalDatastoreType store,
InstanceIdentifier<T> path) {
return rwTx.read(store, path);
}
package org.opendaylight.transportpce.common.mapping;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.transportpce.common.StringConstants;
import org.opendaylight.transportpce.common.Timeouts;
import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
.child(Nodes.class, new NodesKey(nodeId))
.child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
- CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
- submit.checkedGet();
+ ListenableFuture<Void> submit = writeTransaction.submit();
+ submit.get();
return true;
}
return false;
- } catch (TransactionCommitFailedException e) {
- LOG.error("Transaction Commit Error updating Mapping {} for node {}",
- oldMapping.getLogicalConnectionPoint(), nodeId, e);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
return false;
}
} else {
InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
Network network = nwBldr.build();
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
- CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
+ ListenableFuture<Void> submit = writeTransaction.submit();
try {
- submit.checkedGet();
+ submit.get();
return true;
- } catch (TransactionCommitFailedException e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed to post {}", network, e);
return false;
}
package org.opendaylight.transportpce.common.mapping;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.transportpce.common.StringConstants;
import org.opendaylight.transportpce.common.Timeouts;
import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
.child(Nodes.class, new NodesKey(nodeId))
.child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
- CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
- submit.checkedGet();
+ ListenableFuture<Void> submit = writeTransaction.submit();
+ submit.get();
return true;
}
return false;
- } catch (TransactionCommitFailedException e) {
- LOG.error("Transaction Commit Error updating Mapping {} for node {}", oldMapping
- .getLogicalConnectionPoint(), nodeId, e);
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
return false;
}
} else {
InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
Network network = nwBldr.build();
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
- CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
+ ListenableFuture<Void> submit = writeTransaction.submit();
try {
- submit.checkedGet();
+ submit.get();
return true;
- } catch (TransactionCommitFailedException e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed to post {}", network, e);
return false;
}
package org.opendaylight.transportpce.common.network;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
}
- public <T extends DataObject> CheckedFuture<com.google.common.base.Optional<T>,
- ReadFailedException> read(LogicalDatastoreType store, InstanceIdentifier<T> path) {
+ public <T extends DataObject> ListenableFuture<com.google.common.base.Optional<T>>
+ read(LogicalDatastoreType store, InstanceIdentifier<T> path) {
return requestProcessor.read(store, path);
}
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public interface NetworkTransactionService {
- <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store,
+ <T extends DataObject> ListenableFuture<Optional<T>> read(LogicalDatastoreType store,
InstanceIdentifier<T> path);
void delete(LogicalDatastoreType store, InstanceIdentifier<?> path);
package org.opendaylight.transportpce.common.network;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-
public class RequestProcessor {
private static final Logger LOG = LoggerFactory.getLogger(RequestProcessor.class);
}
- public <T extends DataObject> CheckedFuture<Optional<T>,
- ReadFailedException> read(LogicalDatastoreType store,InstanceIdentifier<T> path) {
+ public <T extends DataObject> ListenableFuture<Optional<T>>
+ read(LogicalDatastoreType store,InstanceIdentifier<T> path) {
- CheckedFuture<Optional<T>, ReadFailedException> result = null;
+ ListenableFuture<Optional<T>> result = null;
acquireReadLock();
- LOG.debug("Number of threads in queue to read " + lock.getQueueLength());
+ LOG.debug("Number of threads in queue to read {}", lock.getQueueLength());
result = rwTx.read(store, path);
releaseReadLock();
public <T extends DataObject> void delete(LogicalDatastoreType store, InstanceIdentifier<?> path) {
acquireLock();
- LOG.info("Number of delete requests waiting in queue :" + lock.getQueueLength());
+ LOG.info("Number of delete requests waiting in queue :{}", lock.getQueueLength());
rwTx.delete(store, path);
}
InstanceIdentifier<T> path, T data, boolean createMissingParents) {
acquireLock();
- LOG.debug("Number of put requests waiting in queue :" + lock.getQueueLength());
+ LOG.debug("Number of put requests waiting in queue :{}", lock.getQueueLength());
rwTx.put(store, path, data, createMissingParents);
}
InstanceIdentifier<T> path, T data) {
acquireLock();
- LOG.debug("Number of put requests waiting in queue :" + lock.getQueueLength());
+ LOG.debug("Number of put requests waiting in queue :{}", lock.getQueueLength());
rwTx.put(store, path, data);
}
InstanceIdentifier<T> path, T data, boolean createMissingParents) {
acquireLock();
- LOG.debug("Number of merge requests waiting in queue :" + lock.getQueueLength());
+ LOG.debug("Number of merge requests waiting in queue :{}", lock.getQueueLength());
rwTx.merge(store, path, data, createMissingParents);
}
InstanceIdentifier<T> path, T data) {
acquireLock();
- LOG.debug("Number of merge requests waiting in queue :" + lock.getQueueLength());
+ LOG.debug("Number of merge requests waiting in queue :{}", lock.getQueueLength());
rwTx.merge(store, path, data);
}
private void acquireLock() {
if (!lock.writeLock().isHeldByCurrentThread()) {
lock.writeLock().lock();
- LOG.debug("Number of write lock requests waiting in queue :" + lock.getQueueLength());
- LOG.info("Write Lock acquired by : " + Thread.currentThread().getName());
+ LOG.debug("Number of write lock requests waiting in queue :{}", lock.getQueueLength());
+ LOG.info("Write Lock acquired by : {}", Thread.currentThread().getName());
rwTx = resetRwTx();
} else {
- LOG.debug("Lock already acquired by : " + Thread.currentThread().getName());
+ LOG.debug("Lock already acquired by : {}", Thread.currentThread().getName());
}
}
private void acquireReadLock() {
if (lock.getReadHoldCount() > 0) {
- LOG.info("Read Lock already acquired by : " + Thread.currentThread().getName());
+ LOG.info("Read Lock already acquired by : {}", Thread.currentThread().getName());
} else {
lock.readLock().lock();
rwTx = resetRwTx();
- LOG.info("Read Lock acquired by : " + Thread.currentThread().getName());
+ LOG.info("Read Lock acquired by : {}", Thread.currentThread().getName());
}
}
private void releaseLock() {
if (lock.writeLock().isHeldByCurrentThread()) {
- LOG.info("Write Lock released by : " + Thread.currentThread().getName());
+ LOG.info("Write Lock released by : {}", Thread.currentThread().getName());
lock.writeLock().unlock();
}
}
private void releaseReadLock() {
- LOG.info("Read Lock released by : " + Thread.currentThread().getName());
+ LOG.info("Read Lock released by : {}", Thread.currentThread().getName());
lock.readLock().unlock();
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkBuilder;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
Mockito.when(mountPointServiceMock.getMountPoint(any())).thenReturn(Optional.of(mountPointMock));
Mockito.when(mountPointMock.getService(any())).thenReturn(Optional.of(dataBrokerMock));
Mockito.when(dataBrokerMock.newReadWriteTransaction()).thenReturn(rwTransactionMock);
- Mockito.when(rwTransactionMock.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+ Mockito.doReturn(FluentFutures.immediateNullFluentFuture()).when(rwTransactionMock.submit());
this.transactionManager = new DeviceTransactionManagerImpl(mountPointServiceMock, 3000);
}
}
- Mockito.when(rwTransactionMock.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+ Mockito.doReturn(FluentFutures.immediateNullFluentFuture()).when(rwTransactionMock.submit());
try {
putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData);
package org.opendaylight.transportpce.networkmodel;
import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.transportpce.common.NetworkUtils;
import org.opendaylight.transportpce.networkmodel.util.LinkIdUtil;
import org.opendaylight.transportpce.networkmodel.util.OpenRoadmFactory;
WriteTransaction wrtx = dataBroker.newWriteOnlyTransaction();
wrtx.merge(LogicalDatastoreType.CONFIGURATION, nwIID.build(), topoNetowkLayer);
- CheckedFuture<Void, TransactionCommitFailedException> submit = wrtx.submit();
+ ListenableFuture<Void> submit = wrtx.submit();
try {
- submit.checkedGet();
+ submit.get();
LOG.info("Post successful");
return true;
- } catch (TransactionCommitFailedException e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed to create Xponder to Roadm link in the Topo layer ");
return false;
new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)));
WriteTransaction wrtx = dataBroker.newWriteOnlyTransaction();
wrtx.merge(LogicalDatastoreType.CONFIGURATION, nwIID.build(), topoNetowkLayer);
- CheckedFuture<Void, TransactionCommitFailedException> submit = wrtx.submit();
+ ListenableFuture<Void> submit = wrtx.submit();
try {
- submit.checkedGet();
+ submit.get();
LOG.info("Post successful");
return true;
- } catch (TransactionCommitFailedException e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed to create Xponder to Roadm link in the Topo layer ");
return false;
}