Search in sources :

Example 1 with EnableAllCommand

use of org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand 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 EnableAllCommand

use of org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand in project wildfly-core by wildfly.

the class DeployHandler method doHandle.

@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    ParsedCommandLine args = ctx.getParsedCommandLine();
    boolean l = this.l.isPresent(args);
    if (!args.hasProperties() || l) {
        try {
            ListCommand.listDeployments(ctx, l);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
        return;
    }
    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 CommandLineException("Filesystem path, --url or --name is " + " required.");
        }
        if (name.equals(ALL)) {
            if (force || disabled) {
                throw new CommandLineException("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;
            try {
                command.execute(ctx);
            } catch (CommandException ex) {
                throw new CommandLineException(ex.getLocalizedMessage());
            }
            return;
        } else {
            EnableCommand command = new EnableCommand(ctx);
            command.allServerGroups = allServerGroups;
            command.headers = headersNode;
            command.serverGroups = serverGroups;
            command.name = name;
            try {
                command.execute(ctx);
            } catch (CommandException ex) {
                throw new CommandLineException(ex.getLocalizedMessage());
            }
            return;
        }
    }
    if (path != null) {
        if (url != null) {
            throw new CommandLineException("Filesystem path and --url can't be used together.");
        }
        File f = new File(path);
        LegacyBridge 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;
        }
        try {
            c.execute(ctx);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
        return;
    }
    if (url != null) {
        if (path != null) {
            throw new CommandLineException("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 CommandLineException(ex);
        }
        command.replace = force;
        command.headers = headersNode;
        command.runtimeName = rtName;
        command.serverGroups = serverGroups;
        try {
            command.execute(ctx);
        } catch (CommandException ex) {
            throw new CommandLineException(ex.getLocalizedMessage());
        }
    }
}
Also used : LegacyBridge(org.jboss.as.cli.impl.aesh.cmd.LegacyBridge) MalformedURLException(java.net.MalformedURLException) CommandException(org.aesh.command.CommandException) CommandLineException(org.jboss.as.cli.CommandLineException) URL(java.net.URL) 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)

Aggregations

File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 DeployArchiveCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployArchiveCommand)2 DeployFileCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployFileCommand)2 DeployUrlCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.DeployUrlCommand)2 EnableAllCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableAllCommand)2 EnableCommand (org.jboss.as.cli.impl.aesh.cmd.deployment.EnableCommand)2 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)2 ModelNode (org.jboss.dmr.ModelNode)2 CommandException (org.aesh.command.CommandException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 LegacyBridge (org.jboss.as.cli.impl.aesh.cmd.LegacyBridge)1 DMRCommand (org.wildfly.core.cli.command.DMRCommand)1