1 package org.opendaylight.controller.sal.compability
3 import org.opendaylight.controller.sal.core.Node
4 import org.opendaylight.controller.sal.core.NodeConnector
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
6 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
8 import static com.google.common.base.Preconditions.*;
9 import static extension org.opendaylight.controller.sal.common.util.Arguments.*;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
14 import org.opendaylight.controller.sal.core.ConstructionException
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
18 public class NodeMapping {
20 public static val MD_SAL_TYPE = "MD_SAL";
21 private static val NODE_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
22 private static val NODECONNECTOR_CLASS = org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.
26 throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
29 public static def toADNode(InstanceIdentifier<?> node) throws ConstructionException {
31 checkNotNull(node.getPath());
32 checkArgument(node.getPath().size() >= 2);
33 val arg = node.getPath().get(1);
34 val item = arg.checkInstanceOf(IdentifiableItem);
35 val nodeKey = item.getKey().checkInstanceOf(NodeKey);
36 return new Node(MD_SAL_TYPE, nodeKey);
39 public static def toADNodeConnector(NodeConnectorRef source) throws ConstructionException {
41 val InstanceIdentifier<?> path = checkNotNull(source.getValue());
42 val node = path.toADNode();
43 checkArgument(path.path.size() >= 3);
44 val arg = path.getPath().get(2);
45 val item = arg.checkInstanceOf(IdentifiableItem);
46 val connectorKey = item.getKey().checkInstanceOf(NodeConnectorKey);
47 return new NodeConnector(MD_SAL_TYPE, connectorKey, node);
50 public static def toNodeRef(Node node) {
51 checkArgument(MD_SAL_TYPE.equals(node.getType()));
52 val nodeKey = node.ID.checkInstanceOf(NodeKey);
53 val nodePath = InstanceIdentifier.builder().node(Nodes).node(NODE_CLASS, nodeKey).toInstance();
54 return new NodeRef(nodePath);
57 public static def toNodeConnectorRef(NodeConnector nodeConnector) {
58 val node = nodeConnector.node.toNodeRef();
59 val connectorKey = nodeConnector.ID.checkInstanceOf(NodeConnectorKey);
60 val path = InstanceIdentifier.builder(node.getValue()).node(NODECONNECTOR_CLASS, connectorKey).toInstance();
61 return new NodeConnectorRef(path);
64 public static def toADNode(NodeRef node) throws ConstructionException {
65 return toADNode(node.getValue());