Added version leaf to ovsdb-node-attributes of type yang::uuid 02/17002/8
authorGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Mon, 23 Mar 2015 15:22:47 +0000 (11:22 -0400)
committerSam Hague <shague@redhat.com>
Wed, 25 Mar 2015 20:27:26 +0000 (20:27 +0000)
Signed-off-by: Gabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Change-Id: I51b913cd6be634f240e158334715e150da4b4bf0

southbound/southbound-api/src/main/yang/ovsdb.yang
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java [new file with mode: 0644]
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbOperationalCommandAggregator.java

index 99fced3c569d2a9facd5237f2b3d4b205b2ac25d..f81743fb79d9b2ac7a94414a2049e001a84d0c84 100755 (executable)
@@ -180,6 +180,10 @@ module ovsdb {
     grouping ovsdb-node-attributes {
         uses overlay:ip-port-locator;
 
+        leaf ovs-version {
+            type string;
+        }
+
         list managed-node-entry {
             key "bridge-ref";
             leaf bridge-ref {
diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OpenVSwitchUpdateCommand.java
new file mode 100644 (file)
index 0000000..8e8e7cb
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 Inocybe 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.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;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder;
+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.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class OpenVSwitchUpdateCommand extends AbstractTransactionCommand{
+
+    private static final Logger LOG = LoggerFactory.getLogger(OpenVSwitchUpdateCommand.class);
+
+    public OpenVSwitchUpdateCommand(OvsdbClientKey key, TableUpdates updates,
+            DatabaseSchema dbSchema){
+        super(key,updates,dbSchema);
+    }
+
+    @Override
+    public void execute(ReadWriteTransaction transaction) {
+        Map<UUID,OpenVSwitch> updatedOpenVSwitchRows =
+                TyperUtils.extractRowsUpdated(OpenVSwitch.class, getUpdates(), getDbSchema());
+
+        for (Entry<UUID, OpenVSwitch> entry : updatedOpenVSwitchRows.entrySet()){
+            OpenVSwitch openVSwitch = entry.getValue();
+            final InstanceIdentifier<Node> nodePath = getKey().toInstanceIndentifier();
+            Optional<Node> node = Optional.absent();
+            try {
+                node = transaction.read(LogicalDatastoreType.OPERATIONAL, nodePath).checkedGet();
+            } catch (final ReadFailedException e) {
+                LOG.debug("Read Operational/DS for Node fail! {}", nodePath, e);
+            }
+            if (node.isPresent()){
+                LOG.debug("Node {} is present",node);
+                OvsdbNodeAugmentation ovsdbNode = SouthboundMapper.createOvsdbAugmentation(getKey());
+                OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
+                ovsdbNodeBuilder.setOvsVersion(openVSwitch.getVersion().toString());
+                NodeBuilder nodeBuilder = new NodeBuilder();
+                nodeBuilder.setNodeId(SouthboundMapper.createNodeId(ovsdbNode.getIp(),
+                                                                    ovsdbNode.getPort()));
+                nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, ovsdbNodeBuilder.build());
+                transaction.merge(LogicalDatastoreType.OPERATIONAL, nodePath, nodeBuilder.build());
+            }
+        }
+    }
+}
\ No newline at end of file
index b7ecd32bd9b55d7d5cad74c8fe3dd2f3f1471cc1..deb18c59caf0f204f277924595c792be2376f218 100644 (file)
@@ -18,6 +18,7 @@ public class OvsdbOperationalCommandAggregator implements TransactionCommand {
         commands.add(new OvsdbBridgeRemovedCommand(key, updates,  dbSchema));
         commands.add(new OvsdbPortUpdateCommand(key, updates, dbSchema));
         commands.add(new OvsdbPortRemoveCommand(key, updates, dbSchema));
+        commands.add(new OpenVSwitchUpdateCommand(key, updates, dbSchema));
     }
 
     @Override