Communication between two remote Camel routes using Karaf Cellar

February 2, 2012 Posted by jbonofre

Apache Karaf Cellar 2.2.3

Around one week ago, we released Karaf Cellar 2.2.3.

In addition of the first Distributed OSGi support (DOSGi, I already wrote blog), an interesting feature of Cellar 2.2.3 is to give access the whole Hazelcast configuration.

The etc/hazelcast.xml is the core configuration of the Hazelcast instance, started by the Cellar feature. Cellar registers the Hazelcast instance as an OSGi service.

It means that we can use the Hazelcast instance just using a reference to the corresponding OSGi service. We are going to use the Hazelcast OSGi service in a Camel route defined using blueprint DSL (it works using Spring DSL as well).

Apache Camel 2.9.0 and the Hazelcast component

Camel 2.9.0 provides a new component: camel-hazelcast.

This component allows to send (as a producer/to) or receive (as a consumer/from) a Camel exchange through a Hazelcast distributed queue.

The first route timerToQueue fires a message every 5 seconds, and send to a Hazelcast distributed queue.

This distributed queue will be in the Hazelcast instance registered as an OSGi service by Cellar.


<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:camel="http://camel.apache.org/schema/blueprint"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <camelContext id="blueprintContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="timerToQueue">
      <from uri="timer:foo?period=5000"/>
      <setBody>
        <constant>Hello Remote</constant>
      </setBody>
      <to uri="hazelcast:seda:yet.another.queue"/>
    </route>
  </camelContext>

  <bean id="hazelcast" class="org.apache.camel.component.hazelcast.HazelcastComponent">
    <property name="hazelcastInstance" ref="hazelcastInstance"/>
  </bean>

  <reference id="hazelcastInstance" availability="optional" interface="com.hazelcast.core.HazelcastInstance"/>

</blueprint>

On the other hand, the queueToFile route get the exchange from the distributed queue and send to a file.


<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:camel="http://camel.apache.org/schema/blueprint"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

  <camelContext id="blueprintContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="queueToFile">
      <from uri="hazelcast:seda:yet.another.queue"/>
      <to uri="file:/my/folder"/>
   </route>
  </camelContext>

  <bean id="hazelcast" class="org.apache.camel.component.hazelcast.HazelcastComponent">
    <property name="hazelcastInstance" ref="hazelcastInstance"/>
  </bean>

  <reference id="hazelcastInstance" availability="optional" interface="com.hazelcast.core.HazelcastInstance"/>

</blueprint>

The two routes are on different Cellar nodes, the communication uses a queue distributed on all Hazelcast instances (handle by Karaf Cellar).

Conclusion

Lot of Camel users mostly use a JMS queue to “connect” two remote Camel routes. It requires a MQ broker, with a network connector if you want failover/cluster, etc. So it’s required special configuration, etc.

Now, we have an alternative using Cellar, which is just a feature to install, without point of failure (a Hazelcast instance is present on each Cellar node).

Ubuntu boot hang up with kernel 3.0.0-15 and lvm2

January 22, 2012 Posted by jbonofre

Today, I updated my Ubuntu box and a new kernel has been installed (3.0.0-15 x86_64).

At boot, my system hangs up just after the /scripts/init-bottom phase.

I tried with kernel 3.0.0-14, the behavior is the same. The latest working kernel was 3.0.0-13.

After digging, it’s when the init-bottom performs vgchange -a y.

The problem is that the script is waiting for the udev device, and starting from kernel 3.0.0-14, it doesn’t work and we raise the timeout.
So it means that the startup is not totally stuck, it just takes long long long time ;)

The workaround is to disable the udev support during LVM2 vgchange.

To do that, edit the /lib/udev/rules.d/85-lvm2.rules and add the --noudevsync option to vgchange:


SUBSYSTEM=="block", ACTION=="add|change", ENV{ID_FS_TYPE}=="lvm*|LVM*", \
RUN+="watershed sh -c '/sbin/lvm vgscan; /sbin/lvm vgchange --noudevsync -a y'"

We have to update the initramfs:


update-initramfs -u -k all

Apache Karaf 2011 Millesime

January 2, 2012 Posted by jbonofre

We are preparing the new Karaf “Cuvée” 2012, with the main new release Karaf 3.0.

Karaf 2011 is a good millésime with the following activity:

  • New sub-projects: 3 (Cellar, Cave, WebConsole)
  • Number of commits: 1,851
  • Number of releases: 11
  • Number of messages on the forums/mailing lists: 3119
  • Number of direct downloads: 44,829
  • Number of tickets open/resolved: 782/577
  • Karaf active team: 12

A good millésime for sure.

Now, it’s time to focus on the 2012 vendange ;)

Thanks for the Karaf users and the wonderful Karaf team ;)

Coming in Karaf 3.0: new KAR service, command, management

December 27, 2011 Posted by jbonofre

We are working hard on Karaf 3.0. This major new version of Karaf will bring a lot of new features and enhancements.

KAR in Karaf 2.2.4

As you may know, Karaf 2.2.x already provides “basic” KAR support.

A KAR (KARaf archive) is a zip file which gathers a features XML and all bundles and configuration files dependencies. It means that a KAR is an atomic artifact which can be deployed without an Internet connection (as all is shipped in the KAR file itself).

In Karaf 2.2.x, the KAR support was:

  • a KAR deployer: you can copy a KAR file into the deploy folder, and KARAF will uncompress the KAR file, and install all features containing in the shipped features XML.
  • a create-kar goal in the features-maven-plugin: this goal reads a features XML and creates a KAR file, ready to be deployed.

So, all KAR logics were in the KAR deployer.

It means that you are not able to deploy a KAR from a remote URL, etc.

What’s coming in Karaf 3.0

The KAR service

In Karaf 3.0, the KAR core bundle provides a org.apache.karaf.kar.KarService OSGi service.

This service allows you to list the installed KAR files, deploy a KAR file from an URL, uninstall a KAR file.

Now the KAR service use a data/kar directory to store the KAR file and uncompress the KAR directly in the system repository (the local-repo directory is no more needed and created).

The KAR shell commands

Now, you have a complete control on the KAR files (including remotely using a SSH connection).

You can list, install, and uninstall KAR files using the kar:* commands:

  • kar:list displays the installed KAR files
  • kar:install installs a KAR file from a given URL. The URL could be a “classic” file: or http:, but, as for all stuff in Karaf, mvn: (for instance mvn:net.nanthrax/test/1.0-SNAPSHOT/kar)
  • kar:uninstall uninstalls a KAR file (identified by the name as displayed by kar:list). This command doesn’t alter the system repository by default, but you have an option -c (–cleanup) to cleanup the system repository.

The KAR MBean

You can also manipulate KAR files using JMX via a new MBean: org.apache.karaf:type=kar,name=root.

This MBean provides quite the same actions that you can do using the commands:

  • getKars()
  • install(url)
  • uninstall(name)
  • uninstall(name, clean)

In progress

It’s still a work in progress. I will add a bunch of unit tests and new features around the KAR files.

Overview on Apache Karaf, Pax Web, and Camel archetypes

December 19, 2011 Posted by jbonofre

In my previous blog post, I introduced the Karaf Maven plugins.
The Karaf Maven plugins are really helpful, starting from an existing POM.

If you can write this POM by hand (it’s my favorite way ;) ), we also provide several archetypes which create and pre-configure a Maven project for you.

Karaf Archetypes

The next Karaf release (2.2.5) provides a set of new archetypes:

Assembly Archetype

The karaf-assembly-archetype create a Maven project which create a custom Karaf distribution.

It allows you to create your own Karaf distribution. The project downloads a Karaf standard distribution (in tar.gz and zip formats), unpack it, and create a new distribution.

The easiest way to use it is to use the interactive mode:


mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-assembly-archetype -DarchetypeVersion=2.2.5-SNAPSHOT

Bundle Archetype

If basically a bundle is a jar file with some special statement in the MANIFEST, the easiest way to create a bundle is to use the Felix maven-bundle-plugin.

Karaf provides an archetype which prepare a Maven project and provide a bundle Activator (a special callback class when the bundle start/stop).

To generate this project, simply type:


mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-bundle-archetype -DarchetypeVersion=2.2.5-SNAPSHOT

NB: I think that this archetype should be in Felix (as the same level as maven-bundle-plugin), I will propose a donation to the Felix community.

Blueprint Archetype

Blueprint is IoC approach applied to OSGi (it comes from Spring DM in fact). It allows you to avoid to write bundle Activator, ServiceTracker, etc.

Karaf provides a karaf-blueprint-archetype which prepare a Maven project including the maven-bundle-plugin, and a blueprint descriptor with a sample of OSGi service definition:


mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-blueprint-archetype -DarchetypeVersion=2.2.5-SNAPSHOT

NB: I think that this archetype should be in Aries (as it’s the blueprint implementation used in Karaf), I will propose a donation to the Aries community.

Feature Archetype

In Karaf, a feature is an application descriptor, defining all bundles, configurations/configuration files, others features. This features descriptor could be generated by hand (it’s my favorite way, and I guess the recommended one), we also provide a archetype which prepare a project to generate features file regarding the POM dependencies:


mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-feature-archetype -DarchetypeVersion=2.2.5-SNAPSHOT

Kar Archetype

We saw in my previous post a new goal of the features-maven-plugin to create a kar file starting from a features XML. A KAR file is a zip file containing the features XML and all its dependencies.

We also provide an archetype to prepare a Maven project containing a features XML and generate a KAR file:


mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-kar-archetype -DarchetypeVersion=2.2.5-SNAPSHOT

Pax-Web Archetypes

We also add several archetypes in Pax Web to deal with the web bundle. Charles talk about wab-gwt archetype in his last blog entry (http://cmoulliard.blogspot.com/2011/12/run-google-web-toolkit-2-project-on.html), but I added also two others.

Web Bundle Archetype

The Web Bundle Archetype create a “special” bundle containing web resources and statements. It creates a Maven project with webapp resources and WebApp Context in the POM:


mvn archetype:generate -DarchetypeGroupId=org.ops4j.pax.web.archetypes -DarchetypeArtifactId=wab-archetype -DarchetypeVersion=1.1.2-SNAPSHOT

War Archetype

We also provide an archetype to create a Maven project which generate a standard war (that you can deploy “outside” of OSGi) but including OSGi statements in the MANIFEST (which allows you to use OSGi values):


mvn archetype:generate -DarchetypeGroupId=org.ops4j.pax.web.archetypes -DarchetypeArtifactId=war-archetype -DarchetypeVersion=1.1.2-SNAPSHOT

Camel Archetypes

Camel also provides a set of very useful archetypes, especially:

  • camel-archetype-blueprint to generate a Maven project with a blueprint XML in which you can define your routes
  • camel-archetype-component providing a template to create your own Camel component
  • camel-archetype-dataformat providing a template to create your own Camel data format
  • camel-archetype-java providing a template with a class in which you can define your routes
  • camel-archetype-spring to generate a Maven project with a Spring XML in which you can define your routes

For instance, to create a Camel blueprint Maven project, simply type:


mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-blueprint -DarchetypeVersion=2.9-SNAPSHOT

Do you know the Apache Karaf Maven plugins ?

December 12, 2011 Posted by jbonofre

Apache Karaf is not only an OSGi container, it also provides a set of Maven plugins for tooling.

In the next Apache Karaf 2.2.5 release, you will find two Maven plugins:

  • cmdhelp-maven-plugin generates documentation (in DocBook or Scalate format) for Karaf commands
  • features-maven-plugin provides a set of goals to manipulate Karaf features

In this blog post, I will cover the features-maven-plugin as I think it’s the most interesting for your life with Karaf.

Generate a features XML

If I prefer to handle and create the features XML by hand, the features:generate-features-file goal could do it for you.

It takes the dependencies of your project (described in the POM), and create the features XML.

For instance, in the following example, a features XML file will be generated containing the commons-lang bundle:


<xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>net.nanthrax</groupId>
  <artifactId>test-features</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix.bundles</groupId>
      <artifactId>org.apache.servicemix.bundles.commons-lang</artifactId>
      <version>2.4_4</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>features-maven-plugin</artifactId>
        <version>2.2.5-SNAPSHOT</version>
        <executions>
          <execution>
            <id>generate-features-filelt;/id>
            <goals>
              <goal>generate-features-file</goal>
            </goals>
            <configuration>
              <karafVersion>2.2.4</karafVersion>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

You can find the features XML in the target directory.

Copy features resources in a local directory

The features:add-features-to-repo goal reads a set of features and copy features resources into a target folder. Especially, it allows you to prepare a custom distribution, allowing this distribution to avoid Internet connection to resolve features resources.

The following example will read a features XML and populate the target/system directory with the feature A, B, and C resources (bundles and configuration files):


<xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>net.nanthrax</groupId>
  <artifactId>test-features</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>features-maven-plugin</artifactId>
        <version>2.2.5-SNAPSHOT</version>
        <executions>
          <execution>
            <id>add-features-to-repo</id>
            <goals>
              <goal>features-add-to-repo</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>file:${project.basedir}/src/main/resources/features.xml</descriptor>
              </descriptors>
              <features>
                <feature>A</feature>
                <feature>B/2.0-SNAPSHOT</feature>
              </features>
              <repository>target/system</repository>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

NB: with Karaf 2.2.5, you can define a feature with just its name, or with name/version. It allows to target explicitly with which feature populate the target repository directory.

Create a KAR file

A KAR file (Karaf ARchive) is a zip file which package a features XML with all dependencies (bundles and configuration files).

It allows you to deploy (just by copying the kar file in the Karaf deploy folder) an atomic archive shipping all required resources (so no Internet connection is required).

The features:create-kar goal create a kar file starting from a given features XML.

The following example create a kar file (in the target folder) starting from a src/main/resources/features.xml:


<xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>net.nanthrax</groupId>
  <artifactId>test-features</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>features-maven-plugin</artifactId>
        <version>2.2.5-SNAPSHOT</version>
        <executions>
          <execution>
            <id>create-kar</id>
            <goals>
              <goal>create-kar</goal>
            </goals>
            <configuration>
              <featuresFile>${project.basedir}/src/main/resources/features.xml</featuresFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Karaf 3.0 changes

In Karaf 3.0.0, you will find only one Maven plugin: karaf-maven-plugin, gathering the two “old” one.

The KAR support is also extended and give more place to KAR archives (used to construct distributions now).

Apache Karaf Cellar and DOSGi

November 29, 2011 Posted by jbonofre

Next version of Apache Karaf Cellar will include a DOSGi (Distributed OSGi) implementation.

There are several existing DOSGi implementations: in Apache CXF (powered by the CXF stack), in Fuse Fabric, etc.

The purpose of the Cellar one is to leverage the Cellar existing (Hazelcast instance, distributed map, etc), and to be very easy to use.

Karaf Cellar DOSGi installation

Cellar DOSGi is part of the main cellar feature. To install it:


karaf@root> features:addurl mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0-SNAPSHOT/xml/features
karaf@root> features:install cellar

Distributed services

You can note a new command available in Cellar:


karaf@root> cluster:list-services

It displays the list of services “cluster aware”. It means a service that could be used remotely from another node.

Code sample

To illustrate the Cellar DOSGi usage, we will use two bundles:

  • the provider bundle is installed on node A and “expose” a distributed service
  • the client bundle is installed on node B and will use the provider service

Provider bundle

The provider bundle expose an OSGi service, flagged as a distributed service.

The service is very simple, it’s just an echo service.

Here’s the interface describing the service:


package org.apache.karaf.cellar.sample;

public interface EchoService {

  String process(String message);

}

and the corresponding implementation:


package org.apache.karaf.cellar.sample;

public class EchoServiceImpl implements EchoService {

&nbps; public String process(String message) {
    return "Processed by distributed service: " + message;
  }

}

Up to now, nothing special, nothing related to DOSGi or Cellar.

To expose the service in Karaf, we create a blueprint descriptor:


<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <bean id="echoService" class="org.apache.karaf.cellar.sample.EchoServiceImpl"/>

  <service ref="echoService" interface="org.apache.karaf.cellar.sample.EchoService">
    <service-properties>
      <entry key="service.exported.interfaces" value="*"/>
    </service-properties>
  </service>

</blueprint>

We can note that the only “special” part is that we added the service.exported.interfaces property to the echoService.

It’s just a flag to define the interface/service to define as distributed (it means accessible from remote node).

We didn’t change the code of the service itself, just added this property. It means that it’s really easy to turn an existing service as a distributed service.

Client bundle

The client bundle will get a reference to the echoService. In fact, the reference will be a kind of proxy to the service implementation located remotely, on another node.

The client is really simple, it indefinitely iterates to use the clusterService:


package org.apache.karaf.cellar.sample.client;

public class ServiceClient {

  private EchoService echoService;

  public void setEchoService(EchoService echoService) {
    this.echoService = echoService;
  }

  public EchoService getEchoService() {
    return this.echoService;
  }

  public void process() throws Exception {
    int count = 0;
    while (true) {
      System.out.println(echoService.process("Call " + count));
      Thread.sleep(5000);
      count++;
    }
  }

}

We inject the echoService using Blueprint:


&lt?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <reference id="echoService" interface="org.apache.karaf.cellar.sample.EchoService"/>

  <bean id="serviceClient" class="org.apache.karaf.cellar.sample.client.ServiceClient" init-method="process">
&nbps;   <property name="echoService" ref="echoService"/>
  </bean>

</blueprint>

It’s done. The serviceClient will use the echoService. If a “local” echoService exists, the OSGi framework will bind the reference to this service, else Cellar will look for a distributed service (on all node) exporting the EchoService interface and bind a proxy to the distributed service.

ApacheCon NA11 2011: so great

November 12, 2011 Posted by jbonofre

Sad, too early ;) . You know this feeling when something great is ended.

I was at the ApacheCon NA11, Vancouver this week, and it was simply awesome.

I gave two talks:

On the other hand, I attended to the following session:

  • Business and Open Source, open discussion with especially Bertrand (Delacretaz), Debbie (Moynihan), Ross (Turk)
  • Apache, Branding and Trademark, with Shane (Curcuru)
  • Archiva by Brett (Porter)
  • Whirr by Tom (White)
  • DOSGi and cloud by Guillaume (Nodet)

I discussed with a lot of people:

  • Of course Dan (Kulp), Hadrian (Zbarcea), Ross (Turk)
  • Guillaume (Nodet), it was really great to work together, discussed about our roadmap for Karaf and ServiceMix, etc. Thanks a bunch Guillaume ;)
  • Christian (Muller) and Jon (Anstey), we talked about Camel. These guys are so cool ;)
  • Mohammad (Nour El-Din) about projects in the incubator, proposals, etc
  • Brett (Porter) and Carlos (Sanchez) about Archiva
  • Marcel (Offermans), Alex, Bram, about ACE and OSGi
  • lot of others (Bertrand, Shane, etc, etc) that I would like to thank too

Once again, thank you all.

See you in November 2012 for the ApacheCon Europe, Germany ;)

Apache Karaf moved to OSGi r4.3

November 3, 2011 Posted by jbonofre

Apache Karaf trunk (future 3.0 release) now fully supports OSGi 4.3 release by running Apache Felix framework 4.0.1 and Eclipse Equinox 3.7.1.

If this update is just a support update, it gives us the opportunity to see what we can leverage from the OSGi r4 early draft.

What’s in preparation in OSGi r4 ?

I will not cover the whole OSGi 4 specification. I will just spot some features that will be “key” features in Karaf.

New OBR specification (RFC-0112)

Currently, there are a number of available solutions to downloading and installing bundles:

  • current OBR stores the bundles and allows users to discover bundles
  • P2 provisioning platform used in Eclipse
  • Maven repositories as used in Karaf
  • Nimble Repositories which are an extension of OBR to deal with active state dependencies

The idea is to gather all these concepts into a new OBR specification.

The new OBR will be able to:

  • handle bundle fragments dependencies, provide management tooling
  • can use a resolver strategy allowing to work with Felix OBR, Sigil or Nimble
  • a normalized and new OBR XML schema, supporting bundle execution environment, etc.

Karaf Cave will be the perfect place to leverage new OBR specification implementation. It will allow Karaf to deploy bundles provided by P2, OBR, Nimble, etc.

Karaf Cave will also extend the OBR specification in order to directly handle Karaf features.

ACE will also use this new OBR specification for the ACE repository implementation.

Subsystems (RFC-0152)

Most of container defines a concept to gather bundles together and provide complete applications.

Depending of the container, we have different wording:

  • in Karaf, we name it features
  • in Spring DM, the name is applications
  • in Aries, it’s applications too
  • in Eclipse, it’s features or installable units

If the core concept is the same, the implementations are very different.

The Subsystems specification aim to use an unique way to define the concept of applications.

Subsystems leverages others OSGi technologies:

  • OBR, we already discussed about that in the first section. It’s the repository used to store all bundles required to be deploy to form an application.
  • framework hooks (RFC-0138) to isolate or group subsystems within a single OSGi framework.
  • deployment admin defines a file format to ship and deploy applications.
  • application admin provides the concept of an application in OSGi.

Subsystems could become a key feature in Karaf 3.0, as it could handle Karaf features and KAR.

We implemented in features concepts defined in this specification. For instance, in a Karaf features, we can use an OBR resolver.

More over, subsystems provides new features missing in the current Karaf features, especially a complete lifecycle, better subsystems dependencies.

Regarding the new OBR and subsystems specifications, we can have a consistent way to deploy applications and bundles.

OSGi for Enterprise (RFC-0164 and RFC-0146)

RFC-0146 covers Java EE JCA for OSGi. It will provides support for resource adapters, packaged as a RAR. The resources can be integrate with OSGi services.

On the other hand, RFC-0164 deals with Blueprint Declarative Transaction. It means that we can define the transaction on a bean methods by declaration in the blueprint descriptor:


<bean ...>
<tx:transaction method="count*" value="Required"/>
<tx:transaction method="count*Row" value="RequiresNew"/>
</bean>

These two specifications are a step forward to a Karaf EE distribution, by including such features and providing others.

OSGi JMX (RFC-0169)

Lot of comments and bugs have been raised regarding the OSGi-JMX specification.

This specification aim to implement most of suggestions and fix bugs.

What’s new in Karaf 2.2.4 ?

October 17, 2011 Posted by jbonofre

Apache Karaf 2.2.4 has been released this week end.

You can take a look on the release notes.

More than a bug fixes release, this version includes several new features and enhancements.

Command aliases

Previously, the osgi:* commands gathered different kind of usage: osgi:start, osgi:stop, etc are related to bundles, osgi:shutdown is related to container itself, and osgi:ls is OSGi service related.

To be clearer for the users, new aliases have been introduced.

NB: on Karaf trunk (future 3.0.0 release), the commands have been fully renamed (not aliased).

system:*

The system:* commands are related to the Karaf container itself:

  •  system:shutdown is equivalent to osgi:shutdown and shutdown the Karaf container
  •  system:start-level is equivalent to osgi:start-level and defines the default start-level to consider bundles as system bundles

services:*

The services:* commands are related to OSGi services:

  • services:list is equivalent to ls and lists the OSGi services available

bundles:*

The bundles:* commands are related to OSGi bundles:

  • bundles:list is equivalent to osgi:list and lists the OSGi bundles
  • bundles:install is equivalent to osgi:install and installs OSGi bundles
  • bundles:uninstall is equivalent to osgi:uninstall and uninstalls OSGi bundles
  • bundles:start is equivalent to osgi:start and starts OSGi bundles
  • bundles:stop is equivalent to osgi:stop and stops OSGi bundles
  • bundles:header is equivalent to osgi:headers and displays OSGi bundles headers
  • bundles:info is equivalent to osgi:info and displays bundle.info file
  • bundles:refresh is equivalent to osgi:refresh and refresh OSGi bundles
  • bundles:resolve is equivalent to osgi:resolve and resolves OSGi bundles
  • bundles:restart is equivalent to osgi:restart and restarts OSGi bundles
  • bundles:start-level is equivalent to osgi:start-level and defines the OSGi bundles start level
  • bundles:update is equivalent to osgi:update and updates OSGi bundles

New MBeans

To be able to monitor and administrate with your own tool (Nagios, Apache Kalumet, your own JMX client), Karaf now provides a set of new MBeans.

Bundles MBean

The bundles MBean (org.apache.karaf:type=bundles) allows you to view and change the bundles. As with bundles:* shell commands, you can select bundles using bundle ID (for instance 20), bundle ID range (for instance 21-25 means bundle ID 21, 22, 23, 24, 25), bundle name and version including support of regex (for instance mybunde, mybundle/version, myb*).

  • list() operation gives your a tabular view about all bundles deployed, including the ID, the location, and the current status of the bundle
  • getStartLevel() and setStartLevel() allows you to get/set the start level of bundles
  • refresh() allows to refresh bundles
  • update() allows to update bundles
  • resolve() allows to resolve bundles
  • restart() allows to restart bundles
  • install() installs bundles from an URL. The URL could be a “classic” one (file: or http:), a Maven URL (mvn:), an OBR URL (obr:)
  • start() starts bundles
  • stop() stops bundles
  • uninstall() uninstalls bundles

Config MBean

The config MBean (org.apache.karaf:type=config) allows you to view and change the OSGi configuration (ConfigAdmin layer). As with config:* shell commands, the changes are flushed into the /etc configuration file.

  • list() gives you all configuration PID present in the Karaf container
  • create() creates a new configuration PID
  • delete() deletes a configuration PID
  • proplist() list properties for a given configuration PID
  • propdel() deletes a property from a given configuration PID
  • propappend() appends content to a property in the given configuration PID
  • propset() set/add a property in the given configuration PID

Dev MBean

The dev MBean (org.apache.karaf:type=dev) allows you view the OSGi framework in use and set the framework options:

  • framework() gives the current OSGi framework in use (Felix or Equinox)
  • frameworkOptions() allows you to define OSGi framework options (debug mode, framework to use)
  • restart() allows you to restart the Karaf container

Log MBean

The log MBean (org.apache.karaf:type=log) allows you to view/change the log level currently used (globally or for a given logger):

  • set() sets the log level to use (for the root logger, or for a given logger)
  • get() gives the log level in use (for the root logger, or for a given logger)

OBR MBean

The OBR MBean (org.apache.karaf:type=obr) allows you to manipulate the OBR client:

  • listUrls() list the OBR server URL (containing the repository.xml file) register in the Karaf OBR
  • addUrl() adds a new OBR server in the OBR client
  • removeUrl() removes an OBR server from the OBR client
  • refreshUrl() updates the OBR information in the OBR client
  • list() lists the bundles available via the OBR client
  • deploy() deploys a bundle (and its dependency bundles) from the OBR

Packages MBean

The packages MBean (org.apache.karaf:type=packages) allows you to get information about exported and imported packages (and the related bundles):

  • exportedPackages lists the exported package (globally or for a given bundle)
  • importedPackages lists the imported package (globally or for a given bundle)

Services MBean

The services MBean (org.apache.karaf:type=services) allows you to view the OSGi services available:

  • list() lists the OSGi services available (globally, or only one in use, or provided by a given bundle)

System MBean

The system MBean (org.apache.karaf:type=system) allows you to manipulate the Karaf container itself:

  • shutdown() shutdown the Karaf container

Web MBean

The web MBean (org.apache.karaf:type=web) allows you to see the web bundles (web application) available:

  • list() gives you a tabular view of all web application deployed in Karaf (including the bundle and the context path)

Better KAR support

A KAR (Karaf ARchive) artifact is a zip file containing a feature XML descriptor and related bundles jar.

In previous Karaf version, we had issue with the Kar support. In Karaf 2.2.4:

  • the features Maven plugin provides a goal to create a KAR. Simply use a the create-kar goal with a feature.xml and you will have a ready to deploy KAR in the target directory
  • the KAR deployer was not able to correctly uncompress the KAR zip entries, it’s now fixed
  • the KAR deployer now automatically starts all features containing in a KAR file. It means that simply by dropping the KAR file in the deploy folder, Karaf will uncompress the KAR file, correctly creating a Karaf local repository for the KAR, and start all features containing in the KAR shipped feature XML

Spring features

To avoid Spring versions mismatch in others projects (such as Apache Camel, CXF, or ServiceMix), Karaf now provides a large set of Spring features:

  • spring
  • spring-web
  • spring-aspects
  • spring-dm
  • spring-dm-web
  • spring-instrument
  • spring-jdbc
  • spring-jms
  • spring-struts
  • spring-test
  • spring-orm
  • spring-oxm
  • spring-tx
  • spring-web
  • spring-web-portlet

It allows others projects to directly use these features (with a version range), and so, be less coupled to a Spring version.

Others

Some others minors things have been added:

  • the dev:watch command now supports multiple bundle as argument
  • the wrapper service provides a lib for Linux 64 bits platform
  • the J2SE-1.6 and J2SE-1.7 execution environment have been added
  • obr:deploy shell command now supports a -s option to automatically start bundles
  • Karaf JMX service could be configured to use SSL now
  • system:shutdown shell command displays the instance name (for confirmation)