Search in sources :

Example 1 with HandledRequest

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

the class CommandContextImpl method buildRequest.

protected HandledRequest buildRequest(String line, boolean batchMode) throws CommandFormatException {
    if (line == null || line.isEmpty()) {
        throw new OperationFormatException("The line is null or empty.");
    }
    final DefaultCallbackHandler originalParsedArguments = this.parsedCmd;
    final String originalCmdLine = this.cmdLine;
    try {
        this.parsedCmd = new DefaultCallbackHandler();
        resetArgs(line);
        if (parsedCmd.getFormat() == OperationFormat.INSTANCE) {
            final ModelNode request = this.parsedCmd.toOperationRequest(this);
            return new HandledRequest(request, null);
        }
        final CommandHandler handler = cmdRegistry.getCommandHandler(parsedCmd.getOperationName());
        if (handler != null) {
            if (batchMode) {
                if (!handler.isBatchMode(this)) {
                    throw new OperationFormatException("The command is not allowed in a batch.");
                }
                Batch batch = getBatchManager().getActiveBatch();
                return ((OperationCommand) handler).buildHandledRequest(this, batch.getAttachments());
            } else if (!(handler instanceof OperationCommand)) {
                throw new OperationFormatException("The command does not translate to an operation request.");
            }
            return new HandledRequest(((OperationCommand) handler).buildRequest(this), null);
        } else {
            return buildAeshCommandRequest(parsedCmd, batchMode);
        }
    } finally {
        clear(Scope.REQUEST);
        this.parsedCmd = originalParsedArguments;
        this.cmdLine = originalCmdLine;
    }
}
Also used : OperationCommand(org.jboss.as.cli.OperationCommand) OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) Batch(org.jboss.as.cli.batch.Batch) HandledRequest(org.jboss.as.cli.OperationCommand.HandledRequest) DefaultCallbackHandler(org.jboss.as.cli.operation.impl.DefaultCallbackHandler) CommandHandler(org.jboss.as.cli.CommandHandler) CommandCommandHandler(org.jboss.as.cli.handlers.CommandCommandHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with HandledRequest

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

the class CommandContextImpl method handleLegacyCommand.

private void handleLegacyCommand(String opLine, CommandHandler handler, boolean direct) throws CommandLineException {
    if (isBatchMode() && handler.isBatchMode(this)) {
        if (!(handler instanceof OperationCommand)) {
            throw new CommandLineException("The command is not allowed in a batch.");
        } else {
            try {
                Batch batch = getBatchManager().getActiveBatch();
                HandledRequest request = ((OperationCommand) handler).buildHandledRequest(this, batch.getAttachments());
                BatchedCommand batchedCmd = new DefaultBatchedCommand(this, opLine, request.getRequest(), request.getResponseHandler());
                batch.add(batchedCmd);
            } catch (CommandFormatException e) {
                throw new CommandFormatException("Failed to add to batch '" + opLine + "'", e);
            }
        }
    } else if (direct) {
        handler.handle(CommandContextImpl.this);
    } else {
        execute(() -> {
            executor.execute(handler, timeout, TimeUnit.SECONDS);
            return null;
        }, opLine);
    }
}
Also used : OperationCommand(org.jboss.as.cli.OperationCommand) Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) HandledRequest(org.jboss.as.cli.OperationCommand.HandledRequest) DefaultBatchedCommand(org.jboss.as.cli.batch.impl.DefaultBatchedCommand) CommandLineException(org.jboss.as.cli.CommandLineException) DefaultBatchedCommand(org.jboss.as.cli.batch.impl.DefaultBatchedCommand) BatchedCommand(org.jboss.as.cli.batch.BatchedCommand)

Aggregations

OperationCommand (org.jboss.as.cli.OperationCommand)2 HandledRequest (org.jboss.as.cli.OperationCommand.HandledRequest)2 Batch (org.jboss.as.cli.batch.Batch)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandHandler (org.jboss.as.cli.CommandHandler)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 BatchedCommand (org.jboss.as.cli.batch.BatchedCommand)1 DefaultBatchedCommand (org.jboss.as.cli.batch.impl.DefaultBatchedCommand)1 CommandCommandHandler (org.jboss.as.cli.handlers.CommandCommandHandler)1 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)1 DefaultCallbackHandler (org.jboss.as.cli.operation.impl.DefaultCallbackHandler)1 ModelNode (org.jboss.dmr.ModelNode)1