문제

빌드 파이프 라인의 일부로 Jenkins 빌드 서버에서 Jenkins 빌드 서버에서 자동으로 원격 JBoss 서버로 자동 배포하고 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