How to access detailed Java EE application deployment status on JBoss AS 7? -
im trying write small "watchdog" *.war monitors deployment state of (much larger) *.ear on jboss 7.1.3
how @ exact deployment state of *.ear?
i know can (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 give me all-green if deployment failed. exmaple - have @startup @singleton, who's @postconstruct method (called part of boot) throws exception. @ point deployment has logically failed (initialization threw exception) yet jboss mark .ear deployed - both using marker files in deployment directory (.isdeploying --> *.deployed) , using values controller above.
jboss have containerstatemonitor class keeps list of services missing dependencies need - @singletons fails start cause bunch of @ejbs rely on fail deploy - have no idea how @ it.
the closest found this:
sc.getservice(org.jboss.as.serverservices.jboss_server_controller).getservice()
this gets me instance of serverservice has controller (transient) field holds data. in private fields , dont want resort reflection.
so question - there way @ data? jboss knows @singletons failed deploy, @ejbs missing dependencies, datasources failed connect etc, there way me it? doesnt have msc, jmx (though think maps msc in jboss 7) or other api.
you use management api , check results.
the code like:
import java.net.inetaddress; import org.jboss.as.controller.client.modelcontrollerclient; import org.jboss.as.controller.client.helpers.clientconstants; import org.jboss.as.controller.client.helpers.operations; import org.jboss.dmr.modelnode; public class clientexample { public static void main(final string[] args) throws exception { final modelcontrollerclient client = modelcontrollerclient.factory.create(inetaddress.getlocalhost(), 9999); try { final modelnode address = new modelnode().setemptylist(); address.add("deployment", "jboss-as-helloworld.war"); final modelnode op = operations.createreadresourceoperation(address, true); op.get(clientconstants.include_runtime).set(true); final modelnode outcome = client.execute(op); if (operations.issuccessfuloutcome(outcome)) { system.out.println(outcome); } else { system.err.printf("operation failure: %s%n", operations.getfailuredescription(outcome)); } } { client.close(); } } }
note using 7.2.0.final version of api should work older versions of jboss as7, jboss eap 6.x , wildfly.
this outputs result like
{ "outcome" => "success", "result" => { "content" => [{"hash" => bytes { 0xab, 0x77, 0x61, 0x49, 0x4b, 0x30, 0x3b, 0x4f, 0xd7, 0x80, 0x13, 0x5a, 0x6c, 0x48, 0x1e, 0x3d, 0xb3, 0xbe, 0xc1, 0xc2 }}], "enabled" => true, "name" => "jboss-as-helloworld.war", "persistent" => true, "runtime-name" => "jboss-as-helloworld.war", "status" => "ok", "subdeployment" => undefined, "subsystem" => {"web" => { "active-sessions" => 0, "context-root" => "/jboss-as-helloworld", "duplicated-session-ids" => 0, "expired-sessions" => 0, "max-active-sessions" => 0, "rejected-sessions" => 0, "session-avg-alive-time" => 0, "session-max-alive-time" => 0, "sessions-created" => 0, "virtual-host" => "default-host", "servlet" => {"org.jboss.as.quickstarts.helloworld.helloworldservlet" => { "load-time" => 0l, "maxtime" => 9223372036854775807l, "min-time" => 0l, "processingtime" => 0l, "requestcount" => 0, "servlet-class" => "org.jboss.as.quickstarts.helloworld.helloworldservlet", "servlet-name" => "org.jboss.as.quickstarts.helloworld.helloworldservlet" }} }} } }
or if want status change above example , do:
final modelnode op = operations.createreadattributeoperation(address, "status"); final modelnode outcome = client.execute(op); if (operations.issuccessfuloutcome(outcome)) { system.out.println(operations.readresult(outcome).asstring()); } else { system.err.printf("operation failure: %s%n", operations.getfailuredescription(outcome)); }
Comments
Post a Comment