architectureosgi

Deploying different versions of OSGI-application stack in the same container


I'm building an API which has a REST frontend and the whole stack contains almost 10 different bundles, and slowly growing. This works great so far.

In the long run I'm planning to have different versions of the API-stack (using OSGi versoning mechanism), accessible via the REST-frontend in the format of /api/v2/path/to/resource or something similar.

My first thought was just to deploy the whole stack for the new version, eg. install all my bundles. The new REST-bundle will add /api/<version-number> to jaxrs-server in blueprint and everything should work, but my concern is that there will be ALOT of bundles deployed in the long run. I'm sensing that I will lose the overall overview of installed bundles and so on.

Is there any way to separate my stacks in some way? I don't want to install a new container for each version. I have looked a bit at Karaf's instances but will I be able to "append" to jaxrs-servers in the same way as if the bundles was installed in the same instance? Eg. access the REST-frontend on the same host, port etc.

Thanks


Solution

  • I agree that isolation is important. The OSGi Framework was only ever designed to host a single "application". If you deploy multiple applications to the same framework without isolation, you will get interference between the two, such as undesired sharing of packages and services.

    For example, you could thoroughly test one application and find that it works. Then you thoroughly test a second application and find that it also works. Finally you deploy both of them into an OSGi framework and find that neither works! This is not good...

    The subsystems spec does provide isolation but it is complex and the implementations immature. I would suggest simply instantiating multiple OSGi frameworks. This can be done easily within a single JVM, there are no static or singletons in OSGi that would prevent it. The basic code required to instantiate an OSGi framework is around 5-10 lines.

    UPDATE: For detailed information on how to instantiate a new OSGi Framework, see my blog post "How to Embed OSGi"