How and where configure bundles through "apache felix configAdmin" - osgi

I try to use the "Apache Felix" implementation of OSGi for my project, I launch the framework from the distributable jar (/bin /felix.jar). I have created simple example bundles to register or consume services in the registry.
I want to use a configuration management service so I installed the bundle "org.apache.felix.configadmin" felix in the framework, and then I do not know how and where to put the configuration file of another bundle, for example I want to install the bundle "org.apache.felix.http.jetty" and then I want to configure this bundle through the configAdmin, so how I rename my config file, and where to put it?
Another question, what is the difference between setting, for example, the property "org.osgi.service.http.port" of the jetty bundle using the framework properties(conf/config.properties) or configure it through the bundle of configuration admin service.
Best regards,

You probably also need the file-installer from felix for it to pick up the config files.
If you want to see a working example of this take a look at Apache Karaf. It's a OSGi Container with lots of nice preconfigured features. The config admin service works out of the box.

Normally you use the felix config admin service together with the felix fileinstall. So fileinstall takes care of the directory to be monitored for config files and hands over to config admin to make it available as configs in OSGi.
For a fully working example take a look at Apache Karaf. There you can see the configs you need for it to work together. You might also consider to simply install your own bundles into karaf as it makes managing the felix framework a lot easier.

Related

How Configuration Values Persist in Felix

I've been using Maven to deploy my bundles over a felix server.
One of the things that fascinates me about Felix/OSGi is if i have configured a component with some values and i deploy my bundle again, even though the #Activate method will be called again for that configuration but my values which i've put there before deployment still persist.
How is Felix able to achieve this and is the configuration shown at /system/console/configMgr not an instance of my Java class used to create the OSGi Component ?
It's the job of the Configuration Admin service (for which Apache Felix provides an implementation) to deal with those details. Ideally, the "how" is irrelevant because those are implementation details, but if you are running an OSGi framework in a specialized environment (an embedded device for example), you would have to select a Configuration Admin provider that works within the limits of the host platform.
Under the hood, the Felix Configuration Admin service uses one or more PersistenceManagers to persist and retrieve the configuration data for your managed services. If you're curious about these implementation details you can read about them on the Felix website or you can take a look at the source code.
The configuration is OSGi is handled by the Configuration Admin Service
If you use OSGi container such as Karaf, you will remark that your configuration is independent from your bundle ($KARAF_HOME/etc) and are injected by the configuration admin service.
As was already said, Configuration Admin is your friend here. In OSGi enRoute we've a page about Configuration Admin and a sample project with lots of Configuration Admin example code.

How can I run OSGi blueprint in Felix in Scala?

I am able to get OSGi blueprint to work in Karaf, but I don't understand how to do it in Apache Felix, or my question can be also defined as how can I use OSGi blueprint in plain OSGi?
I made an example here https://github.com/PhilAndrew/sbt-osgi-felix-akka-blueprint-camel using https://github.com/doolse/sbt-osgi-felix in which Akka is working but Blueprint and Camel not yet working.
This question may help Is Apache Aries running in Felix?
It's not starting Blueprint because your bundle's code doesn't actually rely on any of the classes in blueprint, so you either need to add "Require-Bundle" header to your manifest:
requireBundle := Seq("org.apache.aries.blueprint")
or add the bundles that needed to be started to the osgiDependencies of run:
osgiDependencies in run := bundleReqs("org.apache.aries.blueprint.core",
"org.apache.aries.proxy")
Apache Karaf also runs on felix. So for the most part you just need to install the correct bundles and maybe do the necessary system package exports if you hit package use constraint violations.
Check what karaf installs and try to do the same.

Does Apache Felix FileInstall works for dynamic configuration of an application?

I am trying to develop an application that can be configured by its users. I need the configuration to be done by installing/updating/stopping/uninstalling bundles. All this should be of course done dynamically during the run-time of the application.
I found a nice framework which is Apache Felix FileInstall that provides a directory in which it seems to add a bundle when you add the bundle file in the directory (update, and remove bundles similarly).
But I can see that this method does not work in my case. I need to have the bundles in the directory but to stop or even uninstall them by my application. And I want to install them when it is appropriate. This is how I am expecting the configuration of my application to be done.
Is what I am trying to achieve supported by Apache FileInstall? Am I making any wrong assumptions about this framework? What are other possible ways that would help me if Apache FileInstall is not enough? Thanks.
You don't need FileInstall for this, just use the OSGi APIs. You specifically mentioned installing, updating, stopping and uninstalling; these are supported with the following API calls respectively:
BundleContext.installBundle
Bundle.update
Bundle.stop
Bundle.uninstall
Incidentally these are exactly the same methods that are called by FileInstall to implements its directory-based bundle management.

Branding Apache Felix web console

I am trying to brand a Apache Felix web console, but I am not able to find resource for the same. As per Apache Felix website,
Branding for the Web Console can be provided in two ways: By registering a BrandingPlugin service or by providing a branding properties files. The Web Console uses the branding from the BrandingPlugin service registered with the highest ranking.
But I am not understanding how to register a BrandingPlugin service? What and Jar files should I put? Is there any guidance or tutorial available for the same? If yes, can you guide me in this?
Since I am totaly getting confused with Apache Felix's website, since those documents are not clear on this.
You may find it helpful to do some background reading on OSGi services. OSGi provides a service registry, and most interactions in an OSGi environment are handled by registering and consuming services. It doesn't matter what jar file you put the service in; the only thing that matters is the interface name its registered under.
You can register services in lots of ways; programmatically from a BundleActivator, using Declarative Services (also known as SCR), and using Blueprint are some of the most popular patterns. Which one is easiest for you depends on how you're building your jars and what other OSGi facilities you're using. If you've already got an Activator the programmatic route may be the quickest way to get started; if you're using the Maven bundle plugin you may find SCR annotations easiest.
What you'll need to do is include an implementation of the 'BrandingPlugin' interface in a jar which gets started by your OSGi runtime, and register that implementation as an OSGi service. Once you've done this you should see that the Felix console discovers your BrandingPlugin implementation and uses it.

Passing Java arguments to bundle under Equinox OSGI framework?

I our application we have several bundles that are running by the Equinox OSGI framework (with Tomcat).
Currently we are passing the application configuration mostly by Java system properties.
This properties are shared across all bundles and all of them can access to the properties value.
We are trying to find other option to pass them so only a specific bundle could access a specific property.
Is there a way to do it by a Java arguments?
How can i pass a java argument to a specific bundle?
You should have a look at the Config Admin service, it is designed for this use case, providing specific bundles with configuration information. Apache Felix File Install provides a convenient mechanism to supply configuration data through property files. Probably Equinox has something similar, but felix file install should run on Equinox.

Resources