fix CheckedFutures deprecated warnings 08/83608/2
authorguillaume.lambert <guillaume.lambert@orange.com>
Wed, 14 Aug 2019 07:49:58 +0000 (09:49 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 19 Aug 2019 14:28:24 +0000 (16:28 +0200)
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

common/src/main/java/org/opendaylight/transportpce/common/device/DeviceTransaction.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java
common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionImpl.java
common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionService.java
common/src/main/java/org/opendaylight/transportpce/common/network/RequestProcessor.java
common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/Rdm2XpdrLink.java

index 056bbff5fe3c722a5e084582c3e66b83da68f4d3..baee138a2a302d995c0cdba73186d49b378a6680 100644 (file)
@@ -9,7 +9,6 @@
 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;
@@ -23,7 +22,6 @@ import javax.annotation.Nullable;
 
 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;
@@ -55,7 +53,7 @@ public class DeviceTransaction {
         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);
     }
index 6eda98e65406727f4a66aaa5e7e3bcf2a242cbb4..6a03fe952464ae895c8d5394ba5393046f09b3f9 100644 (file)
@@ -8,7 +8,7 @@
 
 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;
@@ -16,13 +16,13 @@ import java.util.HashMap;
 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;
@@ -160,14 +160,13 @@ public class PortMappingVersion121 {
                         .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 {
@@ -591,12 +590,12 @@ public class PortMappingVersion121 {
         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;
         }
index cb3ca129bcf3c67654dd4fa8fb17d4e69204866c..2ff91ffe1acd53b1b37a1f2d5e83cf924d34ccbd 100644 (file)
@@ -8,7 +8,7 @@
 
 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;
@@ -16,12 +16,12 @@ import java.util.HashMap;
 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;
@@ -157,14 +157,13 @@ public class PortMappingVersion221 {
                         .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 {
@@ -586,12 +585,12 @@ public class PortMappingVersion221 {
         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;
         }
index b073de53be3482d7e67c9ab1644eed4d0ddeb2eb..ff99c6842550746d562f39ac1ce93da2b4f4905e 100644 (file)
@@ -8,10 +8,8 @@
 
 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;
 
@@ -26,8 +24,8 @@ public class NetworkTransactionImpl implements NetworkTransactionService {
 
     }
 
-    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);
     }
 
index 23dc9b542ee3c09f497c26871e48c18c91d87613..83020f128a739a9c6b37369a776118a95ff5dbbd 100644 (file)
@@ -10,11 +10,9 @@ 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 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;
 
@@ -22,7 +20,7 @@ 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);
index f64c18195c6e51a8ebc7073372fe82fcbcb5c186..02d5a8644fb5a8b0964068bd4c181c437b9df945 100644 (file)
@@ -8,7 +8,6 @@
 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;
@@ -18,15 +17,12 @@ import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 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);
@@ -47,12 +43,12 @@ public class RequestProcessor {
 
     }
 
-    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();
@@ -62,7 +58,7 @@ public class RequestProcessor {
     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);
     }
 
@@ -70,7 +66,7 @@ public class RequestProcessor {
         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);
     }
 
@@ -78,7 +74,7 @@ public class RequestProcessor {
         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);
     }
 
@@ -87,7 +83,7 @@ public class RequestProcessor {
         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);
     }
 
@@ -95,7 +91,7 @@ public class RequestProcessor {
         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);
     }
 
@@ -115,33 +111,33 @@ public class RequestProcessor {
     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();
     }
 
index 355d57367c5c125f40d140c40d2ae55569f21232..8512c6811adb9a9e3b7f9cbf44c496fa4cead0ca 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 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;
 
@@ -64,7 +65,7 @@ public class DeviceTransactionManagerTest {
         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);
     }
@@ -336,7 +337,7 @@ public class DeviceTransactionManagerTest {
         }
 
 
-        Mockito.when(rwTransactionMock.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        Mockito.doReturn(FluentFutures.immediateNullFluentFuture()).when(rwTransactionMock.submit());
 
         try {
             putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData);
index 4ed0c9461f5d71085bdccfabc20c4b165829df78..794ef8e575c7184a21b59e291090516fb4fc46fb 100644 (file)
@@ -9,11 +9,11 @@
 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;
@@ -55,14 +55,14 @@ final class Rdm2XpdrLink {
         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;
 
@@ -86,13 +86,13 @@ final class Rdm2XpdrLink {
             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;
         }