Additional considerations on the new Features service

I want to give a bit more detailed explanations on some new stuff provided by the Karaf 4.x FeaturesService.

Transitive closure

The karaf-maven-plugin provides a new goal named verify. It's an enhanced version of the previous validate goal. This goal helps ensuring that all features are transitively closed with respect to their requirements. This means that all the requirements for a given feature can be fulfilled without relying on already installed bundles or features. This new goal actually uses the OSGi resolver to ensure that, so that it ensures your features can be deployed everywhere, without additional requirements.

Viable deployments

One of the new features I mentioned in my previous post is that the new Features service ensures that the features requirements are fully available. When installing new features, this is usually not much of a problem, as we usually only add new bundles. However, when uninstalling a feature, things can be a bit more complicated when those features are not transitively closed. Some features do not express all their dependencies so that the user is required to install a few features in order to make them work. Problems can appear when a feature which is required, but not explicitly, is uninstalled by the user. The previous behaviour when uninstalling a feature was to uninstall all the bundles that were previously installed by that feature and were not directly required by another feature. What this means is that if a feature did not have a dependency on that bundle, the removal of that bundle would cause the feature not to work anymore.
The new Features service does not have this bad behaviour anymore. If the user uninstalls a feature, a new resolution will take place, making sure that all requirements are solved for the remaining features.
A simple example involves camel, but the same is true for cxf or activemq features. The camel-core feature depends on the shell for the commands. The shell has changed in Karaf 4, but a compatibility layer is provided to allow the installation of previous commands. However, the camel-core feature does not have an expressed dependency on the shell-compat feature, which means that in order to install camel-core, you also need to install the shell-compat feature. Once that's done, you won't be able to uninstall the shell-compat feature unless you also uninstall camel-core.
Your deployments are always valid and safe !

Full uninstallation of a feature

In order to minimise the disruption when uninstalling features, the FeaturesService in Karaf 2.x and 3.x did not uninstall feature dependencies when uninstalling a given feature (see the above point). Now that the service uses a set of requirements as the input for the resolution, uninstalling a feature will automatically uninstall all the bundles that are not needed anymore.
I'll talk about the input requirements in more details in a next post.

Optional feature dependencies

In Karaf 2.x or 3.x, a feature can have feature dependencies. The behaviour is that the Features Service will install those dependencies when the feature is installed. The goal is usually to solve some requirements, for example the webconsole feature depends on the http feature.
Karaf 4.0 adds new possibilities: those dependencies can be flagged as being optional. This means that the Features Service will install them if they are actually needed to solve some requirements, but if this feature is not really needed, it won't be installed.
This is particularly useful when we define features that provide a given specification along with an implementation. For example, the http feature provides the OSGi HttpService, but pax-web provides multiple containers that can be used such as jetty or tomcat. In Karaf 2.x and 3.x, having a dependency on the http feature always lead to the jetty container being installed. With Karaf 4.x, the real behaviour is that the HttpService will be installed, using jetty by default, but not necessarily.
This is modelled using the following:

<feature name="pax-http">
 <feature dependency="true">pax-http-jetty</feature>
 <requirement>
 pax.http.provider
 </requirement>
</feature>

<feature name="pax-http-jetty">
 ... jetty bundles ...
 <capability>
 pax.http.provider;provider:=jetty
 </capability>
</feature>

<feature name="pax-http-tomcat">
 ... tomcat bundles ...
 <capability>
 pax.http.provider;provider:=tomcat
 </capability>
</feature>
The benefit is that features can safely depend on pax-http. This will always provide the HttpService. If no specific http provider is installed, it will install the pax-http-jetty feature, but if the user installs pax-http-tomcat explicitly, the jetty provider will not be installed.

Comments

Popular posts from this blog

SSH Server in Java

ServiceMix Kernel is a small container based on OSGi. The latest release allows external clients to connect to it and issue commands using a simple protocol implemented on top of TCP or SSL. However, this remoting protocol has some drawbacks as the internals makes it unable to do another remote login from a remote session. In addition to that, completion and history do not really work great. So I've been thinking about using the SSH protocol, which is widely used, secured, with tons of different clients available. Unfortunately, no SSH server is available in Java. Over the past weeks, I've been working on implementing this SSH server, based on the IEFT specifications, the JSch SSH client library, and the OpenSSH server source code. The server itself is based on Apache Mina which is a great framework for using NIO. The project is available at http://code.google.com/p/sshd/ and although there are lots of limitations right now, the basics of the SSH protocol work. I plan t...

Apache Karaf

ApacheCon was really interesting this year! Recently, a lot of people have expressed a real interest in ServiceMix Kernel , our generic OSGi distribution for server side applications. We've been discussing moving this subproject into Apache Felix for several reasons: raise the visibility and awareness on ServiceMix Kernel attract a broader community Several Apache projects are planning to use ServiceMix Kernel as their container: this includes Apache James , Apache Directory and Apache ActiveMQ . The Apache Sling community is also willing to contribute to this effort along with some other groups like the OPS4J project. During this discussion, a name as been proposed by Jamie Goodyear: Apache Karaf . A carafe is a small container used for serving wine and other drinks (http://en.wikipedia.org/wiki/Carafe). In similarity to the name the Kernel allows applications to be more easily handled, and improves their characteristics (much like a bottle of wine left to breath in a dec...

Camel Endpoint DSL

Camel Endpoint DSL One of the new features of Camel 3.0  is an Endpoint DSL.  This new API aims to provide a type safe replacement for the URLs that are used in Camel to designate the consumer or producer endpoints.  These URLs provide 3 things: the scheme of the URL identifies the component to use, a unique name or id for the endpoint, and a set of parameters to customize the endpoint behavior. Here is an example of an FTP consumer endpoint definition: from( "ftp://foo@myserver?password=secret& recursive=true& ftpClient.dataTimeout=30000& ftpClientConfig.serverLanguageCode=fr" ) .to( "bean:doSomething" ); There are several drawbacks with such constructs : no type safety, bad readability and no simple completion. So we now use the meta model, which is currently extracted from the source using an annotation processor and written in various JSON files, to generate a fluent DSL for each endpoint.  The same...