Search in sources :

Example 6 with MountPointContext

use of org.opendaylight.yangtools.rfc8528.data.api.MountPointContext 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());
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) BaseSchema(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 NetconfDeviceRpc (org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc)2 NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)2 Immutable (org.opendaylight.yangtools.concepts.Immutable)2 MountPointChild (org.opendaylight.yangtools.rfc8528.data.api.MountPointChild)2 MountPointContextFactory (org.opendaylight.yangtools.rfc8528.data.api.MountPointContextFactory)2 MountPointIdentifier (org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier)2 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)2 SchemaMountConstants (org.opendaylight.yangtools.rfc8528.model.api.SchemaMountConstants)2 QName (org.opendaylight.yangtools.yang.common.QName)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)2 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)2