Search code examples
osgiapache-karafkaraf

Apache Karaf feature prerequisite


Karaf 4.0.3

I have the following pseudo-feature:

<features name="my-feature" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">
<feature name="C" version="${project.version}" start-level="25" install="auto">
    <bundle start-level="25">...BundleC1...</bundle>
</feature>

<feature name="A" version="${project.version}" start-level="30" install="auto">
    <feature prerequisite="true">C</feature>
    <bundle start-level="30">...BundleA1...</bundle>
</feature>

<feature name="B" version="${project.version}" start-level="35" install="auto">
    <feature prerequisite="true">C</feature>
    <bundle start-level="35">...BundleB1...</bundle>
</feature>

C is independant
A depends on C
B depends on C

In this example the bundle 'BundleB1' imports wrong major version of 'BundleC1' and we get the "missing requirement" error (as expected). However if I log into the karaf console and run 'feature:list' I will see that C is Started, A is Uninstalled and B is Uninstalled.

I expect A to be Started since it only has dependencies to C. A will start fine if I comment out the entire C feature or if I afterwards run feature:install A

If I put each of these three features in seperate feature.xml files I get the expected outcome of C+A as Started and B as Uninstalled.

What am I doing wrong?

Am I misunderstanding how the prerequisite attribute works? As a sidenote, if I skip the prerequisite attribute all together then no feature will get installed whatsover...


Solution

  • This is the expected behavior in Karaf 4 : Karaf creates one subsystem with all the features to install. This subsystem is resolved in one pass : either it success or it fails, as a whole.

    The prerequisite attribute tells Karaf to install this feature in an independent subsystem : All the bundles are installed and started before trying to resolve the others features.

    In your case :

    • C is installed/started ;
    • A+B is resolved, but it fails