From: Robert Varga Date: Wed, 4 Jun 2014 20:43:10 +0000 (+0200) Subject: BUG-1089: convert AdSalTopologyMapping X-Git-Tag: release/helium~691 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=12597e4a426fdeb7a29e484cfa6185a6630d8733 BUG-1089: convert AdSalTopologyMapping Converts AdSalTopologyMapping from xtend to Java, optimizing it in the process. Change-Id: I62b6c17240cf3588a051c8945769dd6ea8fa2af0 Signed-off-by: Robert Varga --- 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 index 0000000000..a7a7a9ac3a --- /dev/null +++ b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java @@ -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 topologyPath; + + public AdSalTopologyMapping(final TopologyKey topology) { + this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class) + .child(Topology.class, topology).toInstance(); + } + + public InstanceIdentifier getTopologyPath() { + return topologyPath; + } + + public InstanceIdentifier toTerminationPoint(final NodeConnector connector) { + return getTopologyPath().builder() + .child(Node.class) + .child(TerminationPoint.class, toTerminationPointKey(connector)) + .toInstance(); + } + + public Map> toEdgePropertiesMap(final Iterable links) { + final HashMap> 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 toEdges(final Iterable links) throws ConstructionException { + final HashSet ret = new HashSet(); + 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 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 index aa238a8a8e..0000000000 --- a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend +++ /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 topologyPath; - - new(TopologyKey topology) { - topologyMapping = topology; - _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topology).toInstance; - } - - def InstanceIdentifier toTerminationPoint(NodeConnector connector) { - InstanceIdentifier.builder(topologyPath).child(Node).child(TerminationPoint, connector.toTerminationPointKey()).toInstance; - } - - def Map> toEdgePropertiesMap(Iterable links) { - val ret = new HashMap> - for (link : links) { - ret.put(link.toEdge(), link.toProperties()) - } - return ret; - } - - def Set toEdges(Iterable links) { - val ret = new HashSet - 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 toProperties(Link link) { - } -} diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java index 184c06eb70..11320a12cd 100644 --- a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java +++ b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java @@ -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> 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() { - @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() { + @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() {