public class CommandUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
CommandUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <A extends IgniteDataTransferObject> |
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 Ignite ignite,
Class<? extends ComputeTask<VisorTaskArgument<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 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 String |
join(String delimeter,
Object... params)
Join input parameters with specified
delimeter between them. |
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 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> |
visitCommandParams(Class<A> argCls,
Consumer<Field> positionalParamVisitor,
Consumer<Field> namedParamVisitor,
BiConsumer<ArgumentGroup,List<Field>> argumentGroupVisitor)
Utility method.
|
public static final String NAME_PREFIX
public static final char CMD_WORDS_DELIM
public static final char PARAM_WORDS_DELIM
public static final String INDENT
public static final String DOUBLE_INDENT
public static String cmdText(Command<?,?> cmd)
"SystemView" -> "system-view".cmd - Command class.public static String cmdKey(Class<?> cmdCls, Class<? extends CommandsRegistry<?,?>> parent)
cmdCls - Command class.parent - Parent registry.public static String toFormattedCommandName(Class<?> cls)
"SystemView" -> "system-view".cls - Command name class.public static String toFormattedCommandName(Class<?> cls, char delim)
"SystemView" -> "system-view".cls - Command name class.public static String toFormattedFieldName(Field fld)
fld - Field.public static Set<String> toFormattedNames(Class<?> argCls, Set<String> flds)
argCls - Argument class.flds - Fields to format.public static String fromFormattedCommandName(String formatted, char delim)
"system-view" -> "SystemView".formatted - Formatted command name.delim - Words delimeter.public static String parameterExample(Field fld, boolean appendOptional)
fld - Field.appendOptional - If true then example must be marked as optional.public static String valueExample(Field fld)
fld - Fieldpublic static boolean isBoolean(Class<?> cls)
public static <T> T parseVal(String val, Class<T> type)
T - Value type.val - String value.type - Class of the value.public static <A extends IgniteDataTransferObject> void visitCommandParams(Class<A> argCls, Consumer<Field> positionalParamVisitor, Consumer<Field> namedParamVisitor, BiConsumer<ArgumentGroup,List<Field>> argumentGroupVisitor)
A - Argument type.argCls - Argument class.positionalParamVisitor - Visitor of positional parameters.namedParamVisitor - Visitor of named parameters.argumentGroupVisitor - Visitor of "one of" parameters.public static List<Set<String>> argumentGroupsValues(Class<?> cls)
ArgumentGroup.value() declared at cls.public static List<Set<String>> argumentGroupsValues(List<ArgumentGroup> argGrps)
ArgumentGroup.value() holding in argGrps.argumentGroupsValues(Class)public static int argumentGroupIdx(List<Set<String>> argGrpValues, String name)
argGrpValues containing name. -1 if not found.argumentGroupsValues(Class)public static boolean hasDescribedParameters(Command<?,?> cmd)
cmd - Command.True if command has described parameters.public static boolean hasDescription(Field fld)
True if argument has description.@Nullable public static @Nullable Collection<GridClientNode> coordinatorOrNull(Collection<GridClientNode> nodes)
nodes - Nodes.nodes are empty.@Nullable public static @Nullable Collection<GridClientNode> nodeOrNull(@Nullable @Nullable UUID nodeId, Collection<GridClientNode> nodes)
public static Collection<GridClientNode> nodeOrAll(@Nullable @Nullable UUID nodeId, Collection<GridClientNode> nodes)
public static Collection<GridClientNode> nodes(UUID[] nodeIds, Collection<GridClientNode> nodes)
public static List<GridClientNode> node(UUID nodeId, Collection<GridClientNode> nodes)
public static Collection<GridClientNode> servers(Collection<GridClientNode> nodes)
nodes - Nodes.public static boolean executable(Command<?,?> cmd)
cmd - Command.True if command can be executed, false otherwise.public static Collection<GridClientNode> nodes(@Nullable @Nullable GridClient cli, @Nullable @Nullable Ignite ignite) throws GridClientException
cli - Grid client.ignite - Ignite node.GridClientExceptionpublic static String join(String delimeter, Object... params)
delimeter between them.delimeter - Specified delimeter.params - Other input parameter.delimeter.public static SB join(SB sb, String sbDelimeter, String delimeter, Object... params)
delimeter between them and append to the end delimeter.sb - Specified string builder.sbDelimeter - Delimeter between sb and appended param.delimeter - Specified delimeter.params - Other input parameter.delimeter.public static boolean printErrors(Map<UUID,Exception> exceptions, String infoMsg, Consumer<String> printer)
exceptions - map containing node ids and exceptions.infoMsg - single message to log.printer - Printer to use.public static void printNodeError(Consumer<String> printer, UUID nodeId, @Nullable @Nullable Object consistentId, Exception err)
printer - Printer to use.nodeId - Node id.consistentId - Node consistent id.err - Exception.public static boolean experimental(Command<?,?> cmd)
public static <A extends IgniteDataTransferObject> A argument(Class<A> argCls, BiFunction<Field,Integer,Object> positionalParamProvider, Function<Field,Object> paramProvider)
A - Argument type.argCls - Argument class.positionalParamProvider - Provider of positional parameters.paramProvider - Provider of named parameters.public static <A,R> R execute(@Nullable
@Nullable GridClient cli,
@Nullable
@Nullable Ignite ignite,
Class<? extends ComputeTask<VisorTaskArgument<A>,R>> taskCls,
A arg,
Collection<GridClientNode> nodes)
throws GridClientException
GridClientExceptionpublic static GridClientNode clusterToClientNode(ClusterNode n)
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.16.0 Release Date : December 15 2023