Merge "L3: Add eth to br-ex"
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeUpdateCommand.java
index a02c5c44cf604876fa686a8cbcd0d9632b0fd389..47767f9da1f5c12613bcbc8ad0c3f854aaccdbb9 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.southbound.transactions.md;
 
 import java.net.InetAddress;
@@ -12,7 +20,6 @@ import java.util.Set;
 import org.apache.commons.lang3.math.NumberUtils;
 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.ovsdb.lib.error.SchemaVersionMismatchException;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.notation.UUID;
@@ -23,6 +30,7 @@ import org.opendaylight.ovsdb.schema.openvswitch.Controller;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.ovsdb.southbound.SouthboundUtil;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
@@ -81,7 +89,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
     private void updateBridge(ReadWriteTransaction transaction,
             Bridge bridge) {
         final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
-        Optional<Node> connection = readNode(transaction, connectionIId);
+        Optional<Node> connection = SouthboundUtil.readNode(transaction, connectionIId);
         if (connection.isPresent()) {
             LOG.debug("Connection {} is present",connection);
 
@@ -110,8 +118,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
         Preconditions.checkNotNull(bridgeIid);
         Preconditions.checkNotNull(bridge);
-        List<InstanceIdentifier<BridgeOtherConfigs>> result =
-                new ArrayList<InstanceIdentifier<BridgeOtherConfigs>>();
+        List<InstanceIdentifier<BridgeOtherConfigs>> result = new ArrayList<>();
 
         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
 
@@ -135,8 +142,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
         Preconditions.checkNotNull(bridgeIid);
         Preconditions.checkNotNull(bridge);
-        List<InstanceIdentifier<BridgeExternalIds>> result =
-                new ArrayList<InstanceIdentifier<BridgeExternalIds>>();
+        List<InstanceIdentifier<BridgeExternalIds>> result = new ArrayList<>();
 
         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
 
@@ -160,8 +166,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
         Preconditions.checkNotNull(bridgeIid);
         Preconditions.checkNotNull(bridge);
-        List<InstanceIdentifier<ProtocolEntry>> result =
-                new ArrayList<InstanceIdentifier<ProtocolEntry>>();
+        List<InstanceIdentifier<ProtocolEntry>> result = new ArrayList<>();
         Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
 
         try {
@@ -180,22 +185,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                 }
             }
         } catch (SchemaVersionMismatchException e) {
-            LOG.warn("protocol not supported by this version of ovsdb", e);
+            // We don't care about the exception stack trace here
+            LOG.warn("protocol not supported by this version of ovsdb: {}", e.getMessage());
         }
         return result;
     }
 
-    private Optional<Node> readNode(ReadWriteTransaction transaction,
-            final InstanceIdentifier<Node> connectionIid) {
-        Optional<Node> node = Optional.absent();
-        try {
-            node = transaction.read(LogicalDatastoreType.OPERATIONAL, connectionIid).checkedGet();
-        } catch (final ReadFailedException e) {
-            LOG.warn("Read Operational/DS for Node fail! {}", connectionIid, e);
-        }
-        return node;
-    }
-
     private Node buildConnectionNode(
             Bridge bridge) {
         //Update node with managed node reference
@@ -203,7 +198,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         connectionNode.setNodeId(getOvsdbConnectionInstance().getNodeId());
 
         OvsdbNodeAugmentationBuilder ovsdbConnectionAugmentationBuilder = new OvsdbNodeAugmentationBuilder();
-        List<ManagedNodeEntry> managedBridges = new ArrayList<ManagedNodeEntry>();
+        List<ManagedNodeEntry> managedBridges = new ArrayList<>();
         InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
                 bridge);
         ManagedNodeEntry managedBridge = new ManagedNodeEntryBuilder().setBridgeRef(
@@ -213,7 +208,8 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
 
         connectionNode.addAugmentation(OvsdbNodeAugmentation.class, ovsdbConnectionAugmentationBuilder.build());
 
-        LOG.debug("Update node with bridge node ref {}",ovsdbConnectionAugmentationBuilder.toString());
+        LOG.debug("Update node with bridge node ref {}",
+                ovsdbConnectionAugmentationBuilder.getManagedNodeEntry().iterator().next());
         return connectionNode.build();
     }
 
@@ -235,7 +231,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
 
         LOG.debug("Built with the intent to store bridge data {}",
-                ovsdbBridgeAugmentationBuilder.toString());
+                ovsdbBridgeAugmentationBuilder.build());
         return bridgeNodeBuilder.build();
     }
 
@@ -268,7 +264,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                 .getOtherConfigColumn().getData();
         if (otherConfigs != null && !otherConfigs.isEmpty()) {
             Set<String> otherConfigKeys = otherConfigs.keySet();
-            List<BridgeOtherConfigs> otherConfigList = new ArrayList<BridgeOtherConfigs>();
+            List<BridgeOtherConfigs> otherConfigList = new ArrayList<>();
             String otherConfigValue;
             for (String otherConfigKey : otherConfigKeys) {
                 otherConfigValue = otherConfigs.get(otherConfigKey);
@@ -289,7 +285,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                 .getData();
         if (externalIds != null && !externalIds.isEmpty()) {
             Set<String> externalIdKeys = externalIds.keySet();
-            List<BridgeExternalIds> externalIdsList = new ArrayList<BridgeExternalIds>();
+            List<BridgeExternalIds> externalIdsList = new ArrayList<>();
             String externalIdValue;
             for (String externalIdKey : externalIdKeys) {
                 externalIdValue = externalIds.get(externalIdKey);