accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cjno...@apache.org
Subject svn commit: r1482390 - in /accumulo/trunk: server/ server/src/main/java/org/apache/accumulo/server/mini/ server/src/test/java/org/apache/accumulo/server/mini/ start/src/main/java/org/apache/accumulo/start/
Date Tue, 14 May 2013 15:25:08 GMT
Author: cjnolet
Date: Tue May 14 15:25:07 2013
New Revision: 1482390

URL: http://svn.apache.org/r1482390
Log:
ACCUMULO-1368 MiniAccumuloRunner for easily starting up an instance from the command line.
Added to start/Main.class but can't be used without a Hadoop classpath available.

Added:
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloRunner.java
Modified:
    accumulo/trunk/server/pom.xml
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java
    accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloClusterTest.java
    accumulo/trunk/start/src/main/java/org/apache/accumulo/start/Main.java

Modified: accumulo/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/pom.xml?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/pom.xml (original)
+++ accumulo/trunk/server/pom.xml Tue May 14 15:25:07 2013
@@ -34,6 +34,10 @@
       <artifactId>gson</artifactId>
     </dependency>
     <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
       <groupId>jline</groupId>
       <artifactId>jline</artifactId>
     </dependency>

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MemoryUnit.java Tue
May 14 15:25:07 2013
@@ -17,21 +17,34 @@
 package org.apache.accumulo.server.mini;
 
 /**
- * 
  * @since 1.6.0
  */
 
 public enum MemoryUnit {
   
-  BYTE(1l), KILOBYTE(1024l), MEGABYTE(1024 * 1024l), GIGABYTE(1024 * 1024 * 1024l);
+  BYTE(1l,""), KILOBYTE(1024l,"K"), MEGABYTE(1024 * 1024l,"M"), GIGABYTE(1024 * 1024 * 1024l,"G");
   
   private final long multiplier;
+  private final String suffix;
   
-  private MemoryUnit(long multiplier) {
+  private MemoryUnit(long multiplier, String suffix) {
     this.multiplier = multiplier;
+    this.suffix = suffix;
   }
   
   public long toBytes(long memory) {
     return memory * multiplier;
   }
+
+  public String suffix() {
+    return suffix;
+  }
+
+  public static MemoryUnit fromSuffix(String suffix) {
+    for(MemoryUnit memoryUnit : MemoryUnit.values()) {
+      if(memoryUnit.suffix .equals(suffix))
+        return memoryUnit;
+    }
+    return null;
+  }
 }

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloCluster.java
Tue May 14 15:25:07 2013
@@ -44,7 +44,7 @@ import org.apache.zookeeper.server.ZooKe
 
 /**
  * A utility class that will create Zookeeper and Accumulo processes that write all of their
data to a single local directory. This class makes it easy to test
- * code against a real Accumulo instance. Its much more accurate for testing than MockAccumulo,
but much slower than MockAccumulo.
+ * code against a real Accumulo instance. Its much more accurate for testing than {@link
org.apache.accumulo.core.client.mock.MockAccumulo}, but much slower.
  * 
  * @since 1.5.0
  */
@@ -161,7 +161,7 @@ public class MiniAccumuloCluster {
     List<String> jvmOpts = new ArrayList<String>();
     jvmOpts.add("-Xmx" + config.getMemory(serverType));
     
-    if (config.isDebug()) {
+    if (config.isJWDPEnabled()) {
       Integer port = PortUtils.getRandomFreePort();
       jvmOpts.addAll(buildRemoteDebugParams(port));
       debugPorts.add(new Pair<ServerType,Integer>(serverType, port));

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloConfig.java
Tue May 14 15:25:07 2013
@@ -38,7 +38,7 @@ public class MiniAccumuloConfig {
   private int numTservers = 2;
   private Map<ServerType,Long> memoryConfig = new HashMap<ServerType,Long>();
   
-  private boolean debug = false;
+  private boolean jwdpEnabled = false;
   
   private String instanceName = "miniInstance";
   
@@ -200,7 +200,7 @@ public class MiniAccumuloConfig {
    * @param memory
    *          amount of memory to set
    * 
-   * @memoryUnit the units for which to apply with the memory size
+   * @param memoryUnit the units for which to apply with the memory size
    * 
    * @since 1.6.0
    */
@@ -309,23 +309,23 @@ public class MiniAccumuloConfig {
   }
   
   /**
-   * @return is the current configuration in debug mode?
+   * @return is the current configuration in jwdpEnabled mode?
    * 
    * @since 1.6.0
    */
-  public boolean isDebug() {
-    return debug;
+  public boolean isJWDPEnabled() {
+    return jwdpEnabled;
   }
   
   /**
-   * @param debug
-   *          should the processes run remote debug servers?
+   * @param jwdpEnabled
+   *          should the processes run remote jwdpEnabled servers?
    * @return the current instance
    * 
    * @since 1.6.0
    */
-  public MiniAccumuloConfig setDebug(boolean debug) {
-    this.debug = debug;
+  public MiniAccumuloConfig setJWDPEnabled(boolean jwdpEnabled) {
+    this.jwdpEnabled = jwdpEnabled;
     return this;
   }
   

Added: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloRunner.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloRunner.java?rev=1482390&view=auto
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloRunner.java
(added)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/MiniAccumuloRunner.java
Tue May 14 15:25:07 2013
@@ -0,0 +1,193 @@
+package org.apache.accumulo.server.mini;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.util.Pair;
+import org.apache.commons.io.FileUtils;
+
+import com.beust.jcommander.IStringConverter;
+import com.beust.jcommander.Parameter;
+import com.google.common.io.Files;
+
+/**
+ * A runner for starting up a {@link MiniAccumuloCluster} from the command line using an
optional configuration properties file. An example property file looks
+ * like the following:
+ * 
+ * <pre>
+ * rootPassword=secret
+ * instanceName=testInstance
+ * numTServers=1
+ * zooKeeperPort=3191
+ * jwdpEnabled=true
+ * zooKeeperMemory=128M
+ * tserverMemory=256M
+ * masterMemory=128M
+ * defaultMemory=256M
+ * shutdownPort=4446
+ * site.instance.secret=HUSH
+ * </pre>
+ * 
+ * All items in the properties file above are optional and a default value will be provided
in their absence. Any site configuration properties (typically found
+ * in the accumulo-site.xml file) should be prefixed with "site." in the properties file.
+ * 
+ * @since 1.6.0
+ */
+public class MiniAccumuloRunner {
+  public static class PropertiesConverter implements IStringConverter<Properties> {
+    @Override
+    public Properties convert(String fileName) {
+      Properties prop = new Properties();
+      InputStream is;
+      try {
+        is = new FileInputStream(fileName);
+        try {
+          prop.load(is);
+        } finally {
+          is.close();
+        }
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+      return prop;
+    }
+  }
+  
+  private static final String FORMAT_STRING = "  %-21s %s";
+  
+  public static class Opts extends Help {
+    @Parameter(names = "-p", required = false, description = "properties file name", converter
= PropertiesConverter.class)
+    Properties prop = new Properties();
+  }
+  
+  /**
+   * Runs the {@link MiniAccumuloCluster} given a -p argument with a property file. Establishes
a shutdown port for asynchronous operation.
+   * 
+   * @param args
+   *          An optional -p argument can be specified with the path to a valid properties
file.
+   * 
+   * @throws Exception
+   */
+  public static void main(String[] args) throws Exception {
+    Opts opts = new Opts();
+    opts.parseArgs(MiniAccumuloRunner.class.getName(), args);
+    
+    int shutdownPort = 4445;
+    
+    final File tempDir = Files.createTempDir();
+    String rootPass = opts.prop.containsKey("rootPassword") ? opts.prop.getProperty("rootPassword")
: "secret";
+    
+    MiniAccumuloConfig config = new MiniAccumuloConfig(tempDir, rootPass);
+    
+    if (opts.prop.containsKey("instanceName"))
+      config.setInstanceName(opts.prop.getProperty("instanceName"));
+    if (opts.prop.containsKey("numTServers"))
+      config.setNumTservers(Integer.parseInt(opts.prop.getProperty("numTServers")));
+    if (opts.prop.containsKey("zooKeeperPort"))
+      config.setZooKeeperPort(Integer.parseInt(opts.prop.getProperty("zooKeeperPort")));
+    if (opts.prop.containsKey("jwdpEnabled"))
+      config.setJWDPEnabled(Boolean.parseBoolean(opts.prop.getProperty("jwdpEnabled")));
+    if (opts.prop.containsKey("zooKeeperMemory"))
+      setMemoryOnConfig(config, opts.prop.getProperty("zooKeeperMemory"), ServerType.ZOOKEEPER);
+    if (opts.prop.containsKey("tserverMemory"))
+      setMemoryOnConfig(config, opts.prop.getProperty("tserverMemory"), ServerType.TABLET_SERVER);
+    if (opts.prop.containsKey("masterMemory"))
+      setMemoryOnConfig(config, opts.prop.getProperty("masterMemory"), ServerType.MASTER);
+    if (opts.prop.containsKey("defaultMemory"))
+      setMemoryOnConfig(config, opts.prop.getProperty("defaultMemory"));
+    if (opts.prop.containsKey("shutdownPort"))
+      shutdownPort = Integer.parseInt(opts.prop.getProperty("shutdownPort"));
+    
+    Map<String,String> siteConfig = new HashMap<String,String>();
+    for (Map.Entry<Object,Object> entry : opts.prop.entrySet()) {
+      String key = (String) entry.getKey();
+      if (key.startsWith("site."))
+        siteConfig.put(key.replaceFirst("site.", ""), (String) entry.getValue());
+    }
+    
+    config.setSiteConfig(siteConfig);
+    
+    final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(config);
+    
+    Runtime.getRuntime().addShutdownHook(new Thread() {
+      @Override
+      public void run() {
+        try {
+          accumulo.stop();
+          FileUtils.deleteDirectory(tempDir);
+          System.out.println("\nShut down gracefully on " + new Date());
+        } catch (IOException e) {
+          e.printStackTrace();
+        } catch (InterruptedException e) {
+          e.printStackTrace();
+        }
+      }
+    });
+    
+    accumulo.start();
+    
+    printInfo(accumulo, shutdownPort);
+    
+    // start a socket on the shutdown port and block- anything connected to this port will
activate the shutdown
+    ServerSocket shutdownServer = new ServerSocket(shutdownPort);
+    shutdownServer.accept();
+    
+    System.exit(0);
+  }
+  
+  private static boolean validateMemoryString(String memoryString) {
+    String unitsRegex = "[";
+    MemoryUnit[] units = MemoryUnit.values();
+    for (int i = 0; i < units.length; i++) {
+      unitsRegex += units[i].suffix();
+      if (i < units.length - 1)
+        unitsRegex += "|";
+    }
+    unitsRegex += "]";
+    Pattern p = Pattern.compile("\\d+" + unitsRegex);
+    return p.matcher(memoryString).matches();
+  }
+  
+  private static void setMemoryOnConfig(MiniAccumuloConfig config, String memoryString) {
+    setMemoryOnConfig(config, memoryString, null);
+  }
+  
+  private static void setMemoryOnConfig(MiniAccumuloConfig config, String memoryString, ServerType
serverType) {
+    if (!validateMemoryString(memoryString))
+      throw new IllegalArgumentException(memoryString + " is not a valid memory string");
+    
+    long memSize = Long.parseLong(memoryString.substring(0, memoryString.length() - 1));
+    MemoryUnit memUnit = MemoryUnit.fromSuffix(memoryString.substring(memoryString.length()
- 1));
+    
+    if (serverType != null)
+      config.setMemory(serverType, memSize, memUnit);
+    else
+      config.setDefaultMemory(memSize, memUnit);
+  }
+  
+  private static void printInfo(MiniAccumuloCluster accumulo, int shutdownPort) {
+    System.out.println("Mini Accumulo Cluster\n");
+    System.out.println(String.format(FORMAT_STRING, "Directory:", accumulo.getConfig().getDir().getAbsoluteFile()));
+    System.out.println(String.format(FORMAT_STRING, "Logs:", accumulo.getConfig().getLogDir().getAbsoluteFile()));
+    System.out.println(String.format(FORMAT_STRING, "Instance Name:", accumulo.getConfig().getInstanceName()));
+    System.out.println(String.format(FORMAT_STRING, "Root Password:", accumulo.getConfig().getRootPassword()));
+    System.out.println(String.format(FORMAT_STRING, "ZooKeeper:", accumulo.getConfig().getZooKeepers()));
+    
+    for (Pair<ServerType,Integer> pair : accumulo.getDebugPorts()) {
+      System.out.println(String.format(FORMAT_STRING, pair.getFirst().prettyPrint() + " JDWP
Host:", "localhost:" + pair.getSecond()));
+    }
+    
+    System.out.println(String.format(FORMAT_STRING, "Shutdown Port:", shutdownPort));
+    
+    System.out.println("\n\nSuccessfully started on " + new Date());
+  }
+}

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java (original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/mini/ServerType.java Tue
May 14 15:25:07 2013
@@ -17,10 +17,19 @@
 package org.apache.accumulo.server.mini;
 
 /**
- * 
  * @since 1.6.0
  */
 
 public enum ServerType {
-  MASTER, ZOOKEEPER, TABLET_SERVER
+  MASTER("Master"), ZOOKEEPER("ZooKeeper"), TABLET_SERVER("TServer");
+
+  private final String prettyPrint;
+
+  public String prettyPrint() {
+    return prettyPrint;
+  }
+
+  ServerType(String prettyPrint) {
+    this.prettyPrint = prettyPrint;
+  }
 }

Modified: accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloClusterTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloClusterTest.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloClusterTest.java
(original)
+++ accumulo/trunk/server/src/test/java/org/apache/accumulo/server/mini/MiniAccumuloClusterTest.java
Tue May 14 15:25:07 2013
@@ -59,7 +59,7 @@ public class MiniAccumuloClusterTest {
     Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
     
     folder.create();
-    MiniAccumuloConfig config = new MiniAccumuloConfig(folder.getRoot(), "superSecret").setDebug(true);
+    MiniAccumuloConfig config = new MiniAccumuloConfig(folder.getRoot(), "superSecret").setJWDPEnabled(true);
     accumulo = new MiniAccumuloCluster(config);
     accumulo.start();
   }

Modified: accumulo/trunk/start/src/main/java/org/apache/accumulo/start/Main.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/start/src/main/java/org/apache/accumulo/start/Main.java?rev=1482390&r1=1482389&r2=1482390&view=diff
==============================================================================
--- accumulo/trunk/start/src/main/java/org/apache/accumulo/start/Main.java (original)
+++ accumulo/trunk/start/src/main/java/org/apache/accumulo/start/Main.java Tue May 14 15:25:07
2013
@@ -62,6 +62,8 @@ public class Main {
         runTMP = cl.loadClass("org.apache.accumulo.server.trace.TraceServer");
       } else if (args[0].equals("proxy")) {
         runTMP = cl.loadClass("org.apache.accumulo.proxy.Proxy");
+      } else if (args[0].equals("mini")) {
+        runTMP = cl.loadClass("org.apache.accumulo.server.mini.MiniAccumuloRunner");
       } else if (args[0].equals("classpath")) {
         vfsClassLoader.getMethod("printClassPath", new Class[] {}).invoke(vfsClassLoader,
new Object[] {});
         return;



Mime
View raw message