Search in sources :

Example 31 with ParsedCommandLine

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);
        }
    }
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode) SaslException(javax.security.sasl.SaslException) CommandLineException(org.jboss.as.cli.CommandLineException) RedirectException(org.xnio.http.RedirectException)

Example 32 with ParsedCommandLine

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);
    }
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Example 33 with ParsedCommandLine

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);
}
Also used : OperationCommand(org.jboss.as.cli.OperationCommand) CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 34 with ParsedCommandLine

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;
}
Also used : OperationCommand(org.jboss.as.cli.OperationCommand) CommandFormatException(org.jboss.as.cli.CommandFormatException) CommandArgument(org.jboss.as.cli.CommandArgument) ArrayList(java.util.ArrayList) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 35 with ParsedCommandLine

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);
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine)

Aggregations

ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)95 Test (org.junit.Test)42 CommandFormatException (org.jboss.as.cli.CommandFormatException)38 ModelNode (org.jboss.dmr.ModelNode)26 CommandLineException (org.jboss.as.cli.CommandLineException)14 OperationRequestAddress (org.jboss.as.cli.operation.OperationRequestAddress)14 File (java.io.File)12 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 DefaultOperationRequestAddress (org.jboss.as.cli.operation.impl.DefaultOperationRequestAddress)8 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)8 CommandArgument (org.jboss.as.cli.CommandArgument)4 CommandContext (org.jboss.as.cli.CommandContext)4 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)4 ZipException (java.util.zip.ZipException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 CommandException (org.aesh.command.CommandException)3 BatchManager (org.jboss.as.cli.batch.BatchManager)3 CommandLineParser (org.jboss.as.cli.operation.CommandLineParser)3 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)3