Provide an MDSalNodeFactory to construct an MD-SAL node for NB interfaces like the... 83/3883/1
authorMoiz Raja <moraja@cisco.com>
Fri, 20 Dec 2013 23:47:29 +0000 (15:47 -0800)
committerMoiz Raja <moraja@cisco.com>
Fri, 20 Dec 2013 23:47:29 +0000 (15:47 -0800)
When you try to get flows using the FR NB API for a given node you have to provide both a node type and node id. Since MD_SAL nodes
have a type MD_SAL which is not one of the standard types you need to provide and register a NodeFactory which can construct a Node
for an MD_SAL Node type.

Change-Id: Idc6631f58e248a1d958227312de07faa1fbc3d6e
Signed-off-by: Moiz Raja <moraja@cisco.com>
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ComponentActivator.xtend
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDSalNodeFactory.java [new file with mode: 0644]

index b460edf..a031289 100644 (file)
@@ -44,6 +44,9 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
     @Property
     DataPacketAdapter dataPacket = new DataPacketAdapter;
 
+    @Property
+    org.opendaylight.controller.sal.utils.INodeFactory nodeFactory = new MDSalNodeFactory
+
     override protected init() {
         Node.NodeIDType.registerIDType(MD_SAL_TYPE, NodeKey);
         NodeConnector.NodeConnectorIDType.registerIDType(MD_SAL_TYPE, NodeConnectorKey, MD_SAL_TYPE);
@@ -78,18 +81,24 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
     }
 
     override protected getGlobalImplementations() {
-        return Arrays.asList(this, flow, inventory, dataPacket)
+        return Arrays.asList(this, flow, inventory, dataPacket, nodeFactory)
     }
 
     override protected configureGlobalInstance(Component c, Object imp) {
         configure(imp, c);
     }
 
+    private def dispatch configure(MDSalNodeFactory imp, Component it) {
+        setInterface(org.opendaylight.controller.sal.utils.INodeFactory.name, properties);
+    }
+
     private def dispatch configure(ComponentActivator imp, Component it) {
         add(
             createServiceDependency().setService(BindingAwareBroker) //
             .setCallbacks("setBroker", "setBroker") //
             .setRequired(true))
+
+
     }
 
     private def dispatch configure(DataPacketAdapter imp, Component it) {
@@ -137,6 +146,7 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
     private def Dictionary<String, Object> properties() {
         val props = new Hashtable<String, Object>();
         props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString, MD_SAL_TYPE)
+        props.put("protocolName", MD_SAL_TYPE);
         return props;
     }
 }
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDSalNodeFactory.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/MDSalNodeFactory.java
new file mode 100644 (file)
index 0000000..0c1ee78
--- /dev/null
@@ -0,0 +1,24 @@
+package org.opendaylight.controller.sal.compatibility;
+
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.INodeFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MDSalNodeFactory implements INodeFactory{
+    private Logger logger = LoggerFactory.getLogger(MDSalNodeFactory.class);
+
+    @Override
+    public Node fromString(String type, String id) {
+
+        try {
+            return new Node(type, new NodeKey(new NodeId(id)));
+        } catch (ConstructionException e) {
+            logger.error("Could not construct Node", e);
+        }
+        return null;
+    }
+}