Class CommandUtils


  • public class CommandUtils
    extends Object
    Utility class for management commands.
    • Field Detail

      • CMD_WORDS_DELIM

        public static final char CMD_WORDS_DELIM
        Delimeter for words in parameter and command names.
        See Also:
        Constant Field Values
      • PARAM_WORDS_DELIM

        public static final char PARAM_WORDS_DELIM
        Delimeter for words in positional parameters and parameter examples.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CommandUtils

        public CommandUtils()
    • Method Detail

      • cmdText

        public static String cmdText​(Command<?,​?> cmd)
        Example: "SystemView" -> "system-view".
        Parameters:
        cmd - Command class.
        Returns:
        Formatted command name.
      • cmdKey

        public static String cmdKey​(Class<?> cmdCls,
                                    Class<? extends CommandsRegistry<?,​?>> parent)
        Parameters:
        cmdCls - Command class.
        parent - Parent registry.
        Returns:
        Command key without parent prefix.
      • toFormattedCommandName

        public static String toFormattedCommandName​(Class<?> cls)
        Example: "SystemView" -> "system-view".
        Parameters:
        cls - Command name class.
        Returns:
        Formatted command name.
      • toFormattedCommandName

        public static String toFormattedCommandName​(Class<?> cls,
                                                    char delim)
        Example: "SystemView" -> "system-view".
        Parameters:
        cls - Command name class.
        Returns:
        Formatted command name.
      • toFormattedFieldName

        public static String toFormattedFieldName​(Field fld)
        Parameters:
        fld - Field.
        Returns:
        Formatted name of parameter for this field.
      • toFormattedNames

        public static Set<String> toFormattedNames​(Class<?> argCls,
                                                   Set<String> flds)
        Parameters:
        argCls - Argument class.
        flds - Fields to format.
        Returns:
        Formatted names.
      • fromFormattedCommandName

        public static String fromFormattedCommandName​(String formatted,
                                                      char delim)
        Example: "system-view" -> "SystemView".
        Parameters:
        formatted - Formatted command name.
        delim - Words delimeter.
        Returns:
        Source command name.
      • parameterExample

        public static String parameterExample​(Field fld,
                                              boolean appendOptional)
        Parameters:
        fld - Field.
        appendOptional - If true then example must be marked as optional.
        Returns:
        Example of the field.
      • valueExample

        public static String valueExample​(Field fld)
        Parameters:
        fld - Field
        Returns:
        Example of value for the field.
      • isBoolean

        public static boolean isBoolean​(Class<?> cls)
      • asOptional

        public static String asOptional​(String str,
                                        boolean optional)
      • parseVal

        public static <T> T parseVal​(String val,
                                     Class<T> type)
        Type Parameters:
        T - Value type.
        Parameters:
        val - String value.
        type - Class of the value.
        Returns:
        Value.
      • visitCommandParams

        public static <A extends IgniteDataTransferObject> void visitCommandParams​(Class<A> argCls,
                                                                                   Consumer<Field> positionalParamVisitor,
                                                                                   Consumer<Field> namedParamVisitor,
                                                                                   BiConsumer<ArgumentGroup,​List<Field>> argumentGroupVisitor)
        Utility method. Scans argument class fields and visits each field representing command argument.
        Type Parameters:
        A - Argument type.
        Parameters:
        argCls - Argument class.
        positionalParamVisitor - Visitor of positional parameters.
        namedParamVisitor - Visitor of named parameters.
        argumentGroupVisitor - Visitor of "one of" parameters.
      • hasDescribedParameters

        public static boolean hasDescribedParameters​(Command<?,​?> cmd)
        Parameters:
        cmd - Command.
        Returns:
        True if command has described parameters.
      • hasDescription

        public static boolean hasDescription​(Field fld)
        Returns:
        True if argument has description.
      • executable

        public static boolean executable​(Command<?,​?> cmd)
        Parameters:
        cmd - Command.
        Returns:
        True if command can be executed, false otherwise.
      • join

        public static String join​(String delimeter,
                                  Object... params)
        Join input parameters with specified delimeter between them.
        Parameters:
        delimeter - Specified delimeter.
        params - Other input parameter.
        Returns:
        Joined paramaters with specified delimeter.
      • join

        public static SB join​(SB sb,
                              String sbDelimeter,
                              String delimeter,
                              Object... params)
        Join input parameters with specified delimeter between them and append to the end delimeter.
        Parameters:
        sb - Specified string builder.
        sbDelimeter - Delimeter between sb and appended param.
        delimeter - Specified delimeter.
        params - Other input parameter.
        Returns:
        SB with appended to the end joined paramaters with specified delimeter.
      • printErrors

        public static boolean printErrors​(Map<UUID,​Exception> exceptions,
                                          String infoMsg,
                                          Consumer<String> printer)
        Prints exception messages to log
        Parameters:
        exceptions - map containing node ids and exceptions.
        infoMsg - single message to log.
        printer - Printer to use.
        Returns:
        true if errors were printed.
      • printNodeError

        public static void printNodeError​(Consumer<String> printer,
                                          UUID nodeId,
                                          @Nullable
                                          @Nullable Object consistentId,
                                          Exception err)
        Prints single node exception message to the log.
        Parameters:
        printer - Printer to use.
        nodeId - Node id.
        consistentId - Node consistent id.
        err - Exception.
      • experimental

        public static boolean experimental​(Command<?,​?> cmd)
      • argument

        public static <A extends IgniteDataTransferObject> A argument​(Class<A> argCls,
                                                                      BiFunction<Field,​Integer,​Object> positionalParamProvider,
                                                                      Function<Field,​Object> paramProvider)
        Fill and vaildate command argument.
        Type Parameters:
        A - Argument type.
        Parameters:
        argCls - Argument class.
        positionalParamProvider - Provider of positional parameters.
        paramProvider - Provider of named parameters.
        Returns:
        Argument filled with parameters.