Package org.jboss.as.cli

Examples of org.jboss.as.cli.CommandLineException


    }

    public static IfElseBlock remove(CommandContext ctx) throws CommandLineException {
        final IfElseBlock ifBlock = (IfElseBlock) ctx.remove(IF_BLOCK);
        if(ifBlock == null) {
            throw new CommandLineException("Not in an if block.");
        }
        return ifBlock;
    }
View Full Code Here


        return conditionExpression;
    }

    public void setIfRequest(ModelNode request) throws CommandLineException {
        if(request == null) {
            throw new CommandLineException("if request is null.");
        }
        if(this.ifRequest != null) {
            throw new CommandLineException("if request is already initialized: " + this.ifRequest);
        }
        this.ifRequest = request;
    }
View Full Code Here

    @Override
    public Object resolveValue(CommandContext ctx, ModelNode response) throws CommandLineException {
        final List<Operand> operands = getOperands();
        if(operands.isEmpty()) {
            throw new CommandLineException(getName() + " has no operands.");
        }
        if(operands.size() != 2) {
            throw new CommandLineException(getName() + " expects 2 operands but got " + operands.size());
        }
        final Object left = operands.get(0).resolveValue(ctx, response);
        if(left == null) {
            return false;
        }
        final Object right = operands.get(1).resolveValue(ctx, response);
        if(right == null) {
            return false;
        }
        if(!(left instanceof ModelNode) || !(right instanceof ModelNode)) {
            throw new CommandLineException("Operands aren't instances of org.jboss.dmr.ModelNode: " +
                left.getClass().getName() + ", " + right.getClass().getName());
        }
        if(((ModelNode) left).getType() != ((ModelNode)right).getType()) {
            return false;
        }
View Full Code Here

            }
            return;
        }

        if(batchManager.isBatchActive()) {
            throw new CommandLineException("Can't start a new batch while in batch mode.");
        }

        if(path != null) {
            if(name != null) {
                throw new CommandFormatException("Either --file or name argument can be specified at a time.");
            }

            final File f = new File(path);
            if(!f.exists()) {
                throw new CommandLineException("File " + f.getAbsolutePath() + " does not exist.");
            }

            final File currentDir = ctx.getCurrentDir();
            final File baseDir = f.getParentFile();
            if(baseDir != null) {
                ctx.setCurrentDir(baseDir);
            }

            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(f));
                String line = reader.readLine();
                batchManager.activateNewBatch();
                final Batch batch = batchManager.getActiveBatch();
                while(line != null) {
                    batch.add(ctx.toBatchedCommand(line));
                    line = reader.readLine();
                }
            } catch(IOException e) {
                batchManager.discardActiveBatch();
                throw new CommandLineException("Failed to read file " + f.getAbsolutePath(), e);
            } catch(CommandFormatException e) {
                batchManager.discardActiveBatch();
                throw new CommandLineException("Failed to create batch from " + f.getAbsolutePath(), e);
            } finally {
                if(baseDir != null) {
                    ctx.setCurrentDir(currentDir);
                }
                if(reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {}
                }
            }
            return;
        }

        boolean activated;
        if(batchManager.isHeldback(name)) {
            activated = batchManager.activateHeldbackBatch(name);
            if (activated) {
                final String msg = name == null ? "Re-activated batch" : "Re-activated batch '" + name + "'";
                ctx.printLine(msg);
                List<BatchedCommand> batch = batchManager.getActiveBatch().getCommands();
                if (!batch.isEmpty()) {
                    for (int i = 0; i < batch.size(); ++i) {
                        BatchedCommand cmd = batch.get(i);
                        ctx.printLine("#" + (i + 1) + ' ' + cmd.getCommand());
                    }
                }
            }
        } else if(name != null) {
            throw new CommandLineException("'" + name + "' not found among the held back batches.");
        } else {
            activated = batchManager.activateNewBatch();
        }

        if(!activated) {
            // that's more like illegal state
            throw new CommandLineException("Failed to activate batch.");
        }
    }
View Full Code Here

        final IfElseBlock ifBlock = IfElseBlock.remove(ctx);

        final BatchManager batchManager = ctx.getBatchManager();
        if(!batchManager.isBatchActive()) {
            if(ifBlock.isInIf()) {
                throw new CommandLineException("if block did not activate batch mode.");
            } else {
                throw new CommandLineException("else 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 conditionRequest = ifBlock.getConditionRequest();
        if(conditionRequest == null) {
            throw new CommandLineException("The condition request is not available.");
        }

        final Operation expression = ifBlock.getConditionExpression();
        if(expression == null) {
            throw new CommandLineException("The if expression is not available.");
        }

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

        final Object value = expression.resolveValue(ctx, targetValue);
        if(value == null) {
            throw new CommandLineException("if expression resolved to a null");
        }

        if(Boolean.TRUE.equals(value)) {
            ModelNode ifRequest = ifBlock.getIfRequest();
            if(ifRequest == null) {
                if(batch.size() == 0) {
                    throw new CommandLineException("if request is missing.");
                }
                ifRequest = batch.toRequest();
            }
            try {
                final ModelNode response = client.execute(ifRequest);
                if(!Util.isSuccess(response)) {
                    new CommandLineException("if request failed: " + Util.getFailureDescription(response));
                }
            } catch (IOException e) {
                throw new CommandLineException("if request failed", e);
            }
        } else if(ifBlock.isInElse()) {
            if(batch.size() == 0) {
                throw new CommandLineException("else block is empty.");
            }
            try {
                final ModelNode response = client.execute(batch.toRequest());
                if(!Util.isSuccess(response)) {
                    throw new CommandLineException("else request failed: " + Util.getFailureDescription(response));
                }
            } catch (IOException e) {
                throw new CommandLineException("else request failed", e);
            }
        }
    }
View Full Code Here

            op.get(Util.CHILD_TYPE).set(Util.DEPLOYMENT_OVERLAY);
            final ModelNode response;
            try {
                response = ctx.getModelControllerClient().execute(op);
            } catch (IOException e) {
                throw new CommandLineException("Failed to execute " + Util.READ_CHILDREN_NAMES, e);
            }
            final ModelNode result = response.get(Util.RESULT);
            if(!result.isDefined()) {
                final String descr = Util.getFailureDescription(response);
                if(descr != null) {
                    throw new CommandLineException(descr);
                }
                throw new CommandLineException("The response of " + Util.READ_CHILDREN_NAMES + " is missing result: " + response);
            }

            if(l.isPresent(args)) {
                for(ModelNode node : result.asList()) {
                    ctx.printLine(node.asString());
View Full Code Here

        final ParsedCommandLine args = ctx.getParsedCommandLine();

        final String name = this.name.getValue(args, true);
        if(!Util.isValidPath(ctx.getModelControllerClient(), Util.DEPLOYMENT_OVERLAY, name)) {
            throw new CommandLineException("Deployment overlay " + name + " does not exist.");
        }
        final String contentStr = content.getValue(args, true);

        final String[] contentPairs = contentStr.split(",+");
        if(contentPairs.length == 0) {
View Full Code Here

        op.get(Util.CHILD_TYPE).set(Util.CONTENT);
        final ModelNode response;
        try {
            response = client.execute(op);
        } catch (IOException e) {
            throw new CommandLineException("Failed to load the list of the existing content for overlay " + overlay, e);
        }

        final ModelNode result = response.get(Util.RESULT);
        if(!result.isDefined()) {
            throw new CommandLineException("Failed to load the list of the existing content for overlay " + overlay + ": " + response);
        }
        contentList = new ArrayList<String>();
        for(ModelNode node : result.asList()) {
            contentList.add(node.asString());
        }
View Full Code Here

        op.get(Util.CHILD_TYPE).set(Util.DEPLOYMENT);
        final ModelNode response;
        try {
            response = client.execute(op);
        } catch (IOException e) {
            throw new CommandLineException("Failed to load the list of deployments for overlay " + overlay, e);
        }

        final ModelNode result = response.get(Util.RESULT);
        if(!result.isDefined()) {
            final String descr = Util.getFailureDescription(response);
            if(descr != null && descr.contains("JBAS014807")) {
                // resource doesn't exist
                return Collections.emptyList();
            }
            throw new CommandLineException("Failed to load the list of deployments for overlay " + overlay + ": " + response);
        }
        final List<String> contentList = new ArrayList<String>();
        for(ModelNode node : result.asList()) {
            contentList.add(node.asString());
        }
View Full Code Here

        op.get(Util.CHILD_TYPE).set(Util.DEPLOYMENT);
        final ModelNode response;
        try {
            response = client.execute(op);
        } catch (IOException e) {
            throw new CommandLineException("Failed to load the list of deployments for overlay " + overlay, e);
        }

        final ModelNode result = response.get(Util.RESULT);
        if(!result.isDefined()) {
            final String descr = Util.getFailureDescription(response);
            if(descr != null && (descr.contains("JBAS014807") || descr.contains("JBAS014793"))) {
                // resource doesn't exist
                return null;
            }
            throw new CommandLineException("Failed to load the list of deployments for overlay " + overlay + ": " + response);
        }
        return result;
    }
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.