Package org.jboss.as.cli

Examples of org.jboss.as.cli.CommandFormatException


     * @see org.jboss.as.cli.operation.OperationRequestHeader#toModelNode()
     */
    @Override
    public void addTo(CommandContext ctx, ModelNode headers) throws CommandFormatException {
        if(name == null) {
            throw new CommandFormatException("Header name is null.");
        }
        if(value == null) {
            throw new CommandFormatException("Value for header '" + name + "' is null.");
        }
        headers.get(name).set(value);
    }
View Full Code Here


     */
    @Override
    protected void doHandle(CommandContext ctx) throws CommandFormatException {
        String argsStr = ctx.getArgumentsString();
        if(argsStr == null) {
            throw new CommandFormatException("Missing the command or operation to translate to DMR.");
        }
        ctx.printLine(ctx.buildRequest(argsStr).toString());
    }
View Full Code Here

        } else if(disable.isPresent(args)) {
            ctx.getHistory().setUseHistory(false);
        } else if(enable.isPresent(args)) {
            ctx.getHistory().setUseHistory(true);
        } else {
            throw new CommandFormatException("Unexpected argument '" + ctx.getArgumentsString() + '\'');
        }
    }
View Full Code Here

        ModelNode outcome;
        try {
            outcome = ctx.getModelControllerClient().execute(composite);
        } catch (IOException e) {
            throw new CommandFormatException("Failed to read resource: "
                    + e.getLocalizedMessage(), e);
        }

        if (Util.isSuccess(outcome)) {
            if (outcome.hasDefined(Util.RESULT)) {
                ModelNode resultNode = outcome.get(Util.RESULT);

                ModelNode attrDescriptions = null;
                ModelNode childDescriptions = null;
                if (resultNode.hasDefined(Util.STEP_3)) {
                    final ModelNode stepOutcome = resultNode.get(Util.STEP_3);
                    if (Util.isSuccess(stepOutcome)) {
                        if (stepOutcome.hasDefined(Util.RESULT)) {
                            final ModelNode descrResult = stepOutcome.get(Util.RESULT);
                            if (descrResult.hasDefined(Util.ATTRIBUTES)) {
                                attrDescriptions = descrResult.get(Util.ATTRIBUTES);
                            }
                            if (descrResult.hasDefined(Util.CHILDREN)) {
                                childDescriptions = descrResult.get(Util.CHILDREN);
                            }
                        } else {
                            throw new CommandFormatException("Result is not available for read-resource-description request: " + outcome);
                        }
                    } else {
                        throw new CommandFormatException("Failed to get resource description: " + outcome);
                    }
                }

                List<String> typeNames = null;
                if (resultNode.hasDefined(Util.STEP_1)) {
                    ModelNode typesOutcome = resultNode.get(Util.STEP_1);
                    if (Util.isSuccess(typesOutcome)) {
                        if (typesOutcome.hasDefined(Util.RESULT)) {
                            final ModelNode resourceResult = typesOutcome.get(Util.RESULT);
                            final List<ModelNode> types = resourceResult.asList();
                            if (!types.isEmpty()) {
                                typeNames = new ArrayList<String>();
                                for (ModelNode type : types) {
                                    typeNames.add(type.asString());
                                }
                                if (childDescriptions == null && attrDescriptions == null) {
                                    names = typeNames;
                                }
                            }
                        } else {
                            throw new CommandFormatException("Result is not available for read-children-types request: " + outcome);
                        }
                    } else {
                        throw new CommandFormatException("Failed to fetch type names: " + outcome);
                    }
                } else {
                    throw new CommandFormatException("The result for children type names is not available: " + outcome);
                }

                if (resultNode.hasDefined(Util.STEP_2)) {
                    ModelNode resourceOutcome = resultNode.get(Util.STEP_2);
                    if (Util.isSuccess(resourceOutcome)) {
                        if (resourceOutcome.hasDefined(Util.RESULT)) {
                            final ModelNode resourceResult = resourceOutcome.get(Util.RESULT);
                            final List<Property> props = resourceResult.asPropertyList();
                            if (!props.isEmpty()) {
                                final SimpleTable attrTable;
                                if (attrDescriptions == null) {
                                    attrTable = null;
                                } else {
                                    if (additionalProps != null) {
                                        String[] headers = new String[3 + additionalProps.length];
                                        headers[0] = "ATTRIBUTE";
                                        headers[1] = "VALUE";
                                        headers[2] = "TYPE";
                                        int i = 3;
                                        for (String additional : additionalProps) {
                                            headers[i++] = additional.toUpperCase();
                                        }
                                        attrTable = new SimpleTable(headers);
                                    } else {
                                        attrTable = new SimpleTable(new String[] { "ATTRIBUTE", "VALUE", "TYPE" });
                                    }
                                }
                                SimpleTable childrenTable = childDescriptions == null ? null : new SimpleTable(new String[] { "CHILD", "MIN-OCCURS", "MAX-OCCURS" });
                                if (typeNames == null && attrTable == null && childrenTable == null) {
                                    typeNames = new ArrayList<String>();
                                }

                                for (Property prop : props) {
                                    final StringBuilder buf = new StringBuilder();
                                    if (typeNames == null || !typeNames.contains(prop.getName())) {
                                        if (attrDescriptions == null) {
                                            buf.append(prop.getName());
                                            buf.append('=');
                                            buf.append(prop.getValue().asString());
                                            // TODO the value should be formatted nicer but the current
                                            // formatter uses new lines for complex value which doesn't work here
                                            // final ModelNode value = prop.getValue();
                                            // ModelNodeFormatter.Factory.forType(value.getType()).format(buf, 0, value);
                                            typeNames.add(buf.toString());
                                            buf.setLength(0);
                                        } else {
                                            final String[] line = new String[attrTable.columnsTotal()];
                                            line[0] = prop.getName();
                                            line[1] = prop.getValue().asString();
                                            if (attrDescriptions.hasDefined(prop.getName())) {
                                                final ModelNode attrDescr = attrDescriptions.get(prop.getName());
                                                line[2] = getAsString(attrDescr, Util.TYPE);
                                                if (additionalProps != null) {
                                                    int i = 3;
                                                    for (String additional : additionalProps) {
                                                        line[i++] = getAsString(attrDescr, additional);
                                                    }
                                                }
                                            } else {
                                                for (int i = 2; i < line.length; ++i) {
                                                    line[i] = "n/a";
                                                }
                                            }
                                            attrTable.addLine(line);
                                        }
                                    } else if (childDescriptions != null) {
                                        if (childDescriptions.hasDefined(prop.getName())) {
                                            final ModelNode childDescr = childDescriptions.get(prop.getName());
                                            final Integer maxOccurs = getAsInteger(childDescr, Util.MAX_OCCURS);
                                            childrenTable.addLine(new String[] {prop.getName(), getAsString(childDescr, Util.MIN_OCCURS), maxOccurs == null ? "n/a"
                                                                    : (maxOccurs == Integer.MAX_VALUE ? "unbounded" : maxOccurs.toString()) });
                                        } else {
                                            childrenTable.addLine(new String[] {prop.getName(), "n/a", "n/a" });
                                        }
                                    }
                                }

                                StringBuilder buf = null;
                                if (attrTable != null && !attrTable.isEmpty()) {
                                    buf = new StringBuilder();
                                    attrTable.append(buf, true);
                                }
                                if (childrenTable != null
                                        && !childrenTable.isEmpty()) {
                                    if (buf == null) {
                                        buf = new StringBuilder();
                                    } else {
                                        buf.append("\n\n");
                                    }
                                    childrenTable.append(buf, true);
                                }
                                if (buf != null) {
                                    ctx.printLine(buf.toString());
                                }
                            }
                        } else {
                            throw new CommandFormatException("Result is not available for read-resource request: " + outcome);
                        }
                    } else {
                        throw new CommandFormatException("Failed to fetch attributes: " + outcome);
                    }
                } else {
                    throw new CommandFormatException("The result for attributes is not available: " + outcome);
                }
            }
        } else {
            throw new CommandFormatException("Failed to fetch the list of children: " + outcome);
        }

        if(names != null) {
            printList(ctx, names, l.isPresent(parsedCmd));
        }
View Full Code Here

    @Override
    protected void handleResponse(CommandContext ctx, ModelNode opResponse, boolean composite) throws CommandFormatException {
        //System.out.println(opResponse);
        if (!Util.isSuccess(opResponse)) {
            throw new CommandFormatException(Util.getFailureDescription(opResponse));
        }
        final StringBuilder buf = formatResponse(ctx, opResponse, composite, null);
        if(buf != null) {
            ctx.printLine(buf.toString());
        }
View Full Code Here

        if(composite) {
            final Set<String> keys;
            try {
                keys = result.keys();
            } catch(Exception e) {
                throw new CommandFormatException("Failed to get step results from a composite operation response " + opResponse);
            }
            for(String key : keys) {
                final ModelNode stepResponse = result.get(key);
                buf = formatResponse(ctx, stepResponse, false, buf); // TODO nested composite ops aren't expected for now
            }
View Full Code Here

                continue;
            }

            final ArgumentWithValue arg = (ArgumentWithValue) nodeProps.get(argName);
            if(arg == null) {
                throw new CommandFormatException("Unrecognized argument name '" + argName + "'");
            }

            DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
            if (profile != null) {
                builder.addNode(Util.PROFILE, profile);
View Full Code Here

            if(argsMap == null) {
                if(argName.equals(this.name.getFullName())) {
                    continue;
                }
                throw new CommandFormatException("Command '" + operation + "' is not expected to have arguments other than " + this.name.getFullName() + ".");
            }

            final ArgumentWithValue arg = (ArgumentWithValue) argsMap.get(argName);
            if(arg == null) {
                if(argName.equals(this.name.getFullName())) {
                    continue;
                }
                throw new CommandFormatException("Unrecognized argument " + argName + " for command '" + operation + "'.");
            }

            final String propName;
            if(argName.charAt(1) == '-') {
                propName = argName.substring(2);
View Full Code Here

        }

        try {
            ModelNode result = getOperationDescription(ctx, operationName);
            if(!result.hasDefined(Util.DESCRIPTION)) {
                throw new CommandFormatException("Operation description is not available.");
            }

            final StringBuilder buf = new StringBuilder();
            buf.append("\nDESCRIPTION:\n\n");
            buf.append(result.get(Util.DESCRIPTION).asString());
View Full Code Here

            request.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
            ModelNode result = null;
            try {
                result = ctx.getModelControllerClient().execute(request);
                if(!result.hasDefined(Util.RESULT)) {
                    throw new CommandFormatException("Node description is not available.");
                }
                result = result.get(Util.RESULT);
                if(!result.hasDefined(Util.DESCRIPTION)) {
                    throw new CommandFormatException("Node description is not available.");
                }
            } catch (Exception e) {
            }

            if(result != null) {
View Full Code Here

TOP

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

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.