BUG-1089: convert AdSalTopologyMapping 16/7716/4
authorRobert Varga <rovarga@cisco.com>
Wed, 4 Jun 2014 20:43:10 +0000 (22:43 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 6 Jun 2014 09:51:00 +0000 (09:51 +0000)
Converts AdSalTopologyMapping from xtend to Java, optimizing it in the
process.

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

diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java
new file mode 100644 (file)
index 0000000..a7a7a9a
--- /dev/null
@@ -0,0 +1,109 @@
+/**
+ * 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.topologymanager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.compatibility.NodeMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+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.link.attributes.Destination;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source;
+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.Node;
+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;
+
+public class AdSalTopologyMapping {
+    private final InstanceIdentifier<Topology> topologyPath;
+
+    public AdSalTopologyMapping(final TopologyKey topology) {
+        this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
+                .child(Topology.class, topology).toInstance();
+    }
+
+    public InstanceIdentifier<Topology> getTopologyPath() {
+        return topologyPath;
+    }
+
+    public InstanceIdentifier<TerminationPoint> toTerminationPoint(final NodeConnector connector) {
+        return getTopologyPath().builder()
+                .child(Node.class)
+                .child(TerminationPoint.class, toTerminationPointKey(connector))
+                .toInstance();
+    }
+
+    public Map<Edge,Set<Property>> toEdgePropertiesMap(final Iterable<Link> links) {
+        final HashMap<Edge,Set<Property>> ret = new HashMap<>();
+        for (final Link link : links) {
+            try {
+                ret.put(toEdge(link), toProperties(link));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create edge properties for {}", link), e);
+            }
+        }
+        return ret;
+    }
+
+    public static Set<Edge> toEdges(final Iterable<Link> links) throws ConstructionException {
+        final HashSet<Edge> ret = new HashSet<Edge>();
+        for (final Link link : links) {
+            ret.add(toEdge(link));
+        }
+        return ret;
+    }
+
+    public static Edge toEdge(final Link link) throws ConstructionException {
+        final NodeConnector tail = toNodeConnector(link.getSource());
+        final NodeConnector head = toNodeConnector(link.getDestination());
+        return new Edge(tail, head);
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toAdNode(final Node node) throws ConstructionException {
+        return toAdNode(node.getNodeId());
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toAdNode(final NodeId node) throws ConstructionException {
+        final NodeKey key = new NodeKey(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(node));
+        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
+    }
+
+    public static NodeConnector toNodeConnector(final Source ref) throws ConstructionException {
+        final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getSourceNode());
+        final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getSourceTp()));
+        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
+    }
+
+    public static NodeConnector toNodeConnector(final Destination ref) throws ConstructionException {
+        final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getDestNode());
+        final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getDestTp()));
+        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
+    }
+
+    public TerminationPointKey toTerminationPointKey(final NodeConnector connector) {
+        return null;
+    }
+
+    public Set<Property> toProperties(final Link link) {
+        return null;
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend
deleted file mode 100644 (file)
index aa238a8..0000000
+++ /dev/null
@@ -1,96 +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.topologymanager
-
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-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
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
-import java.util.Map
-import org.opendaylight.controller.sal.core.Edge
-import java.util.Set
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import java.util.HashSet
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
-import org.opendaylight.controller.sal.compatibility.NodeMapping
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
-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.link.attributes.Source
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
-import java.util.HashMap
-
-class AdSalTopologyMapping {
-
-    val TopologyKey topologyMapping;
-    @Property
-    val InstanceIdentifier<Topology> topologyPath;
-
-    new(TopologyKey topology) {
-        topologyMapping = topology;
-        _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topology).toInstance;
-    }
-
-    def InstanceIdentifier<TerminationPoint> toTerminationPoint(NodeConnector connector) {
-        InstanceIdentifier.builder(topologyPath).child(Node).child(TerminationPoint, connector.toTerminationPointKey()).toInstance;
-    }
-
-    def Map<Edge, Set<org.opendaylight.controller.sal.core.Property>> toEdgePropertiesMap(Iterable<Link> links) {
-        val ret = new HashMap<Edge, Set<org.opendaylight.controller.sal.core.Property>>
-        for (link : links) {
-            ret.put(link.toEdge(), link.toProperties())
-        }
-        return ret;
-    }
-
-    def Set<Edge> toEdges(Iterable<Link> links) {
-        val ret = new HashSet<Edge>
-        for (link : links) {
-            ret.add(link.toEdge)
-        }
-        return ret;
-    }
-
-    def Edge toEdge(Link link) {
-        val tail = link.source.toNodeConnector();
-        val head = link.destination.toNodeConnector();
-        return new Edge(tail, head);
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdNode(Node node) {
-        return node.nodeId.toAdNode;
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdNode(
-        org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId node) {
-        val key = new NodeKey(new NodeId(node))
-        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
-    }
-
-    def NodeConnector toNodeConnector(Source ref) {
-        val adNode = ref.sourceNode.toAdNode();
-        val key = new NodeConnectorKey(new NodeConnectorId(ref.sourceTp))
-        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
-    }
-
-    def NodeConnector toNodeConnector(Destination ref) {
-        val adNode = ref.destNode.toAdNode();
-        val key = new NodeConnectorKey(new NodeConnectorId(ref.destTp))
-        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
-    }
-
-    def TerminationPointKey toTerminationPointKey(NodeConnector connector) {
-    }
-
-    def Set<org.opendaylight.controller.sal.core.Property> toProperties(Link link) {
-    }
-}
index 184c06eb70f37613a67a0b96953aed81e8c096f4..11320a12cd3b0708561e5bb107a5519024a08d55 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
+import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Edge;
 import org.opendaylight.controller.sal.core.Host;
 import org.opendaylight.controller.sal.core.NodeConnector;
@@ -63,22 +64,25 @@ public class CompatibleTopologyManager extends ConfigurableLinkManager implement
         final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
         final HashMap<org.opendaylight.controller.sal.core.Node, Set<Edge>> ret = new HashMap<>();
         for (final Node node : topology.getNode()) {
-            final org.opendaylight.controller.sal.core.Node adNode = topologyMapping.toAdNode(node);
-            ret.put(adNode, topologyMapping.toEdges(
-                    FluentIterable.from(topology.getLink()).filter(new Predicate<Link>() {
-                        @Override
-                        public boolean apply(final Link input) {
-                            final NodeId nodeId = node.getNodeId();
-                            if (nodeId.equals(input.getSource().getSourceNode())) {
-                                return true;
+            try {
+                ret.put(topologyMapping.toAdNode(node), topologyMapping.toEdges(
+                        FluentIterable.from(topology.getLink()).filter(new Predicate<Link>() {
+                            @Override
+                            public boolean apply(final Link input) {
+                                final NodeId nodeId = node.getNodeId();
+                                if (nodeId.equals(input.getSource().getSourceNode())) {
+                                    return true;
+                                }
+                                if (nodeId.equals(input.getDestination().getDestNode())) {
+                                    return true;
+                                }
+
+                                return false;
                             }
-                            if (nodeId.equals(input.getDestination().getDestNode())) {
-                                return true;
-                            }
-
-                            return false;
-                        }
-                    })));
+                        })));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to construct node for {}", node), e);
+            }
         }
         return ret;
     }
@@ -86,7 +90,7 @@ public class CompatibleTopologyManager extends ConfigurableLinkManager implement
     /**
      * Returns true if point is connected to link
      */
-    public boolean isInternal(final TerminationPoint point) {
+    private boolean isInternal(final TerminationPoint point) {
         final Topology topology = getDataReader().readConfigurationData(topologyMapping.getTopologyPath());
         final TpId tpId = point.getKey().getTpId();
         return FluentIterable.from(topology.getLink()).anyMatch(new Predicate<Link>() {