accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [1/4] accumulo git commit: ACCUMULO-4605 Remove hard-coded commands from Main
Date Wed, 14 Jun 2017 00:26:12 GMT
Repository: accumulo
Updated Branches:
  refs/heads/1.8 122423151 -> e7e5b6ba8
  refs/heads/master d0281f20f -> 3efff9b96


ACCUMULO-4605 Remove hard-coded commands from Main

Add usageGroup to KeywordExecutable, so the Main class can print usage
of commands in categorical groups.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f110b584
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f110b584
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f110b584

Branch: refs/heads/master
Commit: f110b584ccb22e391e4ab044a71cc42b69ae6945
Parents: d0281f2
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Tue Jun 13 20:16:08 2017 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Tue Jun 13 20:16:08 2017 -0400

----------------------------------------------------------------------
 .../apache/accumulo/core/util/Classpath.java    |  7 ++++-
 .../org/apache/accumulo/core/util/Help.java     |  5 ++++
 .../org/apache/accumulo/core/util/Version.java  |  5 ++++
 .../minicluster/impl/MiniClusterExecutable.java |  5 ++++
 .../java/org/apache/accumulo/proxy/Proxy.java   |  5 ++++
 .../apache/accumulo/server/init/Initialize.java |  5 ++++
 .../org/apache/accumulo/server/util/Admin.java  |  5 ++++
 .../org/apache/accumulo/server/util/Info.java   |  5 ++++
 .../accumulo/server/util/ZooKeeperMain.java     |  5 ++++
 .../org/apache/accumulo/gc/GCExecutable.java    |  5 ++++
 .../accumulo/master/MasterExecutable.java       |  5 ++++
 .../accumulo/monitor/MonitorExecutable.java     |  5 ++++
 .../accumulo/tracer/TracerExecutable.java       |  5 ++++
 .../accumulo/tserver/TServerExecutable.java     |  5 ++++
 .../java/org/apache/accumulo/shell/Shell.java   |  5 ++++
 .../java/org/apache/accumulo/start/Main.java    | 30 ++++++++++----------
 .../accumulo/start/spi/KeywordExecutable.java   | 11 +++++++
 17 files changed, 102 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/core/src/main/java/org/apache/accumulo/core/util/Classpath.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Classpath.java b/core/src/main/java/org/apache/accumulo/core/util/Classpath.java
index 66adb64..ed83e91 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Classpath.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Classpath.java
@@ -16,10 +16,10 @@
  */
 package org.apache.accumulo.core.util;
 
-import com.beust.jcommander.Parameter;
 import org.apache.accumulo.start.Main;
 import org.apache.accumulo.start.spi.KeywordExecutable;
 
+import com.beust.jcommander.Parameter;
 import com.google.auto.service.AutoService;
 
 @AutoService(KeywordExecutable.class)
@@ -37,6 +37,11 @@ public class Classpath implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Prints Accumulo classpath";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/core/src/main/java/org/apache/accumulo/core/util/Help.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Help.java b/core/src/main/java/org/apache/accumulo/core/util/Help.java
index 2602ddc..960265c 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Help.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Help.java
@@ -29,6 +29,11 @@ public class Help implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Prints usage";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/core/src/main/java/org/apache/accumulo/core/util/Version.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Version.java b/core/src/main/java/org/apache/accumulo/core/util/Version.java
index a2e900a..5dd9831 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Version.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Version.java
@@ -38,6 +38,11 @@ public class Version implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Prints Accumulo version";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniClusterExecutable.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniClusterExecutable.java
b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniClusterExecutable.java
index cdccd58..ca233df 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniClusterExecutable.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniClusterExecutable.java
@@ -30,6 +30,11 @@ public class MiniClusterExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo minicluster";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
----------------------------------------------------------------------
diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
index ee6067d..438e0d3 100644
--- a/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
+++ b/proxy/src/main/java/org/apache/accumulo/proxy/Proxy.java
@@ -113,6 +113,11 @@ public class Proxy implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo proxy";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
index 5c4cf8d..212dc6b 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/init/Initialize.java
@@ -756,6 +756,11 @@ public class Initialize implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Initializes Accumulo";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
index 1400777..b188f41 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
@@ -159,6 +159,11 @@ public class Admin implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Executes administrative commands";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/base/src/main/java/org/apache/accumulo/server/util/Info.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/Info.java b/server/base/src/main/java/org/apache/accumulo/server/util/Info.java
index b32dcf2..0c856ef 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/Info.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/Info.java
@@ -33,6 +33,11 @@ public class Info implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Prints Accumulo cluster info";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/base/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
b/server/base/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
index 72f7be9..db07815 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/ZooKeeperMain.java
@@ -50,6 +50,11 @@ public class ZooKeeperMain implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Apache Zookeeper instance";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/gc/src/main/java/org/apache/accumulo/gc/GCExecutable.java
----------------------------------------------------------------------
diff --git a/server/gc/src/main/java/org/apache/accumulo/gc/GCExecutable.java b/server/gc/src/main/java/org/apache/accumulo/gc/GCExecutable.java
index 61f76b7..0f8d397 100644
--- a/server/gc/src/main/java/org/apache/accumulo/gc/GCExecutable.java
+++ b/server/gc/src/main/java/org/apache/accumulo/gc/GCExecutable.java
@@ -30,6 +30,11 @@ public class GCExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo garbage collector";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/master/src/main/java/org/apache/accumulo/master/MasterExecutable.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/MasterExecutable.java
b/server/master/src/main/java/org/apache/accumulo/master/MasterExecutable.java
index bbe4e65..46435c8 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/MasterExecutable.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/MasterExecutable.java
@@ -29,6 +29,11 @@ public class MasterExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo master";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/monitor/src/main/java/org/apache/accumulo/monitor/MonitorExecutable.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/MonitorExecutable.java
b/server/monitor/src/main/java/org/apache/accumulo/monitor/MonitorExecutable.java
index 77cd701..ddd34c5 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/MonitorExecutable.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/MonitorExecutable.java
@@ -29,6 +29,11 @@ public class MonitorExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo monitor";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/tracer/src/main/java/org/apache/accumulo/tracer/TracerExecutable.java
----------------------------------------------------------------------
diff --git a/server/tracer/src/main/java/org/apache/accumulo/tracer/TracerExecutable.java
b/server/tracer/src/main/java/org/apache/accumulo/tracer/TracerExecutable.java
index e0191d6..f4b7744 100644
--- a/server/tracer/src/main/java/org/apache/accumulo/tracer/TracerExecutable.java
+++ b/server/tracer/src/main/java/org/apache/accumulo/tracer/TracerExecutable.java
@@ -29,6 +29,11 @@ public class TracerExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo tracer";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/server/tserver/src/main/java/org/apache/accumulo/tserver/TServerExecutable.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TServerExecutable.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/TServerExecutable.java
index 1b74e6f..7cf2946 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TServerExecutable.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TServerExecutable.java
@@ -29,6 +29,11 @@ public class TServerExecutable implements KeywordExecutable {
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.PROCESS;
+  }
+
+  @Override
   public String description() {
     return "Starts Accumulo tablet server";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/shell/src/main/java/org/apache/accumulo/shell/Shell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
index 5615795..d302a5a 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -587,6 +587,11 @@ public class Shell extends ShellOptions implements KeywordExecutable
{
   }
 
   @Override
+  public UsageGroup usageGroup() {
+    return UsageGroup.CORE;
+  }
+
+  @Override
   public String description() {
     return "Runs Accumulo shell";
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/start/src/main/java/org/apache/accumulo/start/Main.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/Main.java b/start/src/main/java/org/apache/accumulo/start/Main.java
index f4c954d..5e7858e 100644
--- a/start/src/main/java/org/apache/accumulo/start/Main.java
+++ b/start/src/main/java/org/apache/accumulo/start/Main.java
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Map;
 import java.util.ServiceLoader;
@@ -29,6 +28,7 @@ import java.util.TreeSet;
 
 import org.apache.accumulo.start.classloader.AccumuloClassLoader;
 import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.accumulo.start.spi.KeywordExecutable.UsageGroup;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -198,26 +198,26 @@ public class Main {
     System.exit(1);
   }
 
-  public static void printCommand(KeywordExecutable ke) {
-    System.out.printf("  %-30s %s\n", ke.usage(), ke.description());
+  public static void printCommands(TreeSet<KeywordExecutable> set, UsageGroup group)
{
+    set.stream().filter(e -> e.usageGroup() == group).forEach(ke -> System.out.printf("
 %-30s %s\n", ke.usage(), ke.description()));
   }
 
   public static void printUsage() {
-    Map<String,KeywordExecutable> executableMap = new TreeMap<>(getExecutables(getClassLoader()));
+    TreeSet<KeywordExecutable> executables = new TreeSet<>((x, y) -> x.keyword().compareTo(y.keyword()));
+    executables.addAll(getExecutables(getClassLoader()).values());
+
+    System.out.println("\nUsage: accumulo <command> [-h] (<argument> ...)\n\n
 -h   Prints usage for specified command");
+    System.out.println("\nCore Commands:");
+    printCommands(executables, UsageGroup.CORE);
 
-    System.out.println("\nUsage: accumulo <command> [-h] (<argument> ...)\n\n
 -h   Prints usage for specified command\n\nCore Commands:");
-    for (String cmd : Arrays.asList("init", "shell", "classpath", "version", "admin", "info",
"help")) {
-      printCommand(executableMap.remove(cmd));
-    }
     System.out.println("  <main class> args              Runs Java <main class>
located on Accumulo classpath");
+
     System.out.println("\nProcess Commands:");
-    for (String cmd : Arrays.asList("gc", "master", "monitor", "minicluster", "proxy", "tserver",
"tracer", "zookeeper")) {
-      printCommand(executableMap.remove(cmd));
-    }
-    System.out.println("\nAdvanced Commands:");
-    for (Map.Entry<String,KeywordExecutable> entry : executableMap.entrySet()) {
-      printCommand(entry.getValue());
-    }
+    printCommands(executables, UsageGroup.PROCESS);
+
+    System.out.println("\nOther Commands:");
+    printCommands(executables, UsageGroup.OTHER);
+
     System.out.println();
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f110b584/start/src/main/java/org/apache/accumulo/start/spi/KeywordExecutable.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/spi/KeywordExecutable.java b/start/src/main/java/org/apache/accumulo/start/spi/KeywordExecutable.java
index 30ebdda..5b781ce 100644
--- a/start/src/main/java/org/apache/accumulo/start/spi/KeywordExecutable.java
+++ b/start/src/main/java/org/apache/accumulo/start/spi/KeywordExecutable.java
@@ -36,6 +36,10 @@ import java.util.ServiceLoader;
  */
 public interface KeywordExecutable {
 
+  public static enum UsageGroup {
+    CORE, PROCESS, OTHER;
+  }
+
   /**
    * @return Keyword which identifies this service
    */
@@ -49,6 +53,13 @@ public interface KeywordExecutable {
   }
 
   /**
+   * @return Usage group for this command
+   */
+  default UsageGroup usageGroup() {
+    return UsageGroup.OTHER;
+  }
+
+  /**
    * @return Description of service
    */
   String description();


Mime
View raw message