Search in sources :

Example 1 with GetTopologiesOutput

use of org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.GetTopologiesOutput in project lighty-netconf-simulator by PANTHEONtech.

the class NetworkTopologyServiceImpl method getTopologies.

@Override
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public ListenableFuture<RpcResult<GetTopologiesOutput>> getTopologies(final GetTopologiesInput input) {
    Preconditions.checkNotNull(this.dataBrokerService);
    LOG.info("Searching data for all topologies");
    final SettableFuture<RpcResult<GetTopologiesOutput>> result = SettableFuture.create();
    this.executor.submit(new Callable<RpcResult<GetTopologiesOutput>>() {

        @Override
        public RpcResult<GetTopologiesOutput> call() throws Exception {
            try (ReadTransaction readTx = NetworkTopologyServiceImpl.this.dataBrokerService.newReadOnlyTransaction()) {
                final InstanceIdentifier<NetworkTopology> tii = InstanceIdentifier.builder(NetworkTopology.class).build();
                final Optional<NetworkTopology> networkTopology = readTx.read(LogicalDatastoreType.CONFIGURATION, tii).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
                if (networkTopology.isPresent()) {
                    final org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.TopologyBuilder topologyBuilder = new org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.TopologyBuilder();
                    final Collection<Topology> topologyList = networkTopology.get().nonnullTopology().values();
                    final Map<org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.TopologyKey, org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.Topology> topologyMapFinal = new HashMap<>();
                    for (final Topology t : topologyList) {
                        final Map<NodeKey, Node> nodeMap = new HashMap<>();
                        if (t.getNode() != null) {
                            for (final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node n : t.nonnullNode().values()) {
                                final NodeKey nk = new NodeKey(n.getNodeId());
                                final Node nb = buildNode(nk, n);
                                nodeMap.put(nb.key(), nb);
                            }
                        }
                        final org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.Topology tp = topologyBuilder.withKey(new TopologyKey(t.getTopologyId())).setTopologyId(t.getTopologyId()).setNode(nodeMap).build();
                        topologyMapFinal.put(tp.key(), tp);
                    }
                    final GetTopologiesOutput getTopologiesOutput = new GetTopologiesOutputBuilder().setNetworkTopology(new NetworkTopologyBuilder().setTopology(topologyMapFinal).build()).build();
                    final RpcResult<GetTopologiesOutput> rpcResult = RpcResultBuilder.success(getTopologiesOutput).build();
                    result.set(rpcResult);
                    return rpcResult;
                }
                final RpcResult<GetTopologiesOutput> rpcResult = RpcResultBuilder.success(new GetTopologiesOutputBuilder().build()).build();
                result.set(rpcResult);
                return rpcResult;
            }
        }
    });
    return result;
}
Also used : NetworkTopologyBuilder(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.get.topologies.output.NetworkTopologyBuilder) TopologyBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder) Preconditions(com.google.common.base.Preconditions) Node(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.node.data.Node) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) GetTopologiesOutput(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.GetTopologiesOutput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NodeKey(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.node.data.NodeKey) Optional(java.util.Optional) GetTopologiesOutputBuilder(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.GetTopologiesOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) TopologyKey(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.TopologyKey) Collection(java.util.Collection) NetworkTopologyBuilder(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.get.topologies.output.NetworkTopologyBuilder) Map(java.util.Map) HashMap(java.util.HashMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReadTransaction (org.opendaylight.mdsal.binding.api.ReadTransaction)1 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)1 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)1 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)1 TopologyBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder)1 GetTopologiesOutput (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.GetTopologiesOutput)1 GetTopologiesOutputBuilder (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.GetTopologiesOutputBuilder)1 NetworkTopologyBuilder (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.get.topologies.output.NetworkTopologyBuilder)1 Node (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.node.data.Node)1 NodeKey (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.node.data.NodeKey)1 TopologyKey (org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.topology.data.TopologyKey)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1