This is an automated email from the ASF dual-hosted git repository.

jmark99 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 1a2ef83  Make LogReader more discoverable (#2106)
1a2ef83 is described below

commit 1a2ef83cd7159b78f33377d917799c6ad299c9e2
Author: Mark Owens <[email protected]>
AuthorDate: Thu May 13 12:44:42 2021 -0400

    Make LogReader more discoverable (#2106)
    
    Use the KeywordExecutable service to make wal-info (the WAL LogReader 
class) available as part of the Accumulo command line. Can be used by running:
    
      accumulo wal-info
    
    Closes #2100
---
 .../apache/accumulo/tserver/logger/LogReader.java  | 40 +++++++++++++++++-----
 .../apache/accumulo/test/start/KeywordStartIT.java |  3 ++
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git 
a/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogReader.java
 
b/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogReader.java
index 17415bc..5c0ce29 100644
--- 
a/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogReader.java
+++ 
b/server/tserver/src/main/java/org/apache/accumulo/tserver/logger/LogReader.java
@@ -22,7 +22,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 
 import java.io.DataInputStream;
 import java.io.EOFException;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -37,6 +36,7 @@ import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.TableId;
 import org.apache.accumulo.core.dataImpl.KeyExtent;
 import org.apache.accumulo.server.fs.VolumeManagerImpl;
+import org.apache.accumulo.start.spi.KeywordExecutable;
 import org.apache.accumulo.tserver.log.DfsLogger;
 import org.apache.accumulo.tserver.log.DfsLogger.LogHeaderIncompleteException;
 import org.apache.accumulo.tserver.log.RecoveryLogReader;
@@ -47,10 +47,14 @@ import org.apache.hadoop.io.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.beust.jcommander.JCommander;
 import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
+@AutoService(KeywordExecutable.class)
+public class LogReader implements KeywordExecutable {
 
-public class LogReader {
   private static final Logger log = LoggerFactory.getLogger(LogReader.class);
 
   static class Opts extends Help {
@@ -73,19 +77,37 @@ public class LogReader {
    * @param args
    *          - first argument is the file to print
    */
-  public static void main(String[] args) throws IOException {
+  public static void main(String[] args) throws Exception {
+    new LogReader().execute(args);
+  }
+
+  @Override
+  public String keyword() {
+    return "wal-info";
+  }
+
+  @Override
+  public String description() {
+    return "Prints WAL Info";
+  }
+
+  @SuppressFBWarnings(value = "DM_EXIT",
+      justification = "System.exit is fine here because it's a utility class 
executed by a main()")
+  @Override
+  public void execute(String[] args) throws Exception {
     Opts opts = new Opts();
-    opts.parseArgs(LogReader.class.getName(), args);
+    opts.parseArgs("accumulo wal-info", args);
+    if (opts.files.isEmpty()) {
+      System.err.println("No WAL files were given");
+      System.exit(1);
+    }
+
     var siteConfig = SiteConfiguration.auto();
     try (var fs = VolumeManagerImpl.get(siteConfig, new Configuration())) {
 
       Matcher rowMatcher = null;
       KeyExtent ke = null;
       Text row = null;
-      if (opts.files.isEmpty()) {
-        new JCommander(opts).usage();
-        return;
-      }
       if (opts.row != null) {
         row = new Text(opts.row);
       }
diff --git 
a/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java 
b/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
index 87e8d31..f808ecd 100644
--- a/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
@@ -60,6 +60,7 @@ import org.apache.accumulo.tracer.TraceServer;
 import org.apache.accumulo.tracer.TracerExecutable;
 import org.apache.accumulo.tserver.TServerExecutable;
 import org.apache.accumulo.tserver.TabletServer;
+import org.apache.accumulo.tserver.logger.LogReader;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.slf4j.Logger;
@@ -115,6 +116,7 @@ public class KeywordStartIT {
     expectSet.put("minicluster", MiniClusterExecutable.class);
     expectSet.put("monitor", MonitorExecutable.class);
     expectSet.put("rfile-info", PrintInfo.class);
+    expectSet.put("wal-info", LogReader.class);
     expectSet.put("shell", Shell.class);
     expectSet.put("tracer", TracerExecutable.class);
     expectSet.put("tserver", TServerExecutable.class);
@@ -166,6 +168,7 @@ public class KeywordStartIT {
     expectSet.add(MiniAccumuloRunner.class);
     expectSet.add(Monitor.class);
     expectSet.add(PrintInfo.class);
+    expectSet.add(LogReader.class);
     expectSet.add(Shell.class);
     expectSet.add(SimpleGarbageCollector.class);
     expectSet.add(TabletServer.class);

Reply via email to