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 Modifier and Type Field Description static charCMD_WORDS_DELIMDelimeter for words in parameter and command names.static StringDOUBLE_INDENTDouble indent for help output.static StringINDENTIndent for help output.static StringNAME_PREFIXCLI named parameter prefix.static charPARAM_WORDS_DELIMDelimeter for words in positional parameters and parameter examples.
-
Constructor Summary
Constructors Constructor Description CommandUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A extends IgniteDataTransferObject>
Aargument(Class<A> argCls, BiFunction<Field,Integer,Object> positionalParamProvider, Function<Field,Object> paramProvider)Fill and vaildate command argument.static intargumentGroupIdx(List<Set<String>> argGrpValues, String name)static List<Set<String>>argumentGroupsValues(Class<?> cls)static List<Set<String>>argumentGroupsValues(List<ArgumentGroup> argGrps)static StringasOptional(String str, boolean optional)static GridClientNodeclusterToClientNode(ClusterNode n)static StringcmdKey(Class<?> cmdCls, Class<? extends CommandsRegistry<?,?>> parent)static StringcmdText(Command<?,?> cmd)Example:"SystemView" -> "system-view".static @Nullable Collection<GridClientNode>coordinatorOrNull(Collection<GridClientNode> nodes)static booleanexecutable(Command<?,?> cmd)static <A,R>
Rexecute(@Nullable GridClient cli, @Nullable IgniteClient client, @Nullable Ignite ignite, Class<? extends VisorMultiNodeTask<A,R,?>> taskCls, A arg, Collection<GridClientNode> nodes)static booleanexperimental(Command<?,?> cmd)static StringfromFormattedCommandName(String formatted, char delim)Example:"system-view" -> "SystemView".static booleanhasDescribedParameters(Command<?,?> cmd)static booleanhasDescription(Field fld)static booleanisBoolean(Class<?> cls)static Stringjoin(String delimeter, Object... params)Join input parameters with specifieddelimeterbetween them.static SBjoin(SB sb, String sbDelimeter, String delimeter, Object... params)Join input parameters with specifieddelimeterbetween them and append to the enddelimeter.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 StringparameterExample(Field fld, boolean appendOptional)static <T> TparseVal(String val, Class<T> type)static booleanprintErrors(Map<UUID,Exception> exceptions, String infoMsg, Consumer<String> printer)Prints exception messages to logstatic voidprintNodeError(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 StringtoFormattedCommandName(Class<?> cls)Example:"SystemView" -> "system-view".static StringtoFormattedCommandName(Class<?> cls, char delim)Example:"SystemView" -> "system-view".static StringtoFormattedFieldName(Field fld)static Set<String>toFormattedNames(Class<?> argCls, Set<String> flds)static StringvalueExample(Field fld)static <A extends IgniteDataTransferObject>
voidvisitCommandParams(Class<A> argCls, Consumer<Field> positionalParamVisitor, Consumer<Field> namedParamVisitor, BiConsumer<ArgumentGroup,List<Field>> argumentGroupVisitor)Utility method.
-
-
-
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
-
-
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- Iftruethen 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)
-
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 atcls.
-
argumentGroupsValues
public static List<Set<String>> argumentGroupsValues(List<ArgumentGroup> argGrps)
- Returns:
- Sets list of
ArgumentGroup.value()holding inargGrps. - See Also:
argumentGroupsValues(Class)
-
argumentGroupIdx
public static int argumentGroupIdx(List<Set<String>> argGrpValues, String name)
- Returns:
- Index of first value set in
argGrpValuescontainingname. -1 if not found. - See Also:
argumentGroupsValues(Class)
-
hasDescribedParameters
public static boolean hasDescribedParameters(Command<?,?> cmd)
- Parameters:
cmd- Command.- Returns:
Trueif command has described parameters.
-
hasDescription
public static boolean hasDescription(Field fld)
- Returns:
Trueif argument has description.
-
coordinatorOrNull
@Nullable public static @Nullable Collection<GridClientNode> coordinatorOrNull(Collection<GridClientNode> nodes)
- Parameters:
nodes- Nodes.- Returns:
- Coordinator ID or null is
nodesare 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:
Trueif command can be executed,falseotherwise.
-
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 specifieddelimeterbetween 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 specifieddelimeterbetween them and append to the enddelimeter.- Parameters:
sb- Specified string builder.sbDelimeter- Delimeter betweensband appendedparam.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)
-
-