BUG-625: convert TopologyMapping 38/7438/1
authorRobert Varga <rovarga@cisco.com>
Tue, 27 May 2014 20:34:19 +0000 (22:34 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 27 May 2014 20:34:19 +0000 (22:34 +0200)
This converts TopologyMapping from xtend to Java.

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

diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyMapping.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyMapping.java
new file mode 100644 (file)
index 0000000..476a71a
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * 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.sal.compatibility.topology;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
+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.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+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.topology.Link;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+
+public final class TopologyMapping {
+    private static final Logger LOG = LoggerFactory.getLogger(TopologyMapping.class);
+
+    private TopologyMapping() {
+        throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
+    }
+
+    public static List<TopoEdgeUpdate> toADEdgeUpdates(final Topology topology,final TypeSafeDataReader reader) {
+        final List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<>();
+        return FluentIterable.from(topology.getLink()).transform(
+                new Function<Link, TopoEdgeUpdate>() {
+                    @Override
+                    public TopoEdgeUpdate apply(final Link input) {
+                        try {
+                            return toTopoEdgeUpdate(toAdEdge(input, topology), reader);
+                        } catch (ConstructionException e) {
+                            throw new IllegalArgumentException(String.format("Failed to construct edge update for {}", input), e);
+                        }
+                    }}
+                ).copyInto(result);
+    }
+
+    public static Edge toAdEdge(final Link link, final Topology topology) throws ConstructionException {
+        final NodeConnector adSrc = toADNodeConnector(link.getSource().getSourceTp(), link.getSource().getSourceNode());
+        final NodeConnector adDst = toADNodeConnector(link.getDestination().getDestTp(), link.getDestination().getDestNode());
+        return new Edge(adSrc, adDst);
+    }
+
+    public static TopoEdgeUpdate toTopoEdgeUpdate(final Edge e, final TypeSafeDataReader reader) {
+        return toTopoEdgeUpdate(e, UpdateType.ADDED, reader);
+    }
+
+    public static TopoEdgeUpdate toTopoEdgeUpdate(final Edge e,final UpdateType type,final TypeSafeDataReader reader) {
+        return new TopoEdgeUpdate(e, toAdEdgeProperties(e, reader), type);
+    }
+
+    public static Set<Property> toAdEdgeProperties(final Edge e,final TypeSafeDataReader reader) {
+        final NodeConnectorRef ncref = NodeMapping.toNodeConnectorRef(e.getTailNodeConnector());
+        if(ncref == null) {
+            LOG.debug("Edge {} ncref {}",e,ncref);
+            return null;
+        }
+
+        @SuppressWarnings("unchecked")
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> ncInstanceId =
+        (InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>) ncref.getValue();
+        if(ncInstanceId == null) {
+            LOG.debug("Edge {} ncref {}",e,ncref);
+            return null;
+        }
+
+        final  org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc = reader.readOperationalData(ncInstanceId);
+        if(nc == null) {
+            return null;
+        }
+        return NodeMapping.toADNodeConnectorProperties(nc);
+    }
+
+    public static String toADNodeId(final NodeId nodeId) {
+        return nodeId.getValue();
+    }
+
+    public static NodeConnector toADNodeConnector(final TpId source, final NodeId nodeId) throws ConstructionException {
+        checkNotNull(source);
+        return new NodeConnector(NodeMapping.MD_SAL_TYPE, toADNodeConnectorId(source), toADNode(nodeId));
+    }
+
+    public static String toADNodeConnectorId(final TpId nodeConnectorId) {
+        return nodeConnectorId.getValue();
+    }
+
+    public static Node toADNode(final NodeId nodeId) throws ConstructionException {
+        checkNotNull(nodeId);
+        return new Node(NodeMapping.MD_SAL_TYPE, toADNodeId(nodeId));
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyMapping.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/topology/TopologyMapping.xtend
deleted file mode 100644 (file)
index 2d49056..0000000
+++ /dev/null
@@ -1,91 +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.sal.compatibility.topology
-
-import com.google.common.collect.FluentIterable
-import java.util.List
-import java.util.concurrent.CopyOnWriteArrayList
-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.Node
-import org.opendaylight.controller.sal.core.NodeConnector
-import org.opendaylight.controller.sal.core.UpdateType
-import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
-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.topology.Link
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.slf4j.LoggerFactory
-
-import static com.google.common.base.Preconditions.*
-
-import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
-
-class TopologyMapping {
-    private static val LOG = LoggerFactory.getLogger(TopologyMapping);
-    private new() {
-        throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
-    }
-    
-    public static def toADEdgeUpdates(Topology topology,TypeSafeDataReader reader) {
-        val List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<TopoEdgeUpdate>()
-        return FluentIterable.from(topology.link).transform[toAdEdge(topology).toTopoEdgeUpdate(reader)].copyInto(result)
-    }
-    
-    public static def toAdEdge(Link link,Topology topology) {
-        val adSrc = link.source.sourceTp.toADNodeConnector(link.source.sourceNode)
-        val adDst = link.destination.destTp.toADNodeConnector(link.destination.destNode)
-        return new Edge(adSrc,adDst); 
-    }
-    
-    public static def toTopoEdgeUpdate(Edge e,TypeSafeDataReader reader) {
-        return toTopoEdgeUpdate(e,UpdateType.ADDED,reader)
-    }
-    
-    public static def toTopoEdgeUpdate(Edge e,UpdateType type,TypeSafeDataReader reader) {
-        return new TopoEdgeUpdate(e,e.toAdEdgeProperties(reader),type)
-    }
-    
-    public static def toAdEdgeProperties(Edge e,TypeSafeDataReader reader) {
-        val ncref = e.tailNodeConnector.toNodeConnectorRef
-        if(ncref == null) {
-            LOG.debug("Edge {} ncref {}",e,ncref)
-            return null;
-        }
-        val ncInstanceId = (ncref.value as InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>)
-        if(ncInstanceId == null) {
-            LOG.debug("Edge {} ncref {}",e,ncref)
-            return null;
-        }
-        val nc = reader.readOperationalData(ncInstanceId)
-        if(nc == null) {
-            return null;
-        }
-        return nc.toADNodeConnectorProperties     
-    }
-    
-    public static def toADNodeId(NodeId nodeId) {
-        checkNotNull(nodeId);
-        return nodeId.value
-    }
-    public static def toADNodeConnector(TpId source,NodeId nodeId) throws ConstructionException {
-        checkNotNull(source);
-        return new NodeConnector(MD_SAL_TYPE,source.toADNodeConnectorId,nodeId.toADNode)
-    }
-    
-    public static def toADNodeConnectorId(TpId nodeConnectorId) {
-        return nodeConnectorId.value
-    }
-    
-    public static def toADNode(NodeId nodeId) {
-        checkNotNull(nodeId);
-        return new Node(MD_SAL_TYPE,nodeId.toADNodeId);       
-    }
-}

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