use of org.jboss.as.cli.operation.ParsedCommandLine 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;
}
use of org.jboss.as.cli.operation.ParsedCommandLine 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));
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class VariablesTestCase method testEscapingVariableName.
@Test
public void testEscapingVariableName() throws Exception {
final ParsedCommandLine parsed = parse("set v=\\$" + OP_VAR_NAME);
assertEquals("set", parsed.getOperationName());
final List<String> props = parsed.getOtherProperties();
assertEquals(1, props.size());
assertEquals("v=\\$" + OP_VAR_NAME, props.get(0));
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class VariablesTestCase method testCommandArgumentNameAndValue.
@Test
public void testCommandArgumentNameAndValue() throws Exception {
final ParsedCommandLine parsed = parse("command-name --$" + OP_PROP_VAR_NAME + "=$" + OP_PROP_VAR_NAME);
assertEquals("command-name", parsed.getOperationName());
// variables unlike system properties are always resolved
assertEquals(parsed.getPropertyValue("--" + OP_PROP_VAR_VALUE), OP_PROP_VAR_VALUE);
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class VariablesTestCase method testNodeType.
@Test
public void testNodeType() throws Exception {
final ParsedCommandLine parsed = parse("/$" + NODE_TYPE_VAR_NAME + "=test:op");
final OperationRequestAddress address = parsed.getAddress();
assertNotNull(address);
assertEquals(NODE_TYPE_VAR_VALUE, address.getNodeType());
assertEquals("test", address.getNodeName());
}
Aggregations