Remove unused AsyncChangeEvent references 99/63099/1
authorTom Pantelis <tompantelis@gmail.com>
Wed, 13 Sep 2017 13:32:29 +0000 (09:32 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 13 Sep 2017 13:32:29 +0000 (09:32 -0400)
The DataChangeListener API has been deprecated for a couple
releases and is being removed in Oxygen. unimgr has unused
references to AsyncChangeEvent so removed them.

Change-Id: I04c0f338e03cb1a05ff8dccbffda39a1679a2f6d
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
impl/src/main/java/org/opendaylight/unimgr/utils/OvsdbUtils.java
impl/src/test/java/org/opendaylight/unimgr/utils/OvsdbUtilsTest.java

index f35089852d7ca73e0bd6a395750808bb76238251..8cba38d835670a1a655e50ca55037ebeeb5289ee 100644 (file)
@@ -8,20 +8,20 @@
 
 package org.opendaylight.unimgr.utils;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.CheckedFuture;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Set;
 import java.util.UUID;
-
 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.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
@@ -85,11 +85,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.CheckedFuture;
-
 public class OvsdbUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbUtils.class);
@@ -184,7 +179,7 @@ public class OvsdbUtils {
      * @return A List of Controller Entry to be used when adding controllers
      */
     public static List<ControllerEntry> createControllerEntries(String targetString) {
-        final List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
+        final List<ControllerEntry> controllerEntries = new ArrayList<>();
         final ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
         controllerEntryBuilder.setTarget(new Uri(targetString));
         controllerEntries.add(controllerEntryBuilder.build());
@@ -241,11 +236,11 @@ public class OvsdbUtils {
      * @return A List of protocol entry
      */
     public static List<ProtocolEntry> createMdsalProtocols() {
-        final List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+        final List<ProtocolEntry> protocolList = new ArrayList<>();
         final ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
                 SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
         protocolList.add(new ProtocolEntryBuilder().setProtocol(
-                (Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build());
+                mapper.get("OpenFlow13")).build());
         return protocolList;
     }
 
@@ -257,7 +252,7 @@ public class OvsdbUtils {
      */
     public static OvsdbBridgeAugmentation createOvsdbBridgeAugmentation(Uni uni) throws Exception {
         final OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
-        if ((ovsdbNodeRef != null) && (ovsdbNodeRef.getValue() != null)) {
+        if (ovsdbNodeRef != null && ovsdbNodeRef.getValue() != null) {
             final UUID bridgeUuid = UUID.randomUUID();
             final OvsdbBridgeAugmentation ovsdbBridge = new OvsdbBridgeAugmentationBuilder()
                     .setBridgeName(
@@ -788,8 +783,8 @@ public class OvsdbUtils {
      */
     public static <T extends DataObject> Map<InstanceIdentifier<T>,T> extract(
             Map<InstanceIdentifier<?>, DataObject> changes, Class<T> klazz) {
-        final Map<InstanceIdentifier<T>,T> result = new HashMap<InstanceIdentifier<T>,T>();
-        if ((changes != null) && (changes.entrySet() != null)) {
+        final Map<InstanceIdentifier<T>,T> result = new HashMap<>();
+        if (changes != null && changes.entrySet() != null) {
             for (final Entry<InstanceIdentifier<?>, DataObject> created : changes.entrySet()) {
                 if (klazz.isInstance(created.getValue())) {
                     @SuppressWarnings("unchecked")
@@ -806,38 +801,6 @@ public class OvsdbUtils {
         return result;
     }
 
-    /**
-     * Extract original data from the data store.
-     * @param changes The dataChange object
-     * @param klazz The class type
-     * @return The DataObject casted as a Class type
-     */
-    public static <T extends DataObject> Map<InstanceIdentifier<T>,T> extractOriginal(
-            AsyncDataChangeEvent<InstanceIdentifier<?>,DataObject> changes,Class<T> klazz) {
-        return extract(changes.getOriginalData(),klazz);
-    }
-
-    /**
-     * Extracts the removed nodes.
-     * @param changes he dataChange object
-     * @param klazz The class type
-     * @return A set to removed nodes as DataObject casted as the class type
-     */
-    public static <T extends DataObject> Set<InstanceIdentifier<T>> extractRemoved(
-            AsyncDataChangeEvent<InstanceIdentifier<?>,DataObject> changes,Class<T> klazz) {
-        final Set<InstanceIdentifier<T>> result = new HashSet<InstanceIdentifier<T>>();
-        if ((changes != null) && (changes.getRemovedPaths() != null)) {
-            for (final InstanceIdentifier<?> iid : changes.getRemovedPaths()) {
-                if (iid.getTargetType().equals(klazz)) {
-                    @SuppressWarnings("unchecked") // Actually checked above
-                    final InstanceIdentifier<T> iidn = (InstanceIdentifier<T>)iid;
-                    result.add(iidn);
-                }
-            }
-        }
-        return result;
-    }
-
     /**
      * Search the Operational Datastore for a specific OvsdbNode.
      * @param dataBroker The dataBroker instance to create transactions
@@ -915,7 +878,7 @@ public class OvsdbUtils {
         Topology topology = MdsalUtils.read(dataBroker,
                 LogicalDatastoreType.OPERATIONAL,
                 ovsdbTopoIdentifier);
-        if ((topology != null) && (topology.getNode() != null)) {
+        if (topology != null && topology.getNode() != null) {
             for (final Node node : topology.getNode()) {
                 final OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
                 if (ovsdbNodeAugmentation != null) {
@@ -924,7 +887,7 @@ public class OvsdbUtils {
             }
         } else {
             topology = MdsalUtils.read(dataBroker, LogicalDatastoreType.CONFIGURATION, ovsdbTopoIdentifier);
-            if ((topology != null) && (topology.getNode() != null)) {
+            if (topology != null && topology.getNode() != null) {
                 for (final Node node : topology.getNode()) {
                     final OvsdbNodeAugmentation ovsdbNodeAugmentation =
                             node.getAugmentation(OvsdbNodeAugmentation.class);
index 23ddd06c48cd07d365a2d4526b208958ed240530..52ea18d5ddeee34e270e28995adb7e32a8a05422 100644 (file)
@@ -13,22 +13,24 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doNothing;
 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 ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.util.concurrent.CheckedFuture;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -39,7 +41,6 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 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.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
@@ -91,13 +92,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.util.concurrent.CheckedFuture;
-
-import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.Appender;
-
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({LogicalDatastoreType.class, UnimgrMapper.class, OvsdbUtils.class, MdsalUtils.class, UUID.class})
 public class OvsdbUtilsTest {
@@ -201,7 +195,7 @@ public class OvsdbUtilsTest {
     @Test
     public void testCreateControllerEntries() {
         String targetString = new String("controllerEntry");
-        List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
+        List<ControllerEntry> controllerEntries = new ArrayList<>();
         ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
         controllerEntryBuilder.setTarget(new Uri(targetString));
         controllerEntries.add(controllerEntryBuilder.build());
@@ -251,10 +245,10 @@ public class OvsdbUtilsTest {
 
     @Test
     public void testCreateMdsalProtocols() {
-        List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+        List<ProtocolEntry> protocolList = new ArrayList<>();
         ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
                 SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
-        ProtocolEntry protoEntry = new ProtocolEntryBuilder().setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build();
+        ProtocolEntry protoEntry = new ProtocolEntryBuilder().setProtocol(mapper.get("OpenFlow13")).build();
         protocolList.add(protoEntry);
         assertEquals(protocolList, OvsdbUtils.createMdsalProtocols());
     }
@@ -435,29 +429,9 @@ public class OvsdbUtilsTest {
         assertEquals(HashMap.class, OvsdbUtils.extract(changes, klazz).getClass());
     }
 
-    @SuppressWarnings("unchecked")
-    @Test
-    public void testExtractOriginal() {
-        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
-        Class<DataObject> klazz = DataObject.class;
-        Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
-        when(changes.getOriginalData()).thenReturn(map);
-        Map<InstanceIdentifier<DataObject>, DataObject> map1 = new HashMap<>();
-        when(OvsdbUtils.extract(any(Map.class),eq(DataObject.class))).thenReturn(map1);
-        assertEquals(map1, OvsdbUtils.extractOriginal(changes, klazz));
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void testExtractRemoved() {
-        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes = mock(AsyncDataChangeEvent.class);
-        Class<DataObject> klazz = DataObject.class;
-        assertEquals(HashSet.class, OvsdbUtils.extractRemoved(changes, klazz).getClass());
-    }
-
     @Test
     public void testFindOvsdbNode() {
-        List<Node> ovsdbNodes = new ArrayList<Node>();
+        List<Node> ovsdbNodes = new ArrayList<>();
         UniAugmentation uni = new UniAugmentationBuilder()
                                       .setIpAddress(IP)
                                       .build();
@@ -516,7 +490,7 @@ public class OvsdbUtilsTest {
     @Test
     public void testGetOvsdbNodes() {
         Node node = mock(Node.class);
-        List<Node> ndList = new ArrayList<Node>();
+        List<Node> ndList = new ArrayList<>();
         ndList.add(node);
         Topology topology = mock (Topology.class);
         DataBroker dataBroker = mock(DataBroker.class);