From: Giovanni Meo Date: Mon, 25 Aug 2014 14:49:37 +0000 (+0000) Subject: Merge "Bug 1234: Force to use legacy OF plugin if it is installed." X-Git-Tag: release/helium~214 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=2f5c43e6b38ee9709263f64fb18f80f3ffed0177;hp=738248cda591e5253e107080ffea1fd4a3e02645;p=controller.git Merge "Bug 1234: Force to use legacy OF plugin if it is installed." --- diff --git a/features/netconf/pom.xml b/features/netconf/pom.xml index 106e54a338..51d6f6291b 100644 --- a/features/netconf/pom.xml +++ b/features/netconf/pom.xml @@ -74,6 +74,10 @@ org.opendaylight.controller.thirdparty ganymed + + org.apache.sshd + sshd-core + org.openexi nagasena diff --git a/features/netconf/src/main/resources/features.xml b/features/netconf/src/main/resources/features.xml index f1631a5340..1453a5fb96 100644 --- a/features/netconf/src/main/resources/features.xml +++ b/features/netconf/src/main/resources/features.xml @@ -52,6 +52,7 @@ odl-netconf-util mvn:org.opendaylight.controller/netconf-netty-util/${project.version} mvn:org.opendaylight.controller.thirdparty/ganymed/${ganymed.version} + mvn:org.apache.sshd/sshd-core/${sshd-core.version} mvn:org.openexi/nagasena/${exi.nagasena.version} mvn:io.netty/netty-codec/${netty.version} mvn:io.netty/netty-handler/${netty.version} @@ -69,4 +70,4 @@ mvn:org.opendaylight.controller/netconf-monitoring/${project.version} - \ No newline at end of file + diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/pom.xml b/opendaylight/archetypes/opendaylight-configfile-archetype/pom.xml new file mode 100644 index 0000000000..38c86164e9 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-configfile-archetype/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.opendaylight.controller + opendaylight-configfile-archetype + 1.1-SNAPSHOT + maven-archetype + + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + Configuration files for md-sal + + + scm:git:ssh://git.opendaylight.org:29418/controller.git/md-sal-config + scm:git:ssh://git.opendaylight.org:29418/controller.git/md-sal-config + https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL/md-sal-config + + + + + opendaylight-release + http://nexus.opendaylight.org/content/repositories/opendaylight.release/ + + + opendaylight-snapshot + http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ + + + website + dav:http://nexus.opendaylight.org/content/sites/site/sal-parent + + + diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000..d404f99c7a --- /dev/null +++ b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,16 @@ + + + + + + + + src/main/resources + + **/*.xml + + + + diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/pom.xml b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..e217b9abfa --- /dev/null +++ b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + ${artifactId} + ${groupId} + Configuration files for md-sal + + jar + + + 80-configfile.xml + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${configfile} + xml + config + + + + + + + + + + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + HEAD + https://git.opendaylight.org/gerrit/gitweb?p=${repoName}.git;a=summary + + diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/src/main/resources/80-configfile.xml b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/src/main/resources/80-configfile.xml new file mode 100644 index 0000000000..432b947351 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/src/main/resources/80-configfile.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/src/test/resources/projects/basic/archetype.properties b/opendaylight/archetypes/opendaylight-configfile-archetype/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000000..7a940e7a6e --- /dev/null +++ b/opendaylight/archetypes/opendaylight-configfile-archetype/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Mon Aug 25 05:45:18 CDT 2014 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic +repoName=foo diff --git a/opendaylight/archetypes/opendaylight-configfile-archetype/src/test/resources/projects/basic/goal.txt b/opendaylight/archetypes/opendaylight-configfile-archetype/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/opendaylight/archetypes/opendaylight-karaf-distro-archetype/pom.xml b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/pom.xml new file mode 100644 index 0000000000..8883c64295 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.opendaylight.controller + opendaylight-karaf-distro-archetype + 1.0.0-SNAPSHOT + maven-archetype + + distribution-karaf-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + https://wiki.opendaylight.org/view/CrossProject:Integration_Group/distribution-karaf + + + scm:git:ssh://git.opendaylight.org:29418/controller.git + scm:git:ssh://git.opendaylight.org:29418/controller.git + https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main + + diff --git a/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000..4c4f5103ee --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/archetype-resources/pom.xml b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..965c619695 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,285 @@ + + + 4.0.0 + + ${artifactId} + ${groupId} + + pom + + 3.0 + + + + 1.0.0-SNAPSHOT + 1.4.2-SNAPSHOT + 3.0.1 + + + + + + org.apache.karaf.features + framework + ${karaf.version} + kar + + + org.apache.karaf.features + standard + ${karaf.version} + features + xml + runtime + + + + + org.opendaylight.controller + karaf.branding + ${branding.version} + compile + + + + + org.opendaylight.controller + opendaylight-karaf-resources + ${karaf.resources.version} + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.felix + maven-bundle-plugin + [0,) + + cleanVersions + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + [0,) + + copy + unpack + + + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + [0,) + + commands-generate-help + + + + + + + + + org.fusesource.scalate + maven-scalate-plugin + [0,) + + sitegen + + + + + + + + + org.apache.servicemix.tooling + depends-maven-plugin + [0,) + + generate-depends-file + + + + + + + + + + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + ${karaf.version} + true + + + standard + + + + + + + process-resources + + install-kars + + process-resources + + + package + + instance-create-archive + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.6 + + + copy + + copy + + generate-resources + + + + org.opendaylight.controller + karaf.branding + ${karaf.branding.version} + target/assembly/lib + karaf.branding-${branding.version}.jar + + + + + + unpack-karaf-resources + + unpack-dependencies + + prepare-package + + ${project.build.directory}/assembly + org.opendaylight.controller + opendaylight-karaf-resources + META-INF\/** + true + false + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + prepare-package + + run + + + + + + + + + + + + + + + + + + + + + + + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + HEAD + https://git.opendaylight.org/gerrit/gitweb?p=${repoName}.git;a=summary + + diff --git a/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/test/resources/projects/basic/archetype.properties b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000000..dd29db648f --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Thu Aug 21 14:44:29 CDT 2014 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic +repoName=foo diff --git a/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/test/resources/projects/basic/goal.txt b/opendaylight/archetypes/opendaylight-karaf-distro-archetype/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/opendaylight/archetypes/opendaylight-karaf-features/pom.xml b/opendaylight/archetypes/opendaylight-karaf-features/pom.xml new file mode 100644 index 0000000000..4973a69537 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-features/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + org.opendaylight.controller + opendaylight-karaf-features-archetype + 1.0.0-SNAPSHOT + maven-archetype + + opendaylight-karaf-features-archetype + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + + + scm:git:ssh://git.opendaylight.org:29418/controller.git/ + scm:git:ssh://git.opendaylight.org:29418/controller.git/ + https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=summary + + diff --git a/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/META-INF/maven/archetype-metadata.xml b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000..158e448265 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,14 @@ + + + + + + + + src/main/resources + **/*.xml + + + diff --git a/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/pom.xml b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..e135e6b656 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,194 @@ + + + + 4.0.0 + + features-${repoName} + ${groupId} + + jar + + features.xml + + 1.0.0-SNAPSHOT + 1.4.2-SNAPSHOT + 3.0.1 + 0.6.2-SNAPSHOT + 1.4.2-SNAPSHOT + 2.16 + + + + + + + + + + + + org.opendaylight.yangtools + features-test + ${feature.test.version} + test + + + + org.opendaylight.controller + opendaylight-karaf-empty + ${karaf.empty.version} + zip + + + + + + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + generate-resources + + resources + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + package + + attach-artifact + + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + org.opendaylight.controller + opendaylight-karaf-empty + ${karaf.empty.version} + + + org.opendaylight.yangtools:features-test + + + + + + + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + scm:git:ssh://git.opendaylight.org:29418/${repoName}.git + HEAD + https://git.opendaylight.org/gerrit/gitweb?p=${repoName}.git;a=summary + + diff --git a/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/src/main/resources/features.xml b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/src/main/resources/features.xml new file mode 100644 index 0000000000..4a59657431 --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-features/src/main/resources/archetype-resources/src/main/resources/features.xml @@ -0,0 +1,86 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) + + + + + + + + + + + + + diff --git a/opendaylight/archetypes/opendaylight-karaf-features/src/test/resources/projects/basic/archetype.properties b/opendaylight/archetypes/opendaylight-karaf-features/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000000..bab8cd295d --- /dev/null +++ b/opendaylight/archetypes/opendaylight-karaf-features/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,6 @@ +#Thu Aug 21 23:46:25 CDT 2014 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic +repoName=foo diff --git a/opendaylight/archetypes/opendaylight-karaf-features/src/test/resources/projects/basic/goal.txt b/opendaylight/archetypes/opendaylight-karaf-features/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/opendaylight/archetypes/pom.xml b/opendaylight/archetypes/pom.xml index 36af861e84..cb597c10bd 100644 --- a/opendaylight/archetypes/pom.xml +++ b/opendaylight/archetypes/pom.xml @@ -6,9 +6,9 @@ org.opendaylight.controller - commons.parent - 1.0.1-SNAPSHOT - ../commons/parent + commons.opendaylight + 1.4.2-SNAPSHOT + ../commons/opendaylight scm:git:ssh://git.opendaylight.org:29418/controller.git @@ -39,5 +39,8 @@ odl-model-project + opendaylight-configfile-archetype + opendaylight-karaf-distro-archetype + opendaylight-karaf-features diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 2f1cd8b925..873ad7a9b7 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -216,6 +216,7 @@ 2013.09.07.4-SNAPSHOT 1.0.0-SNAPSHOT 0.6.2-SNAPSHOT + 0.12.0 @@ -236,6 +237,11 @@ netconf-netty-util ${netconf.version} + + org.apache.sshd + sshd-core + ${sshd-core.version} + ch.qos.logback logback-classic diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index d70bf46411..9a7677099d 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -1156,6 +1156,10 @@ org.opendaylight.controller.thirdparty ganymed + + org.apache.sshd + sshd-core + org.opendaylight.yangtools binding-generator-api diff --git a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java index 344694381a..dba2908e9c 100644 --- a/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java +++ b/opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java @@ -73,6 +73,7 @@ public class TestHelper { mavenBundle(CONTROLLER, "netconf-client").versionAsInProject(), // mavenBundle(CONTROLLER, "netconf-util").versionAsInProject(), // mavenBundle(CONTROLLER, "netconf-netty-util").versionAsInProject(), // + mavenBundle("org.apache.sshd", "sshd-core").versionAsInProject(), // mavenBundle("org.openexi", "nagasena").versionAsInProject(), // mavenBundle("org.openexi", "nagasena-rta").versionAsInProject(), // mavenBundle(CONTROLLER + ".thirdparty", "ganymed").versionAsInProject(), // diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializer.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializer.java index 87b3f837e8..2aa5d15224 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializer.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializer.java @@ -12,7 +12,7 @@ import io.netty.util.concurrent.Promise; import java.io.IOException; import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshHandler; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler; import org.opendaylight.protocol.framework.SessionListenerFactory; final class SshClientChannelInitializer extends AbstractChannelInitializer { @@ -32,7 +32,7 @@ final class SshClientChannelInitializer extends AbstractChannelInitializer promise) { try { - ch.pipeline().addFirst(SshHandler.createForNetconfSubsystem(authenticationHandler)); + ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler)); super.initialize(ch,promise); } catch (final IOException e) { throw new RuntimeException(e); diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java index 6826b4a09c..56f674bc34 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java @@ -9,13 +9,10 @@ package org.opendaylight.controller.netconf.it; import static java.util.Arrays.asList; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import ch.ethz.ssh2.Connection; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; @@ -30,8 +27,6 @@ import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; @@ -47,6 +42,7 @@ import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProduce import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; import org.opendaylight.controller.netconf.ssh.NetconfSSHServer; import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider; import org.opendaylight.controller.netconf.ssh.authentication.AuthProviderImpl; @@ -144,16 +140,6 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { } public AuthenticationHandler getAuthHandler() throws IOException { - final AuthenticationHandler authHandler = mock(AuthenticationHandler.class); - doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - Connection conn = (Connection) invocation.getArguments()[0]; - conn.authenticateWithPassword("user", "pwd"); - return null; - } - }).when(authHandler).authenticate(any(Connection.class)); - doReturn("auth handler").when(authHandler).toString(); - return authHandler; + return new LoginPassword("user", "pwd"); } } diff --git a/opendaylight/netconf/netconf-netty-util/pom.xml b/opendaylight/netconf/netconf-netty-util/pom.xml index 13041598d1..80dc1ae0fd 100644 --- a/opendaylight/netconf/netconf-netty-util/pom.xml +++ b/opendaylight/netconf/netconf-netty-util/pom.xml @@ -52,6 +52,10 @@ org.opendaylight.controller.thirdparty ganymed + + org.apache.sshd + sshd-core + org.openexi nagasena @@ -73,6 +77,7 @@ xmlunit xmlunit + @@ -82,7 +87,7 @@ maven-bundle-plugin - ch.ethz.ssh2, com.google.common.base, com.google.common.collect, io.netty.buffer, + org.apache.sshd.*, ch.ethz.ssh2, com.google.common.base, com.google.common.collect, io.netty.buffer, io.netty.channel, io.netty.channel.socket, io.netty.handler.codec, io.netty.handler.ssl, io.netty.util, io.netty.util.concurrent, javax.xml.transform, javax.xml.transform.dom, javax.xml.transform.sax, javax.xml.transform.stream, org.opendaylight.controller.netconf.api, diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/AuthenticationHandler.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/AuthenticationHandler.java index b22b792d52..eea2b8693a 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/AuthenticationHandler.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/AuthenticationHandler.java @@ -9,12 +9,17 @@ package org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication; import ch.ethz.ssh2.Connection; - import java.io.IOException; +import org.apache.sshd.ClientSession; /** * Class providing authentication facility to SSH handler. */ public abstract class AuthenticationHandler { public abstract void authenticate(Connection connection) throws IOException; + + + public abstract String getUsername(); + + public abstract org.apache.sshd.client.future.AuthFuture authenticate(final ClientSession session) throws IOException; } diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/LoginPassword.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/LoginPassword.java index b67aa0f96d..553e5359ff 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/LoginPassword.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/authentication/LoginPassword.java @@ -8,10 +8,13 @@ package org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication; -import ch.ethz.ssh2.Connection; - import java.io.IOException; +import org.apache.sshd.ClientSession; +import org.apache.sshd.client.future.AuthFuture; + +import ch.ethz.ssh2.Connection; + /** * Class Providing username/password authentication option to * {@link org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshHandler} @@ -27,10 +30,21 @@ public class LoginPassword extends AuthenticationHandler { @Override public void authenticate(Connection connection) throws IOException { - boolean isAuthenticated = connection.authenticateWithPassword(username, password); + final boolean isAuthenticated = connection.authenticateWithPassword(username, password); if (!isAuthenticated) { throw new IOException("Authentication failed."); } } + + @Override + public String getUsername() { + return username; + } + + @Override + public AuthFuture authenticate(final ClientSession session) throws IOException { + session.addPasswordIdentity(password); + return session.auth(); + } } diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java new file mode 100644 index 0000000000..2761a45d03 --- /dev/null +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOutboundHandlerAdapter; +import io.netty.channel.ChannelPromise; +import java.io.IOException; +import java.net.SocketAddress; +import org.apache.sshd.ClientChannel; +import org.apache.sshd.ClientSession; +import org.apache.sshd.SshClient; +import org.apache.sshd.client.future.AuthFuture; +import org.apache.sshd.client.future.ConnectFuture; +import org.apache.sshd.client.future.OpenFuture; +import org.apache.sshd.common.future.CloseFuture; +import org.apache.sshd.common.future.SshFutureListener; +import org.apache.sshd.common.io.IoInputStream; +import org.apache.sshd.common.io.IoReadFuture; +import org.apache.sshd.common.util.Buffer; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Netty SSH handler class. Acts as interface between Netty and SSH library. + */ +public class AsyncSshHandler extends ChannelOutboundHandlerAdapter { + + private static final Logger logger = LoggerFactory.getLogger(AsyncSshHandler.class); + public static final String SUBSYSTEM = "netconf"; + + public static final SshClient DEFAULT_CLIENT = SshClient.setUpDefaultClient(); + + public static final int SSH_DEFAULT_NIO_WORKERS = 8; + + static { + // TODO make configurable, or somehow reuse netty threadpool + DEFAULT_CLIENT.setNioWorkers(SSH_DEFAULT_NIO_WORKERS); + DEFAULT_CLIENT.start(); + } + + private final AuthenticationHandler authenticationHandler; + private final SshClient sshClient; + + private SshReadAsyncListener sshReadAsyncListener; + private ClientChannel channel; + private ClientSession session; + private ChannelPromise connectPromise; + + public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) throws IOException { + return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT); + } + + /** + * + * @param authenticationHandler + * @param sshClient started SshClient + * @throws IOException + */ + public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient) throws IOException { + this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler); + this.sshClient = Preconditions.checkNotNull(sshClient); + // Start just in case + sshClient.start(); + } + + private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) { + logger.debug("Starting SSH to {} on channel: {}", address, ctx.channel()); + + final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address); + sshConnectionFuture.addListener(new SshFutureListener() { + @Override + public void operationComplete(final ConnectFuture future) { + if (future.isConnected()) { + handleSshSessionCreated(future, ctx); + } else { + handleSshSetupFailure(ctx, future.getException()); + } + } + }); + } + + private synchronized void handleSshSessionCreated(final ConnectFuture future, final ChannelHandlerContext ctx) { + try { + logger.trace("SSH session created on channel: {}", ctx.channel()); + + session = future.getSession(); + final AuthFuture authenticateFuture = authenticationHandler.authenticate(session); + authenticateFuture.addListener(new SshFutureListener() { + @Override + public void operationComplete(final AuthFuture future) { + if (future.isSuccess()) { + handleSshAuthenticated(session, ctx); + } else { + handleSshSetupFailure(ctx, future.getException()); + } + } + }); + } catch (final IOException e) { + handleSshSetupFailure(ctx, e); + } + } + + private synchronized void handleSshAuthenticated(final ClientSession session, final ChannelHandlerContext ctx) { + try { + logger.debug("SSH session authenticated on channel: {}, server version: {}", ctx.channel(), session.getServerVersion()); + + channel = session.createSubsystemChannel(SUBSYSTEM); + channel.setStreaming(ClientChannel.Streaming.Async); + channel.open().addListener(new SshFutureListener() { + @Override + public void operationComplete(final OpenFuture future) { + if(future.isOpened()) { + handleSshChanelOpened(ctx); + } else { + handleSshSetupFailure(ctx, future.getException()); + } + } + }); + + + } catch (final IOException e) { + handleSshSetupFailure(ctx, e); + } + } + + private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) { + logger.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel()); + + connectPromise.setSuccess(); + connectPromise = null; + ctx.fireChannelActive(); + + final IoInputStream asyncOut = channel.getAsyncOut(); + sshReadAsyncListener = new SshReadAsyncListener(ctx, asyncOut); + } + + private synchronized void handleSshSetupFailure(final ChannelHandlerContext ctx, final Throwable e) { + logger.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), e); + connectPromise.setFailure(e); + connectPromise = null; + throw new IllegalStateException("Unable to setup SSH connection on channel: " + ctx.channel(), e); + } + + @Override + public synchronized void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) { + try { + if(channel.getAsyncIn().isClosed() || channel.getAsyncIn().isClosing()) { + handleSshSessionClosed(ctx); + } else { + channel.getAsyncIn().write(toBuffer(msg)); + ((ByteBuf) msg).release(); + } + } catch (final Exception e) { + logger.warn("Exception while writing to SSH remote on channel {}", ctx.channel(), e); + throw new IllegalStateException("Exception while writing to SSH remote on channel " + ctx.channel(),e); + } + } + + private static void handleSshSessionClosed(final ChannelHandlerContext ctx) { + logger.debug("SSH session closed on channel: {}", ctx.channel()); + ctx.fireChannelInactive(); + } + + private Buffer toBuffer(final Object msg) { + // TODO Buffer vs ByteBuf translate, Can we handle that better ? + Preconditions.checkState(msg instanceof ByteBuf); + final ByteBuf byteBuf = (ByteBuf) msg; + final byte[] temp = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(temp, 0, byteBuf.readableBytes()); + return new Buffer(temp); + } + + @Override + public synchronized void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) throws Exception { + this.connectPromise = promise; + startSsh(ctx, remoteAddress); + } + + @Override + public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { + disconnect(ctx, promise); + } + + @Override + public synchronized void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { + if(sshReadAsyncListener != null) { + sshReadAsyncListener.close(); + } + + session.close(false).addListener(new SshFutureListener() { + @Override + public void operationComplete(final CloseFuture future) { + if(future.isClosed() == false) { + session.close(true); + } + session = null; + } + }); + + channel = null; + } + + /** + * Listener over async input stream from SSH session. + * This listeners schedules reads in a loop until the session is closed or read fails. + */ + private static class SshReadAsyncListener implements SshFutureListener, AutoCloseable { + private static final int BUFFER_SIZE = 8192; + + private final ChannelHandlerContext ctx; + + private IoInputStream asyncOut; + private Buffer buf; + private IoReadFuture currentReadFuture; + + public SshReadAsyncListener(final ChannelHandlerContext ctx, final IoInputStream asyncOut) { + this.ctx = ctx; + this.asyncOut = asyncOut; + buf = new Buffer(BUFFER_SIZE); + asyncOut.read(buf).addListener(this); + } + + @Override + public synchronized void operationComplete(final IoReadFuture future) { + if(future.getException() != null) { + + if(asyncOut.isClosed() || asyncOut.isClosing()) { + // We are closing + handleSshSessionClosed(ctx); + } else { + logger.warn("Exception while reading from SSH remote on channel {}", ctx.channel(), future.getException()); + throw new IllegalStateException("Exception while reading from SSH remote on channel " + ctx.channel(), future.getException()); + } + } + + if (future.getRead() > 0) { + ctx.fireChannelRead(Unpooled.wrappedBuffer(buf.array(), 0, future.getRead())); + + // Schedule next read + buf = new Buffer(BUFFER_SIZE); + currentReadFuture = asyncOut.read(buf); + currentReadFuture.addListener(this); + } + } + + @Override + public synchronized void close() throws Exception { + // Remove self as listener on close to prevent reading from closed input + if(currentReadFuture != null) { + currentReadFuture.removeListener(this); + } + + asyncOut = null; + } + } +} diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/Invoker.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/Invoker.java deleted file mode 100644 index eab2546d6e..0000000000 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/Invoker.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; - -import java.io.IOException; - -/** - * Abstract class providing mechanism of invoking various SSH level services. - * Class is not allowed to be extended, as it provides its own implementations via instance initiators. - */ -abstract class Invoker { - private boolean invoked = false; - - private Invoker() { - } - - protected boolean isInvoked() { - return invoked; - } - - public void setInvoked() { - this.invoked = true; - } - - abstract void invoke(SshSession session) throws IOException; - - public static Invoker netconfSubsystem(){ - return subsystem("netconf"); - } - - public static Invoker subsystem(final String subsystem) { - return new Invoker() { - @Override - synchronized void invoke(SshSession session) throws IOException { - if (isInvoked()) { - throw new IllegalStateException("Already invoked."); - } - try { - session.startSubSystem(subsystem); - } finally { - setInvoked(); - } - } - }; - } -} diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClient.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClient.java deleted file mode 100644 index 271b781b99..0000000000 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClient.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; - -import ch.ethz.ssh2.Connection; -import ch.ethz.ssh2.Session; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.VirtualSocket; - -/** - * Wrapper class around GANYMED SSH java library. - */ -class SshClient { - private final VirtualSocket socket; - private final Map openSessions = new HashMap<>(); - private final AuthenticationHandler authenticationHandler; - private Connection connection; - - public SshClient(VirtualSocket socket, AuthenticationHandler authenticationHandler) throws IOException { - this.socket = socket; - this.authenticationHandler = authenticationHandler; - } - - public SshSession openSession() throws IOException { - if (connection == null) { - connect(); - } - - Session session = connection.openSession(); - SshSession sshSession = new SshSession(session); - openSessions.put(openSessions.size(), sshSession); - - return sshSession; - } - - private void connect() throws IOException { - connection = new Connection(socket); - - connection.connect(); - authenticationHandler.authenticate(connection); - } - - - public void close() { - for (SshSession session : openSessions.values()){ - session.close(); - } - - openSessions.clear(); - - if (connection != null) { - connection.close(); - } - } - - @Override - public String toString() { - return "SshClient{" + - "socket=" + socket + - '}'; - } -} diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClientAdapter.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClientAdapter.java deleted file mode 100644 index 4ca7bdf958..0000000000 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshClientAdapter.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPromise; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.LinkedList; -import java.util.Queue; -import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * Worker thread class. Handles all downstream and upstream events in SSH Netty - * pipeline. - */ -class SshClientAdapter implements Runnable { - private static final Logger logger = LoggerFactory.getLogger(SshClientAdapter.class); - - private static final int BUFFER_SIZE = 1024; - - private final SshClient sshClient; - private final Invoker invoker; - - private OutputStream stdIn; - - private final Queue postponed = new LinkedList<>(); - - private ChannelHandlerContext ctx; - private ChannelPromise disconnectPromise; - - private final AtomicBoolean stopRequested = new AtomicBoolean(false); - - private final Object lock = new Object(); - - public SshClientAdapter(final SshClient sshClient, final Invoker invoker) { - this.sshClient = sshClient; - this.invoker = invoker; - } - - // TODO ganymed spawns a Thread that receives the data from remote inside TransportManager - // Get rid of this thread and reuse Ganymed internal thread (not sure if its possible without modifications in ganymed) - public void run() { - try { - final SshSession session = sshClient.openSession(); - invoker.invoke(session); - final InputStream stdOut = session.getStdout(); - - synchronized (lock) { - stdIn = session.getStdin(); - while (postponed.peek() != null) { - writeImpl(postponed.poll()); - } - } - - while (!stopRequested.get()) { - final byte[] readBuff = new byte[BUFFER_SIZE]; - final int c = stdOut.read(readBuff); - if (c == -1) { - continue; - } - - ctx.fireChannelRead(Unpooled.copiedBuffer(readBuff, 0, c)); - } - } catch (final Exception e) { - logger.error("Unexpected exception", e); - } finally { - sshClient.close(); - - synchronized (lock) { - if (disconnectPromise != null) { - ctx.disconnect(disconnectPromise); - } - } - } - } - - // TODO: needs rework to match netconf framer API. - public void write(final ByteBuf message) throws IOException { - synchronized (lock) { - if (stdIn == null) { - postponed.add(message); - return; - } - writeImpl(message); - } - } - - private void writeImpl(final ByteBuf message) throws IOException { - message.getBytes(0, stdIn, message.readableBytes()); - message.release(); - stdIn.flush(); - } - - public void stop(final ChannelPromise promise) { - synchronized (lock) { - stopRequested.set(true); - disconnectPromise = promise; - } - } - - public Thread start(final ChannelHandlerContext ctx, final ChannelFuture channelFuture) { - checkArgument(channelFuture.isSuccess()); - checkNotNull(ctx.channel().remoteAddress()); - synchronized (this) { - checkState(this.ctx == null); - this.ctx = ctx; - } - final String threadName = toString(); - final Thread thread = new Thread(this, threadName); - thread.start(); - return thread; - } - - @Override - public String toString() { - return "SshClientAdapter{" + - "sshClient=" + sshClient + - '}'; - } -} diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java deleted file mode 100644 index c710a010e2..0000000000 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelOutboundHandlerAdapter; -import io.netty.channel.ChannelPromise; -import java.io.IOException; -import java.net.SocketAddress; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.virtualsocket.VirtualSocket; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Netty SSH handler class. Acts as interface between Netty and SSH library. All standard Netty message handling - * stops at instance of this class. All downstream events are handed of to wrapped {@link org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshClientAdapter}; - */ -public class SshHandler extends ChannelOutboundHandlerAdapter { - private static final Logger logger = LoggerFactory.getLogger(SshHandler.class); - private static final String SOCKET = "socket"; - - private final VirtualSocket virtualSocket = new VirtualSocket(); - private final SshClientAdapter sshClientAdapter; - - - public static SshHandler createForNetconfSubsystem(AuthenticationHandler authenticationHandler) throws IOException { - return new SshHandler(authenticationHandler, Invoker.netconfSubsystem()); - } - - - public SshHandler(AuthenticationHandler authenticationHandler, Invoker invoker) throws IOException { - SshClient sshClient = new SshClient(virtualSocket, authenticationHandler); - this.sshClientAdapter = new SshClientAdapter(sshClient, invoker); - } - - @Override - public void handlerAdded(ChannelHandlerContext ctx){ - if (ctx.channel().pipeline().get(SOCKET) == null) { - ctx.channel().pipeline().addFirst(SOCKET, virtualSocket); - } - } - - @Override - public void handlerRemoved(ChannelHandlerContext ctx) { - if (ctx.channel().pipeline().get(SOCKET) != null) { - ctx.channel().pipeline().remove(SOCKET); - } - } - - @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws IOException { - this.sshClientAdapter.write((ByteBuf) msg); - } - - @Override - public void connect(final ChannelHandlerContext ctx, - SocketAddress remoteAddress, - SocketAddress localAddress, - ChannelPromise promise) { - ctx.connect(remoteAddress, localAddress, promise); - - promise.addListener(new ChannelFutureListener() { - public void operationComplete(ChannelFuture channelFuture) { - if (channelFuture.isSuccess()) { - sshClientAdapter.start(ctx, channelFuture); - } else { - logger.debug("Failed to connect to remote host"); - } - }} - ); - } - - @Override - public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) { - sshClientAdapter.stop(promise); - } -} diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshSession.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshSession.java deleted file mode 100644 index 9cdc5926f0..0000000000 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/ssh/client/SshSession.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.netconf.nettyutil.handler.ssh.client; - -import ch.ethz.ssh2.Session; -import ch.ethz.ssh2.channel.Channel; -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Wrapper class for proprietary SSH sessions implementations - */ -class SshSession implements Closeable { - private final Session session; - - public SshSession(final Session session) { - this.session = session; - } - - public void startSubSystem(final String name) throws IOException { - session.startSubSystem(name); - } - - public InputStream getStdout() { - return session.getStdout(); - } - - // FIXME according to http://www.ganymed.ethz.ch/ssh2/FAQ.html#blocking you should read data from both stdout and stderr to prevent window filling up (since stdout and stderr share a window) - // FIXME stdErr is not used anywhere - public InputStream getStderr() { - return session.getStderr(); - } - - public OutputStream getStdin() { - return session.getStdin(); - } - - @Override - public void close() { - if (session.getState() == Channel.STATE_OPEN || session.getState() == Channel.STATE_OPENING) { - session.close(); - } - } -} diff --git a/opendaylight/netconf/netconf-ssh/pom.xml b/opendaylight/netconf/netconf-ssh/pom.xml index febf3abf8e..8d48077f93 100644 --- a/opendaylight/netconf/netconf-ssh/pom.xml +++ b/opendaylight/netconf/netconf-ssh/pom.xml @@ -40,6 +40,10 @@ org.opendaylight.controller.thirdparty ganymed + + org.apache.sshd + sshd-core + org.slf4j slf4j-api diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java index 61297835a0..1b2201170a 100644 --- a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java +++ b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java @@ -29,7 +29,7 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.netconf.netty.EchoClientHandler.State; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; -import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.SshHandler; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.client.AsyncSshHandler; import org.opendaylight.controller.netconf.ssh.NetconfSSHServer; import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider; import org.opendaylight.controller.netconf.ssh.authentication.AuthProviderImpl; @@ -94,7 +94,7 @@ public class SSHTest { ChannelInitializer channelInitializer = new ChannelInitializer() { @Override public void initChannel(NioSocketChannel ch) throws Exception { - ch.pipeline().addFirst(SshHandler.createForNetconfSubsystem(new LoginPassword("a", "a"))); + ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(new LoginPassword("a", "a"))); ch.pipeline().addLast(echoClientHandler); } }; diff --git a/pom.xml b/pom.xml index 22c03ac7ac..10c05e254f 100644 --- a/pom.xml +++ b/pom.xml @@ -136,6 +136,9 @@ opendaylight/distribution/opendaylight-karaf opendaylight/distribution/opendaylight-karaf-resources features + + + opendaylight/archetypes scm:git:ssh://git.opendaylight.org:29418/controller.git