Can OSGi install/deploy bundles hosted on a URL? - java

I'm wondering if I can configure an OSGi container like Karaf (or any other popular ones) to download bundles (.BNDs) from a remote repository hosted on another machine, via any networking mechanism out there (RMI, HTTP, URLClassLoader, etc.)?
Ideally, I'd be able to deploy new versions of my bundles to this remote repo at any time, and somehow have that trigger the OSGi container "downloading" (installing/deploying) the remote bundles and hot-deploying them over older versions of the same bundle.
Is this possible? If so, how? Thanks in advance!

OSGi has an API for managing OSGi frameworks on the BundleContext that every bundle activator receives. This API allows you to install/update a bundle via URL or InputStream.
Since this is a standardized API there have been lots of people making bundles that provide a policy around this deployment process. The archetypical one is Apache FileInstall, it watches a directory and automatically installs every bundle found in this directory and uninstall the bundle when it is gone. This works well with for example dropbox. It also supports configuring via the the Configuration Admin service. On the other hand of the spectrum you find Apache Ace which provides a remote management system.
To find the best solution, try to enlist the requirements you have. One or two systems or 1 million? Local or remote over slow lines?
One thing is for sure, you will find some project or provider being able to provide you with an OSGi bundle that implements your desired management policy.

We use Apache Felix and maintain an OBR repository. Once set up you can deploy new versions from the OSGi shell. This does require you to manually log in and enter the command, for example deploy com.example.foo.
Alternatively you can install directly from urls, like install http://example.com/bundles/bundle.jar.
Your last requirement (auto deploy) is trickier. You could perhaps enable a remote shell on your OSGi container and as part of your build push the commands via telnet.

I recommend taking a look at the provisioning of Karaf at documentation for provisioning.
Your able to deploy bundles either with maven urls, http or file references. Or you might deploy your set of bundles either as a feature definition (which loads all required and used bundles from a maven repo) or by deploying a kar file.

Related

How to access OSGi bundle information remotely

I need to access information about all bundles and services of a remote AEM application (Apache Felix).
Information needed for bundles:
Exported packages and version
Imported packages and version
Bundle status
Information needed for service:
Implemented interface
Ranking
path, resourceTypes, selectors for Servlets
How could we possibly gather all the above information via a Java program?
I cannot deploy any custom remote Service on the OSGi container. Have to gather all the details, only via a Remote Java program executed externally.
Chapter 137 of the OSGi Compendium defines the OSGi REST Management Service. This provides all of the information that you're asking for using standard DTOs in a simple REST model.
The URI framework/bundles will list bundles which can be introspected using framework/bundle/{bundleid}, and framework/services will list services which can be introspected using framework/service/{serviceid}
As requested, this solution does not make use of remote services, but as mentioned in one of the comments there is no way to introspect a remote OSGi framework without installing something. In this case you must add a REST Management Service implementation to the remote framework.

Apache Felix the DOSGI single bundle and Zookeeper

I am trying to implement LAN based service discovery in my project. I have Apache Felix with the DOSGI single bundle distribution deployed. Additionally, I have the Apache Hadoop Zookeeper server running. i have been following this tutorial here
However, i dont know what it means when it says
To configure the ZooKeeper client in CXF/Discovery the following configuration variables apply. They need to be set on Configuration Admin PID org.apache.cxf.dosgi.discovery.zookeeper.
it then says
An easy way to set the configuration, it by placing a file called org.apache.cxf.dosgi.discovery.zookeeper.cfg in the load directory created by the FileInstall bundle with the following content:
zookeeper.host = 127.0.0.1
the problem im having is that i cant find the load directory that the FileInstall bundle is supposed to create. I need this to complete my final year project and am running out of time
any help on this is much appreciated
Many thanks
Billy
You should create the load directory yourself. You can even configure it to point to a different directory if you like. More information about that can be found in the documentation of Apache Felix File Install: http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html
If you're after LAN based service discovery, then you might want to consider using different discovery protocols (like for example SLP).
And, shameless plug, you might also want to take a look at Amdatu Remote, which will be the reference implementation for the updated Remote Services specification: http://amdatu.org/components/remote.html

Generic binding between EJB module and HTTP router module

TL;DR
Is it necessary to have an HTTP router module when deploying an EJB module containing web service implementations to WebSphere 7?
If so, is there a way to create/manage it without relying on IBM-specific files?
I have an application that is being restructured so that it can be built Maven. Currently, I am using was6-maven-plugin's endptEnabler goal to build an HTTP router module for an EJB module that contains some web services. This works well, but I just found out that the build machine we'll get to use won't actually have WebSphere installed on it. In the past this wouldn't have been a problem, since the router module had been developed manually by someone clicking a "Generate Router Module" button in RAD and then actually checking in the generated code into source control. With the Maven-centric build process, we thought it would be better to generate the module during the build process.
So now I am stuck: generating the router module via Maven seems a much cleaner approach but won't work on the build machine. I have a few options:
Extract the generated WAR and add it to our enterprise repository and then create a dependency from my EJB to the WAR. I really don't like this, but it would probably work.
Go back to having a realized HttpRouterModule project in the workspace. The problem with this is that the IBM-specific binding files have valid module IDs for my server, but I don't know if they'd cause problems on someone else's which is why I'd rather generate these files from Maven.
Keep generating the router module with Maven, but find a way to generate it in a way such that there is no WebSphere dependency.
I'd prefer to go with the third option, but I'm not sure how I can generate the module and the binding files in generic way such that it will still be recognized by WebSphere.
I'm open to hearing about other options too...
As far as I know you need http router module. From my experience I was also unable to create the module manually. Is there no way you could install was7 dev server on your build machine? I believe it is free download from IBM.
All my research so far indicates that this is necessary in WebSphere 7, and in earlier versions. It looks like WebSphere 8 does not require HTTP router modules. We're going with the second option, as the build server won't be able to generate the router modules on its own.
Not ideal, but once we move to WAS8 this won't be necessary.

Tomcat and OSGi

I was wondering if it is possible to embed an OSGi container like Karaf inside a Tomcat instance. According to this SO question and a few others, it seems like its possible, but I can't seem to find any solid details on how to do this or what pitfalls/caveats to watch out for.
So:
Is it possible to embed an OSGi container inside Tomcat, so that I can hot-deploy OSGi bundles at any point to this container without having to restart Tomcat?
If the answer to #1 above is "yes", then what system services/ports does embedding OSGi inside Tomcat expose? I ask because I would like to deploy OSGi in a Tomcat server hosted on a Java PaaS where I don't have admin rights. And I'm wondering if - when I try to deploy the embedded OSGi container to Tomcat, that it will try to start listening on ports, or perhaps start doing something to the local file system. If this is the case I will likely receive security/permission errors.
Thanks in advance!
Is it possible to embed an OSGi container inside Tomcat?
Yes. In fact if you download Karaf and look in <KARAF_HOME>/demos/web you'll find a demo project that does exactly that.
what system services/ports does embedding OSGi inside Tomcat expose?
That would depend on what you install in it and how you configure it. Here is somewhat old (but IMHO stil relevant) discussion about default ports and how to configure them.
We deploy our application in the same fashion. We have deployed karaf in tomcat & on weblogic using a servelt bridge. The reason for using the container was to get past environment constraints where some customers are a "oracle" or an "ibm" shop and want all deployments done on these servers.
Since you will be using a servlet bridge it does not need to open a new port to list to http traffic. You may have issues with the karaf console if that port is blocked. Also I recall having issues with running cxf due to an embedded jetty instance it starts on another port.
Other than the ports you will need a karaf home directory with write access.

Dynamically load additional jar files using Web Start / JNLP

The Web Start Developers Guide states
All application resources must be retrieved from the JAR files specified
in the resources section of the JNLP file, or retrieved explicitly
using an HTTP request to the Web server.
Storing resources in JAR files is recommended, since they will be cached
on the local machine by Java Web Start.
Now, I have some resources I want to dynamically load after my application has been started (for example OSGi bundles). I can do this using plain HTTP, but I would like to make use of Web Start's support for local caching and versioned/architecture-specific resources.
Is there a way to download additional jar files from the original code base (as specified in the application's jnlp file) using the Web Start infrastructure?
Or alternatively: is there already an established way to integrate OSGi and Web Start that would relieve me of the task to install bundles from the Web Start server?
If you make your application in itself an Equinox-based OSGI application, you can web-start it with all the addition bundles you need.
This article "WebStarting Equinox OSGi Apps" can give you a good introduction on the required settings.
All bundles have to be deployed as signed JAR files
You need a feature that contains all the necessary bundles
When exporting the feature, make sure that PDE creates a JNLP (Java Network Lauching Protocol) file (a checkbox in the export wizard) for this feature
Provide a root JNLP file for you application
Deploy your application to a web server and make sure that the web server is aware of the application/x-java-jnlp-file mime type
He also has an OSGI demo.
I haven't tried it but look at the javax.jnlp.DownloadService API

Categories