Search in sources :

Example 1 with DMRCommand

use of org.wildfly.core.cli.command.DMRCommand in project wildfly-core by wildfly.

the class DeployHandler method buildRequestWithoutHeaders.

@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    ParsedCommandLine args = ctx.getParsedCommandLine();
    boolean l = this.l.isPresent(args);
    if (!args.hasProperties() || l) {
        throw new CommandFormatException("No Option");
    }
    final boolean unmanaged = this.unmanaged.isPresent(args);
    final String path = this.path.getValue(args);
    final String name = this.name.getValue(args);
    final String rtName = this.rtName.getValue(args);
    final String url = this.url.getValue(args);
    final boolean force = this.force.isPresent(args);
    final boolean disabled = this.disabled.isPresent(args);
    final boolean enabled = this.enabled.isPresent(args);
    final String serverGroups = this.serverGroups.getValue(args);
    final boolean allServerGroups = this.allServerGroups.isPresent(args);
    final ModelNode headersNode = headers.toModelNode(ctx);
    if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
        throw new CommandFormatException("--headers option has wrong value '" + headersNode + "'");
    }
    if (path == null && url == null) {
        if (name == null) {
            throw new CommandFormatException("Filesystem path, --url or --name is " + " required.");
        }
        if (name.equals(ALL)) {
            if (force || disabled) {
                throw new CommandFormatException("force and disabled can't be used " + "when deploying all disabled deployments");
            }
            EnableAllCommand command = new EnableAllCommand(ctx);
            command.allServerGroups = allServerGroups;
            command.headers = headersNode;
            command.serverGroups = serverGroups;
            return command.buildRequest(ctx);
        } else {
            EnableCommand command = new EnableCommand(ctx);
            command.allServerGroups = allServerGroups;
            command.headers = headersNode;
            command.serverGroups = serverGroups;
            command.name = name;
            return command.buildRequest(ctx);
        }
    }
    if (path != null) {
        if (url != null) {
            throw new CommandFormatException("Filesystem path and --url can't be used together.");
        }
        File f = new File(path);
        DMRCommand c;
        if (DeployArchiveCommand.isCliArchive(f)) {
            DeployArchiveCommand command = new DeployArchiveCommand(ctx);
            command.file = f;
            command.script = this.script.getValue(args);
            c = command;
        } else {
            DeployFileCommand command = new DeployFileCommand(ctx, REPLACE_OPTION);
            command.allServerGroups = allServerGroups;
            command.disabled = disabled;
            command.enabled = enabled;
            command.file = f;
            command.replace = force;
            command.headers = headersNode;
            command.name = name;
            command.runtimeName = rtName;
            command.serverGroups = serverGroups;
            command.unmanaged = unmanaged;
            c = command;
        }
        return c.buildRequest(ctx);
    }
    if (url != null) {
        if (path != null) {
            throw new CommandFormatException("Filesystem path and --url can't be " + "used together.");
        }
        DeployUrlCommand command = new DeployUrlCommand(ctx, REPLACE_OPTION);
        command.allServerGroups = allServerGroups;
        command.disabled = disabled;
        command.enabled = enabled;
        try {
            command.deploymentUrl = new URL(url);
        } catch (MalformedURLException ex) {
            throw new CommandFormatException(ex);
        }
        command.replace = force;
        command.headers = headersNode;
        command.runtimeName = rtName;
        command.serverGroups = serverGroups;
        return command.buildRequest(ctx);
    }
    throw new CommandFormatException("Invalid Options.");
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) DMRCommand(org.wildfly.core.cli.command.DMRCommand) DeployUrlCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployUrlCommand) EnableAllCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand) CommandFormatException(org.jboss.as.cli.CommandFormatException) EnableCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.EnableCommand) DeployFileCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployFileCommand) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) DeployArchiveCommand(org.jboss.as.cli.impl.aesh.cmd.deployment.DeployArchiveCommand) ModelNode(org.jboss.dmr.ModelNode) File(java.io.File)

Example 2 with DMRCommand

use of org.wildfly.core.cli.command.DMRCommand in project wildfly-core by wildfly.

the class CommandContextImpl method buildAeshCommandRequest.

public OperationCommand.HandledRequest buildAeshCommandRequest(ParsedCommandLine parsedCmd, boolean batchMode) throws CommandFormatException {
    AeshCommands.CLIExecution execution = null;
    try {
        execution = aeshCommands.newExecutions(parsedCmd).get(0);
        // We are not going to execute the command, it must be populated explicitly
        // to have options injected in Command instance.
        execution.populateCommand();
    } catch (CommandLineParserException | OptionValidatorException | IOException ex) {
        throw new CommandFormatException(ex);
    } catch (CommandNotFoundException ex) {
        throw new OperationFormatException("No command handler for '" + parsedCmd.getOperationName() + "'.");
    }
    BatchCompliantCommand bc = execution.getBatchCompliant();
    if (batchMode) {
        if (bc == null) {
            throw new OperationFormatException("The command is not allowed in a batch.");
        }
        Batch batch = getBatchManager().getActiveBatch();
        return new OperationCommand.HandledRequest(bc.buildRequest(this, batch.getAttachments()), null);
    } else {
        DMRCommand dmr = execution.getDMRCompliant();
        if (dmr == null) {
            throw new OperationFormatException("The command does not translate to an operation request.");
        }
        return new OperationCommand.HandledRequest(dmr.buildRequest(this), null);
    }
}
Also used : OptionValidatorException(org.aesh.command.validator.OptionValidatorException) CLIExecution(org.jboss.as.cli.impl.aesh.AeshCommands.CLIExecution) OperationFormatException(org.jboss.as.cli.operation.OperationFormatException) IOException(java.io.IOException) CommandLineParserException(org.aesh.command.parser.CommandLineParserException) AeshCommands(org.jboss.as.cli.impl.aesh.AeshCommands) DMRCommand(org.wildfly.core.cli.command.DMRCommand) Batch(org.jboss.as.cli.batch.Batch) CommandFormatException(org.jboss.as.cli.CommandFormatException) HandledRequest(org.jboss.as.cli.OperationCommand.HandledRequest) CommandNotFoundException(org.aesh.command.CommandNotFoundException) BatchCompliantCommand(org.wildfly.core.cli.command.BatchCompliantCommand)

Aggregations

CommandFormatException (org.jboss.as.cli.CommandFormatException)2 DMRCommand (org.wildfly.core.cli.command.DMRCommand)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CommandNotFoundException (org.aesh.command.CommandNotFoundException)1 CommandLineParserException (org.aesh.command.parser.CommandLineParserException)1 OptionValidatorException (org.aesh.command.validator.OptionValidatorException)1 HandledRequest (org.jboss.as.cli.OperationCommand.HandledRequest)1 Batch (org.jboss.as.cli.batch.Batch)1 AeshCommands (org.jboss.as.cli.impl.aesh.AeshCommands)1 CLIExecution (org.jboss.as.cli.impl.aesh.AeshCommands.CLIExecution)1 DeployArchiveCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployArchiveCommand)1 DeployFileCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployFileCommand)1 DeployUrlCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployUrlCommand)1 EnableAllCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand)1 EnableCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableCommand)1 OperationFormatException (org.jboss.as.cli.operation.OperationFormatException)1 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)1