use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class GenericTypeOperationHandler method printHelp.
@Override
protected void printHelp(CommandContext ctx) throws CommandLineException {
ParsedCommandLine args = ctx.getParsedCommandLine();
if (helpProperties.isPresent(args)) {
printProperties(ctx, getNodeProperties(ctx));
return;
}
if (helpCommands.isPresent(args)) {
printSupportedCommands(ctx);
return;
}
final String operationName = operation.getValue(args);
if (operationName == null) {
printNodeDescription(ctx);
return;
}
/* if(customHandlers != null && customHandlers.containsKey(operationName)) {
OperationCommand operationCommand = customHandlers.get(operationName);
operationCommand.handle(ctx);
return;
}
*/
final ModelNode result = getOperationDescription(ctx, operationName);
if (!result.hasDefined(Util.DESCRIPTION)) {
throw new CommandLineException("Operation description is not available.");
}
ctx.printLine("\nDESCRIPTION:\n");
formatText(ctx, result.get(Util.DESCRIPTION).asString(), 2);
if (result.hasDefined(Util.REQUEST_PROPERTIES)) {
printProperties(ctx, getAttributeIterator(result.get(Util.REQUEST_PROPERTIES).asPropertyList(), null));
} else {
printProperties(ctx, Collections.<AttributeDescription>emptyIterator());
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class DeploymentOverlayHandler method redeployAffected.
protected ModelNode redeployAffected(CommandContext ctx) throws CommandLineException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
assertNotPresent(serverGroups, args);
assertNotPresent(allServerGroups, args);
assertNotPresent(allRelevantServerGroups, args);
assertNotPresent(content, args);
assertNotPresent(deployments, args);
assertNotPresent(redeployAffected, args);
final String overlay = getName(ctx, false);
final ModelNode redeployOp = new ModelNode();
redeployOp.get(Util.OPERATION).set(Util.COMPOSITE);
redeployOp.get(Util.ADDRESS).setEmptyList();
final ModelNode steps = redeployOp.get(Util.STEPS);
// In domain and standalone, this operation redeploy them all.
addRedeployStep(overlay, steps);
if (!steps.isDefined() || steps.asList().isEmpty()) {
throw new CommandFormatException("None of the deployments affected.");
}
return redeployOp;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class DeploymentOverlayHandler method getName.
/**
* Validate that the overlay exists. If it doesn't exist, throws an
* exception if not in batch mode or if failInBatch is true. In batch mode,
* we could be in the case that the overlay doesn't exist yet.
*/
private String getName(CommandContext ctx, boolean failInBatch) throws CommandLineException {
final ParsedCommandLine args = ctx.getParsedCommandLine();
final String name = this.name.getValue(args, true);
if (name == null) {
throw new CommandFormatException(this.name + " is missing value.");
}
if (!ctx.isBatchMode() || failInBatch) {
if (!Util.isValidPath(ctx.getModelControllerClient(), Util.DEPLOYMENT_OVERLAY, name)) {
throw new CommandFormatException("Deployment overlay " + name + " does not exist.");
}
}
return name;
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class DeploymentOverlayHandler method listLinks.
protected void listLinks(CommandContext ctx) throws CommandLineException {
final ModelControllerClient client = ctx.getModelControllerClient();
final ParsedCommandLine args = ctx.getParsedCommandLine();
assertNotPresent(allRelevantServerGroups, args);
assertNotPresent(content, args);
assertNotPresent(deployments, args);
assertNotPresent(redeployAffected, args);
final String name = getName(ctx, true);
final String sg = serverGroups.getValue(ctx.getParsedCommandLine());
if (ctx.isDomainMode()) {
final List<String> groups;
if (sg == null) {
// throw new CommandFormatException(serverGroups.getFullName() + " is missing value.");
groups = Util.getServerGroups(client);
} else {
groups = Arrays.asList(sg.split(",+"));
}
if (groups.isEmpty()) {
throw new CommandFormatException(serverGroups.getFullName() + " is missing value.");
}
for (String group : groups) {
final List<String> links = loadLinks(client, name, group);
if (!links.isEmpty()) {
ctx.printLine("SERVER GROUP: " + group + Util.LINE_SEPARATOR);
ctx.printColumns(links);
ctx.printLine("");
}
}
} else {
final List<String> content = loadLinks(client, name, sg);
if (l.isPresent(args)) {
for (String contentPath : content) {
ctx.printLine(contentPath);
}
} else {
ctx.printColumns(content);
}
}
}
use of org.jboss.as.cli.operation.ParsedCommandLine in project wildfly-core by wildfly.
the class DeploymentOverlayHandler method remove.
protected ModelNode remove(CommandContext ctx) throws CommandLineException {
final ModelControllerClient client = ctx.getModelControllerClient();
final ParsedCommandLine args = ctx.getParsedCommandLine();
assertNotPresent(allServerGroups, args);
final String name = getName(ctx, false);
final String contentStr = content.getValue(args);
String deploymentStr = deployments.getValue(args);
final String sgStr = serverGroups.getValue(args);
final List<String> sg;
if (sgStr == null) {
if (allRelevantServerGroups.isPresent(args)) {
sg = Util.getServerGroupsReferencingOverlay(name, client);
} else {
sg = null;
}
} else {
sg = Arrays.asList(sgStr.split(",+"));
if (sg.isEmpty()) {
throw new CommandFormatException(serverGroups.getFullName() + " is missing value.");
}
}
final ModelNode composite = new ModelNode();
composite.get(Util.OPERATION).set(Util.COMPOSITE);
composite.get(Util.ADDRESS).setEmptyList();
final ModelNode steps = composite.get(Util.STEPS);
boolean redeploy = this.redeployAffected.isPresent(args);
if (!redeployAffected.isPresent(args)) {
printWarning(ctx, client, name, contentStr, deploymentStr);
}
// If no serverGroup provided in domainMode, remove also overlay in root.
if (contentStr == null && deploymentStr == null) {
if (ctx.isDomainMode()) {
final List<String> groups = sg == null ? Util.getServerGroupsReferencingOverlay(name, client) : sg;
for (String group : groups) {
if (redeploy) {
List<String> links = loadLinks(client, name, group);
for (String link : links) {
addRemoveDeploymentStep(name, group, redeploy, link, steps);
}
}
addRemoveOverlayStep(name, group, steps);
}
// Remove the root if no sgroup provided
if (sg == null) {
addRemoveOverlayStep(name, null, steps);
}
} else {
if (redeploy) {
List<String> links = loadLinks(client, name, null);
for (String link : links) {
addRemoveDeploymentStep(name, null, redeploy, link, steps);
}
}
addRemoveOverlayStep(name, null, steps);
}
return composite;
}
boolean redeployAll = false;
// 2) Remove some content.
if (contentStr != null) {
// If redeploy required, must redeploy them all.
redeployAll = redeploy && true;
final List<String> contentList;
contentList = java.util.Arrays.asList(contentStr.split(",+"));
for (String content : contentList) {
final ModelNode op = new ModelNode();
ModelNode addr = op.get(Util.ADDRESS);
addr.add(Util.DEPLOYMENT_OVERLAY, name);
addr.add(Util.CONTENT, content);
op.get(Util.OPERATION).set(Util.REMOVE);
steps.add(op);
}
}
// remove operation
if (deploymentStr != null) {
final List<String> links = Arrays.asList(deploymentStr.split(",+"));
if (ctx.isDomainMode()) {
if (sg == null) {
throw new CommandFormatException(serverGroups.getFullName() + " or " + allRelevantServerGroups.getFullName() + " is required.");
}
for (String group : sg) {
for (String link : links) {
addRemoveDeploymentStep(name, group, redeploy, link, steps);
}
}
} else {
for (String link : links) {
addRemoveDeploymentStep(name, null, redeploy, link, steps);
}
}
}
// Finally redeploy still referenced links.
if (redeployAll) {
// In domain and standalone, this operation redeploy them all.
addRedeployStep(name, steps);
}
return composite;
}
Aggregations