BUG-1089: migrate InventoryReader 90/7690/5
authorRobert Varga <rovarga@cisco.com>
Wed, 4 Jun 2014 16:48:46 +0000 (18:48 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 6 Jun 2014 09:49:47 +0000 (09:49 +0000)
Migrates InventoryReader from xtend to pure Java.

Change-Id: I285c3dcbae8f407ec75de03d2df3092f9fcab30f
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend [deleted file]

diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java
new file mode 100644 (file)
index 0000000..b37b501
--- /dev/null
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2014 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.compatibility.inventory;
+
+import java.util.ArrayList;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider;
+import org.opendaylight.controller.sal.compatibility.InventoryMapping;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
+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.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InventoryReader implements RuntimeDataProvider {
+    private static final Logger LOG = LoggerFactory.getLogger(InventoryReader.class);
+    private ISwitchManager switchManager;
+
+    public ISwitchManager getSwitchManager() {
+        return switchManager;
+    }
+
+    public void setSwitchManager(final ISwitchManager switchManager) {
+        this.switchManager = switchManager;
+    }
+
+    @Override
+    public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
+        // Topology and Inventory are operational only
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
+        final Class<? extends DataObject> type = path.getTargetType();
+        if (Nodes.class.equals(type)) {
+            return readNodes(((InstanceIdentifier<Nodes>) path));
+        }
+        if (Node.class.equals(type)) {
+            return readNode(((InstanceIdentifier<Node>) path));
+        }
+        if (NodeConnector.class.equals(type)) {
+            return readNodeConnector(((InstanceIdentifier<NodeConnector>) path));
+        }
+
+        LOG.debug("Unsupported type {}", type);
+        return null;
+    }
+
+    private NodeConnector readNodeConnector(final InstanceIdentifier<NodeConnector> identifier) {
+        return constructNodeConnector(InventoryMapping.toAdNodeConnector(identifier));
+    }
+
+    private Node readNode(final InstanceIdentifier<Node> identifier) {
+        return constructNode(InventoryMapping.toAdNode(identifier));
+    }
+
+    private Node constructNode(final org.opendaylight.controller.sal.core.Node node) {
+        final Set<org.opendaylight.controller.sal.core.NodeConnector> connectors = getSwitchManager().getNodeConnectors(node);
+        final ArrayList<NodeConnector> tpList = new ArrayList<NodeConnector>(connectors.size());
+        for (final org.opendaylight.controller.sal.core.NodeConnector connector : connectors) {
+            tpList.add(constructNodeConnector(connector));
+        }
+
+        return new NodeBuilder()
+        .setKey(InventoryMapping.toNodeKey(node))
+        .setNodeConnector(tpList)
+        .build();
+    }
+
+    private Nodes readNodes(final InstanceIdentifier<Nodes> identifier) {
+        final Set<org.opendaylight.controller.sal.core.Node> nodes = getSwitchManager().getNodes();
+        final ArrayList<Node> nodeList = new ArrayList<Node>(nodes.size());
+        for (final org.opendaylight.controller.sal.core.Node node : nodes) {
+            nodeList.add(constructNode(node));
+        }
+
+        return new NodesBuilder().setNode(nodeList).build();
+    }
+
+    private static NodeConnector constructNodeConnector(final org.opendaylight.controller.sal.core.NodeConnector connector) {
+        return new NodeConnectorBuilder().setKey(InventoryMapping.toNodeConnectorKey(connector)).build();
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend
deleted file mode 100644 (file)
index 9b71369..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2014 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.compatibility.inventory
-
-import org.opendaylight.controller.switchmanager.ISwitchManager
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
-import java.util.ArrayList
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
-import static extension org.opendaylight.controller.sal.compatibility.InventoryMapping.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder
-
-class InventoryReader implements RuntimeDataProvider {
-
-    @Property
-    var ISwitchManager switchManager;
-
-    override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
-
-        // Topology and Inventory are operational only
-        return null;
-    }
-
-    override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
-        val type = path.targetType;
-        var DataObject data = null;
-        switch (type) {
-            case Nodes:
-                data = readNodes(path as InstanceIdentifier<Nodes>)
-            case Node:
-                data = readNode(path as InstanceIdentifier<Node>)
-            case NodeConnector:
-                data = readNodeConnector(path as InstanceIdentifier<NodeConnector>)
-        }
-        return data;
-    }
-
-    def DataObject readNodeConnector(InstanceIdentifier<NodeConnector> identifier) {
-        val nodeConnector = identifier.toAdNodeConnector();
-        return constructNodeConnector(nodeConnector)
-    }
-
-    def DataObject readNode(InstanceIdentifier<Node> identifier) {
-        val node = identifier.toAdNode();
-        return constructNode(node);
-    }
-
-
-    def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
-        val connectors = switchManager.getNodeConnectors(node)
-
-        val tpList = new ArrayList<NodeConnector>(connectors.size)
-        for (connector : connectors) {
-            tpList.add(constructNodeConnector(connector));
-        }
-
-        val it = new NodeBuilder()
-        key = node.toNodeKey();
-        nodeConnector = tpList
-        return build();
-    }
-
-    def NodeConnector constructNodeConnector(org.opendaylight.controller.sal.core.NodeConnector connector) {
-        val it = new NodeConnectorBuilder()
-        key = connector.toNodeConnectorKey()
-        return build();
-    }
-
-    def readNodes(InstanceIdentifier<Nodes> identifier) {
-        val nodes = switchManager.nodes
-        val nodeList = new ArrayList<Node>(nodes.size)
-        for (node : nodes) {
-            nodeList.add(constructNode(node))
-        }
-        val it = new NodesBuilder();
-        node = nodeList
-        return build()
-
-    }
-}

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