Search in sources :

Example 6 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class IfElseControlFlow method executeBlock.

private void executeBlock(CommandContext ctx, List<String> block, String blockName) throws CommandLineException {
    if (block != null && !block.isEmpty()) {
        final BatchManager batchManager = ctx.getBatchManager();
        // this is to discard a batch started by the block in case the block fails
        // as the cli remains in the batch mode in case run-batch resulted in an error
        final boolean discardActivatedBatch = !batchManager.isBatchActive();
        try {
            for (String l : block) {
                ctx.handle(l);
            }
        } finally {
            if (discardActivatedBatch && batchManager.isBatchActive()) {
                batchManager.discardActiveBatch();
            }
        }
    }
}
Also used : BatchManager(org.jboss.as.cli.batch.BatchManager)

Example 7 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class TryHandler method doHandle.

/* (non-Javadoc)
     * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
     */
@Override
protected void doHandle(CommandContext ctx) throws CommandLineException {
    final BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
        throw new CommandFormatException("try is not allowed while in batch mode.");
    }
    ctx.registerRedirection(new TryCatchFinallyControlFlow(ctx));
}
Also used : CommandFormatException(org.jboss.as.cli.CommandFormatException) BatchManager(org.jboss.as.cli.batch.BatchManager)

Example 8 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class DeployArchiveCommand method activateNewBatch.

static String activateNewBatch(CommandContext ctx) {
    String currentBatch = null;
    BatchManager batchManager = ctx.getBatchManager();
    Attachments attachments = null;
    if (batchManager.isBatchActive()) {
        Batch current = batchManager.getActiveBatch();
        attachments = current.getAttachments();
        currentBatch = "batch" + System.currentTimeMillis();
        batchManager.holdbackActiveBatch(currentBatch);
    }
    batchManager.activateNewBatch();
    Batch archiveBatch = batchManager.getActiveBatch();
    // computation.
    if (attachments != null) {
        for (String f : attachments.getAttachedFiles()) {
            archiveBatch.getAttachments().addFileAttachment(f);
        }
    }
    return currentBatch;
}
Also used : Batch(org.jboss.as.cli.batch.Batch) BatchManager(org.jboss.as.cli.batch.BatchManager) Attachments(org.jboss.as.cli.Attachments)

Example 9 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class ArchiveHandler method discardBatch.

private void discardBatch(CommandContext ctx, String holdbackBatch) {
    BatchManager batchManager = ctx.getBatchManager();
    batchManager.discardActiveBatch();
    if (holdbackBatch != null) {
        batchManager.activateHeldbackBatch(holdbackBatch);
    }
}
Also used : BatchManager(org.jboss.as.cli.batch.BatchManager)

Example 10 with BatchManager

use of org.jboss.as.cli.batch.BatchManager in project wildfly-core by wildfly.

the class ArchiveHandler method activateNewBatch.

private String activateNewBatch(CommandContext ctx) {
    String currentBatch = null;
    BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
        currentBatch = "batch" + System.currentTimeMillis();
        batchManager.holdbackActiveBatch(currentBatch);
    }
    batchManager.activateNewBatch();
    return currentBatch;
}
Also used : BatchManager(org.jboss.as.cli.batch.BatchManager)

Aggregations

BatchManager (org.jboss.as.cli.batch.BatchManager)18 CommandFormatException (org.jboss.as.cli.CommandFormatException)10 Batch (org.jboss.as.cli.batch.Batch)7 BatchedCommand (org.jboss.as.cli.batch.BatchedCommand)4 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 Attachments (org.jboss.as.cli.Attachments)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 ArrayList (java.util.ArrayList)1 ModelNode (org.jboss.dmr.ModelNode)1