use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class ReloadHandler method ensureServerRebootComplete.
private void ensureServerRebootComplete(CommandContext ctx, ModelControllerClient client) throws CommandLineException {
final long start = System.currentTimeMillis();
final long timeoutMillis = ctx.getConfig().getConnectionTimeout() + 1000L;
final ModelNode getStateOp = new ModelNode();
if (ctx.isDomainMode()) {
final ParsedCommandLine args = ctx.getParsedCommandLine();
final String hostName = host.getValue(args);
getStateOp.get(Util.ADDRESS).add(Util.HOST, hostName);
}
getStateOp.get(ClientConstants.OP).set(ClientConstants.READ_ATTRIBUTE_OPERATION);
// this is left for compatibility with older hosts, it could use runtime-configuration-state on newer hosts.
if (ctx.isDomainMode()) {
getStateOp.get(ClientConstants.NAME).set("host-state");
} else {
getStateOp.get(ClientConstants.NAME).set("server-state");
}
while (true) {
String serverState = null;
try {
final ModelNode response = client.execute(getStateOp);
if (Util.isSuccess(response)) {
serverState = response.get(ClientConstants.RESULT).asString();
if ("running".equals(serverState) || "restart-required".equals(serverState)) {
// we're reloaded and the server is started
break;
}
}
} catch (IOException e) {
// A Redirect Exception? Need to connect again the Client
// if that is an http to https redirect only.
Throwable ex = e;
while (ex != null) {
if (ex instanceof RedirectException) {
// Attempt to reconnect the context
if (Util.reconnectContext((RedirectException) ex, ctx)) {
return;
}
} else if (ex instanceof SaslException) {
// invalid (eg: change of security-realm or SASL reconfiguration).
try {
ctx.connectController();
return;
} catch (CommandLineException clex) {
// Not reconnected.
}
}
ex = ex.getCause();
}
// ignore and try again
} catch (IllegalStateException ex) {
// ignore and try again
// IllegalStateException is because the embedded server ModelControllerClient will
// throw that when the server-state / host-state is "stopping"
}
if (System.currentTimeMillis() - start > timeoutMillis) {
if (!"starting".equals(serverState)) {
ctx.disconnectController();
throw new CommandLineException("Failed to establish connection in " + (System.currentTimeMillis() - start) + "ms");
}
// else we don't wait any longer for start to finish
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
ctx.disconnectController();
throw new CommandLineException("Interrupted while pausing before reconnecting.", e);
}
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class EchoVariableHandler method recognizeArguments.
@Override
protected void recognizeArguments(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
final Set<String> propertyNames = args.getPropertyNames();
if (!propertyNames.isEmpty()) {
final Collection<String> names;
if (helpArg.isPresent(args)) {
if (propertyNames.size() == 1) {
return;
}
names = new ArrayList<String>(propertyNames);
names.remove(helpArg.getFullName());
names.remove(helpArg.getShortName());
} else {
names = propertyNames;
}
throw new CommandFormatException("Unrecognized argument names: " + names);
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class GenericTypeOperationHandler method getArgument.
@Override
public CommandArgument getArgument(CommandContext ctx, String name) {
final ParsedCommandLine args = ctx.getParsedCommandLine();
try {
if (!this.name.isValueComplete(args)) {
return staticArgs.get(name);
}
} catch (CommandFormatException e) {
return null;
}
final String op = operation.getValue(args);
OperationCommand handler;
try {
handler = getHandler(ctx, op);
} catch (CommandLineException e) {
return null;
}
return handler.getArgument(ctx, name);
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class GenericTypeOperationHandler method getArguments.
@Override
public Collection<CommandArgument> getArguments(CommandContext ctx) {
final ParsedCommandLine args = ctx.getParsedCommandLine();
List<CommandArgument> arguments = new ArrayList<>();
try {
if (isChildNode) {
arguments.addAll(staticArgs.values());
} else {
if (!name.isValueComplete(args)) {
return staticArgs.values();
}
}
} catch (CommandFormatException e) {
return Collections.emptyList();
}
final String op = operation.getValue(args);
OperationCommand handler;
try {
handler = getHandler(ctx, op);
} catch (CommandLineException e) {
// Return the static arguments in case of child node.
return arguments;
}
arguments.addAll(handler.getArguments(ctx));
return arguments;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class DeploymentInfoHandler method buildRequestWithoutHeaders.
/* (non-Javadoc)
* @see org.jboss.as.cli.OperationCommand#buildRequest(org.jboss.as.cli.CommandContext)
*/
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
ic.deploymentName = null;
ic.serverGroup = null;
String deploymentName = name.getValue(parsedCmd);
if (name != null) {
ic.deploymentName = deploymentName;
}
ic.serverGroup = serverGroup.getValue(parsedCmd);
return ic.buildRequest(ctx);
}
Aggregations