Bug 6185 - southbound system tests failing when
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-impl / src / main / java / org / opendaylight / ovsdb / hwvtepsouthbound / transact / UcastMacsLocalUpdateCommand.java
index ee1106b333af80b19ccfefc9cecb02160888c8a5..f9a161e81a1137d3e0c601cb923b14aeac863729 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 China Telecom Beijing Research Institute and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 China Telecom Beijing Research Institute 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,
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Optional;
 
 public class UcastMacsLocalUpdateCommand extends AbstractTransactCommand {
-    private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortRemoveCommand.class);
+    private static final Logger LOG = LoggerFactory.getLogger(UcastMacsLocalUpdateCommand.class);
 
     public UcastMacsLocalUpdateCommand(HwvtepOperationalState state,
             Collection<DataTreeModification<Node>> changes) {
@@ -74,34 +74,42 @@ public class UcastMacsLocalUpdateCommand extends AbstractTransactCommand {
             UcastMacsLocal ucastMacsLocal = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), UcastMacsLocal.class);
             setIpAddress(ucastMacsLocal, localUcastMac);
             setLocator(transaction, ucastMacsLocal, localUcastMac);
-            setLogicalSwitch(instanceIdentifier, ucastMacsLocal, localUcastMac);
+            setLogicalSwitch(ucastMacsLocal, localUcastMac);
             if (!operationalMacOptional.isPresent()) {
                 setMac(ucastMacsLocal, localUcastMac, operationalMacOptional);
+                LOG.trace("execute: creating LocalUcastMac entry: {}", ucastMacsLocal);
                 transaction.add(op.insert(ucastMacsLocal));
-            } else {
-                LocalUcastMacs updatedMac = operationalMacOptional.get();
-                String existingMac = updatedMac.getMacEntryKey().getValue();
-                UcastMacsLocal extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), UcastMacsLocal.class);
-                extraMac.setMac("");;
+                transaction.add(op.comment("UcastMacLocal: Creating " + localUcastMac.getMacEntryKey().getValue()));
+            } else if (operationalMacOptional.get().getMacEntryUuid() != null) {
+                UUID macEntryUUID = new UUID(operationalMacOptional.get().getMacEntryUuid().getValue());
+                UcastMacsLocal extraMac = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
+                                UcastMacsLocal.class, null);
+                extraMac.getUuidColumn().setData(macEntryUUID);
+                LOG.trace("execute: updating LocalUcastMac entry: {}", ucastMacsLocal);
                 transaction.add(op.update(ucastMacsLocal)
-                        .where(extraMac.getMacColumn().getSchema().opEqual(existingMac))
+                        .where(extraMac.getUuidColumn().getSchema().opEqual(macEntryUUID))
                         .build());
+                transaction.add(op.comment("UcastMacLocal: Updating " + macEntryUUID));
+            } else {
+                LOG.warn("Unable to update localUcastMacs {} because uuid not found in the operational store",
+                                localUcastMac.getMacEntryKey().getValue());
             }
         }
     }
 
-    private void setLogicalSwitch(InstanceIdentifier<Node> iid, UcastMacsLocal ucastMacsLocal, LocalUcastMacs inputMac) {
+    private void setLogicalSwitch(UcastMacsLocal ucastMacsLocal, LocalUcastMacs inputMac) {
         if (inputMac.getLogicalSwitchRef() != null) {
-            HwvtepNodeName lswitchName = new HwvtepNodeName(inputMac.getLogicalSwitchRef().getValue());
+            @SuppressWarnings("unchecked")
+            InstanceIdentifier<LogicalSwitches> lswitchIid = (InstanceIdentifier<LogicalSwitches>) inputMac.getLogicalSwitchRef().getValue();
             Optional<LogicalSwitches> operationalSwitchOptional =
-                    getOperationalState().getLogicalSwitches(iid, new LogicalSwitchesKey(lswitchName));
+                    getOperationalState().getLogicalSwitches(lswitchIid);
             if (operationalSwitchOptional.isPresent()) {
                 Uuid logicalSwitchUuid = operationalSwitchOptional.get().getLogicalSwitchUuid();
                 UUID logicalSwitchUUID = new UUID(logicalSwitchUuid.getValue());
                 ucastMacsLocal.setLogicalSwitch(logicalSwitchUUID);
             } else {
-                LOG.warn("Create or update localUcastMacs: No logical switch named {} found in operational datastore!",
-                        lswitchName);
+                LOG.warn("Create or update localUcastMacs: No logical switch with iid {} found in operational datastore!",
+                        lswitchIid);
             }
         }
     }