Package org.jboss.as.cli

Examples of org.jboss.as.cli.CommandFormatException


        }
        request.get(Util.OPERATION).set(Util.READ_OPERATION_NAMES);
        try {
            ModelNode result = ctx.getModelControllerClient().execute(request);
            if(!result.hasDefined(Util.RESULT)) {
                throw new CommandFormatException("Operation names aren't available.");
            }
            final List<String> list = Util.getList(result);
            list.removeAll(this.excludeOps);
            list.add("To read the description of a specific command execute '" + this.commandName + " command_name --help'.");
            for(String name : list) {
View Full Code Here


        request.get(Util.NAME).set(operationName);
        ModelNode result;
        try {
            result = ctx.getModelControllerClient().execute(request);
        } catch (IOException e) {
            throw new CommandFormatException("Failed to execute read-operation-description.", e);
        }
        if (!result.hasDefined(Util.RESULT)) {
            return null;
        }
        return result.get(Util.RESULT);
View Full Code Here

        ModelNode request = new ModelNode();
        ModelNode address = request.get(Util.ADDRESS);
        if(isDependsOnProfile() && ctx.isDomainMode()) {
            final String profileName = profile.getValue(ctx.getParsedCommandLine());
            if(profileName == null) {
                throw new CommandFormatException("WARNING: --profile argument is required for the complete description.");
            }
            address.add(Util.PROFILE, profileName);
        }
        for(OperationRequestAddress.Node node : getRequiredAddress()) {
            address.add(node.getType(), node.getName());
View Full Code Here

    @Override
    public void handle(CommandContext ctx) throws CommandLineException {

        ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandFormatException("You are disconnected at the moment." +
                    " Type 'connect' to connect to the server" +
                    " or 'help' for the list of supported commands.");
        }

        ModelNode request = (ModelNode) ctx.get("OP_REQ");
        if(request == null) {
            throw new CommandFormatException("Parsed request isn't available.");
        }

        validateRequest(ctx, request);

        try {
            final ModelNode result = client.execute(request);
            if(Util.isSuccess(result)) {
                ctx.printLine(result.toString());
            } else {
                throw new CommandFormatException(result.toString());
            }
        } catch(NoSuchElementException e) {
            throw new CommandFormatException("ModelNode request is incomplete: " + e.getMessage());
        } catch (CancellationException e) {
            throw new CommandFormatException("The result couldn't be retrieved (perhaps the task was cancelled: " + e.getLocalizedMessage());
        } catch (IOException e) {
            ctx.disconnectController();
            throw new CommandFormatException("Communication error: " + e.getLocalizedMessage());
        } catch (RuntimeException e) {
            throw new CommandFormatException("Failed to execute operation.", e);
        }
    }
View Full Code Here

    private void validateRequest(CommandContext ctx, ModelNode request) throws CommandFormatException {

        final ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandFormatException("No connection to the controller.");
        }

        final Set<String> keys = request.keys();

        if(!keys.contains(Util.OPERATION)) {
            throw new CommandFormatException("Request is missing the operation name.");
        }
        final String operationName = request.get(Util.OPERATION).asString();

        if(!keys.contains(Util.ADDRESS)) {
            throw new CommandFormatException("Request is missing the address part.");
        }
        final ModelNode address = request.get(Util.ADDRESS);

        if(keys.size() == 2) { // no props
            return;
        }

        final ModelNode opDescrReq = new ModelNode();
        opDescrReq.get(Util.ADDRESS).set(address);
        opDescrReq.get(Util.OPERATION).set(Util.READ_OPERATION_DESCRIPTION);
        opDescrReq.get(Util.NAME).set(operationName);

        final ModelNode outcome;
        try {
            outcome = client.execute(opDescrReq);
        } catch(Exception e) {
            throw new CommandFormatException("Failed to perform " + Util.READ_OPERATION_DESCRIPTION + " to validate the request: " + e.getLocalizedMessage());
        }
        if (!Util.isSuccess(outcome)) {
            throw new CommandFormatException("Failed to get the list of the operation properties: \"" + Util.getFailureDescription(outcome) + '\"');
        }

        if(!outcome.has(Util.RESULT)) {
            throw new CommandFormatException("Failed to perform " + Util.READ_OPERATION_DESCRIPTION + " to validate the request: result is not available.");
        }
        final ModelNode result = outcome.get(Util.RESULT);
        if(!result.hasDefined(Util.REQUEST_PROPERTIES)) {
            if(!(keys.size() == 3 && keys.contains(Util.OPERATION_HEADERS))) {
                throw new CommandFormatException("Operation '" + operationName + "' does not expect any property.");
            }
        } else {
            final Set<String> definedProps = result.get(Util.REQUEST_PROPERTIES).keys();
            if(definedProps.isEmpty()) {
                if(!(keys.size() == 3 && keys.contains(Util.OPERATION_HEADERS))) {
                    throw new CommandFormatException("Operation '" + operationName + "' does not expect any property.");
                }
            }

            int skipped = 0;
            for(String prop : keys) {
                if(skipped < 2 && (prop.equals(Util.ADDRESS) || prop.equals(Util.OPERATION))) {
                    ++skipped;
                    continue;
                }
                if(!definedProps.contains(prop)) {
                    if(!Util.OPERATION_HEADERS.equals(prop)) {
                        throw new CommandFormatException("'" + prop + "' is not found among the supported properties: " + definedProps);
                    }
                }
            }
        }
    }
View Full Code Here

            concurrent = true;
            header.groupConcurrentSeparator(ctx.getLocation());
        } else if ("NAME_VALUE_SEPARATOR".equals(id)) {
            name = buffer.length() == 0 ? null : buffer.toString().trim();
            if(name == null || name.isEmpty()) {
                throw new CommandFormatException("Property is missing name at index " + ctx.getLocation());
            }
            if(group != null) {
                group.addProperty(name, lastChunkIndex);
                group.propertyValueSeparator(ctx.getLocation());
            } else {
View Full Code Here

        if(id.equals(HeaderValueState.ID)) {
            handler.header(header);
        } else if(PropertyValueState.ID.equals(id)) {
            final String value = buffer.length() == 0 ? null : buffer.toString().trim();
            if(value == null || value.isEmpty()) {
                throw new CommandFormatException("Property '" + name + "' is missing value at index " + ctx.getLocation());
            }

            if(group == null) {
                if("id".equals(name)) {
                    header.setPlanRef(lastChunkIndex, value);
                } else {
                    header.addProperty(name, value, lastChunkIndex);
                }
            } else {
                group.addProperty(name, value, lastChunkIndex);
                if(!ctx.isEndOfContent()) {
                    group.propertySeparator(ctx.getLocation());
                }
            }
        } else if(PropertyState.ID.equals(id)) {
            if(name == null && buffer.length() > 0) {
                if(group != null) {
                    group.addProperty(buffer.toString().trim(), lastChunkIndex);
                } else {
                    header.addProperty(buffer.toString().trim(), lastChunkIndex);
                }
                buffer.setLength(0);
            } else {
                name = null;
                buffer.setLength(0);
            }
        } else if(ServerGroupNameState.ID.equals(id)) {
            final String groupName = buffer.toString().trim();
            if(groupName.isEmpty()) {
                throw new CommandFormatException("Empty group name at index " + ctx.getLocation());
            }
            group.setGroupName(groupName, lastChunkIndex);
        } else if(ServerGroupState.ID.equals(id)) {
            if(concurrent) {
                header.addConcurrentGroup(group);
View Full Code Here

        final ModelNode result;
        try {
            result = client.execute(request);
        } catch (Exception e) {
            throw new CommandFormatException("Undeploy failed: " + e.getLocalizedMessage());
        }
        if (!Util.isSuccess(result)) {
            throw new CommandFormatException("Undeploy failed: " + Util.getFailureDescription(result));
        }
    }
View Full Code Here

                } else {
                    buf.append(Util.getFailureDescription(response));
                }
                buf.append('\n');
            } catch (IOException e) {
                throw new CommandFormatException("Failed to get the AS release info: " + e.getLocalizedMessage());
            }
        }
        buf.append("JAVA_HOME: ").append(SecurityActions.getEnvironmentVariable("JAVA_HOME")).append('\n');
        buf.append("java.version: ").append(SecurityActions.getSystemProperty("java.version")).append('\n');
        buf.append("java.vm.vendor: ").append(SecurityActions.getSystemProperty("java.vm.vendor")).append('\n');
View Full Code Here

        final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine();
        final List<String> args = parsedCmd.getOtherProperties();

        if(!args.isEmpty()) {
            if(args.size() != 1) {
                throw new CommandFormatException("The command expects only one argument but got " + args);
            }
            final String arg = args.get(0);
            String portStr = null;
            int colonIndex = arg.lastIndexOf(':');
            if(colonIndex < 0) {
                // default port
                host = arg;
            } else if(colonIndex == 0) {
                // default host
                portStr = arg.substring(1).trim();
            } else {
                final boolean hasPort;
                int closeBracket = arg.lastIndexOf(']');
                if (closeBracket != -1) {
                    //possible ip v6
                    if (closeBracket > colonIndex) {
                        hasPort = false;
                    } else {
                        hasPort = true;
                    }
                } else {
                    //probably ip v4
                    hasPort = true;
                }
                if (hasPort) {
                    host = arg.substring(0, colonIndex).trim();
                    portStr = arg.substring(colonIndex + 1).trim();
                } else {
                    host = arg;
                }
            }

            if(portStr != null) {
                try {
                    port = Integer.parseInt(portStr);
                } catch(NumberFormatException e) {
                    throw new CommandFormatException("The port must be a valid non-negative integer: '" + args + "'");
                }
                if(port < 0) {
                    throw new CommandFormatException("The port must be a valid non-negative integer: '" + args + "'");
                }
            }
        }

        ctx.connectController(host, port);
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.