我正在努力从Jenkins构建服务器自动部署到远程JBoss作为7.1.1服务器作为构建管道的一部分,并具有我从Ant调用的小jar文件(基于这个)。

我的问题是我如何知道已经安装了应用程序吗?如果已经部署了应用程序(我可以捕获抛出的异常,但这不是很大),则执行部署计划将失败。

有帮助吗?

解决方案

您可以在执行部署之前读取资源。从那里,您可以重新部署或无效。

这是一个在独立服务器上工作的示例。

private boolean exists(final ModelControllerClient client, final String deploymentName) {
    final ModelNode op = new ModelNode();
    op.get(OP).set("read-children-names");
    op.get("child-type").set(ClientConstants.DEPLOYMENT);
    final ModelNode result;
    try {
        result = client.execute(op);
        // Check to make sure there is an outcome
        if (result.hasDefined(ClientConstants.OUTCOME)) {
            if (result.get(ClientConstants.OUTCOME).asString().equals(ClientConstants.SUCCESS)) {
                final List<ModelNode> deployments = (result.hasDefined(ClientConstants.RESULT) ? result.get(ClientConstants.RESULT).asList() : Collections.<ModelNode>emptyList());
                for (ModelNode n : deployments) {
                    if (n.asString().equals(deploymentName)) {
                        return true;
                    }
                }
            } else if (result.get(ClientConstants.OUTCOME).asString().equals(ClientConstants.FAILED)) {
                throw new IllegalStateException(String.format("A failure occurred when checking existing deployments. Error: %s",
                        (result.hasDefined(ClientConstants.FAILURE_DESCRIPTION) ? result.get(ClientConstants.FAILURE_DESCRIPTION).asString() : "Unknown")));
            }
        } else {
            throw new IllegalStateException(String.format("An unexpected response was found checking the deployment. Result: %s", result));
        }
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Could not execute operation '%s'", op), e);
    }
    return false;
}
.

如果您使用的是maven,有一个 maven plugin 你也可以使用。

其他提示

另一种:

ModelNode res = AS7CliUtils.executeRequest("/deployment=* /:read-resource", ctx.getAS7Client() );

{
    "outcome" => "success",
    "result" => [{
        "address" => [("deployment" => "jboss-as-wicket-ear-ear.ear")],
        "outcome" => "success",
        "result" => {
            "content" => [{"hash" => bytes { ... }}],
            "enabled" => true,
            "name" => "jboss-as-wicket-ear-ear.ear",
            "persistent" => true,
            "runtime-name" => "jboss-as-wicket-ear-ear.ear",
            "subdeployment" => {
                "jboss-as-wicket-ear-ejb.jar" => undefined,
                "jboss-as-wicket-ear-war.war" => undefined
            },
            "subsystem" => {"datasources" => undefined}
        }
    }]
}
.

jboss作为cli客户端lib包含一些API,现在找不到它。

这是查询解析的原始实现(不支持嵌套值,不关心逃逸等)。

/**
 *  Parse CLI command into a ModelNode - /foo=a/bar=b/:operation(param=value,...) .
 * 
 *  TODO: Support nested params.
 */
public static ModelNode parseCommand( String command ) {
   return parseCommand( command, true );
}
public static ModelNode parseCommand( String command, boolean needOp ) {
    String[] parts = StringUtils.split( command, ':' );
    if( needOp && parts.length < 2 )  throw new IllegalArgumentException("Missing CLI command operation: " + command);
    String addr = parts[0];

    ModelNode query = new ModelNode();

    // Addr
    String[] partsAddr = StringUtils.split( addr, '/' );
    for( String segment : partsAddr ) {
        String[] partsSegment = StringUtils.split( segment, "=", 2);
        if( partsSegment.length != 2 )  throw new IllegalArgumentException("Wrong addr segment format - need '=': " + command);
        query.get(ClientConstants.OP_ADDR).add( partsSegment[0], partsSegment[1] );
    }

    // No op?
    if( parts.length < 2 )  return query;

    // Op
    String[] partsOp = StringUtils.split( parts[1], '(' );
    String opName = partsOp[0];
    query.get(ClientConstants.OP).set(opName);

    // Op args
    if( partsOp.length > 1 ){
        String args = StringUtils.removeEnd( partsOp[1], ")" );
        for( String arg : args.split(",") ) {
            String[] partsArg = arg.split("=", 2);
            query.get(partsArg[0]).set( unquote( partsArg[1] ) );
        }
    }
    return query;
}// parseCommand()
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top