Merge changes I6bc37e88,I0514b26e
authorEd Warnicke <eaw@cisco.com>
Wed, 2 Apr 2014 23:28:41 +0000 (23:28 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 2 Apr 2014 23:28:41 +0000 (23:28 +0000)
* changes:
  Fixed missing keys in sal-compatibility flows.
  Bug 508: Fixed concurrent conflicting commits by InventoryManager.

opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDFlowMapping.xtend
opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.xtend
opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/NodeChangeCommiter.java [new file with mode: 0644]

index fe545b0..6a9712b 100644 (file)
@@ -132,8 +132,10 @@ public class MDFlowMapping {
 
         val sourceActions = sourceFlow.actions;
         val targetActions = new ArrayList<Action>();
+        var int action = 0;
         for (sourceAction : sourceActions) {
-            targetActions.add(sourceAction.toAction());
+            targetActions.add(sourceAction.toAction(action));
+            action = action + 1;
         }
         instructions = targetActions.toApplyInstruction();
         match = sourceFlow.match.toMatch();
@@ -154,8 +156,10 @@ public class MDFlowMapping {
     
        val sourceActions = sourceFlow.actions;
        val targetActions = new ArrayList<Action>();
+       var int action = 0;
        for (sourceAction : sourceActions) {
-           targetActions.add(sourceAction.toAction());
+           targetActions.add(sourceAction.toAction(action));
+           action = action+ 1;
        }
        instructions = targetActions.toApplyInstruction();
        match = sourceFlow.match.toMatch();
@@ -199,44 +203,44 @@ public class MDFlowMapping {
         return it.build();
     }
 
-    public static dispatch def toAction(Controller sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(Controller sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new ControllerActionCaseBuilder().setControllerAction(new ControllerActionBuilder().build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(Drop sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(Drop sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new DropActionCaseBuilder().setDropAction(new DropActionBuilder().build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(Flood sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(Flood sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new FloodActionCaseBuilder().setFloodAction(new FloodActionBuilder().build).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(FloodAll sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(FloodAll sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new FloodAllActionCaseBuilder().setFloodAllAction(new FloodAllActionBuilder().build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(HwPath sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(HwPath sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new HwPathActionCaseBuilder().setHwPathAction(new HwPathActionBuilder().build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(Loopback sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(Loopback sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new LoopbackActionCaseBuilder().setLoopbackAction(new LoopbackActionBuilder().build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(Output sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(Output sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new OutputActionBuilder();
         outputNodeConnector = sourceAction.port.toUri;
         actionBuilder.action = new OutputActionCaseBuilder().setOutputAction(it.build()).build();
@@ -244,14 +248,14 @@ public class MDFlowMapping {
 
     }
 
-    public static dispatch def toAction(PopVlan sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(PopVlan sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new PopVlanActionCaseBuilder().build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(PushVlan sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(PushVlan sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new PushVlanActionBuilder();
         cfi = new VlanCfi(sourceAction.cfi);
         vlanId = new VlanId(sourceAction.vlanId);
@@ -261,32 +265,32 @@ public class MDFlowMapping {
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetDlDst sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetDlDst sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetDlDstActionBuilder();
         address = sourceAction.dlAddress.toMacAddress();
         actionBuilder.action = new SetDlDstActionCaseBuilder().setSetDlDstAction(it.build()).build;
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetDlSrc sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetDlSrc sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetDlSrcActionBuilder();
         address = sourceAction.dlAddress.toMacAddress;
         actionBuilder.action = new SetDlSrcActionCaseBuilder().setSetDlSrcAction(it.build()).build;
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetDlType sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetDlType sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetDlTypeActionBuilder();
         dlType = new EtherType(sourceAction.dlType as long);
         actionBuilder.action = new SetDlTypeActionCaseBuilder().setSetDlTypeAction(it.build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetNextHop sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetNextHop sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetNextHopActionBuilder();
         val inetAddress = sourceAction.address;
         address = inetAddress.toInetAddress;
@@ -294,8 +298,8 @@ public class MDFlowMapping {
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetNwDst sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetNwDst sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetNwDstActionBuilder();
         val inetAddress = sourceAction.address;
         address = inetAddress.toInetAddress;
@@ -303,8 +307,8 @@ public class MDFlowMapping {
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetNwSrc sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetNwSrc sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetNwSrcActionBuilder();
         val inetAddress = sourceAction.address;
         address = inetAddress.toInetAddress;
@@ -312,40 +316,40 @@ public class MDFlowMapping {
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetNwTos sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetNwTos sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetNwTosActionBuilder();
         tos = sourceAction.nwTos;
         actionBuilder.action = new SetNwTosActionCaseBuilder().setSetNwTosAction(it.build).build;
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetTpDst sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetTpDst sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetTpDstActionBuilder();
         port = new PortNumber(sourceAction.port);
         actionBuilder.action = new SetTpDstActionCaseBuilder().setSetTpDstAction(it.build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetTpSrc sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetTpSrc sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetTpSrcActionBuilder();
         port = new PortNumber(sourceAction.port);
         actionBuilder.action = new SetTpSrcActionCaseBuilder().setSetTpSrcAction(it.build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetVlanCfi sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetVlanCfi sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetVlanCfiActionBuilder();
         vlanCfi = new VlanCfi(sourceAction.cfi);
         actionBuilder.action = new SetVlanCfiActionCaseBuilder().setSetVlanCfiAction(it.build()).build();
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetVlanId sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetVlanId sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
 
         val it = new SetVlanIdActionBuilder();
         vlanId = new VlanId(sourceAction.vlanId);
@@ -353,16 +357,16 @@ public class MDFlowMapping {
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SetVlanPcp sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SetVlanPcp sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         val it = new SetVlanPcpActionBuilder();
         vlanPcp = new VlanPcp(sourceAction.pcp as short);
         actionBuilder.action = new SetVlanPcpActionCaseBuilder().setSetVlanPcpAction(it.build).build;
         return actionBuilder.build();
     }
 
-    public static dispatch def toAction(SwPath sourceAction) {
-        val actionBuilder = new ActionBuilder();
+    public static dispatch def toAction(SwPath sourceAction, int order) {
+        val actionBuilder = new ActionBuilder().setOrder(order);
         actionBuilder.action = new SwPathActionCaseBuilder().setSwPathAction(new SwPathActionBuilder().build()).build();
         return actionBuilder.build();
     }
@@ -405,8 +409,10 @@ public class MDFlowMapping {
 
         val sourceActions = sourceFlow.actions;
         val targetActions = new ArrayList<Action>();
+        var int action = 0;
         for (sourceAction : sourceActions) {
-            targetActions.add(sourceAction.toAction());
+            targetActions.add(sourceAction.toAction(action));
+            action = action + 1;
         }
         instructions = targetActions.toApplyInstruction();
         match = sourceFlow.match.toMatch();
index 43f48a5..ec8da86 100644 (file)
@@ -60,75 +60,4 @@ class FlowCapableInventoryProvider implements AutoCloseable {
         listenerRegistration?.close();
     }
     
-}
-
-class NodeChangeCommiter implements OpendaylightInventoryListener {
-
-    static val LOG = LoggerFactory.getLogger(NodeChangeCommiter);
-
-    @Property
-    val FlowCapableInventoryProvider manager;
-
-    new(FlowCapableInventoryProvider manager) {
-        _manager = manager;
-    }
-
-    override onNodeConnectorRemoved(NodeConnectorRemoved connector) {
-        val ref = connector.nodeConnectorRef;
-
-        // Check path
-        val it = manager.startChange()
-
-        LOG.debug("removing node connector : " + ref.value.toString());
-
-        removeOperationalData(ref.value as InstanceIdentifier<? extends DataObject>);
-        commit()
-    }
-
-    override onNodeConnectorUpdated(NodeConnectorUpdated connector) {
-        val ref = connector.nodeConnectorRef;
-
-        val flowConnector = connector.getAugmentation(FlowCapableNodeConnectorUpdated);
-
-        val it = manager.startChange()
-        val data = new NodeConnectorBuilder(connector);
-        data.key = (new NodeConnectorKey(connector.id))
-        if (flowConnector != null) {
-            val augment = flowConnector.toInventoryAugment()
-            data.addAugmentation(FlowCapableNodeConnector, augment)
-        }
-
-        LOG.debug("updating node connector : " + ref.value.toString());
-
-        putOperationalData(ref.value as InstanceIdentifier<NodeConnector>, data.build());
-        commit()
-    }
-
-    override onNodeRemoved(NodeRemoved node) {
-        val ref = node.nodeRef;
-        val it = manager.startChange()
-
-        LOG.debug("removing node : " + ref.value.toString());
-
-        removeOperationalData(ref.value as InstanceIdentifier<? extends DataObject>);
-        commit()
-    }
-
-    override onNodeUpdated(NodeUpdated node) {
-        val ref = node.nodeRef;
-        val flowNode = node.getAugmentation(FlowCapableNodeUpdated);
-
-        val it = manager.startChange()
-        val data = new NodeBuilder(node);
-        data.key = (new NodeKey(node.id))
-        if (flowNode != null) {
-            val augment = flowNode.toInventoryAugment();
-            data.addAugmentation(FlowCapableNode, augment)
-        }
-
-        LOG.debug("updating node : " + ref.value.toString());
-
-        putOperationalData(ref.value as InstanceIdentifier<Node>, data.build())
-        commit()
-    }
-}
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/NodeChangeCommiter.java b/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/NodeChangeCommiter.java
new file mode 100644 (file)
index 0000000..ebb3de7
--- /dev/null
@@ -0,0 +1,159 @@
+/**
+ * Copyright (c) 2013 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.controller.md.inventory.manager;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Objects;
+
+@SuppressWarnings("all")
+public class NodeChangeCommiter implements OpendaylightInventoryListener {
+    private final static Logger LOG = LoggerFactory.getLogger(NodeChangeCommiter.class);
+
+    private final FlowCapableInventoryProvider manager;
+
+    public NodeChangeCommiter(final FlowCapableInventoryProvider manager) {
+        this.manager = manager;
+    }
+
+    public FlowCapableInventoryProvider getManager() {
+        return this.manager;
+    }
+
+    @Override
+    public synchronized void onNodeConnectorRemoved(final NodeConnectorRemoved connector) {
+
+        final NodeConnectorRef ref = connector.getNodeConnectorRef();
+        final DataModificationTransaction it = this.getManager().startChange();
+        NodeChangeCommiter.LOG.debug("removing node connector {} ", ref.getValue());
+        it.removeOperationalData(ref.getValue());
+        Future<RpcResult<TransactionStatus>> commitResult = it.commit();
+        try {
+            commitResult.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Node Connector {} not removed.", ref.getValue(), e);
+        }
+
+    }
+
+    @Override
+    public synchronized void onNodeConnectorUpdated(final NodeConnectorUpdated connector) {
+
+        final NodeConnectorRef ref = connector.getNodeConnectorRef();
+        final FlowCapableNodeConnectorUpdated flowConnector = connector
+                .getAugmentation(FlowCapableNodeConnectorUpdated.class);
+        final DataModificationTransaction it = this.getManager().startChange();
+        final NodeConnectorBuilder data = new NodeConnectorBuilder(connector);
+        NodeConnectorId id = connector.getId();
+        NodeConnectorKey nodeConnectorKey = new NodeConnectorKey(id);
+        data.setKey(nodeConnectorKey);
+        boolean notEquals = (!Objects.equal(flowConnector, null));
+        if (notEquals) {
+            final FlowCapableNodeConnector augment = InventoryMapping.toInventoryAugment(flowConnector);
+            data.addAugmentation(FlowCapableNodeConnector.class, augment);
+        }
+        InstanceIdentifier<? extends Object> value = ref.getValue();
+        String string = value.toString();
+        String plus = ("updating node connector : " + string);
+        NodeChangeCommiter.LOG.debug(plus);
+        InstanceIdentifier<? extends Object> value1 = ref.getValue();
+        NodeConnector build = data.build();
+        it.putOperationalData((value1), build);
+        Future<RpcResult<TransactionStatus>> commitResult = it.commit();
+        try {
+            commitResult.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Node Connector {} not updated.", ref.getValue(), e);
+        }
+
+    }
+
+    @Override
+    public synchronized void onNodeRemoved(final NodeRemoved node) {
+
+        final NodeRef ref = node.getNodeRef();
+        FlowCapableInventoryProvider manager = this.getManager();
+        final DataModificationTransaction it = manager.startChange();
+        InstanceIdentifier<? extends Object> value = ref.getValue();
+        String string = value.toString();
+        String plus = ("removing node : " + string);
+        NodeChangeCommiter.LOG.debug(plus);
+        InstanceIdentifier<? extends Object> value1 = ref.getValue();
+        it.removeOperationalData((value1));
+        Future<RpcResult<TransactionStatus>> commitResult = it.commit();
+        try {
+            commitResult.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Node {} not removed.", ref.getValue(), e);
+        }
+    }
+
+    @Override
+    public synchronized void onNodeUpdated(final NodeUpdated node) {
+
+        final NodeRef ref = node.getNodeRef();
+        final FlowCapableNodeUpdated flowNode = node
+                .<FlowCapableNodeUpdated> getAugmentation(FlowCapableNodeUpdated.class);
+        FlowCapableInventoryProvider manager = this.getManager();
+        final DataModificationTransaction it = manager.startChange();
+        NodeBuilder nodeBuilder = new NodeBuilder(node);
+        final NodeBuilder data = nodeBuilder;
+        NodeId id = node.getId();
+        NodeKey nodeKey = new NodeKey(id);
+        data.setKey(nodeKey);
+        boolean equals = Objects.equal(flowNode, null);
+        if (equals) {
+            return;
+        }
+        final FlowCapableNode augment = InventoryMapping.toInventoryAugment(flowNode);
+        data.addAugmentation(FlowCapableNode.class, augment);
+        InstanceIdentifier<? extends Object> value = ref.getValue();
+        InstanceIdentifierBuilder<Node> builder = InstanceIdentifier.<Node> builder(((InstanceIdentifier<Node>) value));
+        InstanceIdentifierBuilder<FlowCapableNode> augmentation = builder
+                .<FlowCapableNode> augmentation(FlowCapableNode.class);
+        final InstanceIdentifier<FlowCapableNode> path = augmentation.build();
+        NodeChangeCommiter.LOG.debug("updating node :{} ", path);
+        it.putOperationalData(path, augment);
+
+        Future<RpcResult<TransactionStatus>> commitResult = it.commit();
+        try {
+            commitResult.get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Node  {} not updated.", ref.getValue(), e);
+        }
+
+    }
+}

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.