Merge "Added Inventory Reader for SwitchManager"
[controller.git] / opendaylight / md-sal / compatibility / inventory-topology-compatibility / src / main / java / org / opendaylight / controller / md / compatibility / inventory / InventoryReader.xtend
1 package org.opendaylight.controller.md.compatibility.inventory
2
3 import org.opendaylight.controller.switchmanager.ISwitchManager
4 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
5 import org.opendaylight.yangtools.yang.binding.DataObject
6 import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
7 import java.util.ArrayList
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
11 import static extension org.opendaylight.controller.sal.compatibility.InventoryMapping.*;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder
15
16 class InventoryReader implements RuntimeDataProvider {
17
18     @Property
19     var ISwitchManager switchManager;
20
21     override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
22
23         // Topology and Inventory are operational only
24         return null;
25     }
26
27     override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
28         val type = path.targetType;
29         var DataObject data = null;
30         switch (type) {
31             case Nodes:
32                 data = readNodes(path as InstanceIdentifier<Nodes>)
33             case Node:
34                 data = readNode(path as InstanceIdentifier<Node>)
35             case NodeConnector:
36                 data = readNodeConnector(path as InstanceIdentifier<NodeConnector>)
37         }
38         return data;
39     }
40
41     def DataObject readNodeConnector(InstanceIdentifier<NodeConnector> identifier) {
42         val nodeConnector = identifier.toAdNodeConnector();
43         return constructNodeConnector(nodeConnector)
44     }
45
46     def DataObject readNode(InstanceIdentifier<Node> identifier) {
47         val node = identifier.toAdNode();
48         return constructNode(node);
49     }
50
51
52     def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
53         val connectors = switchManager.getNodeConnectors(node)
54
55         val tpList = new ArrayList<NodeConnector>(connectors.size)
56         for (connector : connectors) {
57             tpList.add(constructNodeConnector(connector));
58         }
59
60         val it = new NodeBuilder()
61         key = node.toNodeKey();
62         nodeConnector = tpList
63         return build();
64     }
65
66     def NodeConnector constructNodeConnector(org.opendaylight.controller.sal.core.NodeConnector connector) {
67         val it = new NodeConnectorBuilder()
68         key = connector.toNodeConnectorKey()
69         return build();
70     }
71
72     def readNodes(InstanceIdentifier<Nodes> identifier) {
73         val nodes = switchManager.nodes
74         val nodeList = new ArrayList<Node>(nodes.size)
75         for (node : nodes) {
76             nodeList.add(constructNode(node))
77         }
78         val it = new NodesBuilder();
79         node = nodeList
80         return build()
81
82     }
83 }

©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.