Package org.jboss.as.cli

Examples of org.jboss.as.cli.CommandLineException


        final TryBlock tryBlock = TryBlock.get(ctx);

        final BatchManager batchManager = ctx.getBatchManager();
        if(!batchManager.isBatchActive()) {
            throw new CommandLineException("try block did not activate batch mode.");
        }

        final Batch tryBatch = batchManager.getActiveBatch();
        if(tryBatch.size() == 0) {
            throw new CommandLineException("try block is empty.");
        }
        tryBlock.setTryRequest(tryBatch.toRequest());
        tryBlock.setInCatch();
        batchManager.discardActiveBatch();
        batchManager.activateNewBatch();
View Full Code Here


        final TryBlock tryBlock = TryBlock.remove(ctx);

        final BatchManager batchManager = ctx.getBatchManager();
        if(!batchManager.isBatchActive()) {
            if(tryBlock.isInCatch()) {
                throw new CommandLineException("catch block did not activate batch mode.");
            } else {
                throw new CommandLineException("finally block did not activate batch mode.");
            }
        }

        final Batch batch = batchManager.getActiveBatch();
        batchManager.discardActiveBatch();

        final ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandLineException("The connection to the controller has not been established.");
        }

        final ModelNode tryRequest = tryBlock.getTryRequest();
        if(tryRequest == null) {
            throw new CommandLineException("The try request is not available.");
        }

        ModelNode response;
        try {
            response = client.execute(tryRequest);
        } catch (IOException e) {
            throw new CommandLineException("try request failed", e);
        }

        CommandLineException catchError = null;
        if(!Util.isSuccess(response)) {
            ctx.printLine("try block failed: " + Util.getFailureDescription(response));
            ModelNode catchRequest = tryBlock.getCatchRequest();
            if(catchRequest == null && tryBlock.isInCatch() && batch.size() > 0) {
                catchRequest = batch.toRequest();
            }
            if(catchRequest != null) {
                try {
                    response = client.execute(catchRequest);
                } catch (IOException e) {
                    throw new CommandLineException("catch request failed", e);
                }
                if(!Util.isSuccess(response)) {
                    catchError = new CommandLineException("catch request failed: " + Util.getFailureDescription(response));
                }
            }
        }

        if(tryBlock.isInFinally() && batch.size() > 0) {
            final ModelNode finallyRequest = batch.toRequest();
            try {
                response = client.execute(finallyRequest);
            } catch (IOException e) {
                throw new CommandLineException("finally request failed", e);
            }
            if(!Util.isSuccess(response)) {
                throw new CommandLineException("finally request failed: " + Util.getFailureDescription(response));
            }
        }

        if(catchError != null) {
            throw catchError;
View Full Code Here

     */
    @Override
    protected void doHandle(CommandContext ctx) throws CommandLineException {
        final ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandLineException("Connection is now available.");
        }
        if(!(client instanceof CLIModelControllerClient)) {
            throw new CommandLineException("Unsupported ModelControllerClient implementation " + client.getClass().getName());
        }
        final CLIModelControllerClient cliClient = (CLIModelControllerClient) client;

        final ModelNode op = this.buildRequestWithoutHeaders(ctx);
        final ModelNode response;
        try {
            response = cliClient.execute(op, true);
        } catch(IOException e) {
            ctx.disconnectController();
            throw new CommandLineException("Failed to execute :shutdown", e);
        }

        if(Util.isSuccess(response)) {
            final String restartValue = restart.getValue(ctx.getParsedCommandLine());
            if(restartValue == null || !Util.TRUE.equals(restartValue)) {
                ctx.disconnectController();
            }
        } else {
            throw new CommandLineException(Util.getFailureDescription(response));
        }
    }
View Full Code Here

    private static final String TRY_BLOCK = "TRY";

    public static TryBlock create(CommandContext ctx) throws CommandLineException {
        if(ctx.get(TRY_BLOCK) != null) {
            throw new CommandLineException("Nesting try blocks is not supported.");
        }
        final TryBlock tryBlock = new TryBlock();
        ctx.set(TRY_BLOCK, tryBlock);
        return tryBlock;
    }
View Full Code Here

    }

    public static TryBlock get(CommandContext ctx) throws CommandLineException {
        final TryBlock tryBlock = (TryBlock) ctx.get(TRY_BLOCK);
        if(tryBlock == null) {
            throw new CommandLineException("Not in a try block.");
        }
        return tryBlock;
    }
View Full Code Here

    }

    public static TryBlock remove(CommandContext ctx) throws CommandLineException {
        final TryBlock tryBlock = (TryBlock) ctx.remove(TRY_BLOCK);
        if(tryBlock == null) {
            throw new CommandLineException("Not in a try block.");
        }
        return tryBlock;
    }
View Full Code Here

        return tryRequest;
    }

    public void setTryRequest(ModelNode tryRequest) throws CommandLineException {
        if(catchRequest != null) {
            throw new CommandLineException("Only one catch is allowed.");
        }
        if(this.tryRequest != null) {
            throw new CommandLineException("try request is already initialized.");
        }
        this.tryRequest = tryRequest;
    }
View Full Code Here

        return catchRequest;
    }

    public void setCatchRequest(ModelNode catchRequest) throws CommandLineException {
        if(this.catchRequest != null) {
            throw new CommandLineException("catch request is already initialized.");
        }
        this.catchRequest = catchRequest;
    }
View Full Code Here

            return;
        }
*/
        final ModelNode result = getOperationDescription(ctx, operationName);
        if(!result.hasDefined(Util.DESCRIPTION)) {
            throw new CommandLineException("Operation description is not available.");
        }

        ctx.printLine("\nDESCRIPTION:\n");
        formatText(ctx, result.get(Util.DESCRIPTION).asString(), 2);

View Full Code Here

        request.get(Util.OPERATION).set(Util.READ_OPERATION_NAMES);
        ModelNode result;
        try {
            result = ctx.getModelControllerClient().execute(request);
        } catch (IOException e) {
            throw new CommandLineException("Failed to load a list of commands.", e);
        }
        if (!result.hasDefined(Util.RESULT)) {
            throw new CommandLineException("Operation names aren't available.");
        }
        final List<ModelNode> nodeList = result.get(Util.RESULT).asList();
        final List<String> supportedCommands = new ArrayList<String>(nodeList.size());
        if(!nodeList.isEmpty()) {
            for(ModelNode node : nodeList) {
View Full Code Here

TOP

Related Classes of org.jboss.as.cli.CommandLineException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.