如何在JBoss AS 7上访问详细的Java EE应用程序部署状态? [英] How to access detailed Java EE application deployment status on JBoss AS 7?
问题描述
我试着写一个小的看门狗* .war来监视我(更大)的部署状态* .ear on jboss 7.1.3
Im trying to write a small "watchdog" *.war that monitors the deployment state of my (much larger) *.ear on jboss 7.1.3
如何进入* .ear的完全部署状态?
How do I get at the exact deployment state of the *.ear?
我知道我可以这样做(使用jboss MSC类):
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();
但即使部署失败,这也会给我全绿色。例如 - 说我有@Startup @Singleton,谁的@PostConstruct方法(称为引导的一部分)抛出一个异常。此时我的部署逻辑上失败了(初始化引发异常)但jboss会将 .ear标记为已部署 - 两者都使用部署目录中的标记文件( .isDeploying - > * .deployed)使用上面控制器中的值。
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确实有一个ContainerStateMonitor类,它保存了缺少依赖项的服务列表,这正是我所需要的 - 任何@Singletons无法启动将导致一堆依赖它的@EJB无法部署 - 但我不知道如何实现它。
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()
这让我得到一个 ServerService ,具有保存该数据的控制器(瞬态)字段。但它全部都在私人领域,我真的不想诉诸于反思。
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.
所以我的问题是 - 有没有办法获得这些数据? jboss显然知道@Singletons未能部署什么,@ EJBs缺少哪些依赖项,哪些数据源无法连接等等,但是有没有办法让我达到它?不一定是MSC,可能是JMX(虽然我认为只是映射到jboss 7中的MSC)或任何其他API。
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.
推荐答案
您可以使用管理API 并查看结果。
You could use the management API and check the results.
代码如下所示:
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));
}
} finally {
client.close();
}
}
}
注意我使用的是7.2 .0。最终版本的API应该适用于旧版本的JBoss AS7,JBoss EAP 6.x和WildFly。
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.
这会输出像
{
"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 you just want the status you could change the above example slightly and 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));
}
这篇关于如何在JBoss AS 7上访问详细的Java EE应用程序部署状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!