use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.UnavailableCapabilitiesBuilder 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;
}
Aggregations