keith-turner commented on code in PR #4807:
URL: https://github.com/apache/accumulo/pull/4807#discussion_r1722424505


##########
server/base/src/main/java/org/apache/accumulo/server/util/Admin.java:
##########
@@ -907,4 +1003,129 @@ private EnumSet<ReadOnlyTStore.TStatus> 
getCmdLineStatusFilters(List<String> sta
     }
     return statusFilter;
   }
+
+  @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() {
+    System.out.println();
+    System.out.printf("%-20s | %-80s | %-20s%n", "Check Name", "Description", 
"Depends on");
+    System.out.println("-".repeat(120));
+    for (CheckCommand.Check check : CheckCommand.Check.values()) {
+      System.out.printf("%-20s | %-80s | %-20s%n", check.name(),
+          CheckCommand.Check.CHECK_DESCRIPTION.get(check), 
check.getDependencies().stream()
+              .map(CheckCommand.Check::name).collect(Collectors.joining(", 
")));
+    }
+    System.out.println("-".repeat(120));
+    System.out.println();
+  }
+
+  private static void executeRunCheckCommand(List<CheckCommand.Check> checks) {
+    final List<CheckCommand.Check> allChecksToRun = new ArrayList<>();
+    final TreeMap<CheckCommand.Check,CheckCommand.CheckStatus> checkStatus = 
new TreeMap<>();
+
+    // From the given list of checks to run, we need to compute all the checks 
that need to be
+    // run (the given checks and all the checks the given checks depend on)
+    computeAllChecksToRun(checks, allChecksToRun);

Review Comment:
   When checks were filtered I was thinking it would not run their dependencies 
(unless they also matched the filter).  Was thinking when a user wants to run 
specific checks that they may not want to wait on others.



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

Reply via email to