Search in sources :

Example 1 with PatchOperationTarget

use of org.jboss.as.patching.tool.PatchOperationTarget in project wildfly-core by wildfly.

the class AbstractDistributionCommand method execute.

@Override
public CommandResult execute(CLICommandInvocation commandInvocation) throws CommandException, InterruptedException {
    if (host != null && !commandInvocation.getCommandContext().isDomainMode()) {
        throw new CommandException("The --host option is not available in the current context. " + "Connection to the controller might be unavailable or not running in domain mode.");
    } else if (host == null && commandInvocation.getCommandContext().isDomainMode()) {
        throw new CommandException("The --host option must be used in domain mode.");
    }
    final PatchOperationTarget target = createPatchOperationTarget(commandInvocation.getCommandContext());
    final PatchOperationBuilder builder = createPatchOperationBuilder(commandInvocation.getCommandContext());
    final ModelNode response;
    try {
        response = builder.execute(target);
    } catch (Exception e) {
        throw new CommandException(action + " failed", e);
    }
    if (!Util.isSuccess(response)) {
        final ModelNode fd = response.get(ModelDescriptionConstants.FAILURE_DESCRIPTION);
        if (!fd.isDefined()) {
            throw new CommandException("Failed to apply patch: " + response.asString());
        }
        if (fd.has(Constants.CONFLICTS)) {
            final StringBuilder buf = new StringBuilder();
            buf.append(fd.get(Constants.MESSAGE).asString()).append(": ");
            final ModelNode conflicts = fd.get(Constants.CONFLICTS);
            String title = "";
            if (conflicts.has(Constants.BUNDLES)) {
                formatConflictsList(buf, conflicts, "", Constants.BUNDLES);
                title = ", ";
            }
            if (conflicts.has(Constants.MODULES)) {
                formatConflictsList(buf, conflicts, title, Constants.MODULES);
                title = ", ";
            }
            if (conflicts.has(Constants.MISC)) {
                formatConflictsList(buf, conflicts, title, Constants.MISC);
            }
            buf.append(lineSeparator).append("Use the --override-all, --override=[] or --preserve=[] arguments in order to resolve the conflict.");
            throw new CommandException(buf.toString());
        } else {
            throw new CommandException(Util.getFailureDescription(response));
        }
    }
    handleResponse(commandInvocation.getCommandContext(), response);
    return CommandResult.SUCCESS;
}
Also used : PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder) CommandException(org.aesh.command.CommandException) ModelNode(org.jboss.dmr.ModelNode) PatchOperationTarget(org.jboss.as.patching.tool.PatchOperationTarget) OptionValidatorException(org.aesh.command.validator.OptionValidatorException) CommandException(org.aesh.command.CommandException)

Example 2 with PatchOperationTarget

use of org.jboss.as.patching.tool.PatchOperationTarget in project wildfly-core by wildfly.

the class AbstractDistributionCommand method createPatchOperationTarget.

PatchOperationTarget createPatchOperationTarget(CommandContext ctx) throws CommandException {
    final PatchOperationTarget target;
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    if (ctx.getModelControllerClient() != null) {
        if (distribution != null) {
            throw new CommandException("--distribution is not allowed when connected to the controller.");
        }
        if (modulePath != null) {
            throw new CommandException("--module-path is not allowed when connected to the controller.");
        }
        if (bundlePath != null) {
            throw new CommandException("--bundle-path is not allowed when connected to the controller.");
        }
        if (ctx.isDomainMode()) {
            target = PatchOperationTarget.createHost(host, ctx.getModelControllerClient());
        } else {
            target = PatchOperationTarget.createStandalone(ctx.getModelControllerClient());
        }
    } else {
        final File root = getJBossHome();
        final List<File> modules = getFSArgument(modulePath, args, root, "modules");
        final List<File> bundles = getFSArgument(bundlePath, args, root, "bundles");
        try {
            target = PatchOperationTarget.createLocal(root, modules, bundles);
        } catch (Exception e) {
            throw new CommandException("Unable to apply patch to local JBOSS_HOME=" + root, e);
        }
    }
    return target;
}
Also used : ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) CommandException(org.aesh.command.CommandException) File(java.io.File) PatchOperationTarget(org.jboss.as.patching.tool.PatchOperationTarget) OptionValidatorException(org.aesh.command.validator.OptionValidatorException) CommandException(org.aesh.command.CommandException)

Example 3 with PatchOperationTarget

use of org.jboss.as.patching.tool.PatchOperationTarget in project wildfly-core by wildfly.

the class PatchHandler method doHandle.

@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final ParsedCommandLine parsedLine = ctx.getParsedCommandLine();
    if (host.isPresent(parsedLine) && !ctx.isDomainMode()) {
        throw new CommandFormatException("The --host option is not available in the current context. Connection to the controller might be unavailable or not running in domain mode.");
    }
    final String action = this.action.getValue(parsedLine);
    if (INSPECT.equals(action)) {
        doInspect(ctx);
        return;
    }
    final PatchOperationTarget target = createPatchOperationTarget(ctx);
    final PatchOperationBuilder builder = createPatchOperationBuilder(parsedLine);
    final ModelNode response;
    try {
        response = builder.execute(target);
    } catch (Exception e) {
        throw new CommandLineException(action + " failed", e);
    }
    if (!Util.isSuccess(response)) {
        final ModelNode fd = response.get(ModelDescriptionConstants.FAILURE_DESCRIPTION);
        if (!fd.isDefined()) {
            throw new CommandLineException("Failed to apply patch: " + response.asString());
        }
        if (fd.has(Constants.CONFLICTS)) {
            final StringBuilder buf = new StringBuilder();
            buf.append(fd.get(Constants.MESSAGE).asString()).append(": ");
            final ModelNode conflicts = fd.get(Constants.CONFLICTS);
            String title = "";
            if (conflicts.has(Constants.BUNDLES)) {
                formatConflictsList(buf, conflicts, "", Constants.BUNDLES);
                title = ", ";
            }
            if (conflicts.has(Constants.MODULES)) {
                formatConflictsList(buf, conflicts, title, Constants.MODULES);
                title = ", ";
            }
            if (conflicts.has(Constants.MISC)) {
                formatConflictsList(buf, conflicts, title, Constants.MISC);
            }
            buf.append(lineSeparator).append("Use the --override-all, --override=[] or --preserve=[] arguments in order to resolve the conflict.");
            throw new CommandLineException(buf.toString());
        } else {
            throw new CommandLineException(Util.getFailureDescription(response));
        }
    }
    if (INFO.equals(action)) {
        if (patchId.getValue(parsedLine) != null) {
            final ModelNode result = response.get(ModelDescriptionConstants.RESULT);
            if (!result.isDefined()) {
                return;
            }
            SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth());
            table.addLine(new String[] { "Patch ID:", result.get(Constants.PATCH_ID).asString() });
            table.addLine(new String[] { "Type:", result.get(Constants.TYPE).asString() });
            table.addLine(new String[] { "Identity name:", result.get(Constants.IDENTITY_NAME).asString() });
            table.addLine(new String[] { "Identity version:", result.get(Constants.IDENTITY_VERSION).asString() });
            table.addLine(new String[] { "Description:", result.get(Constants.DESCRIPTION).asString() });
            if (result.hasDefined(Constants.LINK)) {
                table.addLine(new String[] { "Link:", result.get(Constants.LINK).asString() });
            }
            ctx.printLine(table.toString(false));
            final ModelNode elements = result.get(Constants.ELEMENTS);
            if (elements.isDefined()) {
                ctx.printLine("");
                ctx.printLine("ELEMENTS");
                for (ModelNode e : elements.asList()) {
                    table = new SimpleTable(2, ctx.getTerminalWidth());
                    table.addLine(new String[] { "Patch ID:", e.get(Constants.PATCH_ID).asString() });
                    table.addLine(new String[] { "Name:", e.get(Constants.NAME).asString() });
                    table.addLine(new String[] { "Type:", e.get(Constants.TYPE).asString() });
                    table.addLine(new String[] { "Description:", e.get(Constants.DESCRIPTION).asString() });
                    ctx.printLine("");
                    ctx.printLine(table.toString(false));
                }
            }
        } else if (jsonOutput.isPresent(parsedLine)) {
            ctx.printLine(response.toJSONString(false));
        } else if (streams.isPresent(parsedLine)) {
            final List<ModelNode> list = response.get(ModelDescriptionConstants.RESULT).asList();
            if (list.size() == 1) {
                ctx.printLine(list.get(0).asString());
            } else {
                final List<String> streams = new ArrayList<String>(list.size());
                for (ModelNode stream : list) {
                    streams.add(stream.asString());
                }
                ctx.printColumns(streams);
            }
        } else {
            final ModelNode result = response.get(ModelDescriptionConstants.RESULT);
            if (!result.isDefined()) {
                return;
            }
            SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth());
            table.addLine(new String[] { "Version:", result.get(Constants.VERSION).asString() });
            addPatchesInfo(result, table);
            ctx.printLine(table.toString(false));
            if (verbose.isPresent(parsedLine)) {
                printLayerPatches(ctx, result, Constants.ADD_ON);
                printLayerPatches(ctx, result, Constants.LAYER);
            }
        }
    } else {
        ctx.printLine(response.toJSONString(false));
    }
}
Also used : SimpleTable(org.jboss.as.cli.util.SimpleTable) ArrayList(java.util.ArrayList) PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder) XMLStreamException(javax.xml.stream.XMLStreamException) ZipException(java.util.zip.ZipException) CommandFormatException(org.jboss.as.cli.CommandFormatException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ModelNode(org.jboss.dmr.ModelNode) PatchOperationTarget(org.jboss.as.patching.tool.PatchOperationTarget)

Example 4 with PatchOperationTarget

use of org.jboss.as.patching.tool.PatchOperationTarget in project wildfly-core by wildfly.

the class PatchHandler method createPatchOperationTarget.

private PatchOperationTarget createPatchOperationTarget(CommandContext ctx) throws CommandLineException {
    final PatchOperationTarget target;
    final ParsedCommandLine args = ctx.getParsedCommandLine();
    if (ctx.getModelControllerClient() != null) {
        if (distribution.isPresent(args)) {
            throw new CommandFormatException(distribution.getFullName() + " is not allowed when connected to the controller.");
        }
        if (modulePath.isPresent(args)) {
            throw new CommandFormatException(modulePath.getFullName() + " is not allowed when connected to the controller.");
        }
        if (bundlePath.isPresent(args)) {
            throw new CommandFormatException(bundlePath.getFullName() + " is not allowed when connected to the controller.");
        }
        if (ctx.isDomainMode()) {
            String hostName = host.getValue(args, true);
            target = PatchOperationTarget.createHost(hostName, ctx.getModelControllerClient());
        } else {
            target = PatchOperationTarget.createStandalone(ctx.getModelControllerClient());
        }
    } else {
        final String jbossHome = getJBossHome(args);
        final File root = new File(jbossHome);
        final List<File> modules = getFSArgument(modulePath, args, root, "modules");
        final List<File> bundles = getFSArgument(bundlePath, args, root, "bundles");
        try {
            target = PatchOperationTarget.createLocal(root, modules, bundles);
        } catch (Exception e) {
            throw new CommandLineException("Unable to apply patch to local JBOSS_HOME=" + jbossHome, e);
        }
    }
    return target;
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ZipFile(java.util.zip.ZipFile) File(java.io.File) PatchOperationTarget(org.jboss.as.patching.tool.PatchOperationTarget) XMLStreamException(javax.xml.stream.XMLStreamException) ZipException(java.util.zip.ZipException) CommandFormatException(org.jboss.as.cli.CommandFormatException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) CommandLineException(org.jboss.as.cli.CommandLineException)

Aggregations

PatchOperationTarget (org.jboss.as.patching.tool.PatchOperationTarget)4 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)3 File (java.io.File)2 IOException (java.io.IOException)2 ZipException (java.util.zip.ZipException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 CommandException (org.aesh.command.CommandException)2 OptionValidatorException (org.aesh.command.validator.OptionValidatorException)2 CommandFormatException (org.jboss.as.cli.CommandFormatException)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 PatchingException (org.jboss.as.patching.PatchingException)2 PatchOperationBuilder (org.jboss.as.patching.tool.PatchOperationBuilder)2 ModelNode (org.jboss.dmr.ModelNode)2 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1 SimpleTable (org.jboss.as.cli.util.SimpleTable)1