Mmuzaf commented on code in PR #4263:
URL: https://github.com/apache/cassandra/pull/4263#discussion_r2219935245
##########
src/java/org/apache/cassandra/tools/nodetool/GuardrailsConfigCommand.java:
##########
@@ -59,51 +61,107 @@ public static class GetGuardrailsConfig extends
GuardrailsConfigCommand
allowedValues = { "values", "thresholds", "flags", "others" })
private String guardrailCategory;
- @Arguments(description = "Specific names or guardrails to get
configuration of.")
+ @Option(name = { "--verbose", "-v" })
+ private boolean verbose = false;
+
+ @Arguments(description = "Specific name of a guardrail to get
configuration of.")
private List<String> args = new ArrayList<>();
@Override
public void execute(NodeProbe probe)
{
GuardrailCategory categoryEnum =
GuardrailCategory.parseCategory(guardrailCategory, probe.output().out);
- if (!args.isEmpty() && categoryEnum != null)
+ if (args.size() > 1)
+ throw new IllegalStateException("Specify only one guardrail
name to get the configuration of or no name to get the configuration of all of
them.");
+
+ String guardrailName = !args.isEmpty() ? args.get(0) : null;
+
+ if (guardrailName != null && categoryEnum != null)
throw new IllegalStateException("Do not specify additional
arguments when --category/-c is set.");
- List<Method> allGetters =
stream(probe.getGuardrailsMBean().getClass().getDeclaredMethods())
- .filter(method ->
method.getName().startsWith("get")
- &&
!method.getName().endsWith("CSV"))
- .filter(method -> args.isEmpty() ||
args.contains(toSnakeCase(method.getName().substring(3))))
- .sorted(comparing(Method::getName))
- .collect(toList());
+ Map<String, List<Method>> allGetters =
stream(probe.getGuardrailsMBean().getClass().getDeclaredMethods())
+ .filter(method ->
method.getName().startsWith("get")
+ &&
!method.getName().endsWith("CSV")
+ &&
!(method.getName().endsWith("WarnThreshold") ||
method.getName().endsWith("FailThreshold")))
+ .filter(method ->
guardrailName == null ||
guardrailName.equals(toSnakeCase(method.getName().substring(3))))
+
.collect(Collectors.groupingBy(method ->
toSnakeCase(method.getName().substring(3))));
+
+ Map<String, List<Method>> thresholds =
stream(probe.getGuardrailsMBean().getClass().getDeclaredMethods())
+ .filter(method ->
method.getName().startsWith("get")
+ &&
!method.getName().endsWith("CSV")
+ &&
(method.getName().endsWith("WarnThreshold") ||
method.getName().endsWith("FailThreshold")))
+ .filter(method -> {
+ if (guardrailName ==
null)
+ return true;
+
+ String snakeCase =
toSnakeCase(method.getName().substring(3));
+ String
snakeCaseSuccinct = snakeCase.replace("_warn_", "_")
+
.replace("_fail_", "_");
+
+ return
guardrailName.equals(snakeCase) || guardrailName.equals(snakeCaseSuccinct);
+ })
+
.sorted(comparing(Method::getName))
+
.collect(Collectors.groupingBy(method -> {
+ String methodName =
method.getName().substring(3);
+ String snakeCase =
toSnakeCase(methodName);
+ if
(snakeCase.endsWith("warn_threshold"))
+ return
snakeCase.replaceAll("_warn_", "_");
+ else
+ return
snakeCase.replaceAll("_fail_", "_");
+ }));
+
+ allGetters.putAll(thresholds);
+
+ allGetters = allGetters.entrySet()
+ .stream()
+ .sorted(Map.Entry.comparingByKey())
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
Review Comment:
Identation is wrong, probably
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]