Search in sources :

Example 1 with PatchOperationBuilder

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

the class PatchRollback method createUnconfiguredOperationBuilder.

@Override
protected PatchOperationBuilder createUnconfiguredOperationBuilder(CommandContext ctx) throws CommandException {
    PatchOperationBuilder builder;
    String patchId = getPatchId();
    if (patchId != null) {
        builder = PatchOperationBuilder.Factory.rollback(patchStream, patchId, rollbackTo, resetConfiguration);
    } else {
        builder = PatchOperationBuilder.Factory.rollbackLast(patchStream, resetConfiguration);
    }
    return builder;
}
Also used : PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder)

Example 2 with PatchOperationBuilder

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

the class PatchRollbackActivator method getAllPatches.

private static List<ModelNode> getAllPatches(PatchOperationTarget target, String stream) throws PatchingException {
    if (stream == null) {
        PatchOperationBuilder streams = PatchOperationBuilder.Factory.streams();
        // retrieve all streams.
        ModelNode response = streams.execute(target);
        final ModelNode result = response.get(ModelDescriptionConstants.RESULT);
        if (!result.isDefined()) {
            return Collections.emptyList();
        }
        // retrieve patches in stream.
        List<ModelNode> patches = new ArrayList<>();
        List<ModelNode> list = response.get(ModelDescriptionConstants.RESULT).asList();
        for (ModelNode s : list) {
            patches.addAll(getPatches(target, s.asString()));
        }
        return patches;
    } else {
        return getPatches(target, stream);
    }
}
Also used : ArrayList(java.util.ArrayList) PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder) ModelNode(org.jboss.dmr.ModelNode)

Example 3 with PatchOperationBuilder

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

the class PatchRollbackActivator method getPatches.

private static List<ModelNode> getPatches(PatchOperationTarget target, String stream) throws PatchingException {
    PatchOperationBuilder history = PatchOperationBuilder.Factory.history(stream);
    ModelNode resp = history.execute(target);
    ModelNode res = resp.get(ModelDescriptionConstants.RESULT);
    return res.asList();
}
Also used : PatchOperationBuilder(org.jboss.as.patching.tool.PatchOperationBuilder) ModelNode(org.jboss.dmr.ModelNode)

Example 4 with PatchOperationBuilder

use of org.jboss.as.patching.tool.PatchOperationBuilder 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 5 with PatchOperationBuilder

use of org.jboss.as.patching.tool.PatchOperationBuilder 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)

Aggregations

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