Reputation: 2111
I'm designing a shell to administer an application. It is planned to let the next application verison use OSGi, but the OSGi platform (Felix, Equinox, ...) is not decided yet. it would be nice if we could administer OSGi with our shell, too.
How can I administer OSGi in a platform independent way? Could you point me to example code?
Thanks, Ulrich
Upvotes: 0
Views: 402
Reputation: 19606
In fact you can not only use the console from karaf. You can simply use Apache Karaf as your server. It can be switched from Felix to Equinox with just a config setting. I did a tutorial series about Karaf if you are interested in how it works in practice. http://www.liquid-reality.de/display/liquid/Karaf+Tutorials
Upvotes: 1
Reputation: 662
Yes, of course it is possible to administer OSGi in a platform-independent way. It all depends on how much of the administration you are ready to implement yourself.
The OSGi APIs give you access to everything, you only need to design/choose your shell, format of the commands etc.
Do you want a command prompt based one, a web-based one or a remote management protocol to be used with some backend management server?
1) Let's start with the functionality. Your shell will be implemented as a bundle itself. You can use the BundleContext of this bundle to get access to the other bundle objects. Through them you can:
BundleContext.installBundle(String)
– Installs a bundle from the specified location
string (which should be a URL).
BundleContext.getBundles( )
Bundle.start()
Bundle.update( InputStream input )
Inspect bundles, bundle versions, exported/imported packages, registered services
From the OSGi service registry you can get the ConfigurationAdmin service, through which you can list the configurations of bundles, and change them
From the registry you can also get the LogService, to read the logs
From the StartLevel service you can control the order of starting of the bundles when the fw is started
etc etc
2) How do you want to make the above info accessible? If you want a command-based console, you can write one, using the system output. You can check this implementation for ideas
If you want a web-based one, the easiest way to remain platform-independent is to write a standard servlet and register it in the standard OSGi HTTP service. The relevant web pages will then call the functions above.
If you want a remote management protocol, you can map to many different possibilities. Check for example the OSGi DMT service, which maps to the OMA DM spec, which maps easily to the TR-069 management protocol. There are existing implementations.
All this is completely independent from Felix, Equinox etc and will work on any of them, as well as any other OSGi fw.
Upvotes: 0
Reputation: 2694
You can checkout console implementation of e.g. Apache Karaf. It's fully featured OSGi runtime. Here is overview of the commands, you would maybe select only subset.
You could as well use the runtime and extend the console with your commands: http://karaf.apache.org/manual/latest-2.2.x/developers-guide/extending-console.html
Upvotes: 1