From 7600ff43d8769cc58fd46d908f29d39129133853 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Wed, 14 Aug 2019 09:49:58 +0200 Subject: [PATCH] fix CheckedFutures deprecated warnings 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 Change-Id: I138268e9a117306107f5a7c30093b7b3132fa9c9 --- .../common/device/DeviceTransaction.java | 4 +-- .../common/mapping/PortMappingVersion121.java | 19 +++++----- .../common/mapping/PortMappingVersion221.java | 19 +++++----- .../network/NetworkTransactionImpl.java | 6 ++-- .../network/NetworkTransactionService.java | 4 +-- .../common/network/RequestProcessor.java | 36 +++++++++---------- .../device/DeviceTransactionManagerTest.java | 5 +-- .../networkmodel/Rdm2XpdrLink.java | 16 ++++----- 8 files changed, 49 insertions(+), 60 deletions(-) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/device/DeviceTransaction.java b/common/src/main/java/org/opendaylight/transportpce/common/device/DeviceTransaction.java index 056bbff5f..baee138a2 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/device/DeviceTransaction.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/device/DeviceTransaction.java @@ -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 CheckedFuture, ReadFailedException> read(LogicalDatastoreType store, + public ListenableFuture> read(LogicalDatastoreType store, InstanceIdentifier path) { return rwTx.read(store, path); } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java index 6eda98e65..6a03fe952 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java @@ -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 submit = writeTransaction.submit(); - submit.checkedGet(); + ListenableFuture 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 nodesIID = InstanceIdentifier.builder(Network.class).build(); Network network = nwBldr.build(); writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network); - CheckedFuture submit = writeTransaction.submit(); + ListenableFuture 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; } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java index cb3ca129b..2ff91ffe1 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java @@ -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 submit = writeTransaction.submit(); - submit.checkedGet(); + ListenableFuture 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 nodesIID = InstanceIdentifier.builder(Network.class).build(); Network network = nwBldr.build(); writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network); - CheckedFuture submit = writeTransaction.submit(); + ListenableFuture 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; } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionImpl.java b/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionImpl.java index b073de53b..ff99c6842 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionImpl.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionImpl.java @@ -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 CheckedFuture, - ReadFailedException> read(LogicalDatastoreType store, InstanceIdentifier path) { + public ListenableFuture> + read(LogicalDatastoreType store, InstanceIdentifier path) { return requestProcessor.read(store, path); } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionService.java b/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionService.java index 23dc9b542..83020f128 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionService.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/network/NetworkTransactionService.java @@ -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 { - CheckedFuture, ReadFailedException> read(LogicalDatastoreType store, + ListenableFuture> read(LogicalDatastoreType store, InstanceIdentifier path); void delete(LogicalDatastoreType store, InstanceIdentifier path); diff --git a/common/src/main/java/org/opendaylight/transportpce/common/network/RequestProcessor.java b/common/src/main/java/org/opendaylight/transportpce/common/network/RequestProcessor.java index f64c18195..02d5a8644 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/network/RequestProcessor.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/network/RequestProcessor.java @@ -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 CheckedFuture, - ReadFailedException> read(LogicalDatastoreType store,InstanceIdentifier path) { + public ListenableFuture> + read(LogicalDatastoreType store,InstanceIdentifier path) { - CheckedFuture, ReadFailedException> result = null; + ListenableFuture> 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 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 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 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 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 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(); } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java b/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java index 355d57367..8512c6811 100644 --- a/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java +++ b/common/src/test/java/org/opendaylight/transportpce/common/device/DeviceTransactionManagerTest.java @@ -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); diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/Rdm2XpdrLink.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/Rdm2XpdrLink.java index 4ed0c9461..794ef8e57 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/Rdm2XpdrLink.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/Rdm2XpdrLink.java @@ -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 submit = wrtx.submit(); + ListenableFuture 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 submit = wrtx.submit(); + ListenableFuture 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; } -- 2.36.6