From 9c35db15f3cd24251703946640b7cb2f252ae41c Mon Sep 17 00:00:00 2001 From: Marian Dubai Date: Tue, 25 Nov 2014 17:33:30 +0100 Subject: [PATCH] Netconf-cli compilable and included in project Change-Id: Ia08396f52c98ea2661e13f60a3787b18c4ae50d6 Signed-off-by: Marian Dubai --- .../controller/netconf/cli/Main.java | 4 +++- .../cli/NetconfDeviceConnectionManager.java | 21 ++++++++++++++++++- opendaylight/netconf/pom.xml | 3 +-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/Main.java b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/Main.java index 79c083c1ed..64397de118 100644 --- a/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/Main.java +++ b/opendaylight/netconf/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/Main.java @@ -7,6 +7,8 @@ */ package org.opendaylight.controller.netconf.cli; +import static com.google.common.base.Throwables.getStackTraceAsString; + import com.google.common.base.Preconditions; import java.io.IOException; import java.net.InetAddress; @@ -105,7 +107,7 @@ public class Main { } private static void handleException(final Exception e, final String message) { - // FIXME syserr the exception and stacktrace + System.console().writer().println(String.format("Error %s cause %s", message, getStackTraceAsString(e.fillInStackTrace()))); } private static void writeStatus(final ConsoleIO io, final String blueprint, final Object... args) { 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..f4e21714cd 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 @@ -22,12 +22,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 +51,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; @@ -70,7 +81,15 @@ public class NetconfDeviceConnectionManager implements Closeable { 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()); diff --git a/opendaylight/netconf/pom.xml b/opendaylight/netconf/pom.xml index 885bdb4fdd..8b14adf252 100644 --- a/opendaylight/netconf/pom.xml +++ b/opendaylight/netconf/pom.xml @@ -19,8 +19,7 @@ netconf-api - - + netconf-cli netconf-config netconf-impl config-netconf-connector -- 2.36.6