kevinrr888 commented on code in PR #4806:
URL: https://github.com/apache/accumulo/pull/4806#discussion_r1717171779
##########
server/base/src/main/java/org/apache/accumulo/server/util/Admin.java:
##########
@@ -1113,4 +1206,129 @@ private static void getAllFateIds(TabletMetadata
tabletMetadata,
fateIdConsumer.accept(tabletMetadata.getOperationId().getFateId());
}
}
+
+ @VisibleForTesting
+ public static void executeCheckCommand(ServerContext context, CheckCommand
cmd) {
+ List<CheckCommand.Check> checks;
+
+ validateAndTransformCheckCommand(cmd);
+
+ if (cmd.list) {
+ listChecks();
+ } else if (cmd.run) {
+ checks =
cmd.checks.stream().map(CheckCommand.Check::valueOf).collect(Collectors.toList());
+ executeRunCheckCommand(checks);
+ }
+ }
+
+ private static void validateAndTransformCheckCommand(CheckCommand cmd) {
+ Preconditions.checkArgument(cmd.list != cmd.run, "Must use either 'list'
or 'run'");
+ if (cmd.list) {
+ Preconditions.checkArgument(cmd.checks == null,
+ "'list' does not expect any further arguments");
+ } else if (cmd.useRegex) {
+ // run with regex provided
+ Preconditions.checkArgument(cmd.checks != null, "Expected a regex
pattern to be provided");
+ Preconditions.checkArgument(cmd.checks.size() == 1,
+ "Expected one argument (the regex pattern)");
+ String regex = cmd.checks.get(0).toUpperCase();
+ List<String> matchingChecks = new ArrayList<>();
+ var pattern = Pattern.compile(regex);
+ for (CheckCommand.Check check : CheckCommand.Check.values()) {
+ if (pattern.matcher(check.name()).matches()) {
+ matchingChecks.add(check.name());
+ }
+ }
+ Preconditions.checkArgument(!matchingChecks.isEmpty(),
+ "No checks matched the given pattern: " + regex);
+ cmd.checks = matchingChecks;
+ } else {
+ // run without regex provided
+ if (cmd.checks == null) {
+ cmd.checks =
EnumSet.allOf(CheckCommand.Check.class).stream().map(Enum::name)
+ .collect(Collectors.toList());
+ }
+ }
+ }
+
+ private static void listChecks() {
Review Comment:
The admin commands print using System.out which is what I stuck with. I'm
not really sure how using a logger here would work... It wouldn't print to the
console when something like `accumulo admin check run` is executed from the
shell as far as I'm aware. It may also be harder to format nicely using a
logger. I'm not sure what would be gained from using a logger. If we want time
to be included, we can just manually include that.
--
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]