Checking in OSGI if a bundle is still operating normally

208 Views Asked by At

I'm currently making a watchdog to check if all bundles in a pipeline are still functioning properly. (This will be in a distributed environment so failure can be a network failure, software failure, one of the servers failing, ...)

Because a bundle can be bound to N amount of services, N arbitrary, the checking should will happen recursively using the following methodology:

START at the first step in the pipeline
Use getServicesInUse to get the services references of the next step
use getBundle() on the gathered ServiceRerefence objects
REPEAT until we arrive at the bundle we want to stop at

So that way I can get all the bundle objects of the pipeline (I assume) now to check if they are functioning correctly (or just if they are still reachable) I was wondering if

Bundle b = ...
if(b.getState() == Bundle.ACTIVE) ...;

will do the trick? Ofcourse also surrounding this with the necessary try catch clauses to detect hardware/network failure.

1

There are 1 best solutions below

2
On

Can you clarify what you mean by "all bundles in a pipeline"?

You are right that a bundle can provide and consume zero or more services, but if I were to create a watchdog for an OSGi system I would use one of two approaches:

  1. If the nodes in your distributed system provide mainly REST services, I would write a separate "watchdog" program that monitors these REST services to see if they still respond (on any of the nodes in my distributed system). You can either make "real" calls or just request some HEAD and see if you get a response.
  2. If the nodes in your distributed system provide mainly OSGi services, I would write a watchdog bundle and deploy that to each node. I would then add a REST endpoint to my watchdog to allow me to monitor it remotely (by another watchdog, similar to approach #1).

Checking the active state of a bundle will tell you nothing. Bundles will remain active once started, but the services they provide could be unresponsive.