Search in sources :

Example 1 with AwaiterModelControllerClient

use of org.jboss.as.cli.AwaiterModelControllerClient in project wildfly-core by wildfly.

the class ReloadHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final ModelControllerClient client = ctx.getModelControllerClient();
    if (client == null) {
        throw new CommandLineException("Connection is not available.");
    }
    if (embeddedServerRef != null && embeddedServerRef.get() != null) {
        doHandleEmbedded(ctx, client);
        return;
    }
    if (!(client instanceof AwaiterModelControllerClient)) {
        throw new CommandLineException("Unsupported ModelControllerClient implementation " + client.getClass().getName());
    }
    final AwaiterModelControllerClient cliClient = (AwaiterModelControllerClient) client;
    final ModelNode op = this.buildRequestWithoutHeaders(ctx);
    try {
        final ModelNode response = cliClient.execute(op, true);
        if (!Util.isSuccess(response)) {
            throw new CommandLineException(Util.getFailureDescription(response));
        }
    } catch (IOException e) {
        // if it's not connected it's assumed the reload is in process
        if (cliClient.isConnected()) {
            StreamUtils.safeClose(client);
            throw new CommandLineException("Failed to execute :reload", e);
        }
    }
    ensureServerRebootComplete(ctx, client);
}
Also used : AwaiterModelControllerClient(org.jboss.as.cli.AwaiterModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) AwaiterModelControllerClient(org.jboss.as.cli.AwaiterModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 2 with AwaiterModelControllerClient

use of org.jboss.as.cli.AwaiterModelControllerClient in project wildfly-core by wildfly.

the class ShutdownHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final ModelControllerClient client = ctx.getModelControllerClient();
    if (client == null) {
        throw new CommandLineException("Connection is not available.");
    }
    if (embeddedServerRef != null && embeddedServerRef.get() != null) {
        embeddedServerRef.get().stop();
        return;
    }
    if (!(client instanceof AwaiterModelControllerClient)) {
        throw new CommandLineException("Unsupported ModelControllerClient implementation " + client.getClass().getName());
    }
    final AwaiterModelControllerClient cliClient = (AwaiterModelControllerClient) client;
    final ModelNode op = this.buildRequestWithoutHeaders(ctx);
    boolean disconnect = true;
    final String restartValue = restart.getValue(ctx.getParsedCommandLine());
    if (Util.TRUE.equals(restartValue) || ctx.isDomainMode() && !isLocalHost(ctx.getModelControllerClient(), host.getValue(ctx.getParsedCommandLine()))) {
        disconnect = false;
    }
    try {
        final ModelNode response = cliClient.execute(op, true);
        if (!Util.isSuccess(response)) {
            throw new CommandLineException(Util.getFailureDescription(response));
        }
    } catch (IOException e) {
        // if it's not connected, it's assumed the connection has already been shutdown
        if (cliClient.isConnected()) {
            StreamUtils.safeClose(client);
            throw new CommandLineException("Failed to execute :shutdown", e);
        }
    }
    if (disconnect) {
        ctx.disconnectController();
    } else {
        // waiting half a sec on my machine works perfectly
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new CommandLineException("Interrupted while pausing before reconnecting.", e);
        }
        try {
            cliClient.ensureConnected(ctx.getConfig().getConnectionTimeout() + 1000L);
        } catch (CommandLineException e) {
            ctx.disconnectController();
            throw e;
        } catch (IOException ex) {
            if (ex instanceof RedirectException) {
                if (!Util.reconnectContext((RedirectException) ex, ctx)) {
                    throw new CommandLineException("Can't reconnect context.", ex);
                }
            } else {
                throw new CommandLineException(ex);
            }
        }
    }
}
Also used : AwaiterModelControllerClient(org.jboss.as.cli.AwaiterModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) IOException(java.io.IOException) AwaiterModelControllerClient(org.jboss.as.cli.AwaiterModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) CommandLineException(org.jboss.as.cli.CommandLineException) RedirectException(org.xnio.http.RedirectException)

Example 3 with AwaiterModelControllerClient

use of org.jboss.as.cli.AwaiterModelControllerClient in project wildfly-core by wildfly.

the class ManagementDisableSSLCommand method reload.

private void reload(CommandContext ctx) throws CommandException, OperationFormatException {
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    AwaiterModelControllerClient aclient = (AwaiterModelControllerClient) ctx.getModelControllerClient();
    try {
        String mode = Util.getRunningMode(ctx);
        builder.setOperationName(Util.RELOAD);
        builder.addProperty(Util.START_MODE, Util.ADMIN_ONLY.equals(mode) ? Util.ADMIN_ONLY : Util.NORMAL);
        ModelNode response;
        response = aclient.execute(builder.buildRequest(), true);
        if (!Util.isSuccess(response)) {
            throw new CommandException(Util.getFailureDescription(response));
        }
    } catch (IOException ex) {
        // if it's not connected it's assumed the reload is in process
        if (aclient.isConnected()) {
            throw new CommandException(ex);
        }
    }
}
Also used : DefaultOperationRequestBuilder(org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder) CommandException(org.aesh.command.CommandException) IOException(java.io.IOException) AwaiterModelControllerClient(org.jboss.as.cli.AwaiterModelControllerClient) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

IOException (java.io.IOException)3 AwaiterModelControllerClient (org.jboss.as.cli.AwaiterModelControllerClient)3 ModelNode (org.jboss.dmr.ModelNode)3 CommandLineException (org.jboss.as.cli.CommandLineException)2 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)2 CommandException (org.aesh.command.CommandException)1 DefaultOperationRequestBuilder (org.jboss.as.cli.operation.impl.DefaultOperationRequestBuilder)1 RedirectException (org.xnio.http.RedirectException)1