@Override protected void doHandle(CommandContext ctx) { ModelControllerClient client = ctx.getModelControllerClient(); ParsedArguments args = ctx.getParsedArguments(); boolean l = this.l.isPresent(args); if (!args.hasArguments() || l) { printList(ctx, Util.getDeployments(client), l); return; } final String name = this.name.getValue(ctx.getParsedArguments()); if (name == null) { printList(ctx, Util.getDeployments(client), l); return; } DefaultOperationRequestBuilder builder; // undeploy builder = new DefaultOperationRequestBuilder(); builder.setOperationName("undeploy"); builder.addNode("deployment", name); ModelNode result; try { ModelNode request = builder.buildRequest(); result = client.execute(request); } catch (Exception e) { ctx.printLine("Failed to undeploy: " + e.getLocalizedMessage()); return; } // TODO undeploy may fail if the content failed to deploy but remove should still be executed if (!Util.isSuccess(result)) { ctx.printLine("Undeploy failed: " + Util.getFailureDescription(result)); return; } // remove builder = new DefaultOperationRequestBuilder(); builder.setOperationName("remove"); builder.addNode("deployment", name); try { ModelNode request = builder.buildRequest(); result = client.execute(request); } catch (Exception e) { ctx.printLine( "Failed to remove the deployment content from the repository: " + e.getLocalizedMessage()); return; } if (!Util.isSuccess(result)) { ctx.printLine("Remove failed: " + Util.getFailureDescription(result)); return; } ctx.printLine("Successfully undeployed " + name + "."); }
@Override public ModelNode buildRequest(CommandContext ctx) throws OperationFormatException { ModelNode composite = new ModelNode(); composite.get("operation").set("composite"); composite.get("address").setEmptyList(); ModelNode steps = composite.get("steps"); final String name = this.name.getValue(ctx.getParsedArguments()); if (name == null) { throw new OperationFormatException("Required argument name are missing."); } DefaultOperationRequestBuilder builder; // undeploy builder = new DefaultOperationRequestBuilder(); builder.setOperationName("undeploy"); builder.addNode("deployment", name); steps.add(builder.buildRequest()); builder = new DefaultOperationRequestBuilder(); builder.setOperationName("remove"); builder.addNode("deployment", name); steps.add(builder.buildRequest()); return composite; }
@Override public ModelNode buildRequest(CommandContext ctx) throws OperationFormatException { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); ParsedArguments args = ctx.getParsedArguments(); if (ctx.isDomainMode()) { String profile = this.profile.getValue(args); if (profile == null) { throw new OperationFormatException("--profile argument value is missing."); } builder.addNode("profile", profile); } final String name; try { name = this.name.getValue(args); } catch (IllegalArgumentException e) { throw new OperationFormatException(e.getLocalizedMessage()); } builder.addNode("subsystem", "jms"); builder.addNode("queue", name); builder.setOperationName("add"); ModelNode entriesNode = builder.getModelNode().get("entries"); final String entriesStr = this.entries.getValue(args); if (entriesStr == null) { entriesNode.add(name); } else { String[] split = entriesStr.split(","); for (int i = 0; i < split.length; ++i) { String entry = split[i].trim(); if (!entry.isEmpty()) { entriesNode.add(entry); } } } final String selector = this.selector.getValue(args); if (selector != null) { builder.addProperty("selector", selector); } final String durable = this.durable.getValue(args); if (durable != null) { builder.addProperty("durable", durable); } return builder.buildRequest(); }
/* (non-Javadoc) * @see org.jboss.as.cli.CommandHandler#handle(org.jboss.as.cli.CommandContext) */ @Override public void handle(CommandContext ctx) throws CommandFormatException { if (helpArg.isPresent(ctx.getParsedArguments())) { printHelp(ctx); return; } if (!isAvailable(ctx)) { ctx.printLine( "The command is not available in the current context (e.g. required subsystems or connection to the controller might be unavailable)."); return; } doHandle(ctx); }
@Override protected void doHandle(CommandContext ctx) { ParsedArguments args = ctx.getParsedArguments(); if (!args.hasArguments()) { printHistory(ctx); return; } if (clear.isPresent(args)) { ctx.getHistory().clear(); } else if (disable.isPresent(args)) { ctx.getHistory().setUseHistory(false); } else if (enable.isPresent(args)) { ctx.getHistory().setUseHistory(true); } else { ctx.printLine("Unexpected argument '" + ctx.getArgumentsString() + '\''); } }