Search in sources :

Example 1 with AddNodeIntoTopologyOutput

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

the class NetworkTopologyServiceImpl method addNodeIntoTopology.

@Override
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
public ListenableFuture<RpcResult<AddNodeIntoTopologyOutput>> addNodeIntoTopology(final AddNodeIntoTopologyInput input) {
    Preconditions.checkNotNull(this.dataBrokerService);
    LOG.info("Adding node to topology {}", input.getTopologyId());
    final SettableFuture<RpcResult<AddNodeIntoTopologyOutput>> result = SettableFuture.create();
    this.executor.submit(new Callable<RpcResult<AddNodeIntoTopologyOutput>>() {

        @Override
        public RpcResult<AddNodeIntoTopologyOutput> call() throws Exception {
            final WriteTransaction writeTx = NetworkTopologyServiceImpl.this.dataBrokerService.newWriteOnlyTransaction();
            final TopologyId topologyId = input.getTopologyId();
            final Collection<Node> nodeCollection = input.nonnullNode().values();
            final Map<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nodeConfigMap = new HashMap<>();
            final Map<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nodeOperMap = new HashMap<>();
            for (final Node node : nodeCollection) {
                NetconfNode netconfNode = new NetconfNodeBuilder().setHost(node.getHost()).setPort(node.getPort()).setCredentials(node.getCredentials()).setKeepaliveDelay(node.getKeepaliveDelay()).setSchemaless(node.getSchemaless()).setTcpOnly(node.getTcpOnly()).build();
                final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node nConfig = createNetworkTopologyNode(node, netconfNode);
                final List<AvailableCapability> availableCapabilities = new ArrayList<>();
                for (final Module m : NetworkTopologyServiceImpl.this.effectiveModelContext.getModules()) {
                    final Revision revision = m.getRevision().orElse(Revision.of("2017-01-01"));
                    final AvailableCapability ac = new AvailableCapabilityBuilder().setCapabilityOrigin(AvailableCapability.CapabilityOrigin.DeviceAdvertised).setCapability(String.format("(%s?revision=%s)%s", m.getNamespace(), revision, m.getName())).build();
                    availableCapabilities.add(ac);
                }
                netconfNode = new NetconfNodeBuilder().setConnectionStatus(NetconfNodeConnectionStatus.ConnectionStatus.Connected).setUnavailableCapabilities(new UnavailableCapabilitiesBuilder().build()).setAvailableCapabilities(new AvailableCapabilitiesBuilder().setAvailableCapability(availableCapabilities).build()).setHost(node.getHost()).setPort(node.getPort()).build();
                final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node nOper = createNetworkTopologyNode(node, netconfNode);
                nodeConfigMap.put(nConfig.key(), nConfig);
                nodeOperMap.put(nOper.key(), nOper);
            }
            Topology topology = new TopologyBuilder().setTopologyId(topologyId).setNode(nodeConfigMap).build();
            final InstanceIdentifier<Topology> tii = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topology.key()).build();
            writeTx.merge(LogicalDatastoreType.CONFIGURATION, tii, topology);
            topology = new TopologyBuilder().setTopologyId(topologyId).setNode(nodeOperMap).build();
            writeTx.merge(LogicalDatastoreType.OPERATIONAL, tii, topology);
            writeTx.commit().get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
            final AddNodeIntoTopologyOutput addNodeIntoTopologyOutput = new AddNodeIntoTopologyOutputBuilder().build();
            final RpcResult<AddNodeIntoTopologyOutput> rpcResult = RpcResultBuilder.success(addNodeIntoTopologyOutput).build();
            result.set(rpcResult);
            return rpcResult;
        }
    });
    return result;
}
Also used : Preconditions(com.google.common.base.Preconditions) 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) 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) AddNodeIntoTopologyOutput(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.AddNodeIntoTopologyOutput) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) AvailableCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder) AvailableCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder) AddNodeIntoTopologyOutputBuilder(org.opendaylight.yang.gen.v1.urn.tech.pantheon.netconfdevice.network.topology.rpcs.rev180320.AddNodeIntoTopologyOutputBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) List(java.util.List) ArrayList(java.util.ArrayList) AvailableCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) 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) UnavailableCapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.UnavailableCapabilitiesBuilder) Revision(org.opendaylight.yangtools.yang.common.Revision) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Collection(java.util.Collection) Module(org.opendaylight.yangtools.yang.model.api.Module) Map(java.util.Map) HashMap(java.util.HashMap) TopologyId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)1 NetconfNodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder)1 AvailableCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder)1 UnavailableCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.UnavailableCapabilitiesBuilder)1 AvailableCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability)1 AvailableCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder)1 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)1 TopologyId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId)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