From 1e6e271e520066d84098d09250e4d9178c7dfd0b Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Mon, 6 Feb 2012 17:46:16 +0100 Subject: [PATCH] AS7-3409 more precise results for deployment-info command --- cli/src/main/java/org/jboss/as/cli/Util.java | 2 + .../cli/handlers/DeploymentInfoHandler.java | 198 +++++++++++------- .../main/resources/help/deployment-info.txt | 18 +- 3 files changed, 145 insertions(+), 73 deletions(-) diff --git a/cli/src/main/java/org/jboss/as/cli/Util.java b/cli/src/main/java/org/jboss/as/cli/Util.java index 5b6e6dc359dc..dd0296e1190d 100644 --- a/cli/src/main/java/org/jboss/as/cli/Util.java +++ b/cli/src/main/java/org/jboss/as/cli/Util.java @@ -54,6 +54,7 @@ public class Util { public static final String DEPLOYMENT = "deployment"; public static final String DESCRIPTION = "description"; public static final String DOMAIN_FAILURE_DESCRIPTION = "domain-failure-description"; + public static final String DOMAIN_RESULTS = "domain-results"; public static final String ENABLED = "enabled"; public static final String EXPRESSIONS_ALLOWED = "expressions-allowed"; public static final String FAILURE_DESCRIPTION = "failure-description"; @@ -76,6 +77,7 @@ public class Util { public static final String OPERATION_HEADERS = "operation-headers"; public static final String OUTCOME = "outcome"; public static final String PROFILE = "profile"; + public static final String PERSISTENT = "persistent"; public static final String READ_ATTRIBUTE = "read-attribute"; public static final String READ_CHILDREN_NAMES = "read-children-names"; public static final String READ_CHILDREN_TYPES = "read-children-types"; diff --git a/cli/src/main/java/org/jboss/as/cli/handlers/DeploymentInfoHandler.java b/cli/src/main/java/org/jboss/as/cli/handlers/DeploymentInfoHandler.java index 6596d20bb8af..fa3d23fde6ea 100644 --- a/cli/src/main/java/org/jboss/as/cli/handlers/DeploymentInfoHandler.java +++ b/cli/src/main/java/org/jboss/as/cli/handlers/DeploymentInfoHandler.java @@ -21,7 +21,10 @@ */ package org.jboss.as.cli.handlers; +import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import org.jboss.as.cli.CommandContext; @@ -33,6 +36,7 @@ import org.jboss.as.cli.operation.ParsedCommandLine; import org.jboss.as.cli.util.SimpleTable; import org.jboss.as.cli.util.StrictSizeTable; +import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; @@ -44,7 +48,8 @@ public class DeploymentInfoHandler extends BaseOperationCommand { private final ArgumentWithValue name; - private List serverGroups; + private List addedServerGroups; + private List otherServerGroups; public DeploymentInfoHandler(CommandContext ctx) { super(ctx, "deployment-info", true); @@ -68,6 +73,74 @@ public ModelNode buildRequest(CommandContext ctx) throws CommandFormatException final ModelNode request = new ModelNode(); if(ctx.isDomainMode()) { + final List serverGroups = Util.getServerGroups(ctx.getModelControllerClient()); + addedServerGroups = null; + otherServerGroups = null; + { + final ModelNode validateRequest = new ModelNode(); + validateRequest.get(Util.OPERATION).set(Util.COMPOSITE); + validateRequest.get(Util.ADDRESS).setEmptyList(); + final ModelNode steps = validateRequest.get(Util.STEPS); + for(String serverGroup : serverGroups) { + final ModelNode step = new ModelNode(); + step.get(Util.ADDRESS).setEmptyList(); + step.get(Util.OPERATION).set(Util.VALIDATE_ADDRESS); + final ModelNode value = step.get(Util.VALUE); + value.add(Util.SERVER_GROUP, serverGroup); + value.add(Util.DEPLOYMENT, deploymentName); + steps.add(step); + } + final ModelControllerClient client = ctx.getModelControllerClient(); + final ModelNode response; + try { + response = client.execute(validateRequest); + } catch (IOException e) { + throw new CommandFormatException("Failed to query server groups for deployment " + deploymentName, e); + } + + if(!response.hasDefined(Util.RESULT)) { + throw new CommandFormatException("The validation response came back w/o result: " + response); + } + ModelNode result = response.get(Util.RESULT); +// if(!result.hasDefined(Util.DOMAIN_RESULTS)) { +// throw new CommandFormatException(Util.DOMAIN_RESULTS + " aren't available for validation request: " + result); +// } +// result = result.get(Util.DOMAIN_RESULTS); + + // TODO could be this... could be that + if(result.hasDefined(Util.DOMAIN_RESULTS)) { + result = result.get(Util.DOMAIN_RESULTS); + } + final List stepResponses = result.asPropertyList(); + for(int i = 0; i < serverGroups.size() ; ++i) { + final Property prop = stepResponses.get(i); + ModelNode 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.VALID) && stepResult.get(Util.VALID).asBoolean()) { + if(addedServerGroups == null) { + addedServerGroups = new ArrayList(); + } + addedServerGroups.add(serverGroups.get(i)); + } else { + if(otherServerGroups == null) { + otherServerGroups = new ArrayList(); + } + otherServerGroups.add(serverGroups.get(i)); + } + } else { + if(otherServerGroups == null) { + otherServerGroups = new ArrayList(); + } + otherServerGroups.add(serverGroups.get(i)); + } + } + + } + request.get(Util.OPERATION).set(Util.COMPOSITE); request.get(Util.ADDRESS).setEmptyList(); final ModelNode steps = request.get(Util.STEPS); @@ -78,28 +151,16 @@ public ModelNode buildRequest(CommandContext ctx) throws CommandFormatException step.get(Util.OPERATION).set(Util.READ_RESOURCE); steps.add(step); - serverGroups = Util.getServerGroups(ctx.getModelControllerClient()); - for(String serverGroup : serverGroups) { -/* // this was supposed to be a read-resource on deployment - // but if the deployment isn't added to a server-group - // it will fail the whole composite op and will not return the desired info in the response - readResource = new ModelNode(); - address = readResource.get(Util.ADDRESS); - address.add(Util.SERVER_GROUP, serverGroup); - readResource.get(Util.OPERATION).set(Util.READ_CHILDREN_NAMES); - readResource.get(Util.CHILD_TYPE).set(Util.DEPLOYMENT); - steps.add(readResource); -*/ - step = new ModelNode(); - step.get(Util.ADDRESS).setEmptyList(); - step.get(Util.OPERATION).set(Util.VALIDATE_ADDRESS); - final ModelNode value = step.get(Util.VALUE); - value.add(Util.SERVER_GROUP, serverGroup); - value.add(Util.DEPLOYMENT, deploymentName); - steps.add(step); + if(addedServerGroups != null) { + for(String serverGroup : addedServerGroups) { + step = new ModelNode(); + address = step.get(Util.ADDRESS); + address.add(Util.SERVER_GROUP, serverGroup); + address.add(Util.DEPLOYMENT, deploymentName); + step.get(Util.OPERATION).set(Util.READ_RESOURCE); + steps.add(step); + } } - -// request.get(Util.OPERATION_HEADERS, Util.ROLLBACK_ON_RUNTIME_FAILURE).set(false); } else { final ModelNode address = request.get(Util.ADDRESS); address.add(Util.DEPLOYMENT, deploymentName); @@ -116,17 +177,29 @@ protected void handleResponse(CommandContext ctx, ModelNode response, boolean co ctx.error("The operation response came back w/o result: " + response); return; } - final ModelNode result = response.get(Util.RESULT); + ModelNode result = response.get(Util.RESULT); if(ctx.isDomainMode()) { - final List steps = result.asPropertyList(); - if(steps.isEmpty()) { - ctx.error("Response for the main resource info of the deployment is missing."); +// if(!result.hasDefined(Util.DOMAIN_RESULTS)) { +// ctx.error(Util.DOMAIN_RESULTS + " aren't available " + result); +// return; +// } + // TODO it could be... could be not... + if(result.hasDefined(Util.DOMAIN_RESULTS)) { + result = result.get(Util.DOMAIN_RESULTS); + } + + final Iterator steps = result.asPropertyList().iterator(); + if(!steps.hasNext()) { + ctx.error("Response for the main resource info of the deployment is missing: " + result); return; } // /deployment= - ModelNode step = steps.get(0).getValue(); + 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)) { ctx.error("Failed to read the main resource info of the deployment: " + Util.getFailureDescription(step)); return; @@ -137,53 +210,36 @@ protected void handleResponse(CommandContext ctx, ModelNode response, boolean co table.addCell(Util.RUNTIME_NAME, stepResponse.get(Util.RUNTIME_NAME).asString()); ctx.printLine(table.toString()); - if(serverGroups == null) { - ctx.error("Server group list is lost."); - return; - } - if(serverGroups.size() != steps.size() - 1) { - ctx.error("Expected results for " + serverGroups.size() + " server groups but received " + (steps.size() - 1)); - return; - } + final SimpleTable groups = new SimpleTable(new String[]{"SERVER GROUP", "STATE"}); + if(addedServerGroups == null) { + if(steps.hasNext()) { + ctx.error("Didn't expect results for server groups but received " + (result.asPropertyList().size() - 1) + " more steps."); + return; + } + } 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()); + } - //final String deploymentName = name.getValue(ctx.getParsedCommandLine()); - final SimpleTable groups = new SimpleTable(new String[]{"SERVER GROUP", "ENABLED"}); - for(int i = 1; i < steps.size(); ++i) { - stepResponse = steps.get(i).getValue(); -/* - String enabled = "no"; - if(stepResponse.hasDefined(Util.RESULT)) { - final ModelNode stepResult = stepResponse.get(Util.RESULT); - if(stepResult.has(Util.ENABLED)) { - if(stepResult.get(Util.ENABLED).asBoolean()) { - enabled = "yes"; + 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"}); } } - groups.addLine(new String[]{serverGroups.get(i - 1), enabled}); -*/ - /* - // not nice - // this is just a check whether the deployment is present - // but it's not checking whether the deployment is enabled - // if the cli was used to deploy/undeploy then the presence means it's enabled - // but there could be other tools too... - if(Util.listContains(stepResponse, deploymentName)) { - groups.addLine(new String[]{serverGroups.get(i - 1), "yes"}); - } else { - groups.addLine(new String[]{serverGroups.get(i - 1), "no"}); - } - */ + } - if(stepResponse.hasDefined(Util.RESULT)) { - final ModelNode stepResult = stepResponse.get(Util.RESULT); - if(stepResult.hasDefined(Util.VALID)) { - groups.addLine(new String[]{serverGroups.get(i - 1), stepResult.get(Util.VALID).asString()}); - } else { - groups.addLine(new String[]{serverGroups.get(i - 1), "n/a"}); - } - } else { - groups.addLine(new String[]{serverGroups.get(i - 1), "no response"}); + if(otherServerGroups != null) { + for(String sg : otherServerGroups) { + groups.addLine(new String[]{sg, "not added"}); } } ctx.printLine(groups.toString(true)); @@ -191,12 +247,14 @@ protected void handleResponse(CommandContext ctx, ModelNode response, boolean co final StrictSizeTable table = new StrictSizeTable(1); table.addCell(Util.NAME, result.get(Util.NAME).asString()); table.addCell(Util.RUNTIME_NAME, result.get(Util.RUNTIME_NAME).asString()); + table.addCell(Util.PERSISTENT, result.get(Util.PERSISTENT).asString()); table.addCell(Util.ENABLED, result.get(Util.ENABLED).asString()); table.addCell(Util.STATUS, result.get(Util.STATUS).asString()); ctx.printLine(table.toString()); } } finally { - serverGroups = null; + addedServerGroups = null; + otherServerGroups = null; } } } diff --git a/cli/src/main/resources/help/deployment-info.txt b/cli/src/main/resources/help/deployment-info.txt index 63f448300aff..d7b499ad0ff8 100644 --- a/cli/src/main/resources/help/deployment-info.txt +++ b/cli/src/main/resources/help/deployment-info.txt @@ -17,7 +17,13 @@ DESCRIPTION 'runtime-name' (e.g. two versions of \"foo.war\") both available in the deployment content repository, in which case the deployments would need to have distinct 'name' values but would have the same 'runtime-name'. - + + - PERSISTENT - indicates whether the existence of the deployment should be recorded + in the persistent server configuration. Only relevant to a standalone + mode server. Default is 'true'. A deployment managed by a deployment scanner + would have this set to 'false' to ensure the deployment is only deployed + at server start if the scanner again detects the deployment. + - ENABLED - boolean indicating whether the deployment content is currently deployed in the runtime (or should be deployed in the runtime the next time the server starts.) @@ -27,8 +33,14 @@ DESCRIPTION STOPPED indicates that the deployment was manually stopped. In the domain mode, the name and the runtime name (as in the standalone mode) are followed - by a table with headers SERVER-GROUP and ENABLED (STATUS is not available), i.e. - the value of ENABLED is displayed per server group. + by a table with headers SERVER-GROUP and STATE, the STATE could contain the following values: + + added - the deployment has been added to the server group but it's not enabled; + enabled - the deployment has been added and enabled for the server group + (this is the expected state of a deployment when it is deployed to + a server group with the CLI deploy command); + not added - the server group is not referencing the deployment. + ARGUMENTS