Hwvtep minor refactor to getPhysicalLocator 01/88801/2
authorChandra Shekar S <chandra.shekar.s@ericsson.com>
Mon, 30 Mar 2020 08:50:32 +0000 (14:20 +0530)
committerChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Thu, 2 Apr 2020 06:43:26 +0000 (06:43 +0000)
Signed-off-by: Chandra Shekar S <chandra.shekar.s@ericsson.com>
Change-Id: I41147c1e6549c430572390cf0eee5d2a975de63c

12 files changed:
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundUtil.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/EmptyDependencyGetter.java [new file with mode: 0644]
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/LogicalRouterRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/LogicalSwitchRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/LogicalSwitchUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsLocalRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/McastMacsRemoteRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsLocalRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/UcastMacsRemoteRemoveCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepMcastMacsRemoteUpdateCommand.java

index e0605f371f63f64088db3c580925509064624deb..7dfd368abc440f5e07065152de682f37d1f64baa 100644 (file)
@@ -132,7 +132,11 @@ public class HwvtepDeviceInfo {
     }
 
     public LogicalSwitch getLogicalSwitch(UUID uuid) {
-        return (LogicalSwitch) getDeviceOperData(LogicalSwitches.class, uuid);
+        DeviceData deviceData = getDeviceOperData(LogicalSwitches.class, uuid);
+        if (deviceData != null && deviceData.getData() != null) {
+            return (LogicalSwitch) deviceData.getData();
+        }
+        return null;
     }
 
     public Map<UUID, LogicalSwitch> getLogicalSwitches() {
@@ -163,7 +167,11 @@ public class HwvtepDeviceInfo {
     }
 
     public PhysicalLocator getPhysicalLocator(UUID uuid) {
-        return (PhysicalLocator) getDeviceOperData(TerminationPoint.class, uuid);
+        DeviceData deviceData = getDeviceOperData(TerminationPoint.class, uuid);
+        if (deviceData != null && deviceData.getData() != null) {
+            return (PhysicalLocator) deviceData.getData();
+        }
+        return null;
     }
 
     public Map<UUID, PhysicalLocator> getPhysicalLocators() {
@@ -262,8 +270,8 @@ public class HwvtepDeviceInfo {
         }
     }
 
-    public Object getDeviceOperData(Class<? extends Identifiable> cls, UUID uuid) {
-        return HwvtepSouthboundUtil.getData(uuidVsData, cls, uuid).getData();
+    public DeviceData getDeviceOperData(Class<? extends Identifiable> cls, UUID uuid) {
+        return HwvtepSouthboundUtil.getData(uuidVsData, cls, uuid);
     }
 
     public DeviceData getDeviceOperData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
index 2f931527ad5d70d0d848941046f50938d9f8a7ce..1bea8e3c947c0dbdd339746b5235e587d6fc847a 100644 (file)
@@ -163,6 +163,7 @@ public final class HwvtepSouthboundUtil {
 
     public static <K, D> void updateData(Map<Class<? extends Identifiable>, Map<K, D>> map,
             Class<? extends Identifiable> cls, K key, D data) {
+        LOG.debug("Updating data {} {} {}", cls, key, data);
         if (key == null) {
             return;
         }
@@ -196,6 +197,7 @@ public final class HwvtepSouthboundUtil {
 
     public static <K, D> void clearData(Map<Class<? extends Identifiable>, Map<K, D>> map,
             Class<? extends Identifiable> cls, K key) {
+        LOG.debug("Clearing data {} {}", cls, key);
         if (key == null) {
             return;
         }
index 3b910da6963915528f06be7f8aed5384e78abd69..8437224791757ebd9ec7e1da08d8a9bd17f76bf4 100644 (file)
@@ -108,7 +108,7 @@ public abstract class AbstractTransactCommand<T extends Identifiable, A extends
         Map inTransitDependencies = new HashMap<>();
         Map configDependencies = new HashMap<>();
 
-        if (!isRemoveCommand() && unMetDependencyGetter != null) {
+        if (!isDeleteCmd() && unMetDependencyGetter != null) {
             inTransitDependencies = unMetDependencyGetter.getInTransitDependencies(getOperationalState(), data);
             configDependencies = unMetDependencyGetter.getUnMetConfigDependencies(getOperationalState(), data);
             //we can skip the config termination point dependency as we can create them in device as part of this tx
@@ -126,7 +126,7 @@ public abstract class AbstractTransactCommand<T extends Identifiable, A extends
         if (HwvtepSouthboundUtil.isEmptyMap(configDependencies) && HwvtepSouthboundUtil.isEmptyMap(
                 inTransitDependencies)) {
             doDeviceTransaction(transaction, nodeIid, data, key, extraData);
-            if (isRemoveCommand()) {
+            if (isDeleteCmd()) {
                 getDeviceInfo().clearConfigData((Class<? extends Identifiable>) classType, key);
             } else {
                 getDeviceInfo().updateConfigData((Class<? extends Identifiable>) classType, key, data);
@@ -358,7 +358,7 @@ public abstract class AbstractTransactCommand<T extends Identifiable, A extends
         return false;
     }
 
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return false;
     }
 
diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/EmptyDependencyGetter.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/EmptyDependencyGetter.java
new file mode 100644 (file)
index 0000000..f46d51f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2020 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public final class EmptyDependencyGetter extends UnMetDependencyGetter {
+
+    public static final EmptyDependencyGetter INSTANCE = new EmptyDependencyGetter();
+
+    private EmptyDependencyGetter() {
+    }
+
+    @Override
+    public List<InstanceIdentifier<?>> getLogicalSwitchDependencies(Identifiable data) {
+        return Collections.EMPTY_LIST;
+    }
+
+    @Override
+    public List<InstanceIdentifier<?>> getTerminationPointDependencies(Identifiable data) {
+        return Collections.EMPTY_LIST;
+    }
+}
index 1ff121d52aeaed42569806a9fe96ce10ecbaef1c..019cffa333f49e51defa0240d08e8abf8d6a7ca9 100644 (file)
@@ -105,4 +105,9 @@ public class LogicalRouterRemoveCommand extends AbstractTransactCommand<LogicalR
     protected boolean areEqual(final LogicalRouters routers1, final LogicalRouters routers2) {
         return routers1.key().equals(routers2.key());
     }
+
+    @Override
+    public boolean isDeleteCmd() {
+        return true;
+    }
 }
index 8bb63be1e61ce4c07e79cbffa3cbfb2a4729ff2a..47b7e9366423f4cef615f6517915c1c316a8737b 100644 (file)
@@ -146,7 +146,7 @@ public class LogicalSwitchRemoveCommand extends AbstractTransactCommand<LogicalS
     }
 
     @Override
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return true;
     }
 
index 9002127f887aec93fcf19b366c0b5ef2fd41ae64..2238724cab16e691f2e4b403ed51ebc1a44d8d9a 100644 (file)
@@ -66,7 +66,7 @@ public class LogicalSwitchUpdateCommand extends AbstractTransactCommand<LogicalS
                                final LogicalSwitches lswitch,
                                final InstanceIdentifier lsKey,
                                final Object... extraData) {
-        processDependencies(null, transaction, nodeIid, lsKey, lswitch);
+        processDependencies(EmptyDependencyGetter.INSTANCE, transaction, nodeIid, lsKey, lswitch);
     }
 
     @Override
index a575803a9f00bd796bee4f590fb93189dff5b70a..5ece6d77f2e9ed6ff9b01ed34c11ef6da69ec5e4 100644 (file)
@@ -99,7 +99,7 @@ public class McastMacsLocalRemoveCommand extends AbstractTransactCommand<LocalMc
     }
 
     @Override
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return true;
     }
 }
index 6dab0fdc32b5bc7e94e26cba1d488c9b495e0f1a..29558f2b1b908192222562e4cedb25c693f71e27 100644 (file)
@@ -83,7 +83,7 @@ public class McastMacsRemoteRemoveCommand extends AbstractTransactCommand<Remote
                                final RemoteMcastMacs remoteMcastMac,
                                final InstanceIdentifier macKey,
                                final Object... extraData) {
-        processDependencies(null, transaction, nodeIid, macKey, remoteMcastMac);
+        processDependencies(EmptyDependencyGetter.INSTANCE, transaction, nodeIid, macKey, remoteMcastMac);
     }
 
     @Override
@@ -123,7 +123,7 @@ public class McastMacsRemoteRemoveCommand extends AbstractTransactCommand<Remote
     }
 
     @Override
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return true;
     }
 
index a3a06b111485c6be4a0bc66798a5061e5b8766c7..fd0dd552a9ee379026f2d347b3f8b3ce52196d62 100644 (file)
@@ -99,7 +99,7 @@ public class UcastMacsLocalRemoveCommand extends AbstractTransactCommand<LocalUc
     }
 
     @Override
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return true;
     }
 }
index 008b2e12dc5e38af76f7cee1b87bc923f8f9e650..b794030c9a478c2b372a42fb470cdaf46f5a3420 100644 (file)
@@ -99,7 +99,7 @@ public class UcastMacsRemoteRemoveCommand extends AbstractTransactCommand<Remote
     }
 
     @Override
-    protected boolean isRemoveCommand() {
+    protected boolean isDeleteCmd() {
         return true;
     }
 
index 9099504e19fe579ba651d5996450a67099a025fe..c7bb3abb16d33b9a00a4b37f2c326a638f33e4ed 100644 (file)
@@ -68,9 +68,6 @@ public class HwvtepMcastMacsRemoteUpdateCommand extends AbstractTransactionComma
         final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
         Node connectionNode = buildConnectionNode(macRemote);
         transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
-        InstanceIdentifier<RemoteMcastMacs> macIid = getMacIid(connectionIId, connectionNode);
-        getOvsdbConnectionInstance().getDeviceInfo().updateDeviceOperData(RemoteMcastMacs.class,
-                macIid, macRemote.getUuid(), macRemote);
     }
 
     InstanceIdentifier<RemoteMcastMacs> getMacIid(InstanceIdentifier<Node> connectionIId, Node connectionNode) {
@@ -96,11 +93,16 @@ public class HwvtepMcastMacsRemoteUpdateCommand extends AbstractTransactionComma
         setLogicalSwitch(macRemoteBuilder, macRemote);
 
         List<RemoteMcastMacs> macRemoteList = new ArrayList<>();
-        macRemoteList.add(macRemoteBuilder.build());
+        RemoteMcastMacs mac = macRemoteBuilder.build();
+        macRemoteList.add(mac);
 
         HwvtepGlobalAugmentationBuilder hgAugmentationBuilder = new HwvtepGlobalAugmentationBuilder();
         hgAugmentationBuilder.setRemoteMcastMacs(macRemoteList);
         connectionNode.addAugmentation(HwvtepGlobalAugmentation.class, hgAugmentationBuilder.build());
+        InstanceIdentifier<RemoteMcastMacs> macIid = getOvsdbConnectionInstance().getInstanceIdentifier()
+                .augmentation(HwvtepGlobalAugmentation.class).child(RemoteMcastMacs.class, mac.key());
+        getOvsdbConnectionInstance().getDeviceInfo().updateDeviceOperData(RemoteMcastMacs.class,
+                macIid, macRemote.getUuid(), macRemote);
         return connectionNode.build();
     }
 
@@ -134,7 +136,7 @@ public class HwvtepMcastMacsRemoteUpdateCommand extends AbstractTransactionComma
                         PhysicalLocator locator = updatedPLocRows.get(locUUID);
                         if (locator == null) {
                             locator = (PhysicalLocator) getOvsdbConnectionInstance()
-                                    .getDeviceInfo().getDeviceOperData(TerminationPoint.class, locUUID);
+                                    .getDeviceInfo().getPhysicalLocator(locUUID);
                         }
                         InstanceIdentifier<TerminationPoint> tpIid = HwvtepSouthboundMapper.createInstanceIdentifier(
                                 getOvsdbConnectionInstance().getInstanceIdentifier(), locator);