273d062309cbfa0161833f984c4b4c137f1051a6
[netconf.git] / opendaylight / netconf / abstract-topology / src / main / java / org / opendaylight / netconf / topology / util / TopologyUtil.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.topology.util;
10
11 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
17 import org.opendaylight.yangtools.yang.binding.Identifier;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 public final class TopologyUtil {
21
22     private TopologyUtil() {
23         throw new AssertionError("Instantiating utility class.");
24     }
25
26     /**
27      * Determines the Netconf Node Node ID, given the node's instance
28      * identifier.
29      *
30      * @param pathArgument Node's path argument
31      * @return     NodeId for the node
32      */
33     public static NodeId getNodeId(final InstanceIdentifier.PathArgument pathArgument) {
34         if (pathArgument instanceof InstanceIdentifier.IdentifiableItem<?, ?>) {
35
36             final Identifier key = ((InstanceIdentifier.IdentifiableItem) pathArgument).getKey();
37             if(key instanceof NodeKey) {
38                 return ((NodeKey) key).getNodeId();
39             }
40         }
41         throw new IllegalStateException("Unable to create NodeId from: " + pathArgument);
42     }
43
44     public static InstanceIdentifier<Topology> createTopologyId(final String topologyId) {
45         final InstanceIdentifier<NetworkTopology> networkTopology = InstanceIdentifier.create(NetworkTopology.class);
46         return networkTopology.child(Topology.class, new TopologyKey(new TopologyId(topologyId)));
47     }
48 }