X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2FNetconfDeviceConnectionManager.java;h=67e965858a0b84b76fcab34de12090bc649a4f0c;hp=3dd892e16952860ea0c226221d20623c15ffa481;hb=bd8beb1bfee9f421ad8f2d07b1424b21038234a2;hpb=005fe06825937461a29bcb621c223734194f07ad diff --git a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/NetconfDeviceConnectionManager.java b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/NetconfDeviceConnectionManager.java index 3dd892e169..67e965858a 100644 --- a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/NetconfDeviceConnectionManager.java +++ b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/NetconfDeviceConnectionManager.java @@ -14,6 +14,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.InetSocketAddress; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -22,12 +23,21 @@ import org.opendaylight.controller.netconf.cli.io.ConsoleIO; import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; import org.opendaylight.controller.sal.connect.netconf.NetconfDevice; +import org.opendaylight.controller.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO; +import org.opendaylight.controller.sal.connect.netconf.NetconfStateSchemas.NetconfStateSchemasResolverImpl; import org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator; +import org.opendaylight.controller.sal.connect.netconf.schema.mapping.NetconfMessageTransformer; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; +import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory; +import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter; +import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache; import org.opendaylight.yangtools.yang.model.util.repo.AbstractCachingSchemaSourceProvider; import org.opendaylight.yangtools.yang.model.util.repo.FilesystemSchemaCachingProvider; import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider; import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProviders; +import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository; +import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer; /** * Manages connect/disconnect to 1 remote device @@ -42,6 +52,8 @@ public class NetconfDeviceConnectionManager implements Closeable { private final NioEventLoopGroup nettyThreadGroup; private final NetconfClientDispatcherImpl netconfClientDispatcher; + private static final String CACHE = "cache/schema"; + // Connection private NetconfDeviceConnectionHandler handler; private NetconfDevice device; @@ -62,15 +74,23 @@ public class NetconfDeviceConnectionManager implements Closeable { // TODO we receive configBuilder in order to add SessionListener, Session // Listener should not be part of config - public synchronized void connect(final String name, final NetconfClientConfigurationBuilder configBuilder) { + public synchronized void connect(final String name, final InetSocketAddress address, final NetconfClientConfigurationBuilder configBuilder) { // TODO change IllegalState exceptions to custom ConnectionException Preconditions.checkState(listener == null, "Already connected"); - final RemoteDeviceId deviceId = new RemoteDeviceId(name); + final RemoteDeviceId deviceId = new RemoteDeviceId(name, address); handler = new NetconfDeviceConnectionHandler(commandDispatcher, schemaContextRegistry, console, name); - device = NetconfDevice.createNetconfDevice(deviceId, getGlobalNetconfSchemaProvider(), executor, handler); + + final SharedSchemaRepository repository = new SharedSchemaRepository("repo"); + final SchemaContextFactory schemaContextFactory = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT); + final FilesystemSchemaSourceCache cache = new FilesystemSchemaSourceCache<>(repository, YangTextSchemaSource.class, new File(CACHE)); + repository.registerSchemaSourceListener(cache); + repository.registerSchemaSourceListener(TextToASTTransformer.create(repository, repository)); + + device = new NetconfDevice(new SchemaResourcesDTO(repository, schemaContextFactory, new NetconfStateSchemasResolverImpl()), + deviceId, handler, executor, new NetconfMessageTransformer()); listener = new NetconfDeviceCommunicator(deviceId, device); configBuilder.withSessionListener(listener); listener.initializeRemoteConnection(netconfClientDispatcher, configBuilder.build()); @@ -79,8 +99,8 @@ public class NetconfDeviceConnectionManager implements Closeable { /** * Blocks thread until connection is fully established */ - public synchronized Set connectBlocking(final String name, final NetconfClientConfigurationBuilder configBuilder) { - this.connect(name, configBuilder); + public synchronized Set connectBlocking(final String name, final InetSocketAddress address, final NetconfClientConfigurationBuilder configBuilder) { + this.connect(name, address, configBuilder); synchronized (handler) { while (handler.isUp() == false) { try {