Monthly Archives: August 2017

OSGi Declarative Services – Configuration Binding

As explained in OSGi Components – Simply Simple – Part II when using Declarative Services (DS) you get support for configurations stored in a Configuration Admin service for free. At runtime especially when checking the status of the system – or looking for misconfigurations, there is always the question how to find out if a component is using a certain configuration.

The ServiceComponentRuntime Service

Since R6 of the OSGi specification, the Declarative Service Specification defines the ServiceComponentRuntime service. This service can be used at runtime to get the status of the components and services managed by DS. The top level DTO available from that service is the ComponentDescriptionDTO. This is basically a representation of the XML provided by a bundle and read by DS. So the first step is to find the ComponentDescriptionDTO for the component you’re interested in.

Once you have found such a description you can again use the ServiceComponentRuntime service to get the ComponentConfigurationDTO(s) for the description. This DTO has some useful information like whether the component is satisfied and if not it provides more info about the reason. For example, a reference might be unsatisfied. You can now iterate over the references and find the one(s) which is not satisfied.

Now for the configurations, the first check is to see whether the PID of the configuration you’re interested in is listed in the configurationPid field of the ComponentDescriptionDTO. However this does not provide you the information whether such a configuration exists and is used by your component.

Therefore you have to check the properties from the ComponentConfigurationDTO and check whether the properties contain a property and whether the value for this property contains the configuration PID you’re interested in. Note that the type of this property can be a String, an array of Strings or a collection of Strings.

This requires a little bit of coding, iterating over the various DTOs and searching for the info you’re interested in.

The Declarative Services WebConsole Plugin

Another way of figuring this out without writing code is to use the famous Apache Felix Web Console. The web console allows you to manage and monitor a running OSGi application through a web interface. The Apache Felix project has a plugin for the web console. The Apache Maven coordinates for the current release are org.apache.felix/org.apache.felix.webconsole.plugins.ds/2.0.6.

Once this plugin is installed it gives you an UI for the previously mentioned ServiceComponentRuntime service and you can browse through the DTOs and find the ones you’re interested in.

Bound OSGi Configurations

An OSGi configuration supports the concept of configuration binding. By checking the bundle location field of a configuration object, it is possible to figure our whether a managed service is using this configuration.

However, don’t use this information to figure out whether a configuration is used by a DS component. Configuration binding is considered legacy and more important a DS implementation is not required to bind a configuration to the bundle of a bundle containing the component. While older implementations of the Apache Felix SCR did the configuration binding, newer versions don’t.

Therefore don’t even look there if you want to figure out whether your configuration is used by a DS component.