use of org.jboss.as.cli.util.StrictSizeTable in project wildfly-core by wildfly.
the class InfoCommand method handleResponse.
public void handleResponse(CommandContext ctx, ModelNode response) throws CommandFormatException {
try {
if (!response.hasDefined(Util.RESULT)) {
throw new CommandFormatException("The operation response came back " + "w/o result: " + response);
}
ModelNode result = response.get(Util.RESULT);
if (ctx.isDomainMode()) {
// TODO it could be... could be not...
if (result.hasDefined(Util.DOMAIN_RESULTS)) {
result = result.get(Util.DOMAIN_RESULTS);
}
final Iterator<Property> steps = result.asPropertyList().iterator();
if (!steps.hasNext()) {
throw new CommandFormatException("Response for the main resource " + "info of the deployment is missing: " + result);
}
// /deployment=<name>
ModelNode step = steps.next().getValue();
if (step.has(Util.STEP_1)) {
// TODO remove when the structure is consistent
step = step.get(Util.STEP_1);
}
if (!step.has(Util.RESULT)) {
throw new CommandFormatException("Failed to read the main resource " + "info of the deployment: " + Util.getFailureDescription(step));
}
ModelNode stepResponse = step.get(Util.RESULT);
if (serverGroup != null) {
step = result.get(Util.STEP_1);
if (!step.isDefined()) {
throw new CommandFormatException("No step outcome for deployment " + "resources (step-1): " + result);
}
final ModelNode allDeployments = step.get(Util.RESULT);
if (!allDeployments.isDefined()) {
throw new CommandFormatException("No result for deployment " + "resources (step-1): " + result);
}
step = result.get(Util.STEP_2);
if (!step.isDefined()) {
throw new CommandFormatException("No step outcome for " + "server-group deployment resources (step-2): " + result);
}
final ModelNode sgDeployments = step.get(Util.RESULT);
if (!sgDeployments.isDefined()) {
throw new CommandFormatException("No result for server-group " + "deployment resources (step-2): " + result);
}
final String deploymentName = getName();
final Pattern pattern = Pattern.compile(Util.wildcardToJavaRegex(deploymentName == null ? "*" : deploymentName));
final SimpleTable table = new SimpleTable(new String[] { NAME, RUNTIME_NAME, STATE }, ctx.getTerminalWidth());
for (String name : allDeployments.keys()) {
if (!pattern.matcher(name).matches()) {
continue;
}
if (sgDeployments.hasDefined(name)) {
final ModelNode node = sgDeployments.get(name);
table.addLine(new String[] { node.get(Util.NAME).asString(), node.get(Util.RUNTIME_NAME).asString(), node.get(Util.ENABLED).asBoolean() ? Util.ENABLED : ADDED });
} else {
final ModelNode resource = allDeployments.get(name);
table.addLine(new String[] { resource.get(Util.NAME).asString(), resource.get(Util.RUNTIME_NAME).asString(), NOT_ADDED });
}
}
if (!table.isEmpty()) {
ctx.printLine(table.toString(true));
}
} else {
final StrictSizeTable table = new StrictSizeTable(1);
table.addCell(Util.NAME, stepResponse.get(Util.NAME).asString());
table.addCell(Util.RUNTIME_NAME, stepResponse.get(Util.RUNTIME_NAME).asString());
ctx.printLine(table.toString());
final SimpleTable groups = new SimpleTable(new String[] { SERVER_GROUP, STATE }, ctx.getTerminalWidth());
if (addedServerGroups == null) {
if (steps.hasNext()) {
throw new CommandFormatException("Didn't expect results " + "for server groups but received " + (result.asPropertyList().size() - 1) + " more steps.");
}
} else {
for (String sg : addedServerGroups) {
final Property prop = steps.next();
stepResponse = prop.getValue();
if (stepResponse.has(prop.getName())) {
// TODO remove when the structure is consistent
stepResponse = stepResponse.get(prop.getName());
}
if (stepResponse.hasDefined(Util.RESULT)) {
final ModelNode stepResult = stepResponse.get(Util.RESULT);
if (stepResult.hasDefined(Util.ENABLED)) {
groups.addLine(new String[] { sg, stepResult.get(Util.ENABLED).asBoolean() ? Util.ENABLED : ADDED });
} else {
groups.addLine(new String[] { sg, N_A });
}
} else {
groups.addLine(new String[] { sg, "no response" });
}
}
}
if (otherServerGroups != null) {
for (String sg : otherServerGroups) {
groups.addLine(new String[] { sg, NOT_ADDED });
}
}
ctx.printLine(groups.toString(true));
}
} else {
final SimpleTable table = new SimpleTable(new String[] { NAME, RUNTIME_NAME, PERSISTENT, ENABLED, STATUS }, ctx.getTerminalWidth());
final String deploymentName = getName();
if (deploymentName == null || deploymentName.indexOf('*') >= 0) {
final List<Property> list = result.asPropertyList();
if (!list.isEmpty()) {
final Pattern pattern = Pattern.compile(Util.wildcardToJavaRegex(deploymentName == null ? "*" : deploymentName));
for (Property p : list) {
final ModelNode node = p.getValue();
final String name = node.get(Util.NAME).asString();
if (pattern.matcher(name).matches()) {
table.addLine(new String[] { name, node.get(Util.RUNTIME_NAME).asString(), node.get(Util.PERSISTENT).asString(), node.get(Util.ENABLED).asString(), node.get(Util.STATUS).asString() });
}
}
}
} else {
table.addLine(new String[] { result.get(Util.NAME).asString(), result.get(Util.RUNTIME_NAME).asString(), result.get(Util.PERSISTENT).asString(), result.get(Util.ENABLED).asString(), result.get(Util.STATUS).asString() });
}
if (!table.isEmpty()) {
ctx.printLine(table.toString());
}
}
} finally {
addedServerGroups = null;
otherServerGroups = null;
}
}
use of org.jboss.as.cli.util.StrictSizeTable in project wildfly-core by wildfly.
the class ListCommand method listDeployments.
public static void listDeployments(CommandContext ctx, boolean l) throws CommandException {
if (!l) {
printList(ctx, Util.getDeployments(ctx.getModelControllerClient()), l);
return;
}
final ModelControllerClient client = ctx.getModelControllerClient();
final List<String> names = Util.getDeployments(client);
if (names.isEmpty()) {
return;
}
final StrictSizeTable table = new StrictSizeTable(names.size());
final List<Property> descriptions = getDeploymentDescriptions(ctx, names).asPropertyList();
for (Property prop : descriptions) {
final ModelNode step = prop.getValue();
if (step.hasDefined(Util.RESULT)) {
final ModelNode result = step.get(Util.RESULT);
table.addCell(Util.NAME, result.get(Util.NAME).asString());
table.addCell(Util.RUNTIME_NAME, result.get(Util.RUNTIME_NAME).asString());
if (result.has(Util.ENABLED)) {
table.addCell(Util.ENABLED, result.get(Util.ENABLED).asString());
}
if (result.has(Util.PERSISTENT)) {
table.addCell(Util.PERSISTENT, result.get(Util.PERSISTENT).asString());
}
if (result.has(Util.STATUS)) {
table.addCell(Util.STATUS, result.get(Util.STATUS).asString());
}
}
if (!table.isAtLastRow()) {
table.nextRow();
}
}
ctx.printLine(table.toString());
}
use of org.jboss.as.cli.util.StrictSizeTable in project wildfly-core by wildfly.
the class DeploymentHandler method listDeployments.
protected void listDeployments(CommandContext ctx, boolean l) throws CommandFormatException {
if (!l) {
printList(ctx, Util.getDeployments(ctx.getModelControllerClient()), l);
return;
}
final ModelControllerClient client = ctx.getModelControllerClient();
final List<String> names = Util.getDeployments(client);
if (names.isEmpty()) {
return;
}
final StrictSizeTable table = new StrictSizeTable(names.size());
final List<Property> descriptions = getDeploymentDescriptions(ctx, names).asPropertyList();
for (Property prop : descriptions) {
final ModelNode step = prop.getValue();
if (step.hasDefined(Util.RESULT)) {
final ModelNode result = step.get(Util.RESULT);
table.addCell(Util.NAME, result.get(Util.NAME).asString());
table.addCell(Util.RUNTIME_NAME, result.get(Util.RUNTIME_NAME).asString());
if (result.has(Util.ENABLED)) {
table.addCell(Util.ENABLED, result.get(Util.ENABLED).asString());
}
if (result.has(Util.STATUS)) {
table.addCell(Util.STATUS, result.get(Util.STATUS).asString());
}
}
if (!table.isAtLastRow()) {
table.nextRow();
}
}
ctx.printLine(table.toString());
}
Aggregations