/* (non-Javadoc) * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext) */ @Override protected void doHandle(CommandContext ctx) throws CommandFormatException { BatchManager batchManager = ctx.getBatchManager(); if (!batchManager.isBatchActive()) { throw new CommandFormatException("No active batch to holdback."); } String name = null; ParsedCommandLine args = ctx.getParsedCommandLine(); if (args.hasProperties()) { name = args.getOtherProperties().get(0); } if (batchManager.isHeldback(name)) { throw new CommandFormatException( "There already is " + (name == null ? "unnamed" : "'" + name + "'") + " batch held back."); } if (!batchManager.holdbackActiveBatch(name)) { throw new CommandFormatException("Failed to holdback the batch."); } }
@Test @InSequence(1) public void testModClusterAdd() throws Exception { final CommandContext ctx = CLITestUtil.getCommandContext(); final ModelControllerClient controllerClient = managementClient.getControllerClient(); try { ctx.connectController(); // Add the mod_cluster extension first (not in this profile by default) ModelNode request = ctx.buildRequest("/extension=org.wildfly.extension.mod_cluster:add"); ModelNode response = controllerClient.execute(request); String outcome = response.get("outcome").asString(); Assert.assertEquals( "Adding mod_cluster extension failed! " + request.toJSONString(false), "success", outcome); // Now lets execute subsystem add operation but we need to specify a connector ctx.getBatchManager().activateNewBatch(); Batch b = ctx.getBatchManager().getActiveBatch(); b.add( ctx.toBatchedCommand( "/socket-binding-group=standard-sockets/socket-binding=mod_cluster:add(multicast-port=23364, multicast-address=224.0.1.105)")); b.add(ctx.toBatchedCommand("/subsystem=modcluster:add")); b.add( ctx.toBatchedCommand( "/subsystem=modcluster/mod-cluster-config=configuration:add(connector=http,advertise-socket=mod_cluster)")); request = b.toRequest(); b.clear(); ctx.getBatchManager().discardActiveBatch(); response = controllerClient.execute(request); outcome = response.get("outcome").asString(); Assert.assertEquals( "Adding mod_cluster subsystem failed! " + request.toJSONString(false), "success", outcome); } finally { ctx.terminateSession(); } }
/* (non-Javadoc) * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext) */ @Override protected void doHandle(CommandContext ctx) throws CommandLineException { boolean failed = false; try { super.doHandle(ctx); ctx.printLine("The batch executed successfully"); } catch (CommandLineException e) { failed = true; throw e; } finally { if (!failed) { ctx.getBatchManager().discardActiveBatch(); } } }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { final BatchManager batchManager = ctx.getBatchManager(); if (!batchManager.isBatchActive()) { throw new CommandFormatException("No active batch."); } final Batch batch = batchManager.getActiveBatch(); List<BatchedCommand> currentBatch = batch.getCommands(); if (currentBatch.isEmpty()) { batchManager.discardActiveBatch(); throw new CommandFormatException("The batch is empty."); } return batch.toRequest(); }
/* (non-Javadoc) * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext) */ @Override protected void doHandle(CommandContext ctx) throws CommandLineException { String argsStr = ctx.getArgumentsString(); if (argsStr == null) { throw new CommandFormatException("The command is missing arguments."); } final BatchManager batchManager = ctx.getBatchManager(); if (batchManager.isBatchActive()) { throw new CommandFormatException("if is not allowed while in batch mode."); } final ParsedCommandLine args = ctx.getParsedCommandLine(); final String conditionStr = this.condition.getValue(args, true); int i = argsStr.indexOf(conditionStr); if (i < 0) { throw new CommandFormatException( "Failed to locate '" + conditionStr + "' in '" + argsStr + "'"); } i = argsStr.indexOf("of", i + conditionStr.length()); if (i < 0) { throw new CommandFormatException("Failed to locate 'of' in '" + argsStr + "'"); } final String line = argsStr.substring(i + 2); try { IfElseBlock.create(ctx).setCondition(conditionStr, ctx.buildRequest(line)); } catch (CommandLineException e) { IfElseBlock.remove(ctx); throw e; } if (!batchManager.activateNewBatch()) { IfElseBlock.remove(ctx); // that's more like illegal state throw new CommandFormatException("Failed to activate batch mode for if."); } }