ovsdb enable checkstyle on error
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / transactions / md / OvsdbBridgeUpdateCommand.java
index 116eddc9e635ef5314f0cf7ea7dd3eaccaad8e1d..83facc2ab003fb3703e7433b3dec00d167b094d6 100644 (file)
@@ -1,5 +1,18 @@
+/*
+ * 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 static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.net.InetAddresses;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.util.ArrayList;
@@ -8,7 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 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;
@@ -55,10 +67,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.base.Preconditions;
-import com.google.common.net.InetAddresses;
-
 public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
     private Map<UUID,Bridge> updatedBridgeRows;
@@ -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,7 +185,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                 }
             }
         } catch (SchemaVersionMismatchException e) {
-            LOG.warn("protocol not supported by this version of ovsdb", e);
+            schemaMismatchLog("protocols", "Bridge", e);
         }
         return result;
     }
@@ -192,7 +197,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(
@@ -222,6 +227,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         setFailMode(ovsdbBridgeAugmentationBuilder, bridge);
         setOpenFlowNodeRef(ovsdbBridgeAugmentationBuilder, bridge);
         setManagedBy(ovsdbBridgeAugmentationBuilder);
+        setAutoAttach(ovsdbBridgeAugmentationBuilder, bridge);
         bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
 
         LOG.debug("Built with the intent to store bridge data {}",
@@ -229,6 +235,22 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         return bridgeNodeBuilder.build();
     }
 
+    private void setAutoAttach(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
+            Bridge bridge) {
+        try {
+            if (bridge.getAutoAttachColumn() != null
+                    && bridge.getAutoAttachColumn().getData() != null
+                    && !bridge.getAutoAttachColumn().getData().isEmpty()) {
+                Set<UUID> uuids = bridge.getAutoAttachColumn().getData();
+                for (UUID uuid : uuids) {
+                    ovsdbBridgeAugmentationBuilder.setAutoAttach(new Uuid(uuid.toString()));
+                }
+            }
+        } catch (SchemaVersionMismatchException e) {
+            schemaMismatchLog("auto_attach", "Bridge", e);
+        }
+    }
+
     private void setManagedBy(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder) {
         InstanceIdentifier<Node> connectionNodePath = getOvsdbConnectionInstance().getInstanceIdentifier();
         ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
@@ -258,7 +280,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);
@@ -279,7 +301,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);
@@ -349,11 +371,12 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
                         }
                     }
                 } catch (Exception e) {
-                    LOG.warn("Error getting local ip address {}", e);
+                    LOG.warn("Error getting local ip address", e);
                 }
             }
         }
     }
+
     private InstanceIdentifier<Node> getInstanceIdentifier(Bridge bridge) {
         return SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
                 bridge);