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;
}
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);
}
}
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();
}
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;
}
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));
}
}
Aggregations