BUG-1089: migrate TopologyMapping 82/7682/4
authorRobert Varga <rovarga@cisco.com>
Wed, 4 Jun 2014 12:51:06 +0000 (14:51 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 5 Jun 2014 20:25:21 +0000 (22:25 +0200)
Simple transformation from xtend to Java, along with some optimizations.

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

diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.java
new file mode 100644 (file)
index 0000000..dbb6bdc
--- /dev/null
@@ -0,0 +1,81 @@
+/**
+ * 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.topology;
+
+import java.util.Iterator;
+
+import org.opendaylight.controller.sal.compatibility.InventoryMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+import com.google.common.base.Splitter;
+
+public class TopologyMapping {
+    private static final Splitter QUAD_COLON_SPLITTER = Splitter.on("::::");
+
+    public TopologyMapping(final TopologyKey path, final InstanceIdentifier<Topology> key) {
+        // No-op for now. Multi-instance will require fixing InventoryMapping first.
+    }
+
+    public Edge toAdTopologyEdge(final InstanceIdentifier<Link> identifier) throws ConstructionException {
+        @SuppressWarnings("unchecked")
+        final LinkKey linkKey = ((KeyedInstanceIdentifier<Link, LinkKey>)identifier).getKey();
+
+        final Iterator<String> it = QUAD_COLON_SPLITTER.split(linkKey.getLinkId().getValue()).iterator();
+        final NodeConnector tail = InventoryMapping.nodeConnectorFromId(it.next());
+        final NodeConnector head = InventoryMapping.nodeConnectorFromId(it.next());
+        return new Edge(tail, head);
+    }
+
+    public NodeConnector toAdTopologyNodeConnector(final InstanceIdentifier<TerminationPoint> identifier) {
+        @SuppressWarnings("unchecked")
+        final TerminationPointKey tpKey = ((KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey>)identifier).getKey();
+
+        return InventoryMapping.nodeConnectorFromId(tpKey.getTpId().getValue());
+    }
+
+    public org.opendaylight.controller.sal.core.Node toAdTopologyNode(final InstanceIdentifier<Node> identifier) {
+        @SuppressWarnings("unchecked")
+        final NodeKey nodeKey = ((KeyedInstanceIdentifier<Node, NodeKey>)identifier).getKey();
+
+        return InventoryMapping.nodeFromNodeId(nodeKey.getNodeId().getValue());
+    }
+
+    public NodeKey toTopologyNodeKey(final org.opendaylight.controller.sal.core.Node node) {
+        return new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
+    }
+
+    public TerminationPointKey toTopologyTerminationPointKey(final NodeConnector nc) {
+        return new TerminationPointKey(new TpId(InventoryMapping.toNodeConnectorId(nc)));
+    }
+
+    public LinkKey toTopologyLinkKey(final Edge edge) {
+        final TerminationPointKey sourceTp = toTopologyTerminationPointKey(edge.getTailNodeConnector());
+        final TerminationPointKey destTp = toTopologyTerminationPointKey(edge.getHeadNodeConnector());
+
+        final StringBuilder sb = new StringBuilder();
+        sb.append(sourceTp.getTpId().toString());
+        sb.append("::::");
+        sb.append(destTp.getTpId().toString());
+        return new LinkKey(new LinkId(sb.toString()));
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.xtend
deleted file mode 100644 (file)
index 0889de1..0000000
+++ /dev/null
@@ -1,74 +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.topology
-
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
-import org.opendaylight.controller.sal.core.Edge
-import java.util.Set
-import org.opendaylight.controller.sal.core.Property
-import org.opendaylight.controller.sal.core.NodeConnector
-
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import org.opendaylight.controller.sal.compatibility.InventoryMapping
-class TopologyMapping {
-
-    new(TopologyKey path, InstanceIdentifier<Topology> key) {
-        // NOOP
-    }
-
-    def Edge toAdTopologyEdge(InstanceIdentifier<Link> identifier) {
-        val linkKey = (identifier.path.last as IdentifiableItem<Link,LinkKey>).key;
-        val components = linkKey.linkId.value.split("::::");
-        val tail = InventoryMapping.nodeConnectorFromId(components.get(0));
-        val head = InventoryMapping.nodeConnectorFromId(components.get(1));
-        return new Edge(tail, head);
-    }
-
-    def NodeConnector toAdTopologyNodeConnector(InstanceIdentifier<TerminationPoint> identifier) {
-        val tpKey = (identifier.path.last as IdentifiableItem<TerminationPoint,TerminationPointKey>).key;
-        return InventoryMapping.nodeConnectorFromId(tpKey.tpId.value);
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdTopologyNode(
-        InstanceIdentifier<Node> identifier) {
-        val tpKey = (identifier.path.last as IdentifiableItem<Node,NodeKey>).key;
-        return InventoryMapping.nodeFromNodeId(tpKey.nodeId.value);
-    }
-    
-
-
-    def NodeKey toTopologyNodeKey(org.opendaylight.controller.sal.core.Node node) {
-        val nodeId = new NodeId(InventoryMapping.toNodeId(node));
-        return new NodeKey(nodeId);
-    }
-
-    def TerminationPointKey toTopologyTerminationPointKey(NodeConnector nc) {
-        val node = nc.node;
-        val nodeId = new TpId(InventoryMapping.toNodeConnectorId(nc))
-        return new TerminationPointKey(nodeId);
-    }
-
-    def LinkKey toTopologyLinkKey(Edge edge) {
-        val sourceTp = edge.tailNodeConnector.toTopologyTerminationPointKey;
-        val destTp = edge.headNodeConnector.toTopologyTerminationPointKey;
-        val linkId = new LinkId('''«sourceTp.tpId»::::«destTp.tpId»''')
-        return new LinkKey(linkId);
-    }
-}

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