Im trying to write a small "watchdog" *.war that monitors the deployment state of my (much larger) *.ear on jboss 7.1.3
How do I get at the exact deployment state of the *.ear?
I know I can do this (using jboss MSC classes):
ServiceContainer sc = CurrentServiceContainer.getServiceContainer(); //jboss msc
ServiceController earController = sc.getService(Services.deploymentUnitName("my.ear"));
return "my.ear - "+earController.getMode()+"-"+earController.getState()+"-"+earController.getSubstate();
but this will give me the all-green even if deployment failed. for exmaple - say I have a @Startup @Singleton, who's @PostConstruct method (called as part of boot) throws an exception. at this point my deployment has logically failed (initialization threw an exception) yet jboss will mark the .ear as deployed - both using the marker files in the deployment directory (.isDeploying --> *.deployed) and using the values from the controller above.
jboss does have a ContainerStateMonitor class that keeps a list of services with missing dependencies which is just what I need - any @Singletons that fails to start will cause a bunch of @EJBs that rely on it to fail to deploy - but I have no idea how to get at it.
the closest I found was this:
sc.getService(org.jboss.as.serverServices.JBOSS_SERVER_CONTROLLER).getService()
this gets me an instance of ServerService that has a controller (transient) field which holds that data. but its all in private fields and I really dont want to resort to reflection.
so my question is - is there any way to get at that data? jboss obviously knows what @Singletons failed to deploy, what @EJBs are missing dependencies, what datasources failed to connect etc, but is there a way for me to get to it? doesnt have to be MSC, could be JMX (though I think that just maps to MSC in jboss 7) or any other API.
You could use the management API and check the results.
The code would look something like:
Note I am using the 7.2.0.Final version of the API which should work with older versions of JBoss AS7, JBoss EAP 6.x and WildFly.
This outputs a result like
Or if you just want the status you could change the above example slightly and do: