Fixed the UNI creation process so that Config and Operational are in sync 25/29225/2
authorGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Tue, 3 Nov 2015 23:06:33 +0000 (18:06 -0500)
committerGabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Tue, 3 Nov 2015 23:09:37 +0000 (18:09 -0500)
Some transaction led to some inconsistencies between the Config and
the Operational stores upon Uni create completion.

Change-Id: Idc49b5e4b9db8e45cfbffa2f7c1f6d3009c51195
Signed-off-by: Gabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
api/src/main/yang/cl-unimgr-mef.yang
impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java
impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java

index 86d95bac3907872091d94e055f52b552d710a50f..3311e8ca874afc9f128216caa5a2a6b4071d0d6b 100755 (executable)
@@ -32,11 +32,6 @@ module cl-unimgr-mef {
         description "Updated revision of the unimgr model.";\r
     }\r
 \r
-    typedef ovsdb-node-ref {\r
-        description "A reference to an ovsdb node";\r
-        type ovsdb:ovsdb-node-ref;\r
-    }\r
-\r
     grouping service-speed {\r
         choice speed {\r
             case speed-10M {\r
@@ -65,7 +60,7 @@ module cl-unimgr-mef {
     // represent simplification of MEF Per Uni Attributes\r
     grouping uni {\r
         leaf ovsdb-node-ref {\r
-            type ovsdb-node-ref;\r
+            type ovsdb:ovsdb-node-ref;\r
             description "A reference to the ovsdb node.";\r
         }\r
         leaf physical-medium {\r
index 40ae8915283a001af5ddd4db53288a9148524239..ab799c8b24c614e13d2db70825d3791dc31e4ec0 100644 (file)
@@ -61,14 +61,10 @@ public class UniCreateCommand extends AbstractCreateCommand {
                 if (uni.getOvsdbNodeRef() != null) {
                     OvsdbNodeRef ovsdbNodeRef = uni.getOvsdbNodeRef();
                     Optional<Node> optionalNode = UnimgrUtils.readNode(dataBroker,
-                                                                       ovsdbNodeRef
-                                                                       .getValue());
+                                                                       LogicalDatastoreType.OPERATIONAL,
+                                                                       ovsdbNodeRef.getValue());
                     if (optionalNode.isPresent()) {
                         Node ovsdbNode = optionalNode.get();
-                        UnimgrUtils.createBridgeNode(dataBroker,
-                                                     ovsdbNode,
-                                                     uni,
-                                                     UnimgrConstants.DEFAULT_BRIDGE_NAME);
                     } else {
                         LOG.info("Invalid OVSDB node instance identifier specified, "
                                + "attempting to retrieve the node.");
@@ -81,9 +77,6 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                                       uni,
                                                       ovsdbNode,
                                                       dataBroker);
-                            UnimgrUtils.createBridgeNode(dataBroker,
-                                    ovsdbNode, uni,
-                                    UnimgrConstants.DEFAULT_BRIDGE_NAME);
                         } else {
                             ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker,
                                                                     uni);
@@ -94,10 +87,6 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                                       uni,
                                                       ovsdbNode,
                                                       dataBroker);
-                            UnimgrUtils.createBridgeNode(dataBroker,
-                                                         ovsdbNode,
-                                                         uni,
-                                                         UnimgrConstants.DEFAULT_BRIDGE_NAME);
                         }
                     }
                 } else {
@@ -112,10 +101,6 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                                   uni,
                                                   ovsdbNode,
                                                   dataBroker);
-                        UnimgrUtils.createBridgeNode(dataBroker,
-                                                     ovsdbNode,
-                                                     uni,
-                                                     UnimgrConstants.DEFAULT_BRIDGE_NAME);
                     } else {
                         ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker,
                                                                 uni);
@@ -127,17 +112,13 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                                        uni,
                                                        ovsdbNode,
                                                        dataBroker);
-                             UnimgrUtils.createBridgeNode(dataBroker,
-                                                          ovsdbNode,
-                                                          uni,
-                                                          UnimgrConstants.DEFAULT_BRIDGE_NAME);
                         }
                     }
                 }
             }
             if (created.getValue() != null && created.getValue() instanceof OvsdbNodeAugmentation) {
                 OvsdbNodeAugmentation ovsdbNodeAugmentation = (OvsdbNodeAugmentation) created
-                        .getValue();
+                                                                                          .getValue();
                 InstanceIdentifier<Node> ovsdbIid = created.getKey().firstIdentifierOf(Node.class);
                 if (ovsdbNodeAugmentation != null) {
                     LOG.info("Received an OVSDB node create {}",
@@ -162,6 +143,7 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                                                  uniAugmentation,
                                                                  UnimgrConstants.DEFAULT_BRIDGE_NAME);
                                     Optional<Node> optionalOvsdbNode = UnimgrUtils.readNode(dataBroker,
+                                                                                            LogicalDatastoreType.OPERATIONAL,
                                                                                             ovsdbIid);
                                     if (optionalOvsdbNode.isPresent()) {
                                         Node ovsdbNode = optionalOvsdbNode.get();
@@ -176,17 +158,17 @@ public class UniCreateCommand extends AbstractCreateCommand {
                                 }
                                 // The OVS instance is in ptcp mode.
                             } else if (ovsdbNodeAugmentation
-                                        .getConnectionInfo()
-                                        .getRemoteIp()
-                                        .equals(uniAugmentation.getIpAddress())) {
-                                InstanceIdentifier<Node> ovsdbNodeIid = uniAugmentation.getOvsdbNodeRef().getValue()
-                                        .firstIdentifierOf(Node.class);
+                                          .getConnectionInfo()
+                                          .getRemoteIp()
+                                          .equals(uniAugmentation.getIpAddress())) {
+                                InstanceIdentifier<Node> ovsdbNodeIid = (InstanceIdentifier<Node>) created.getKey();
                                 Optional<Node> ovsdbNode = UnimgrUtils.readNode(dataBroker,
+                                                                                LogicalDatastoreType.OPERATIONAL,
                                                                                 ovsdbNodeIid);
                                 if (ovsdbNode.isPresent()) {
                                     InstanceIdentifier<Node> uniIid = UnimgrMapper.createUniIid(dataBroker,
                                                                                                 uniAugmentation
-                                                                                                .getIpAddress());
+                                                                                                    .getIpAddress());
                                     UnimgrUtils.updateUniNode(LogicalDatastoreType.OPERATIONAL,
                                                               uniIid,
                                                               uniAugmentation,
index 6374b6eabd71defbd7eb0f00c1b9e4e70ff90e02..76a24e5cb5394faf3329c9d5893646636551bec1 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
-import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
@@ -368,6 +367,7 @@ public class UnimgrUtils {
                                                    NodeId ovsdbNodeId) {
         InstanceIdentifier<Node> nodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNodeId);
         Optional<Node> node = readNode(dataBroker,
+                                       LogicalDatastoreType.OPERATIONAL,
                                        nodeIid);
         if (node.isPresent()) {
             Node ovsdbNode = node.get();
@@ -431,9 +431,9 @@ public class UnimgrUtils {
     public static List<Node> getUniNodes(DataBroker dataBroker) {
         List<Node> uniNodes = new ArrayList<>();
         InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.createTopologyIid();
-        Topology topology = UnimgrUtils.read(dataBroker,
-                                             LogicalDatastoreType.OPERATIONAL,
-                                             topologyInstanceIdentifier);
+        Topology topology = read(dataBroker,
+                                 LogicalDatastoreType.CONFIGURATION,
+                                 topologyInstanceIdentifier);
         if (topology != null && topology.getNode() != null) {
             for (Node node : topology.getNode()) {
                 UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
@@ -469,20 +469,33 @@ public class UnimgrUtils {
     }
 
     public static final Optional<Node> readNode(DataBroker dataBroker,
-            InstanceIdentifier<?> genericNode) {
+                                                InstanceIdentifier<?> genericNode) {
+        ReadTransaction read = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
+        CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture =
+                                                              read.read(LogicalDatastoreType.OPERATIONAL,
+                                                                        nodeIid);
+        try {
+            return nodeFuture.checkedGet();
+        } catch (ReadFailedException e) {
+            LOG.info("Unable to read node with Iid {}", nodeIid);
+        }
+        return Optional.absent();
+    }
+
+    public static final Optional<Node> readNode(DataBroker dataBroker,
+                                                LogicalDatastoreType store,
+                                                InstanceIdentifier<?> genericNode) {
         ReadTransaction read = dataBroker.newReadOnlyTransaction();
         InstanceIdentifier<Node> nodeIid = genericNode.firstIdentifierOf(Node.class);
         CheckedFuture<Optional<Node>, ReadFailedException> nodeFuture = read
-                .read(LogicalDatastoreType.OPERATIONAL, nodeIid);
-        Optional<Node> nodeOptional;
+                .read(store, nodeIid);
         try {
-            nodeOptional = nodeFuture.get();
-            return nodeOptional;
-        } catch (InterruptedException e) {
-            return Optional.absent();
-        } catch (ExecutionException e) {
-            return Optional.absent();
+            return nodeFuture.checkedGet();
+        } catch (ReadFailedException e) {
+            LOG.info("Unable to read node with Iid {}", nodeIid);
         }
+        return Optional.absent();
     }
 
     public static void updateUniNode(LogicalDatastoreType dataStore,
@@ -490,16 +503,23 @@ public class UnimgrUtils {
                                      UniAugmentation uni,
                                      Node ovsdbNode,
                                      DataBroker dataBroker) {
-        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNode.getNodeId());
+        OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
         UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
-        Optional<Node> optionalNode = UnimgrUtils.readNode(dataBroker, uniKey);
+        if (ovsdbNodeRef != null) {
+            updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
+        }
+        Optional<Node> optionalNode = readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, uniKey);
         if (optionalNode.isPresent()) {
             Node node = optionalNode.get();
+            WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+            LOG.info("Updating Uni Node {} {} {}", uniKey, ovsdbNodeIid, dataStore);
             NodeBuilder nodeBuilder = new NodeBuilder();
             nodeBuilder.setKey(node.getKey());
             nodeBuilder.setNodeId(node.getNodeId());
             nodeBuilder.addAugmentation(UniAugmentation.class, updatedUniBuilder.build());
             transaction.put(dataStore, uniKey.firstIdentifierOf(Node.class), nodeBuilder.build());
+            transaction.submit();
         }
     }
 }