Change logical-switch-ref to iid in hwvtep.yang
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transactions / md / UcastMacsRemoteUpdateCommand.java
index 6b8cb85c39c3aef84e549e67d7c339d6da102436..7ebe81a2e471954db211a982373308059e618fb7 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -31,47 +30,40 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepLogicalSwitchRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacsBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 
 public class UcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
 
-    private static final Logger LOG = LoggerFactory.getLogger(UcastMacsRemoteUpdateCommand.class);
-    private Map<UUID, UcastMacsRemote> updatedUMacsRemoteRows;
-    private Map<UUID, UcastMacsRemote> oldUMacsRemoteRows;
-    private Map<UUID, PhysicalLocator> updatedPLocRows;
-    private Map<UUID, LogicalSwitch> updatedLSRows;
+    private final Map<UUID, UcastMacsRemote> updatedUMacsRemoteRows;
+    private final Map<UUID, PhysicalLocator> updatedPLocRows;
+    private final Map<UUID, LogicalSwitch> updatedLSRows;
 
-    public UcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
-            DatabaseSchema dbSchema) {
+    public UcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates, DatabaseSchema dbSchema) {
         super(key, updates, dbSchema);
-        updatedUMacsRemoteRows = TyperUtils.extractRowsUpdated(UcastMacsRemote.class, getUpdates(),getDbSchema());
-        oldUMacsRemoteRows = TyperUtils.extractRowsOld(UcastMacsRemote.class, getUpdates(),getDbSchema());
-        updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(),getDbSchema());
-        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(),getDbSchema());
+        updatedUMacsRemoteRows = TyperUtils.extractRowsUpdated(UcastMacsRemote.class, getUpdates(), getDbSchema());
+        updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
+        updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(), getDbSchema());
     }
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        if (updatedUMacsRemoteRows != null || !updatedUMacsRemoteRows.isEmpty()) {
-            for (Entry<UUID, UcastMacsRemote> umrUpdate : updatedUMacsRemoteRows.entrySet()) {
-                updateUcastMacsRemote(transaction, umrUpdate.getValue());
-            }
+        for (UcastMacsRemote ucastMacsRemote : updatedUMacsRemoteRows.values()) {
+            updateUcastMacsRemote(transaction, ucastMacsRemote);
         }
     }
 
     private void updateUcastMacsRemote(ReadWriteTransaction transaction, UcastMacsRemote ucastMacsRemote) {
         final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
         Optional<Node> connection = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
-        if(connection.isPresent()) {
+        if (connection.isPresent()) {
             Node connectionNode = buildConnectionNode(ucastMacsRemote);
             transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
             //TODO: Handle any deletes
@@ -86,26 +78,31 @@ public class UcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
         List<RemoteUcastMacs> remoteUMacs = new ArrayList<>();
         RemoteUcastMacsBuilder rumBuilder = new RemoteUcastMacsBuilder();
         rumBuilder.setMacEntryKey(new MacAddress(uMacRemote.getMac()));
-        if(uMacRemote.getIpAddr() != null && !uMacRemote.getIpAddr().isEmpty()) {
+        if (uMacRemote.getIpAddr() != null && !uMacRemote.getIpAddr().isEmpty()) {
             rumBuilder.setIpaddr(new IpAddress(uMacRemote.getIpAddr().toCharArray()));
         }
-        if(uMacRemote.getLocatorColumn() != null
-                        && uMacRemote.getLocatorColumn().getData() != null) {
+        if (uMacRemote.getLocatorColumn() != null
+                && uMacRemote.getLocatorColumn().getData() != null) {
             UUID pLocUUID = uMacRemote.getLocatorColumn().getData();
-            if(updatedPLocRows.get(pLocUUID) != null) {
-                InstanceIdentifier<TerminationPoint> plIid = HwvtepSouthboundMapper.createInstanceIdentifier(nodeIid, updatedPLocRows.get(pLocUUID));
+            PhysicalLocator physicalLocator = updatedPLocRows.get(pLocUUID);
+            if (physicalLocator != null) {
+                InstanceIdentifier<TerminationPoint> plIid = HwvtepSouthboundMapper.createInstanceIdentifier(nodeIid,
+                        physicalLocator);
                 rumBuilder.setLocatorRef(new HwvtepPhysicalLocatorRef(plIid));
             }
         }
-        if(uMacRemote.getLogicalSwitchColumn() != null
-                        && uMacRemote.getLogicalSwitchColumn().getData() != null) {
+        if (uMacRemote.getLogicalSwitchColumn() != null
+                && uMacRemote.getLogicalSwitchColumn().getData() != null) {
             UUID lsUUID = uMacRemote.getLogicalSwitchColumn().getData();
-            if(updatedLSRows.get(lsUUID) != null) {
-                rumBuilder.setLogicalSwitchRef(new HwvtepLogicalSwitchRef(updatedLSRows.get(lsUUID).getName()));
+            final LogicalSwitch logicalSwitch = updatedLSRows.get(lsUUID);
+            if (logicalSwitch != null) {
+                InstanceIdentifier<LogicalSwitches> lSwitchIid =
+                        HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
+                rumBuilder.setLogicalSwitchRef(new HwvtepLogicalSwitchRef(lSwitchIid));
             }
         }
         remoteUMacs.add(rumBuilder.build());
-        hgAugmentationBuilder.setRemoteUcastMacs(remoteUMacs );
+        hgAugmentationBuilder.setRemoteUcastMacs(remoteUMacs);
         connectionNode.addAugmentation(HwvtepGlobalAugmentation.class, hgAugmentationBuilder.build());
         return connectionNode.build();
     }