use of org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc in project netconf by opendaylight.
the class NetconfDevice method createMountPointContext.
private ListenableFuture<MountPointContext> createMountPointContext(final EffectiveModelContext schemaContext, final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) {
final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext);
if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) {
return Futures.immediateFuture(emptyContext);
}
// Create a temporary RPC invoker and acquire the mount point tree
LOG.debug("{}: Acquiring available mount points", id);
final NetconfDeviceRpc deviceRpc = new NetconfDeviceRpc(schemaContext, listener, new NetconfMessageTransformer(emptyContext, false, baseSchema));
return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_QNAME, Builders.containerBuilder().withNodeIdentifier(NETCONF_GET_NODEID).withChild(NetconfMessageTransformUtil.toFilterStructure(RFC8528_SCHEMA_MOUNTS, schemaContext)).build()), rpcResult -> processSchemaMounts(rpcResult, emptyContext), MoreExecutors.directExecutor());
}
use of org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc in project netconf by opendaylight.
the class NetconfBaseOpsTest method setUp.
@Before
public void setUp() throws Exception {
final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
callback = new NetconfRpcFutureCallback("prefix", id);
baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
use of org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc in project netconf by opendaylight.
the class NetconfDevice method onRemoteSessionUp.
@Override
public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities, final NetconfDeviceCommunicator listener) {
// SchemaContext setup has to be performed in a dedicated thread since
// we are in a netty thread in this method
// Yang models are being downloaded in this method and it would cause a
// deadlock if we used the netty thread
// http://netty.io/wiki/thread-model.html
setConnected(true);
LOG.debug("{}: Session to remote device established with {}", id, remoteSessionCapabilities);
final BaseSchema baseSchema = resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported());
final NetconfDeviceRpc initRpc = new NetconfDeviceRpc(baseSchema.getEffectiveModelContext(), listener, new NetconfMessageTransformer(baseSchema.getMountPointContext(), false, baseSchema));
final ListenableFuture<DeviceSources> sourceResolverFuture = processingExecutor.submit(new DeviceSourcesResolver(id, baseSchema, initRpc, remoteSessionCapabilities, stateSchemasResolver));
if (shouldListenOnSchemaChange(remoteSessionCapabilities)) {
registerToBaseNetconfStream(initRpc, listener);
}
// Set up the SchemaContext for the device
final ListenableFuture<EffectiveModelContext> futureSchema = Futures.transformAsync(sourceResolverFuture, deviceSources -> assembleSchemaContext(deviceSources, remoteSessionCapabilities), processingExecutor);
// Potentially acquire mount point list and interpret it
final ListenableFuture<MountPointContext> futureContext = Futures.transformAsync(futureSchema, schemaContext -> createMountPointContext(schemaContext, baseSchema, listener), processingExecutor);
Futures.addCallback(futureContext, new FutureCallback<MountPointContext>() {
@Override
public void onSuccess(final MountPointContext result) {
handleSalInitializationSuccess(result, remoteSessionCapabilities, getDeviceSpecificRpc(result, listener, baseSchema), listener);
}
@Override
public void onFailure(final Throwable cause) {
LOG.warn("{}: Unexpected error resolving device sources", id, cause);
// No more sources, fail or try to reconnect
if (cause instanceof EmptySchemaContextException) {
if (nodeOptional != null && nodeOptional.getIgnoreMissingSchemaSources().getAllowed()) {
eventExecutor.schedule(() -> {
LOG.warn("Reconnection is allowed! This can lead to unexpected errors at runtime.");
LOG.warn("{} : No more sources for schema context.", id);
LOG.info("{} : Try to remount device.", id);
onRemoteSessionDown();
salFacade.onDeviceReconnected(remoteSessionCapabilities, node);
}, nodeOptional.getIgnoreMissingSchemaSources().getReconnectTime().toJava(), TimeUnit.MILLISECONDS);
return;
}
}
handleSalInitializationFailure(cause, listener);
salFacade.onDeviceFailed(cause);
}
}, MoreExecutors.directExecutor());
}
Aggregations