Package org.apache.ignite.internal.management.api

## Class CommandUtils

- java.lang.Object
- - org.apache.ignite.internal.management.api.CommandUtils

    public class CommandUtils
    extends Object

Utility class for management commands.

### Field Summary

Fields
`static char` `CMD_WORDS_DELIM` Delimeter for words in parameter and command names.
`static String` `DOUBLE_INDENT` Double indent for help output.
`static String` `INDENT` Indent for help output.
`static String` `NAME_PREFIX` CLI named parameter prefix.
`static char` `PARAM_WORDS_DELIM` Delimeter for words in positional parameters and parameter examples.

### Constructor Summary

Constructors
`CommandUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static <A extends IgniteDataTransferObject> A` `argument​(Class<A> argCls, BiFunction<Field,​Integer,​Object> positionalParamProvider, Function<Field,​Object> paramProvider)` Fill and vaildate command argument.
`static int` `argumentGroupIdx​(List<Set<String>> argGrpValues, String name)`
`static List<Set<String>>` `argumentGroupsValues​(Class<?> cls)`
`static List<Set<String>>` `argumentGroupsValues​(List<ArgumentGroup> argGrps)`
`static String` `asOptional​(String str, boolean optional)`
`static GridClientNode` `clusterToClientNode​(ClusterNode n)`
`static String` `cmdKey​(Class<?> cmdCls, Class<? extends CommandsRegistry<?,​?>> parent)`
`static String` `cmdText​(Command<?,​?> cmd)` Example: `"SystemView" -> "system-view"`.
`static @Nullable Collection<GridClientNode>` `coordinatorOrNull​(Collection<GridClientNode> nodes)`
`static boolean` `executable​(Command<?,​?> cmd)`
`static <A,​R> R` `execute​(@Nullable GridClient cli, @Nullable IgniteClient client, @Nullable Ignite ignite, Class<? extends VisorMultiNodeTask<A,​R,​?>> taskCls, A arg, Collection<GridClientNode> nodes)`
`static boolean` `experimental​(Command<?,​?> cmd)`
`static String` `fromFormattedCommandName​(String formatted, char delim)` Example: `"system-view" -> "SystemView"`.
`static boolean` `hasDescribedParameters​(Command<?,​?> cmd)`
`static boolean` `hasDescription​(Field fld)`
`static boolean` `isBoolean​(Class<?> cls)`
`static String` `join​(String delimeter, Object... params)` Join input parameters with specified `delimeter` between them.
`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`.
`static List<GridClientNode>` `node​(UUID nodeId, Collection<GridClientNode> nodes)`
`static Collection<GridClientNode>` `nodeOrAll​(@Nullable UUID nodeId, Collection<GridClientNode> nodes)`
`static @Nullable Collection<GridClientNode>` `nodeOrNull​(@Nullable UUID nodeId, Collection<GridClientNode> nodes)`
`static Collection<GridClientNode>` `nodes​(@Nullable GridClient cli, @Nullable IgniteClient client, @Nullable Ignite ignite)`
`static Collection<GridClientNode>` `nodes​(UUID[] nodeIds, Collection<GridClientNode> nodes)`
`static String` `parameterExample​(Field fld, boolean appendOptional)`
`static <T> T` `parseVal​(String val, Class<T> type)`
`static boolean` `printErrors​(Map<UUID,​Exception> exceptions, String infoMsg, Consumer<String> printer)` Prints exception messages to log
`static void` `printNodeError​(Consumer<String> printer, UUID nodeId, @Nullable Object consistentId, Exception err)` Prints single node exception message to the log.
`static Collection<GridClientNode>` `servers​(Collection<GridClientNode> nodes)`
`static String` `toFormattedCommandName​(Class<?> cls)` Example: `"SystemView" -> "system-view"`.
`static String` `toFormattedCommandName​(Class<?> cls, char delim)` Example: `"SystemView" -> "system-view"`.
`static String` `toFormattedFieldName​(Field fld)`
`static Set<String>` `toFormattedNames​(Class<?> argCls, Set<String> flds)`
`static String` `valueExample​(Field fld)`
`static <A extends IgniteDataTransferObject> void` `visitCommandParams​(Class<A> argCls, Consumer<Field> positionalParamVisitor, Consumer<Field> namedParamVisitor, BiConsumer<ArgumentGroup,​List<Field>> argumentGroupVisitor)` Utility method.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NAME_PREFIX

    public static final String NAME_PREFIX

CLI named parameter prefix.

See Also:
  Constant Field Values

#### 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

#### INDENT

    public static final String INDENT

Indent for help output.

See Also:
  Constant Field Values

#### DOUBLE_INDENT

    public static final String DOUBLE_INDENT

Double indent for help output.

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.

#### argumentGroupsValues

    public static List<Set<String>> argumentGroupsValues​(Class<?> cls)

Returns:
  Sets list of `ArgumentGroup.value()` declared at `cls`.

#### argumentGroupsValues

    public static List<Set<String>> argumentGroupsValues​(List<ArgumentGroup> argGrps)

Returns:
  Sets list of `ArgumentGroup.value()` holding in `argGrps`.
See Also:
  `argumentGroupsValues(Class)`

#### argumentGroupIdx

    public static int argumentGroupIdx​(List<Set<String>> argGrpValues,
                                       String name)

Returns:
  Index of first value set in `argGrpValues` containing `name`. -1 if not found.
See Also:
  `argumentGroupsValues(Class)`

#### 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.

#### coordinatorOrNull

    @Nullable
    public static @Nullable Collection<GridClientNode> coordinatorOrNull​(Collection<GridClientNode> nodes)

Parameters:
  `nodes` - Nodes.
Returns:
  Coordinator ID or null is `nodes` are empty.

#### nodeOrNull

    @Nullable
    public static @Nullable Collection<GridClientNode> nodeOrNull​(@Nullable
                                                                  @Nullable UUID nodeId,
                                                                  Collection<GridClientNode> nodes)

#### nodeOrAll

    public static Collection<GridClientNode> nodeOrAll​(@Nullable
                                                       @Nullable UUID nodeId,
                                                       Collection<GridClientNode> nodes)

#### nodes

    public static Collection<GridClientNode> nodes​(UUID[] nodeIds,
                                                   Collection<GridClientNode> nodes)

#### node

    public static List<GridClientNode> node​(UUID nodeId,
                                            Collection<GridClientNode> nodes)

#### servers

    public static Collection<GridClientNode> servers​(Collection<GridClientNode> nodes)

Parameters:
  `nodes` - Nodes.
Returns:
  Server nodes.

#### executable

    public static boolean executable​(Command<?,​?> cmd)

Parameters:
  `cmd` - Command.
Returns:
  `True` if command can be executed, `false` otherwise.

#### nodes

    public static Collection<GridClientNode> nodes​(@Nullable
                                                   @Nullable GridClient cli,
                                                   @Nullable
                                                   @Nullable IgniteClient client,
                                                   @Nullable
                                                   @Nullable Ignite ignite)
                                            throws GridClientException

Parameters:
  `cli` - Grid client.
  `ignite` - Ignite node.
Returns:
  Collection of cluster nodes.
Throws:
  `GridClientException`

#### 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.

#### execute

    public static <A,​R> R execute​(@Nullable
                                        @Nullable GridClient cli,
                                        @Nullable
                                        @Nullable IgniteClient client,
                                        @Nullable
                                        @Nullable Ignite ignite,
                                        Class<? extends VisorMultiNodeTask<A,​R,​?>> taskCls,
                                        A arg,
                                        Collection<GridClientNode> nodes)
                                 throws Exception

Throws:
  `Exception`

#### clusterToClientNode

    public static GridClientNode clusterToClientNode​(ClusterNode n)