Author: gnodet Date: Thu Sep 23 09:23:42 2010 New Revision: 1000377 URL: http://svn.apache.org/viewvc?rev=1000377&view=rev Log: KARAF-195, KARAF-197: Use cade to handle dynamic configuration changes and use it for the SSH layer
Added: karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshConfig.java - copied, changed from r1000376, karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java Modified: karaf/trunk/assembly/pom.xml karaf/trunk/assembly/src/main/descriptors/unix-bin.xml karaf/trunk/assembly/src/main/descriptors/windows-bin.xml karaf/trunk/assembly/src/main/filtered-resources/etc/startup.properties karaf/trunk/pom.xml karaf/trunk/shell/ssh/pom.xml karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java karaf/trunk/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml Modified: karaf/trunk/assembly/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/assembly/pom.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/assembly/pom.xml (original) +++ karaf/trunk/assembly/pom.xml Thu Sep 23 09:23:42 2010 @@ -277,6 +277,10 @@ <artifactId>org.apache.aries.jmx.blueprint</artifactId> </dependency> <dependency> + <groupId>org.fusesource.cade</groupId> + <artifactId>cade-bundle</artifactId> + </dependency> + <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_2.5_spec</artifactId> <optional>true</optional> Modified: karaf/trunk/assembly/src/main/descriptors/unix-bin.xml URL: http://svn.apache.org/viewvc/karaf/trunk/assembly/src/main/descriptors/unix-bin.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/assembly/src/main/descriptors/unix-bin.xml (original) +++ karaf/trunk/assembly/src/main/descriptors/unix-bin.xml Thu Sep 23 09:23:42 2010 @@ -287,6 +287,15 @@ <include>org.apache.aries.jmx:org.apache.aries.jmx.blueprint</include> </includes> </dependencySet> + <dependencySet> + <outputDirectory>/system</outputDirectory> + <unpack>false</unpack> + <useProjectArtifact>false</useProjectArtifact> + <outputFileNameMapping>org/fusesource/cade/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping> + <includes> + <include>org.fusesource.cade:cade-bundle</include> + </includes> + </dependencySet> </dependencySets> Modified: karaf/trunk/assembly/src/main/descriptors/windows-bin.xml URL: http://svn.apache.org/viewvc/karaf/trunk/assembly/src/main/descriptors/windows-bin.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/assembly/src/main/descriptors/windows-bin.xml (original) +++ karaf/trunk/assembly/src/main/descriptors/windows-bin.xml Thu Sep 23 09:23:42 2010 @@ -274,6 +274,15 @@ <include>org.apache.aries.jmx:org.apache.aries.jmx.blueprint</include> </includes> </dependencySet> + <dependencySet> + <outputDirectory>/system</outputDirectory> + <unpack>false</unpack> + <useProjectArtifact>false</useProjectArtifact> + <outputFileNameMapping>org/fusesource/cade/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping> + <includes> + <include>org.fusesource.cade:cade-bundle</include> + </includes> + </dependencySet> </dependencySets> Modified: karaf/trunk/assembly/src/main/filtered-resources/etc/startup.properties URL: http://svn.apache.org/viewvc/karaf/trunk/assembly/src/main/filtered-resources/etc/startup.properties?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/assembly/src/main/filtered-resources/etc/startup.properties (original) +++ karaf/trunk/assembly/src/main/filtered-resources/etc/startup.properties Thu Sep 23 09:23:42 2010 @@ -34,6 +34,7 @@ org/apache/felix/org.apache.felix.filein # The rest of the services.. # org/apache/aries/blueprint/org.apache.aries.blueprint/${aries.blueprint.version}/org.apache.aries.blueprint-${aries.blueprint.version}.jar=20 +org/fusesource/cade/cade-bundle/${cade.version}/cade-bundle-${cade.version}.jar=21 org/apache/karaf/shell/org.apache.karaf.shell.console/${project.version}/org.apache.karaf.shell.console-${project.version}.jar=30 org/apache/karaf/shell/org.apache.karaf.shell.osgi/${project.version}/org.apache.karaf.shell.osgi-${project.version}.jar=30 Modified: karaf/trunk/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/pom.xml (original) +++ karaf/trunk/pom.xml Thu Sep 23 09:23:42 2010 @@ -109,6 +109,7 @@ <jetty.bundle.version>6.1.22_2</jetty.bundle.version> <junit.bundle.version>4.7_1</junit.bundle.version> + <cade.version>0.1-SNAPSHOT</cade.version> <commons.logging.version>1.1.1</commons.logging.version> <geronimo.servlet.version>1.1.2</geronimo.servlet.version> <depends.maven.plugin.version>1.0</depends.maven.plugin.version> @@ -611,6 +612,11 @@ <version>${jansi.version}</version> </dependency> <dependency> + <groupId>org.fusesource.cade</groupId> + <artifactId>cade-bundle</artifactId> + <version>${cade.version}</version> + </dependency> + <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>${commons.logging.version}</version> Modified: karaf/trunk/shell/ssh/pom.xml URL: http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/pom.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/shell/ssh/pom.xml (original) +++ karaf/trunk/shell/ssh/pom.xml Thu Sep 23 09:23:42 2010 @@ -68,6 +68,11 @@ <groupId>org.apache.sshd</groupId> <artifactId>sshd-core</artifactId> </dependency> + + <dependency> + <groupId>org.fusesource.cade</groupId> + <artifactId>cade-bundle</artifactId> + </dependency> </dependencies> <build> Copied: karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshConfig.java (from r1000376, karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java) URL: http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshConfig.java?p2=karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshConfig.java&p1=karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java&r1=1000376&r2=1000377&rev=1000377&view=diff ============================================================================== --- karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java (original) +++ karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshConfig.java Thu Sep 23 09:23:42 2010 @@ -18,41 +18,19 @@ */ package org.apache.karaf.shell.ssh; -import org.apache.sshd.SshServer; +import org.fusesource.cade.Meta; -public class SshServerFactory { +/** + */ +...@meta.pid("org.apache.karaf.shell") +public interface SshConfig { + + int sshPort(); - private SshServer server; + String sshHost(); - private boolean start; + String sshRealm(); - public SshServerFactory(SshServer server) { - this.server = server; - } - - public boolean isStart() { - return start; - } - - public void setStart(boolean start) { - this.start = start; - } - - public void start() throws Exception { - if (start) { - try { - server.start(); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - } - - public void stop() throws Exception { - if (start) { - server.stop(); - } - } + String hostKey(); } Modified: karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java URL: http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java (original) +++ karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshServerFactory.java Thu Sep 23 09:23:42 2010 @@ -18,16 +18,44 @@ */ package org.apache.karaf.shell.ssh; +import java.util.Map; + import org.apache.sshd.SshServer; +import org.apache.sshd.server.jaas.JaasPasswordAuthenticator; +import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; +import org.fusesource.cade.Configurable; +import org.osgi.service.blueprint.container.BlueprintContainer; +import org.osgi.service.cm.ConfigurationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -public class SshServerFactory { +public class SshServerFactory implements Configurable<SshConfig> { - private SshServer server; + private static final Logger LOGGER = LoggerFactory.getLogger(SshServerFactory.class); + private String serverId; + private BlueprintContainer blueprintContainer; private boolean start; - public SshServerFactory(SshServer server) { - this.server = server; + private SshServer server; + + public SshServerFactory() { + } + + public String getServerId() { + return serverId; + } + + public void setServerId(String serverId) { + this.serverId = serverId; + } + + public BlueprintContainer getBlueprintContainer() { + return blueprintContainer; + } + + public void setBlueprintContainer(BlueprintContainer blueprintContainer) { + this.blueprintContainer = blueprintContainer; } public boolean isStart() { @@ -38,21 +66,46 @@ public class SshServerFactory { this.start = start; } - public void start() throws Exception { + public void start(final SshConfig config) { if (start) { try { + server = (SshServer) blueprintContainer.getComponentInstance(serverId); + server.setPort(config.sshPort()); + server.setHost(config.sshHost()); + server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(config.hostKey())); + server.setPasswordAuthenticator(newJaasPasswordAuthenticator((config.sshRealm()))); server.start(); } catch (Exception e) { - e.printStackTrace(); - throw e; + LOGGER.info("Error updating SSH server", e); } } } - public void stop() throws Exception { - if (start) { - server.stop(); + private JaasPasswordAuthenticator newJaasPasswordAuthenticator(String domain) { + JaasPasswordAuthenticator auth = new JaasPasswordAuthenticator(); + auth.setDomain(domain); + return auth; + } + + public void stop() { + if (start && server != null) { + try { + server.stop(); + } catch (Exception e) { + LOGGER.info("Error stopping SSH server", e); + } finally { + server = null; + } } } + public void setup(SshConfig sshConfig) { + stop(); + start(sshConfig); + } + + public void deleted() { + stop(); + } + } Modified: karaf/trunk/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml URL: http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml?rev=1000377&r1=1000376&r2=1000377&view=diff ============================================================================== --- karaf/trunk/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml (original) +++ karaf/trunk/shell/ssh/src/main/resources/OSGI-INF/blueprint/shell-ssh.xml Thu Sep 23 09:23:42 2010 @@ -33,14 +33,16 @@ </ext:default-properties> </ext:property-placeholder> + <!-- <cm:property-placeholder persistent-id="org.apache.karaf.shell"> <cm:default-properties> <cm:property name="sshPort" value="8101"/> <cm:property name="sshHost" value="0.0.0.0"/> <cm:property name="sshRealm" value="karaf"/> - <cm:property name="hostKey" value="${karaf.base}/etc/host.key"/> + <cm:property name="hostKey" value="$[karaf.base]/etc/host.key"/> </cm:default-properties> </cm:property-placeholder> + --> <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0"> <command name="ssh/ssh"> @@ -63,8 +65,6 @@ </bean> <bean id="sshServer" class="org.apache.sshd.SshServer" factory-method="setUpDefaultServer" scope="prototype"> - <property name="port" value="${sshPort}"/> - <property name="host" value="${sshHost}"/> <property name="shellFactory"> <bean class="org.apache.karaf.shell.ssh.ShellFactoryImpl"> <property name="commandProcessor" ref="commandProcessor"/> @@ -75,23 +75,32 @@ <property name="commandProcessor" ref="commandProcessor"/> </bean> </property> + <!-- <property name="keyPairProvider" ref="keyPairProvider"/> <property name="passwordAuthenticator" ref="passwordAuthenticator"/> + --> </bean> - <bean id="keyPairProvider" class="org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider"> + <!-- + <bean id="keyPairProvider" class="org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider" scope="prototype"> <property name="path" value="${hostKey}"/> </bean> - <bean id="passwordAuthenticator" class="org.apache.sshd.server.jaas.JaasPasswordAuthenticator"> + <bean id="passwordAuthenticator" class="org.apache.sshd.server.jaas.JaasPasswordAuthenticator" scope="prototype"> <property name="domain" value="${sshRealm}"/> </bean> + --> - <bean id="sshServerFactory" class="org.apache.karaf.shell.ssh.SshServerFactory" init-method="start" - destroy-method="stop" activation="eager"> - <argument ref="sshServer"/> + <bean id="sshServerFactory" class="org.apache.karaf.shell.ssh.SshServerFactory" activation="eager"> + <property name="blueprintContainer" ref="blueprintContainer"/> + <property name="serverId"> + <idref component-id="sshServer"/> + </property> <property name="start" value="$[karaf.startRemoteShell]"/> + <cm:managed-properties persistent-id="org.apache.karaf.shell" update-strategy="component-managed" update-method="updated" /> </bean> + <service ref="sshServerFactory" interface="org.fusesource.cade.Configurable"/> + <reference id="commandProcessor" interface="org.apache.felix.service.command.CommandProcessor"> </reference>