9b7136959300e45f5f315a4a95fdeb397564fc20
[controller.git] / opendaylight / md-sal / compatibility / inventory-topology-compatibility / src / main / java / org / opendaylight / controller / md / compatibility / inventory / InventoryReader.xtend
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.md.compatibility.inventory
9
10 import org.opendaylight.controller.switchmanager.ISwitchManager
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yangtools.yang.binding.DataObject
13 import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
14 import java.util.ArrayList
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
18 import static extension org.opendaylight.controller.sal.compatibility.InventoryMapping.*;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder
22
23 class InventoryReader implements RuntimeDataProvider {
24
25     @Property
26     var ISwitchManager switchManager;
27
28     override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
29
30         // Topology and Inventory are operational only
31         return null;
32     }
33
34     override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
35         val type = path.targetType;
36         var DataObject data = null;
37         switch (type) {
38             case Nodes:
39                 data = readNodes(path as InstanceIdentifier<Nodes>)
40             case Node:
41                 data = readNode(path as InstanceIdentifier<Node>)
42             case NodeConnector:
43                 data = readNodeConnector(path as InstanceIdentifier<NodeConnector>)
44         }
45         return data;
46     }
47
48     def DataObject readNodeConnector(InstanceIdentifier<NodeConnector> identifier) {
49         val nodeConnector = identifier.toAdNodeConnector();
50         return constructNodeConnector(nodeConnector)
51     }
52
53     def DataObject readNode(InstanceIdentifier<Node> identifier) {
54         val node = identifier.toAdNode();
55         return constructNode(node);
56     }
57
58
59     def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
60         val connectors = switchManager.getNodeConnectors(node)
61
62         val tpList = new ArrayList<NodeConnector>(connectors.size)
63         for (connector : connectors) {
64             tpList.add(constructNodeConnector(connector));
65         }
66
67         val it = new NodeBuilder()
68         key = node.toNodeKey();
69         nodeConnector = tpList
70         return build();
71     }
72
73     def NodeConnector constructNodeConnector(org.opendaylight.controller.sal.core.NodeConnector connector) {
74         val it = new NodeConnectorBuilder()
75         key = connector.toNodeConnectorKey()
76         return build();
77     }
78
79     def readNodes(InstanceIdentifier<Nodes> identifier) {
80         val nodes = switchManager.nodes
81         val nodeList = new ArrayList<Node>(nodes.size)
82         for (node : nodes) {
83             nodeList.add(constructNode(node))
84         }
85         val it = new NodesBuilder();
86         node = nodeList
87         return build()
88
89     }
90 }

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