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);
}
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);
}
}
}
}
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);
}
}
}
Aggregations