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


##########
server/base/src/main/java/org/apache/accumulo/server/util/Admin.java:
##########
@@ -114,6 +129,82 @@ static class PingCommand {
     List<String> args = new ArrayList<>();
   }
 
+  @Parameters(commandNames = "check",
+      commandDescription = "Performs checks for problems in Accumulo.")
+  public static class CheckCommand {
+    @Parameter(names = "list",
+        description = "Lists the different checks that can be run, the 
description of each check, and the other check(s) each check depends on.")
+    boolean list;
+
+    @Parameter(names = "run",
+        description = "Runs the provided check(s) (explicit list or regex 
pattern specified following '-p'), beginning with their dependencies, or all 
checks if none are provided.")
+    boolean run;
+
+    @Parameter(names = {"--name_pattern", "-p"},
+        description = "Runs all checks that match the provided regex pattern.")
+    boolean useRegex;
+
+    @Parameter(description = "[<Check>...]")
+    List<String> checks;
+
+    public enum Check {
+      // Caution should be taken when changing or adding any new checks: order 
is important
+      SYSTEM_CONFIG, ROOT_METADATA, ROOT_TABLE, METADATA_TABLE, SYSTEM_FILES, 
USER_FILES;
+
+      private static final Map<Check,String> CHECK_DESCRIPTION = new 
EnumMap<>(Check.class);
+      private static final Map<Check,List<Check>> CHECK_DEPENDENCIES = new 
EnumMap<>(Check.class);
+      private static final Map<Check,Supplier<CheckRunner>> CHECK_RUNNERS =
+          new EnumMap<>(Check.class);
+
+      static {
+        CHECK_DESCRIPTION.put(SYSTEM_CONFIG, "Validate the system config 
stored in ZooKeeper");
+        CHECK_DESCRIPTION.put(ROOT_METADATA,
+            "Checks integrity of the root tablet metadata stored in 
ZooKeeper");
+        CHECK_DESCRIPTION.put(ROOT_TABLE,
+            "Scans all the tablet metadata stored in the root table and checks 
integrity");
+        CHECK_DESCRIPTION.put(METADATA_TABLE,
+            "Scans all the tablet metadata stored in the metadata table and 
checks integrity");
+        CHECK_DESCRIPTION.put(SYSTEM_FILES,
+            "Checks that files in system tablet metadata exist in DFS");
+        CHECK_DESCRIPTION.put(USER_FILES, "Checks that files in user tablet 
metadata exist in DFS");
+
+        CHECK_DEPENDENCIES.put(SYSTEM_CONFIG, Collections.emptyList());
+        CHECK_DEPENDENCIES.put(ROOT_METADATA, 
Collections.singletonList(SYSTEM_CONFIG));
+        CHECK_DEPENDENCIES.put(ROOT_TABLE, 
Collections.singletonList(ROOT_METADATA));
+        CHECK_DEPENDENCIES.put(METADATA_TABLE, 
Collections.singletonList(ROOT_TABLE));
+        CHECK_DEPENDENCIES.put(SYSTEM_FILES, 
Collections.singletonList(ROOT_TABLE));
+        CHECK_DEPENDENCIES.put(USER_FILES, 
Collections.singletonList(METADATA_TABLE));
+
+        CHECK_RUNNERS.put(SYSTEM_CONFIG, SystemConfigCheckRunner::new);
+        CHECK_RUNNERS.put(ROOT_METADATA, RootMetadataCheckRunner::new);
+        CHECK_RUNNERS.put(ROOT_TABLE, RootTableCheckRunner::new);
+        CHECK_RUNNERS.put(METADATA_TABLE, MetadataTableCheckRunner::new);
+        CHECK_RUNNERS.put(SYSTEM_FILES, SystemFilesCheckRunner::new);
+        CHECK_RUNNERS.put(USER_FILES, UserFilesCheckRunner::new);
+      }
+
+      /**
+       * @return the list of other checks the check depends on
+       */
+      private List<Check> getDependencies() {
+        return Optional.ofNullable(CHECK_DEPENDENCIES.get(this))
+            .orElseThrow(() -> new IllegalStateException("Invalid check " + 
this));
+      }
+
+      /**
+       * @return the interface for running a check
+       */
+      private CheckRunner getCheckRunner() {
+        return Optional.ofNullable(CHECK_RUNNERS.get(this).get())
+            .orElseThrow(() -> new IllegalStateException("Invalid check " + 
this));
+      }
+    }
+
+    public enum CheckStatus {
+      OK, FAILED, SKIPPED_DEPENDENCY_FAILED;

Review Comment:
   Not sure how well this will work.  Was thinking for the case of filtered 
dependencies could add a a status.  When deciding to run a command, only run it 
if the deps are OK  or FILTERED_OUT
   
   ```suggestion
         OK, FAILED, SKIPPED_DEPENDENCY_FAILED,FILTERED_OUT;
   ```



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