accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject svn commit: r1433166 [17/20] - in /accumulo/branches/ACCUMULO-259: ./ assemble/ assemble/platform/ assemble/scripts/ assemble/scripts/init.d/ bin/ conf/examples/1GB/native-standalone/ conf/examples/1GB/standalone/ conf/examples/2GB/native-standalone/ c...
Date Mon, 14 Jan 2013 22:03:34 GMT
Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Admin.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Admin.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Admin.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Admin.java Mon Jan 14 22:03:24 2013
@@ -16,18 +16,16 @@
  */
 package org.apache.accumulo.server.util;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-
-import jline.ConsoleReader;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.accumulo.cloudtrace.instrument.Tracer;
+import org.apache.accumulo.server.cli.ClientOpts;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.client.impl.ClientExec;
 import org.apache.accumulo.core.client.impl.MasterClient;
 import org.apache.accumulo.core.conf.Property;
@@ -35,83 +33,67 @@ import org.apache.accumulo.core.master.t
 import org.apache.accumulo.core.security.thrift.AuthInfo;
 import org.apache.accumulo.server.client.HdfsZooInstance;
 import org.apache.accumulo.server.security.SecurityConstants;
-import org.apache.commons.cli.BasicParser;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
 import org.apache.log4j.Logger;
 
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+
 public class Admin {
   private static final Logger log = Logger.getLogger(Admin.class);
   
+  static class AdminOpts extends ClientOpts {
+    @Parameter(names={"-f", "--force"}, description="force the given server to stop by removing its lock")
+    boolean force = false;
+  }
+
+  @Parameters(commandDescription="stop the tablet server on the given hosts")
+  static class StopCommand {
+    @Parameter(description="<host> {<host> ... }")
+    List<String> args = new ArrayList<String>();
+  }
+  
+  @Parameters(commandDescription="stop the master")
+  static class StopMasterCommand {
+  }
+
+  @Parameters(commandDescription="stop all the servers")
+  static class StopAllCommand {
+  }
+
   public static void main(String[] args) {
     boolean everything;
+
+    AdminOpts opts = new AdminOpts();
+    JCommander cl = new JCommander(opts);
+    cl.setProgramName(Admin.class.getName());
+    StopCommand stopOpts = new StopCommand();
+    cl.addCommand("stop", stopOpts);
+    StopMasterCommand stopMasterOpts = new StopMasterCommand();
+    cl.addCommand("stopMaster", stopMasterOpts);
+    StopAllCommand stopAllOpts = new StopAllCommand();
+    cl.addCommand("stopAll", stopAllOpts);
+    cl.parse(args);
     
-    final Charset utf8 = Charset.forName("UTF8");
-    
-    CommandLine cl = null;
-    Options opts = new Options();
-    opts.addOption("u", true, "optional administrator user name");
-    opts.addOption("p", true, "optional administrator password");
-    opts.addOption("f", "force", false, "force the given server to stop by removing its lock");
-    opts.addOption("?", "help", false, "displays the help");
-    String user = null;
-    byte[] pass = null;
-    boolean force = false;
-    
-    try {
-      cl = new BasicParser().parse(opts, args);
-      if (cl.hasOption("?"))
-        throw new ParseException("help requested");
-      args = cl.getArgs();
-      
-      user = cl.hasOption("u") ? cl.getOptionValue("u") : "root";
-      pass = cl.hasOption("p") ? cl.getOptionValue("p").getBytes(utf8) : null;
-      force = cl.hasOption("f");
-      
-      if (!((cl.getArgs().length == 1 && (args[0].equalsIgnoreCase("stopMaster") || args[0].equalsIgnoreCase("stopAll"))) || (cl.getArgs().length == 2 && args[0]
-          .equalsIgnoreCase("stop"))))
-        throw new ParseException("Incorrect arguments");
-      
-    } catch (ParseException e) {
-      // print to the log and to stderr
-      if (cl == null || !cl.hasOption("?"))
-        log.error(e, e);
-      HelpFormatter h = new HelpFormatter();
-      StringWriter str = new StringWriter();
-      h.printHelp(new PrintWriter(str), h.getWidth(), Admin.class.getName() + " stopMaster | stopAll | stop <tserver>", null, opts, h.getLeftPadding(),
-          h.getDescPadding(), null, true);
-      if (cl != null && cl.hasOption("?"))
-        log.info(str.toString());
-      else
-        log.error(str.toString());
-      h.printHelp(new PrintWriter(System.err), h.getWidth(), Admin.class.getName() + " stopMaster | stopAll | stop <tserver>", null, opts, h.getLeftPadding(),
-          h.getDescPadding(), null, true);
-      System.exit(3);
+    if (opts.help || cl.getParsedCommand() == null) {
+      cl.usage();
+      return;
     }
-    
+    Instance instance = opts.getInstance();
+      
     try {
       AuthInfo creds;
-      if (args[0].equalsIgnoreCase("stop")) {
-        stopTabletServer(args[1], force);
+      if (opts.getPassword() == null) {
+        creds = SecurityConstants.getSystemCredentials();
       } else {
-        if (!cl.hasOption("u") && !cl.hasOption("p")) {
-          creds = SecurityConstants.getSystemCredentials();
-        } else {
-          if (pass == null) {
-            try {
-              pass = new ConsoleReader().readLine("Enter current password for '" + user + "': ", '*').getBytes(utf8);
-            } catch (IOException ioe) {
-              log.error("Password not specified and unable to prompt: " + ioe);
-              System.exit(4);
-            }
-          }
-          creds = new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID());
-        }
-        
-        everything = args[0].equalsIgnoreCase("stopAll");
-        stopServer(creds, everything);
+        creds = new AuthInfo(opts.user, ByteBuffer.wrap(opts.getPassword()), instance.getInstanceID());
+      }
+
+      if (cl.getParsedCommand().equals("stop")) {
+        stopTabletServer(instance, creds, stopOpts.args, opts.force);
+      } else {
+        everything = cl.getParsedCommand().equals("stopAll");
+        stopServer(instance, creds, everything);
       }
     } catch (AccumuloException e) {
       log.error(e);
@@ -122,7 +104,7 @@ public class Admin {
     }
   }
   
-  private static void stopServer(final AuthInfo credentials, final boolean tabletServersToo) throws AccumuloException, AccumuloSecurityException {
+  private static void stopServer(Instance instance, final AuthInfo credentials, final boolean tabletServersToo) throws AccumuloException, AccumuloSecurityException {
     MasterClient.execute(HdfsZooInstance.getInstance(), new ClientExec<MasterClientService.Client>() {
       @Override
       public void execute(MasterClientService.Client client) throws Exception {
@@ -131,14 +113,17 @@ public class Admin {
     });
   }
   
-  private static void stopTabletServer(String server, final boolean force) throws AccumuloException, AccumuloSecurityException {
-    InetSocketAddress address = AddressUtil.parseAddress(server, Property.TSERV_CLIENTPORT);
-    final String finalServer = org.apache.accumulo.core.util.AddressUtil.toString(address);
-    MasterClient.execute(HdfsZooInstance.getInstance(), new ClientExec<MasterClientService.Client>() {
-      @Override
-      public void execute(MasterClientService.Client client) throws Exception {
-        client.shutdownTabletServer(Tracer.traceInfo(), SecurityConstants.getSystemCredentials(), finalServer, force);
-      }
-    });
+  private static void stopTabletServer(Instance instance, final AuthInfo creds, List<String> servers, final boolean force) throws AccumuloException, AccumuloSecurityException {
+    for (String server : servers) {
+      InetSocketAddress address = AddressUtil.parseAddress(server, Property.TSERV_CLIENTPORT);
+      final String finalServer = org.apache.accumulo.core.util.AddressUtil.toString(address);
+      log.info("Stopping server " + finalServer);
+      MasterClient.execute(HdfsZooInstance.getInstance(), new ClientExec<MasterClientService.Client>() {
+        @Override
+        public void execute(MasterClientService.Client client) throws Exception {
+          client.shutdownTabletServer(Tracer.traceInfo(), creds, finalServer, force);
+        }
+      });
+    }
   }
 }

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ChangeSecret.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ChangeSecret.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ChangeSecret.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ChangeSecret.java Mon Jan 14 22:03:24 2013
@@ -17,11 +17,12 @@
 package org.apache.accumulo.server.util;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.accumulo.server.cli.ClientOpts;
 import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.util.CachedConfiguration;
 import org.apache.accumulo.core.zookeeper.ZooUtil;
@@ -30,7 +31,6 @@ import org.apache.accumulo.fate.zookeepe
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
 import org.apache.accumulo.server.ServerConstants;
-import org.apache.accumulo.server.client.HdfsZooInstance;
 import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -38,28 +38,31 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 
-public class ChangeSecret {
+import com.beust.jcommander.Parameter;
 
-  private static final Charset utf8 = Charset.forName("UTF8");
+public class ChangeSecret {
+  
+  static class Opts extends ClientOpts {
+    @Parameter(names="--old", description="old zookeeper password", password=true, hidden=true)
+    String oldPass;
+    @Parameter(names="--new", description="new zookeeper password", password=true, hidden=true)
+    String newPass;
+  }
   
   public static void main(String[] args) throws Exception {
-    String oldPass = null;
-    String newPass = null;
-    if (args.length < 2) {
-      System.err.println("Usage: accumulo " + ChangeSecret.class.getName() + " oldPass newPass");
-      System.exit(-1);
-    }
-    oldPass = args[0];
-    newPass = args[1];
-    
+    Opts opts = new Opts();
+    List<String> argsList = Arrays.asList(args);
+    argsList.add("--old");
+    argsList.add("--new");
+    opts.parseArgs(ChangeSecret.class.getName(), argsList.toArray(new String[0]));
     FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
-    Instance inst = HdfsZooInstance.getInstance();
-    if (!verifyAccumuloIsDown(inst, oldPass))
+    Instance inst = opts.getInstance();
+    if (!verifyAccumuloIsDown(inst, opts.oldPass))
       System.exit(-1);
-    String instanceId = rewriteZooKeeperInstance(inst, oldPass, newPass);
+    String instanceId = rewriteZooKeeperInstance(inst, opts.oldPass, opts.newPass);
     updateHdfs(fs, inst, instanceId);
-    if (oldPass != null) {
-      deleteInstance(inst, oldPass);
+    if (opts.oldPass != null) {
+      deleteInstance(inst, opts.oldPass);
     }
     System.out.println("New instance id is " + instanceId);
     System.out.println("Be sure to put your new secret in accumulo-site.xml");
@@ -133,7 +136,7 @@ public class ChangeSecret {
     });
     String path = "/accumulo/instances/" + inst.getInstanceName();
     orig.recursiveDelete(path, NodeMissingPolicy.SKIP);
-    new_.putPersistentData(path, newInstanceId.getBytes(utf8), NodeExistsPolicy.OVERWRITE);
+    new_.putPersistentData(path, newInstanceId.getBytes(), NodeExistsPolicy.OVERWRITE);
     return newInstanceId;
   }
   

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CheckForMetadataProblems.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CheckForMetadataProblems.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CheckForMetadataProblems.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CheckForMetadataProblems.java Mon Jan 14 22:03:24 2013
@@ -16,9 +16,6 @@
  */
 package org.apache.accumulo.server.util;
 
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -27,33 +24,25 @@ import java.util.Set;
 import java.util.TreeSet;
 
 import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.server.cli.ClientOpts;
 import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.impl.ScannerImpl;
 import org.apache.accumulo.core.client.impl.Writer;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.KeyExtent;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.security.thrift.AuthInfo;
 import org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException;
 import org.apache.accumulo.core.util.CachedConfiguration;
-import org.apache.accumulo.server.client.HdfsZooInstance;
 import org.apache.accumulo.server.conf.ServerConfiguration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.io.Text;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
+
+import com.beust.jcommander.Parameter;
 
 public class CheckForMetadataProblems {
-  private static String user;
-  private static byte[] pass;
-  private static boolean fix = false;
-  private static boolean offline = false;
-  
   private static boolean sawProblems = false;
   
-  public static void checkTable(String tablename, TreeSet<KeyExtent> tablets, boolean patch) {
+  public static void checkTable(String tablename, TreeSet<KeyExtent> tablets, Opts opts) {
     // sanity check of metadata table entries
     // make sure tablets has no holes, and that it starts and ends w/ null
     
@@ -91,10 +80,10 @@ public class CheckForMetadataProblems {
       if (broke) {
         everythingLooksGood = false;
       }
-      if (broke && patch) {
+      if (broke && opts.fix) {
         KeyExtent ke = new KeyExtent(tabke);
         ke.setPrevEndRow(lastEndRow);
-        MetadataTable.updateTabletPrevEndRow(ke, new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID()));
+        MetadataTable.updateTabletPrevEndRow(ke, opts.getAuthInfo());
         System.out.println("KE " + tabke + " has been repaired to " + ke);
       }
       
@@ -106,16 +95,15 @@ public class CheckForMetadataProblems {
       sawProblems = true;
   }
   
-  public static void checkMetadataTableEntries(ServerConfiguration conf, FileSystem fs, boolean offline, boolean patch) throws Exception {
+  public static void checkMetadataTableEntries(Opts opts, FileSystem fs) throws Exception {
     Map<String,TreeSet<KeyExtent>> tables = new HashMap<String,TreeSet<KeyExtent>>();
     
     Scanner scanner;
     
-    if (offline) {
-      scanner = new OfflineMetadataScanner(conf.getConfiguration(), fs);
+    if (opts.offline) {
+      scanner = new OfflineMetadataScanner(ServerConfiguration.getSystemConfiguration(opts.getInstance()), fs);
     } else {
-      scanner = new ScannerImpl(conf.getInstance(), new AuthInfo(user, ByteBuffer.wrap(pass), conf.getInstance().getInstanceID()),
-          Constants.METADATA_TABLE_ID, Constants.NO_AUTHS);
+      scanner =  opts.getConnector().createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
     }
     
     scanner.setRange(Constants.METADATA_KEYSPACE);
@@ -141,7 +129,7 @@ public class CheckForMetadataProblems {
         Set<Entry<String,TreeSet<KeyExtent>>> es = tables.entrySet();
         
         for (Entry<String,TreeSet<KeyExtent>> entry2 : es) {
-          checkTable(entry2.getKey(), entry2.getValue(), patch);
+          checkTable(entry2.getKey(), entry2.getValue(), opts);
         }
         
         tables.clear();
@@ -158,8 +146,8 @@ public class CheckForMetadataProblems {
         if (justLoc) {
           System.out.println("Problem at key " + entry.getKey());
           sawProblems = true;
-          if (patch) {
-            Writer t = MetadataTable.getMetadataTable(new AuthInfo(user, ByteBuffer.wrap(pass), HdfsZooInstance.getInstance().getInstanceID()));
+          if (opts.fix) {
+            Writer t = MetadataTable.getMetadataTable(opts.getAuthInfo());
             Key k = entry.getKey();
             Mutation m = new Mutation(k.getRow());
             m.putDelete(k.getColumnFamily(), k.getColumnQualifier());
@@ -183,58 +171,28 @@ public class CheckForMetadataProblems {
     Set<Entry<String,TreeSet<KeyExtent>>> es = tables.entrySet();
     
     for (Entry<String,TreeSet<KeyExtent>> entry : es) {
-      checkTable(entry.getKey(), entry.getValue(), patch);
+      checkTable(entry.getKey(), entry.getValue(), opts);
     }
     
     // end METADATA table sanity check
   }
   
-  private static String[] processOptions(String[] args) {
-    ArrayList<String> al = new ArrayList<String>();
-    
-    for (String s : args) {
-      if (s.equals("--debug")) {
-        enableDebug();
-      } else if (s.equals("--fix")) {
-        fix = true;
-      } else if (s.equals("--offline")) {
-        offline = true;
-      } else {
-        al.add(s);
-      }
-    }
-    
-    if (offline && fix) {
-      throw new IllegalArgumentException("Cannot fix in offline mode");
-    }
+  static class Opts extends ClientOpts {
+    @Parameter(names="--fix", description="best-effort attempt to fix problems found")
+    boolean fix = false;
     
-    return al.toArray(new String[al.size()]);
+    @Parameter(names="--offline", description="perform the check on the files directly")
+    boolean offline = false;
   }
   
-  private static void enableDebug() {
-    Logger logger = Logger.getLogger(Constants.CORE_PACKAGE_NAME);
-    logger.setLevel(Level.TRACE);
-  }
   
   public static void main(String[] args) throws Exception {
-   final Charset utf8 = Charset.forName("UTF8");
-   args = processOptions(args);
+    Opts opts = new Opts();
+    opts.parseArgs(CheckForMetadataProblems.class.getName(), args);
     
     FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
-    Instance instance = HdfsZooInstance.getInstance();
-    ServerConfiguration conf = new ServerConfiguration(instance);
-
-    if (args.length == 2) {
-      user = args[0];
-      pass = args[1].getBytes(utf8);
-      checkMetadataTableEntries(conf, fs, offline, fix);
-    } else if (args.length == 0 && offline) {
-      checkMetadataTableEntries(conf, fs, offline, fix);
-    } else {
-      System.out.println("Usage: " + CheckForMetadataProblems.class.getName() + " (--offline)|([--debug] [--fix] <username> <password>)");
-      System.exit(-1);
-    }
-    
+    checkMetadataTableEntries(opts, fs);
+    opts.stopTracing();
     if (sawProblems)
       System.exit(-1);
   }

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/CleanZookeeper.java Mon Jan 14 22:03:24 2013
@@ -17,9 +17,9 @@
 package org.apache.accumulo.server.util;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
 import org.apache.accumulo.server.client.HdfsZooInstance;
@@ -27,10 +27,19 @@ import org.apache.accumulo.server.zookee
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 
+import com.beust.jcommander.Parameter;
+
 public class CleanZookeeper {
   
   private static final Logger log = Logger.getLogger(CleanZookeeper.class);
   
+  static class Opts extends Help {
+    @Parameter(names={"-z", "--keepers"}, description="comma separated list of zookeeper hosts")
+    String keepers = "localhost:2181";
+    @Parameter(names={"--password"}, description="the system secret", password=true)
+    String auth;
+  }
+  
   /**
    * @param args
    *          must contain one element: the address of a zookeeper node a second parameter provides an additional authentication value
@@ -38,17 +47,13 @@ public class CleanZookeeper {
    *           error connecting to accumulo or zookeeper
    */
   public static void main(String[] args) throws IOException {
-
-    final Charset utf8 = Charset.forName("UTF8");
-	  
-    if (args.length < 1) {
-      System.err.println("Usage: " + CleanZookeeper.class.getName() + " hostname[:port] [auth]");
-      System.exit(1);
-    }
+    Opts opts = new Opts();
+    opts.parseArgs(CleanZookeeper.class.getName(), args);
+    
     String root = Constants.ZROOT;
     IZooReaderWriter zk = ZooReaderWriter.getInstance();
-    if (args.length == 2) {
-      zk.getZooKeeper().addAuthInfo("digest", args[1].getBytes(utf8));
+    if (opts.auth != null) {
+      zk.getZooKeeper().addAuthInfo("digest", opts.auth.getBytes());
     }
     
     try {

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DeleteZooInstance.java Mon Jan 14 22:03:24 2013
@@ -20,42 +20,61 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy;
 import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
+import org.apache.zookeeper.KeeperException;
+
+import com.beust.jcommander.Parameter;
 
 public class DeleteZooInstance {
   
+  static class Opts extends Help {
+    @Parameter(names={"-i", "--instance"}, description="the instance name or id to delete")
+    String instance;
+  }
+  
+  static void deleteRetry(IZooReaderWriter zk, String path) throws Exception {
+    for (int i = 0; i < 10; i++){
+      try {
+        zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
+        return;
+      } catch (KeeperException.NotEmptyException ex) {
+        // ignored
+      } catch (Exception ex) {
+        throw ex;
+      }
+    }
+  }
+  
   /**
    * @param args
    *          : the name or UUID of the instance to be deleted
    */
   public static void main(String[] args) throws Exception {
-    if (args.length < 1) {
-      System.err.println("Usage: " + DeleteZooInstance.class.getName() + " [instanceName|UUID ... ]");
-      System.exit(1);
-    }
+    Opts opts = new Opts();
+    opts.parseArgs(DeleteZooInstance.class.getName(), args);
+    
     IZooReaderWriter zk = ZooReaderWriter.getInstance();
     // try instance name:
     Set<String> instances = new HashSet<String>(zk.getChildren(Constants.ZROOT + Constants.ZINSTANCES));
     Set<String> uuids = new HashSet<String>(zk.getChildren(Constants.ZROOT));
     uuids.remove("instances");
-    for (String name : args) {
-      if (instances.contains(args[0])) {
-        String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + name;
+    if (instances.contains(opts.instance)) {
+      String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + opts.instance;
+      byte[] data = zk.getData(path, null);
+      deleteRetry(zk, path);
+      deleteRetry(zk, Constants.ZROOT + "/" + new String(data));
+    } else if (uuids.contains(opts.instance)) {
+      // look for the real instance name
+      for (String instance : instances) {
+        String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance;
         byte[] data = zk.getData(path, null);
-        zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
-        zk.recursiveDelete(Constants.ZROOT + "/" + new String(data), NodeMissingPolicy.SKIP);
-      } else if (uuids.contains(name)) {
-        // look for the real instance name
-        for (String instance : instances) {
-          String path = Constants.ZROOT + Constants.ZINSTANCES + "/" + instance;
-          byte[] data = zk.getData(path, null);
-          if (name.equals(new String(data)))
-            zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
-        }
-        zk.recursiveDelete(Constants.ZROOT + "/" + name, NodeMissingPolicy.SKIP);
+        if (opts.instance.equals(new String(data)))
+          deleteRetry(zk, path);
       }
+      deleteRetry(zk, Constants.ZROOT + "/" + opts.instance);
     }
   }
   

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/DumpZookeeper.java Mon Jan 14 22:03:24 2013
@@ -19,6 +19,7 @@ package org.apache.accumulo.server.util;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
 import org.apache.commons.codec.binary.Base64;
@@ -27,6 +28,8 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.data.Stat;
 
+import com.beust.jcommander.Parameter;
+
 public class DumpZookeeper {
   
   static IZooReaderWriter zk = null;
@@ -43,24 +46,31 @@ public class DumpZookeeper {
     }
   }
   
+  static class Opts extends Help {
+    @Parameter(names="--root", description="the root of the znode tree to dump")
+    String root = "/";
+  }
+  
   /**
    * @param args
    */
   public static void main(String[] args) {
+    Opts opts = new Opts();
+    opts.parseArgs(DumpZookeeper.class.getName(), args);
+    
     Logger.getRootLogger().setLevel(Level.WARN);
     PrintStream out = System.out;
     // int timeout = 30 * 1000;
     // String server = args[0];
-    String root = "/";
     if (args.length > 0)
-      root = args[0];
+      opts.root = args[0];
     try {
       zk = ZooReaderWriter.getInstance();
       
-      write(out, 0, "<dump root='%s'>", root);
-      for (String child : zk.getChildren(root, null))
+      write(out, 0, "<dump root='%s'>", opts.root);
+      for (String child : zk.getChildren(opts.root, null))
         if (!child.equals("zookeeper"))
-          dump(out, root, child, 1);
+          dump(out, opts.root, child, 1);
       write(out, 0, "</dump>");
     } catch (Exception ex) {
       log.error(ex, ex);

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/EmbeddedWebServer.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/EmbeddedWebServer.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/EmbeddedWebServer.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/EmbeddedWebServer.java Mon Jan 14 22:03:24 2013
@@ -29,91 +29,67 @@ import org.mortbay.jetty.servlet.Session
 
 public class EmbeddedWebServer {
   
-  public static EmbeddedWebServer create(int port) throws ClassNotFoundException {
-    return new EmbeddedWebServer6_1(port);
+  Server server = null;
+  SocketConnector sock;
+  ContextHandlerCollection handler;
+  Context root;
+  boolean usingSsl;
+  
+  public EmbeddedWebServer() {
+    this("0.0.0.0", 0);
   }
   
-  public static EmbeddedWebServer create() throws ClassNotFoundException {
-    return new EmbeddedWebServer6_1();
+  public EmbeddedWebServer(String host, int port) {
+    server = new Server();
+    handler = new ContextHandlerCollection();
+    root = new Context(handler, "/", new SessionHandler(), null, null, null);
+    
+    if (Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE) == ""
+        || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS) == ""
+        || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE) == ""
+        || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS) == "") {
+      sock = new SocketConnector();
+      usingSsl = false;
+    } else {
+      sock = new SslSocketConnector();
+      ((SslSocketConnector) sock).setKeystore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE));
+      ((SslSocketConnector) sock).setKeyPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS));
+      ((SslSocketConnector) sock).setTruststore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE));
+      ((SslSocketConnector) sock).setTrustPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS));
+      usingSsl = true;
+    }
+    sock.setHost(host);
+    sock.setPort(port);
   }
   
-  public void addServlet(Class<? extends HttpServlet> klass, String where) {}
+  public void addServlet(Class<? extends HttpServlet> klass, String where) {
+    root.addServlet(klass, where);
+  }
   
   public int getPort() {
-    return 0;
+    return sock.getLocalPort();
   }
   
-  public void start() {}
-  
-  public void stop() {}
-  
-  public boolean isUsingSsl() {
-    return false;
+  public void start() {
+    try {
+      server.addConnector(sock);
+      server.setHandler(handler);
+      server.start();
+    } catch (Exception e) {
+      stop();
+      throw new RuntimeException(e);
+    }
   }
   
-  static public class EmbeddedWebServer6_1 extends EmbeddedWebServer {
-    // 6.1
-    Server server = null;
-    SocketConnector sock;
-    ContextHandlerCollection handler;
-    Context root;
-    boolean usingSsl;
-    
-    public EmbeddedWebServer6_1() throws ClassNotFoundException {
-      this(0);
-    }
-    
-    public EmbeddedWebServer6_1(int port) {
-      server = new Server();
-      handler = new ContextHandlerCollection();
-      root = new Context(handler, "/", new SessionHandler(), null, null, null);
-      
-      if (Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE) == ""
-          || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS) == ""
-          || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE) == ""
-          || Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS) == "") {
-        sock = new SocketConnector();
-        usingSsl = false;
-      } else {
-        sock = new SslSocketConnector();
-        ((SslSocketConnector) sock).setKeystore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTORE));
-        ((SslSocketConnector) sock).setKeyPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_KEYSTOREPASS));
-        ((SslSocketConnector) sock).setTruststore(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTORE));
-        ((SslSocketConnector) sock).setTrustPassword(Monitor.getSystemConfiguration().get(Property.MONITOR_SSL_TRUSTSTOREPASS));
-        usingSsl = true;
-      }
-      sock.setPort(port);
-    }
-    
-    public void addServlet(Class<? extends HttpServlet> klass, String where) {
-      root.addServlet(klass, where);
-    }
-    
-    public int getPort() {
-      return sock.getLocalPort();
-    }
-    
-    public void start() {
-      try {
-        server.addConnector(sock);
-        server.setHandler(handler);
-        server.start();
-      } catch (Exception e) {
-        stop();
-        throw new RuntimeException(e);
-      }
-    }
-    
-    public void stop() {
-      try {
-        server.stop();
-      } catch (Exception e) {
-        throw new RuntimeException(e);
-      }
-    }
-    
-    public boolean isUsingSsl() {
-      return usingSsl;
+  public void stop() {
+    try {
+      server.stop();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
     }
   }
+  
+  public boolean isUsingSsl() {
+    return usingSsl;
+  }
 }

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/FindOfflineTablets.java Mon Jan 14 22:03:24 2013
@@ -18,8 +18,8 @@ package org.apache.accumulo.server.util;
 
 import java.util.Set;
 
+import org.apache.accumulo.server.cli.ClientOpts;
 import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.ZooKeeperInstance;
 import org.apache.accumulo.core.conf.DefaultConfiguration;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.master.state.tables.TableState;
@@ -30,7 +30,6 @@ import org.apache.accumulo.server.master
 import org.apache.accumulo.server.master.state.TabletLocationState;
 import org.apache.accumulo.server.master.state.TabletState;
 import org.apache.accumulo.server.master.state.tables.TableManager;
-import org.apache.accumulo.server.security.SecurityConstants;
 import org.apache.log4j.Logger;
 
 public class FindOfflineTablets {
@@ -40,15 +39,12 @@ public class FindOfflineTablets {
    * @param args
    */
   public static void main(String[] args) throws Exception {
-    if (args.length != 4) {
-      System.err.println("Usage: accumulo.server.util.FindOfflineTablets instance zookeepers");
-      System.exit(1);
-    }
-    String instance = args[0];
-    String keepers = args[1];
-    Instance zooInst = new ZooKeeperInstance(instance, keepers);
-    MetaDataTableScanner scanner = new MetaDataTableScanner(zooInst, SecurityConstants.getSystemCredentials(), new Range());
-    LiveTServerSet tservers = new LiveTServerSet(zooInst, DefaultConfiguration.getDefaultConfiguration(), new Listener() {
+    ClientOpts opts = new ClientOpts();
+    opts.parseArgs(FindOfflineTablets.class.getName(), args);
+    
+    Instance instance = opts.getInstance();
+    MetaDataTableScanner scanner = new MetaDataTableScanner(instance, opts.getAuthInfo(), new Range());
+    LiveTServerSet tservers = new LiveTServerSet(instance, DefaultConfiguration.getDefaultConfiguration(), new Listener() {
       @Override
       public void update(LiveTServerSet current, Set<TServerInstance> deleted, Set<TServerInstance> added) {
         if (!deleted.isEmpty())

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Initialize.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Initialize.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Initialize.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/Initialize.java Mon Jan 14 22:03:24 2013
@@ -18,7 +18,6 @@ package org.apache.accumulo.server.util;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map.Entry;
@@ -27,6 +26,7 @@ import java.util.UUID;
 import jline.ConsoleReader;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
@@ -65,6 +65,8 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs.Ids;
 
+import com.beust.jcommander.Parameter;
+
 /**
  * This class is used to setup the directory structure and the root tablet to get an instance started
  * 
@@ -72,9 +74,6 @@ import org.apache.zookeeper.ZooDefs.Ids;
 public class Initialize {
   private static final Logger log = Logger.getLogger(Initialize.class);
   private static final String ROOT_USER = "root";
-  private static boolean clearInstanceName = false;
-  private static String cliInstanceName = null;
-  private static String cliPassword = null;
   
   private static ConsoleReader reader = null;
   
@@ -110,10 +109,8 @@ public class Initialize {
     initialMetadataConf.put(Property.TABLE_INDEXCACHE_ENABLED.getKey(), "true");
     initialMetadataConf.put(Property.TABLE_BLOCKCACHE_ENABLED.getKey(), "true");
   }
-
-  private static final Charset utf8 = Charset.forName("UTF8");
   
-  public static boolean doInit(Configuration conf, FileSystem fs) throws IOException {
+  public static boolean doInit(Opts opts, Configuration conf, FileSystem fs) throws IOException {
     if (!ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_DFS_URI).equals(""))
       log.info("Hadoop Filesystem is " + ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_DFS_URI));
     else
@@ -156,34 +153,34 @@ public class Initialize {
     // abort, we don't leave an inconsistent HDFS/ZooKeeper structure
     String instanceNamePath;
     try {
-      instanceNamePath = getInstanceNamePath();
+      instanceNamePath = getInstanceNamePath(opts);
     } catch (Exception e) {
       log.fatal("Failed to talk to zookeeper", e);
       return false;
     }
-    byte[] rootpass = getRootPassword();
-    return initialize(instanceNamePath, fs, rootpass);
+    opts.rootpass = getRootPassword(opts);
+    return initialize(opts, instanceNamePath, fs);
   }
   
-  public static boolean initialize(String instanceNamePath, FileSystem fs, byte[] rootpass) {
+  public static boolean initialize(Opts opts, String instanceNamePath, FileSystem fs) {
     
     UUID uuid = UUID.randomUUID();
     try {
-      initZooKeeper(uuid.toString(), instanceNamePath);
+      initZooKeeper(opts, uuid.toString(), instanceNamePath);
     } catch (Exception e) {
       log.fatal("Failed to initialize zookeeper", e);
       return false;
     }
     
     try {
-      initFileSystem(fs, fs.getConf(), uuid);
+      initFileSystem(opts, fs, fs.getConf(), uuid);
     } catch (Exception e) {
       log.fatal("Failed to initialize filesystem", e);
       return false;
     }
     
     try {
-      initSecurity(uuid.toString(), rootpass);
+      initSecurity(opts, uuid.toString());
     } catch (Exception e) {
       log.fatal("Failed to initialize security", e);
       return false;
@@ -204,8 +201,8 @@ public class Initialize {
       return false;
     }
   }
-
-  private static void initFileSystem(FileSystem fs, Configuration conf, UUID uuid) throws IOException {
+  
+  private static void initFileSystem(Opts opts, FileSystem fs, Configuration conf, UUID uuid) throws IOException {
     FileStatus fstat;
     
     // the actual disk location of the root tablet
@@ -267,7 +264,7 @@ public class Initialize {
       
       // root's directory
       Key rootDirKey = new Key(rootExtent, Constants.METADATA_DIRECTORY_COLUMN.getColumnFamily(), Constants.METADATA_DIRECTORY_COLUMN.getColumnQualifier(), 0);
-      mfw.append(rootDirKey, new Value("/root_tablet".getBytes(utf8)));
+      mfw.append(rootDirKey, new Value("/root_tablet".getBytes()));
       
       // root's prev row
       Key rootPrevRowKey = new Key(rootExtent, Constants.METADATA_PREV_ROW_COLUMN.getColumnFamily(), Constants.METADATA_PREV_ROW_COLUMN.getColumnQualifier(), 0);
@@ -278,11 +275,11 @@ public class Initialize {
       
       // table tablet's directory
       Key tableDirKey = new Key(tableExtent, Constants.METADATA_DIRECTORY_COLUMN.getColumnFamily(), Constants.METADATA_DIRECTORY_COLUMN.getColumnQualifier(), 0);
-      mfw.append(tableDirKey, new Value(Constants.TABLE_TABLET_LOCATION.getBytes(utf8)));
+      mfw.append(tableDirKey, new Value(Constants.TABLE_TABLET_LOCATION.getBytes()));
       
       // table tablet time
       Key tableTimeKey = new Key(tableExtent, Constants.METADATA_TIME_COLUMN.getColumnFamily(), Constants.METADATA_TIME_COLUMN.getColumnQualifier(), 0);
-      mfw.append(tableTimeKey, new Value((TabletTime.LOGICAL_TIME_ID + "0").getBytes(utf8)));
+      mfw.append(tableTimeKey, new Value((TabletTime.LOGICAL_TIME_ID + "0").getBytes()));
       
       // table tablet's prevrow
       Key tablePrevRowKey = new Key(tableExtent, Constants.METADATA_PREV_ROW_COLUMN.getColumnFamily(), Constants.METADATA_PREV_ROW_COLUMN.getColumnQualifier(),
@@ -295,11 +292,11 @@ public class Initialize {
       // default's directory
       Key defaultDirKey = new Key(defaultExtent, Constants.METADATA_DIRECTORY_COLUMN.getColumnFamily(),
           Constants.METADATA_DIRECTORY_COLUMN.getColumnQualifier(), 0);
-      mfw.append(defaultDirKey, new Value(Constants.DEFAULT_TABLET_LOCATION.getBytes(utf8)));
+      mfw.append(defaultDirKey, new Value(Constants.DEFAULT_TABLET_LOCATION.getBytes()));
       
       // default's time
       Key defaultTimeKey = new Key(defaultExtent, Constants.METADATA_TIME_COLUMN.getColumnFamily(), Constants.METADATA_TIME_COLUMN.getColumnQualifier(), 0);
-      mfw.append(defaultTimeKey, new Value((TabletTime.LOGICAL_TIME_ID + "0").getBytes(utf8)));
+      mfw.append(defaultTimeKey, new Value((TabletTime.LOGICAL_TIME_ID + "0").getBytes()));
       
       // default's prevrow
       Key defaultPrevRowKey = new Key(defaultExtent, Constants.METADATA_PREV_ROW_COLUMN.getColumnFamily(),
@@ -339,16 +336,16 @@ public class Initialize {
     }
   }
   
-  private static void initZooKeeper(String uuid, String instanceNamePath) throws KeeperException, InterruptedException {
+  private static void initZooKeeper(Opts opts, String uuid, String instanceNamePath) throws KeeperException, InterruptedException {
     // setup basic data in zookeeper
     IZooReaderWriter zoo = ZooReaderWriter.getInstance();
     ZooUtil.putPersistentData(zoo.getZooKeeper(), Constants.ZROOT, new byte[0], -1, NodeExistsPolicy.SKIP, Ids.OPEN_ACL_UNSAFE);
     ZooUtil.putPersistentData(zoo.getZooKeeper(), Constants.ZROOT + Constants.ZINSTANCES, new byte[0], -1, NodeExistsPolicy.SKIP, Ids.OPEN_ACL_UNSAFE);
     
     // setup instance name
-    if (clearInstanceName)
+    if (opts.clearInstanceName)
       zoo.recursiveDelete(instanceNamePath, NodeMissingPolicy.SKIP);
-    zoo.putPersistentData(instanceNamePath, uuid.getBytes(utf8), NodeExistsPolicy.FAIL);
+    zoo.putPersistentData(instanceNamePath, uuid.getBytes(), NodeExistsPolicy.FAIL);
     
     // setup the instance
     String zkInstanceRoot = Constants.ZROOT + "/" + uuid;
@@ -362,7 +359,7 @@ public class Initialize {
     zoo.putPersistentData(zkInstanceRoot + Constants.ZTRACERS, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZMASTERS, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZMASTER_LOCK, new byte[0], NodeExistsPolicy.FAIL);
-    zoo.putPersistentData(zkInstanceRoot + Constants.ZMASTER_GOAL_STATE, MasterGoalState.NORMAL.toString().getBytes(utf8), NodeExistsPolicy.FAIL);
+    zoo.putPersistentData(zkInstanceRoot + Constants.ZMASTER_GOAL_STATE, MasterGoalState.NORMAL.toString().getBytes(), NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZGC, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZGC_LOCK, new byte[0], NodeExistsPolicy.FAIL);
     zoo.putPersistentData(zkInstanceRoot + Constants.ZCONFIG, new byte[0], NodeExistsPolicy.FAIL);
@@ -372,15 +369,15 @@ public class Initialize {
     zoo.putPersistentData(zkInstanceRoot + Constants.ZRECOVERY, new byte[] {'0'}, NodeExistsPolicy.FAIL);
   }
   
-  private static String getInstanceNamePath() throws IOException, KeeperException, InterruptedException {
+  private static String getInstanceNamePath(Opts opts) throws IOException, KeeperException, InterruptedException {
     // setup the instance name
     String instanceName, instanceNamePath = null;
     boolean exists = true;
     do {
-      if (cliInstanceName == null) {
+      if (opts.cliInstanceName == null) {
         instanceName = getConsoleReader().readLine("Instance name : ");
       } else {
-        instanceName = cliInstanceName;
+        instanceName = opts.cliInstanceName;
       }
       if (instanceName == null)
         System.exit(0);
@@ -388,7 +385,7 @@ public class Initialize {
       if (instanceName.length() == 0)
         continue;
       instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName;
-      if (clearInstanceName) {
+      if (opts.clearInstanceName) {
         exists = false;
         break;
       } else if ((boolean) (exists = ZooReaderWriter.getInstance().exists(instanceNamePath))) {
@@ -396,7 +393,7 @@ public class Initialize {
         if (decision == null)
           System.exit(0);
         if (decision.length() == 1 && decision.toLowerCase(Locale.ENGLISH).charAt(0) == 'y') {
-          clearInstanceName = true;
+          opts.clearInstanceName = true;
           exists = false;
         }
       }
@@ -404,9 +401,9 @@ public class Initialize {
     return instanceNamePath;
   }
   
-  private static byte[] getRootPassword() throws IOException {
-    if (cliPassword != null) {
-      return cliPassword.getBytes(utf8);
+  private static byte[] getRootPassword(Opts opts) throws IOException {
+    if (opts.cliPassword != null) {
+      return opts.cliPassword.getBytes();
     }
     String rootpass;
     String confirmpass;
@@ -420,11 +417,11 @@ public class Initialize {
       if (!rootpass.equals(confirmpass))
         log.error("Passwords do not match");
     } while (!rootpass.equals(confirmpass));
-    return rootpass.getBytes(utf8);
+    return rootpass.getBytes();
   }
   
-  private static void initSecurity(String iid, byte[] rootpass) throws AccumuloSecurityException, ThriftSecurityException {
-    AuditedSecurityOperation.getInstance(iid).initializeSecurity(SecurityConstants.getSystemCredentials(), ROOT_USER, rootpass);
+  private static void initSecurity(Opts opts, String iid) throws AccumuloSecurityException, ThriftSecurityException {
+    AuditedSecurityOperation.getInstance(iid).initializeSecurity(SecurityConstants.getSystemCredentials(), ROOT_USER, opts.rootpass);
   }
   
   protected static void initMetadataConfig() throws IOException {
@@ -457,45 +454,44 @@ public class Initialize {
       Integer.parseInt(rep);
     initialMetadataConf.put(Property.TABLE_FILE_REPLICATION.getKey(), rep);
   }
-
+  
   public static boolean isInitialized(FileSystem fs) throws IOException {
     return (fs.exists(ServerConstants.getInstanceIdLocation()) || fs.exists(ServerConstants.getDataVersionLocation()));
   }
   
+  static class Opts extends Help {
+    @Parameter(names = "--reset-security", description = "just update the security information")
+    boolean resetSecurity = false;
+    @Parameter(names = "--clear-instance-name", description = "delete any existing instance name without prompting")
+    boolean clearInstanceName = false;
+    @Parameter(names = "--instance-name", description = "the instance name, if not provided, will prompt")
+    String cliInstanceName;
+    @Parameter(names = "--password", description = "set the password on the command line")
+    String cliPassword;
+    
+    byte[] rootpass = null;
+  }
+  
   public static void main(String[] args) {
-    boolean justSecurity = false;
+    Opts opts = new Opts();
+    opts.parseArgs(Initialize.class.getName(), args);
     
-    for (int i = 0; i < args.length; i++) {
-      if (args[i].equals("--reset-security")) {
-          justSecurity = true;
-        } else if (args[i].equals("--clear-instance-name")) {
-          clearInstanceName = true;
-        } else if (args[i].equals("--instance-name")) {
-            cliInstanceName = args[i+1];
-            i++;
-        } else if (args[i].equals("--password")) {
-            cliPassword = args[i+1];
-            i++;
-        } else {
-          RuntimeException e = new RuntimeException();
-          log.fatal("Usage: [--reset-security] [--clear-instance-name] [--instance-name {name}] [--password {password}]");
-          log.fatal("Bad argument " + args[i], e);
-          throw e;
-        }
-    }
+    boolean justSecurity = false;
     
     try {
       SecurityUtil.serverLogin();
       Configuration conf = CachedConfiguration.getInstance();
       
       FileSystem fs = FileUtil.getFileSystem(conf, ServerConfiguration.getSiteConfiguration());
-
+      
       if (justSecurity) {
-        if (isInitialized(fs))
-          initSecurity(HdfsZooInstance.getInstance().getInstanceID(), getRootPassword());
-        else
+        if (isInitialized(fs)) {
+          opts.rootpass = getRootPassword(opts);
+          initSecurity(opts, HdfsZooInstance.getInstance().getInstanceID());
+        } else {
           log.fatal("Attempted to reset security on accumulo before it was initialized");
-      } else if (!doInit(conf, fs))
+        }
+      } else if (!doInit(opts, conf, fs))
         System.exit(-1);
     } catch (Exception e) {
       log.fatal(e, e);

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ListInstances.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ListInstances.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ListInstances.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/ListInstances.java Mon Jan 14 22:03:24 2013
@@ -16,7 +16,6 @@
  */
 package org.apache.accumulo.server.util;
 
-import java.util.ArrayList;
 import java.util.Formattable;
 import java.util.Formatter;
 import java.util.List;
@@ -26,6 +25,7 @@ import java.util.TreeSet;
 import java.util.UUID;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
 import org.apache.accumulo.server.conf.ServerConfiguration;
@@ -33,6 +33,8 @@ import org.apache.accumulo.server.zookee
 import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
 import org.apache.log4j.Logger;
 
+import com.beust.jcommander.Parameter;
+
 public class ListInstances {
   
   private static final Logger log = Logger.getLogger(ListInstances.class);
@@ -40,26 +42,26 @@ public class ListInstances {
   private static final int NAME_WIDTH = 20;
   private static final int UUID_WIDTH = 37;
   private static final int MASTER_WIDTH = 30;
-  private static String zooKeepers;
-  private static boolean printErrors;
-  private static boolean printAll;
-  private static int errors = 0;
+  
+  static class Opts extends Help {
+    @Parameter(names="--print-errors", description="display errors while listing instances")
+    boolean printErrors = false;
+    @Parameter(names="--print-all", description="print information for all instances, not just those with names")
+    boolean printAll = false;
+    @Parameter(names={"-z", "--zookeepers"}, description="the zookeepers to contact")
+    String keepers = null;
+  }
+  static Opts opts = new Opts();
+  static int errors = 0;
   
   public static void main(String[] args) {
+    opts.parseArgs(ListInstances.class.getName(), args);
     
-    args = processOptions(args);
-    
-    if (args.length > 1) {
-      System.err.println("Usage : " + ListInstances.class.getName() + " [<zoo keepers>]");
-    }
-    
-    if (args.length == 1) {
-      zooKeepers = args[0];
-    } else {
-      zooKeepers = ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_ZK_HOST);
+    if (opts.keepers == null) {
+      opts.keepers = ServerConfiguration.getSiteConfiguration().get(Property.INSTANCE_ZK_HOST);
     }
     
-    System.out.println("INFO : Using ZooKeepers " + zooKeepers);
+    System.out.println("INFO : Using ZooKeepers " + opts.keepers);
     
     TreeMap<String,UUID> instanceNames = getInstanceNames();
     
@@ -73,7 +75,7 @@ public class ListInstances {
     TreeSet<UUID> instancedIds = getInstanceIDs();
     instancedIds.removeAll(instanceNames.values());
     
-    if (printAll) {
+    if (opts.printAll) {
       for (UUID uuid : instancedIds) {
         printInstanceInfo(null, uuid);
       }
@@ -84,28 +86,12 @@ public class ListInstances {
       System.out.println();
     }
     
-    if (!printErrors && errors > 0) {
+    if (!opts.printErrors && errors > 0) {
       System.err.println("WARN : There were " + errors + " errors, run with --print-errors to see more info");
     }
     
   }
   
-  private static String[] processOptions(String[] args) {
-    ArrayList<String> al = new ArrayList<String>();
-    
-    for (String s : args) {
-      if (s.equals("--print-errors")) {
-        printErrors = true;
-      } else if (s.equals("--print-all")) {
-        printAll = true;
-      } else {
-        al.add(s);
-      }
-    }
-    
-    return al.toArray(new String[al.size()]);
-  }
-  
   private static class CharFiller implements Formattable {
     
     char c;
@@ -220,7 +206,7 @@ public class ListInstances {
   }
   
   private static void handleException(Exception e) {
-    if (printErrors) {
+    if (opts.printErrors) {
       e.printStackTrace();
     }
     

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/LocalityCheck.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/LocalityCheck.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/LocalityCheck.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/LocalityCheck.java Mon Jan 14 22:03:24 2013
@@ -17,16 +17,15 @@
 package org.apache.accumulo.server.util;
 
 import java.net.InetSocketAddress;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.server.cli.ClientOpts;
 import org.apache.accumulo.core.client.Connector;
 import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.ZooKeeperInstance;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.KeyExtent;
 import org.apache.accumulo.core.data.Value;
@@ -38,17 +37,13 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 
 public class LocalityCheck {
-
-  private static final Charset utf8 = Charset.forName("UTF8");
   
   public int run(String[] args) throws Exception {
-    if (args.length < 4) {
-      System.err.println("Usage: " + LocalityCheck.class.getName() + " instance zookeepers username password");
-      System.exit(1);
-    }
-    ZooKeeperInstance instance = new ZooKeeperInstance(args[0], args[1]);
+    ClientOpts opts = new ClientOpts();
+    opts.parseArgs(LocalityCheck.class.getName(), args);
+    
     FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
-    Connector connector = instance.getConnector(args[2], args[3].getBytes(utf8));
+    Connector connector = opts.getConnector();
     Scanner scanner = connector.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
     scanner.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY);
     scanner.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/MetadataTable.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/MetadataTable.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/MetadataTable.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/MetadataTable.java Mon Jan 14 22:03:24 2013
@@ -20,7 +20,6 @@
 package org.apache.accumulo.server.util;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -99,8 +98,6 @@ public class MetadataTable extends org.a
   private static final Logger log = Logger.getLogger(MetadataTable.class);
   
   private static final int SAVE_ROOT_TABLET_RETRIES = 3;
-
-  private static final Charset utf8 = Charset.forName("UTF8");
   
   private MetadataTable() {
     
@@ -116,7 +113,7 @@ public class MetadataTable extends org.a
   }
   
   public static void putLockID(ZooLock zooLock, Mutation m) {
-    Constants.METADATA_LOCK_COLUMN.put(m, new Value(zooLock.getLockID().serialize(ZooUtil.getRoot(HdfsZooInstance.getInstance()) + "/").getBytes(utf8)));
+    Constants.METADATA_LOCK_COLUMN.put(m, new Value(zooLock.getLockID().serialize(ZooUtil.getRoot(HdfsZooInstance.getInstance()) + "/").getBytes()));
   }
   
   public static void update(AuthInfo credentials, Mutation m) {
@@ -195,7 +192,7 @@ public class MetadataTable extends org.a
     
     if (dfv.getNumEntries() > 0) {
       m.put(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(path), new Value(dfv.encode()));
-      Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes(utf8)));
+      Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes()));
       // stuff in this location
       TServerInstance self = getTServerInstance(address, zooLock);
       self.putLastLocation(m);
@@ -210,12 +207,12 @@ public class MetadataTable extends org.a
     }
     
     for (String scanFile : filesInUseByScans)
-      m.put(Constants.METADATA_SCANFILE_COLUMN_FAMILY, new Text(scanFile), new Value("".getBytes(utf8)));
+      m.put(Constants.METADATA_SCANFILE_COLUMN_FAMILY, new Text(scanFile), new Value("".getBytes()));
     
     if (mergeFile != null)
       m.putDelete(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(mergeFile));
     
-    Constants.METADATA_FLUSH_COLUMN.put(m, new Value((flushId + "").getBytes(utf8)));
+    Constants.METADATA_FLUSH_COLUMN.put(m, new Value((flushId + "").getBytes()));
     
     update(credentials, zooLock, m);
     
@@ -237,7 +234,7 @@ public class MetadataTable extends org.a
   public static void updateTabletFlushID(KeyExtent extent, long flushID, AuthInfo credentials, ZooLock zooLock) {
     if (!extent.isRootTablet()) {
       Mutation m = new Mutation(extent.getMetadataEntry());
-      Constants.METADATA_FLUSH_COLUMN.put(m, new Value((flushID + "").getBytes(utf8)));
+      Constants.METADATA_FLUSH_COLUMN.put(m, new Value((flushID + "").getBytes()));
       update(credentials, zooLock, m);
     }
   }
@@ -245,29 +242,29 @@ public class MetadataTable extends org.a
   public static void updateTabletCompactID(KeyExtent extent, long compactID, AuthInfo credentials, ZooLock zooLock) {
     if (!extent.isRootTablet()) {
       Mutation m = new Mutation(extent.getMetadataEntry());
-      Constants.METADATA_COMPACT_COLUMN.put(m, new Value((compactID + "").getBytes(utf8)));
+      Constants.METADATA_COMPACT_COLUMN.put(m, new Value((compactID + "").getBytes()));
       update(credentials, zooLock, m);
     }
   }
   
   public static void updateTabletDataFile(long tid, KeyExtent extent, Map<String,DataFileValue> estSizes, String time, AuthInfo credentials, ZooLock zooLock) {
     Mutation m = new Mutation(extent.getMetadataEntry());
-    byte[] tidBytes = Long.toString(tid).getBytes(utf8);
+    byte[] tidBytes = Long.toString(tid).getBytes();
     
     for (Entry<String,DataFileValue> entry : estSizes.entrySet()) {
       Text file = new Text(entry.getKey());
       m.put(Constants.METADATA_DATAFILE_COLUMN_FAMILY, file, new Value(entry.getValue().encode()));
       m.put(Constants.METADATA_BULKFILE_COLUMN_FAMILY, file, new Value(tidBytes));
     }
-    Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes(utf8)));
+    Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes()));
     update(credentials, zooLock, m);
   }
   
   public static void addTablet(KeyExtent extent, String path, AuthInfo credentials, char timeType, ZooLock lock) {
     Mutation m = extent.getPrevRowUpdateMutation();
     
-    Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(path.getBytes(utf8)));
-    Constants.METADATA_TIME_COLUMN.put(m, new Value((timeType + "0").getBytes(utf8)));
+    Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(path.getBytes()));
+    Constants.METADATA_TIME_COLUMN.put(m, new Value((timeType + "0").getBytes()));
     
     update(credentials, lock, m);
   }
@@ -347,7 +344,7 @@ public class MetadataTable extends org.a
       try {
         log.info("trying to write root tablet location to ZooKeeper as " + address);
         String zRootLocPath = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZROOT_TABLET_LOCATION;
-        zoo.putPersistentData(zRootLocPath, address.getBytes(utf8), NodeExistsPolicy.OVERWRITE);
+        zoo.putPersistentData(zRootLocPath, address.getBytes(), NodeExistsPolicy.OVERWRITE);
         return true;
       } catch (Exception e) {
         log.error("Master: unable to save root tablet location in zookeeper. exception: " + e, e);
@@ -384,12 +381,12 @@ public class MetadataTable extends org.a
       Map<String,Long> bulkLoadedFiles, AuthInfo credentials, String time, long lastFlushID, long lastCompactID, ZooLock zooLock) {
     Mutation m = extent.getPrevRowUpdateMutation();
     
-    Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(path.getBytes(utf8)));
-    Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes(utf8)));
+    Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(path.getBytes()));
+    Constants.METADATA_TIME_COLUMN.put(m, new Value(time.getBytes()));
     if (lastFlushID > 0)
-      Constants.METADATA_FLUSH_COLUMN.put(m, new Value(("" + lastFlushID).getBytes(utf8)));
+      Constants.METADATA_FLUSH_COLUMN.put(m, new Value(("" + lastFlushID).getBytes()));
     if (lastCompactID > 0)
-      Constants.METADATA_COMPACT_COLUMN.put(m, new Value(("" + lastCompactID).getBytes(utf8)));
+      Constants.METADATA_COMPACT_COLUMN.put(m, new Value(("" + lastCompactID).getBytes()));
     
     if (location != null) {
       m.put(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY, location.asColumnQualifier(), location.asMutationValue());
@@ -401,7 +398,7 @@ public class MetadataTable extends org.a
     }
     
     for (Entry<String,Long> entry : bulkLoadedFiles.entrySet()) {
-      byte[] tidBytes = Long.toString(entry.getValue()).getBytes(utf8);
+      byte[] tidBytes = Long.toString(entry.getValue()).getBytes();
       m.put(Constants.METADATA_BULKFILE_COLUMN_FAMILY, new Text(entry.getKey()), new Value(tidBytes));
     }
 
@@ -411,7 +408,7 @@ public class MetadataTable extends org.a
   public static void splitTablet(KeyExtent extent, Text oldPrevEndRow, double splitRatio, AuthInfo credentials, ZooLock zooLock) {
     Mutation m = extent.getPrevRowUpdateMutation(); //
     
-    Constants.METADATA_SPLIT_RATIO_COLUMN.put(m, new Value(Double.toString(splitRatio).getBytes(utf8)));
+    Constants.METADATA_SPLIT_RATIO_COLUMN.put(m, new Value(Double.toString(splitRatio).getBytes()));
     
     Constants.METADATA_OLD_PREV_ROW_COLUMN.put(m, KeyExtent.encodePrevEndRow(oldPrevEndRow));
     Constants.METADATA_CHOPPED_COLUMN.putDelete(m);
@@ -461,13 +458,13 @@ public class MetadataTable extends org.a
       m.putDelete(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(pathToRemove));
     
     for (String scanFile : scanFiles)
-      m.put(Constants.METADATA_SCANFILE_COLUMN_FAMILY, new Text(scanFile), new Value("".getBytes(utf8)));
+      m.put(Constants.METADATA_SCANFILE_COLUMN_FAMILY, new Text(scanFile), new Value("".getBytes()));
     
     if (size.getNumEntries() > 0)
       m.put(Constants.METADATA_DATAFILE_COLUMN_FAMILY, new Text(path), new Value(size.encode()));
     
     if (compactionId != null)
-      Constants.METADATA_COMPACT_COLUMN.put(m, new Value(("" + compactionId).getBytes(utf8)));
+      Constants.METADATA_COMPACT_COLUMN.put(m, new Value(("" + compactionId).getBytes()));
     
     TServerInstance self = getTServerInstance(address, zooLock);
     self.putLastLocation(m);
@@ -794,7 +791,7 @@ public class MetadataTable extends org.a
     } else {
       String value = StringUtil.join(entry.logSet, ";") + "|" + entry.tabletId;
       Mutation m = new Mutation(entry.extent.getMetadataEntry());
-      m.put(Constants.METADATA_LOG_COLUMN_FAMILY, new Text(entry.server + "/" + entry.filename), new Value(value.getBytes(utf8)));
+      m.put(Constants.METADATA_LOG_COLUMN_FAMILY, new Text(entry.server + "/" + entry.filename), new Value(value.getBytes()));
       update(credentials, zooLock, m);
     }
   }
@@ -1108,7 +1105,7 @@ public class MetadataTable extends org.a
       } else {
         // write out marker that this tablet was successfully cloned
         Mutation m = new Mutation(cloneTablet.keySet().iterator().next().getRow());
-        m.put(Constants.METADATA_CLONED_COLUMN_FAMILY, new Text(""), new Value("OK".getBytes(utf8)));
+        m.put(Constants.METADATA_CLONED_COLUMN_FAMILY, new Text(""), new Value("OK".getBytes()));
         bw.addMutation(m);
       }
     }
@@ -1163,7 +1160,7 @@ public class MetadataTable extends org.a
       Key k = entry.getKey();
       Mutation m = new Mutation(k.getRow());
       m.putDelete(k.getColumnFamily(), k.getColumnQualifier());
-      Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(FastFormat.toZeroPaddedString(dirCount++, 8, 16, "/c-".getBytes(utf8))));
+      Constants.METADATA_DIRECTORY_COLUMN.put(m, new Value(FastFormat.toZeroPaddedString(dirCount++, 8, 16, "/c-".getBytes())));
       bw.addMutation(m);
     }
     
@@ -1173,7 +1170,7 @@ public class MetadataTable extends org.a
   
   public static void chopped(KeyExtent extent, ZooLock zooLock) {
     Mutation m = new Mutation(extent.getMetadataEntry());
-    Constants.METADATA_CHOPPED_COLUMN.put(m, new Value("chopped".getBytes(utf8)));
+    Constants.METADATA_CHOPPED_COLUMN.put(m, new Value("chopped".getBytes()));
     update(SecurityConstants.getSystemCredentials(), zooLock, m);
   }
   

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/OfflineMetadataScanner.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/OfflineMetadataScanner.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/OfflineMetadataScanner.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/OfflineMetadataScanner.java Mon Jan 14 22:03:24 2013
@@ -180,6 +180,7 @@ public class OfflineMetadataScanner exte
     return range;
   }
   
+  @Deprecated
   @Override
   public int getTimeOut() {
     throw new UnsupportedOperationException();
@@ -237,6 +238,7 @@ public class OfflineMetadataScanner exte
     this.range = range;
   }
   
+  @Deprecated
   @Override
   public void setTimeOut(int timeOut) {
     throw new UnsupportedOperationException();

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RandomWriter.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RandomWriter.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RandomWriter.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RandomWriter.java Mon Jan 14 22:03:24 2013
@@ -16,23 +16,20 @@
  */
 package org.apache.accumulo.server.util;
 
-import java.nio.charset.Charset;
 import java.util.Iterator;
 import java.util.Random;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.server.cli.ClientOnDefaultTable;
+import org.apache.accumulo.core.cli.BatchWriterOpts;
 import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.MutationsRejectedException;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.server.client.HdfsZooInstance;
 import org.apache.hadoop.io.Text;
 import org.apache.log4j.Logger;
 
+import com.beust.jcommander.Parameter;
+
 public class RandomWriter {
   
   private static String table_name = "test_write_table";
@@ -79,32 +76,26 @@ public class RandomWriter {
       return this;
     }
   }
-  
-  public static void main(String[] args) throws MutationsRejectedException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
+  static class Opts extends ClientOnDefaultTable {
+    @Parameter(names="--count", description="number of mutations to write", required=true)
+    long count;
+    
+    Opts(String table) { super(table); }
+  }
+  public static void main(String[] args) throws Exception {
+    Opts opts = new Opts(table_name);
+    BatchWriterOpts bwOpts = new BatchWriterOpts();
+    opts.parseArgs(RandomWriter.class.getName(), args, bwOpts);
+    
     long start = System.currentTimeMillis();
-    final Charset utf8 = Charset.forName("UTF8");
-    if (args.length != 3) {
-      log.error("Usage: bin/accumulo " + RandomWriter.class.getName() + " <username> <password> <num_mutations_to_write>");
-      return;
-    }
-    log.info("starting at " + start + " for user " + args[0]);
+    log.info("starting at " + start + " for user " + opts.user);
     try {
-      Connector connector = HdfsZooInstance.getInstance().getConnector(args[0], args[1].getBytes(utf8));
-      BatchWriter bw = connector.createBatchWriter(table_name, new BatchWriterConfig());
-      long num_mutations = Long.parseLong(args[2]);
-      log.info("Writing " + num_mutations + " mutations...");
-      bw.addMutations(new RandomMutationGenerator(num_mutations));
+      Connector connector = opts.getConnector();
+      BatchWriter bw = connector.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
+      log.info("Writing " + opts.count + " mutations...");
+      bw.addMutations(new RandomMutationGenerator(opts.count));
       bw.close();
-    } catch (MutationsRejectedException e) {
-      log.error(e);
-      throw e;
-    } catch (AccumuloException e) {
-      log.error(e);
-      throw e;
-    } catch (AccumuloSecurityException e) {
-      log.error(e);
-      throw e;
-    } catch (TableNotFoundException e) {
+    } catch (Exception e) {
       log.error(e);
       throw e;
     }

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RemoveEntriesForMissingFiles.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RemoveEntriesForMissingFiles.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RemoveEntriesForMissingFiles.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RemoveEntriesForMissingFiles.java Mon Jan 14 22:03:24 2013
@@ -16,26 +16,27 @@
  */
 package org.apache.accumulo.server.util;
 
-import java.nio.charset.Charset;
 import java.util.Map.Entry;
 
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.server.cli.ClientOpts;
+import org.apache.accumulo.core.cli.BatchWriterOpts;
+import org.apache.accumulo.core.cli.ScannerOpts;
+import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.ZooKeeperInstance;
-import org.apache.accumulo.core.client.impl.Writer;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.KeyExtent;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.util.CachedConfiguration;
 import org.apache.accumulo.server.ServerConstants;
-import org.apache.accumulo.server.security.SecurityConstants;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.log4j.Logger;
 
+import com.beust.jcommander.Parameter;
+
 /**
  * Remove file entries for map files that don't exist.
  * 
@@ -43,38 +44,48 @@ import org.apache.log4j.Logger;
 public class RemoveEntriesForMissingFiles {
   private static Logger log = Logger.getLogger(RemoveEntriesForMissingFiles.class);
   
+  static class Opts extends ClientOpts {
+    @Parameter(names="--fix")
+    boolean fix = false;
+  }
+  
   public static void main(String[] args) throws Exception {
-    final Charset utf8 = Charset.forName("UTF8");
+    Opts opts = new Opts();
+    ScannerOpts scanOpts = new ScannerOpts();
+    BatchWriterOpts bwOpts = new BatchWriterOpts();
+    opts.parseArgs(RemoveEntriesForMissingFiles.class.getName(), args, scanOpts, bwOpts);
     FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
-    if (args.length < 4) {
-      System.err.println("Usage: accumulo.server.util.RemoveEntriesForMissingFiles instance zookeepers username password [delete]");
-      System.exit(1);
-    }
-    Instance instance = new ZooKeeperInstance(args[0], args[1]);
-    Connector connector = instance.getConnector(args[2], args[3].getBytes(utf8));
-    Scanner metadata = connector.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
-    metadata.setBatchSize(1000 * 1000);
+    Connector connector = opts.getConnector();
+    Scanner metadata = connector.createScanner(Constants.METADATA_TABLE_NAME, opts.auths);
+    metadata.setBatchSize(scanOpts.scanBatchSize);
     metadata.setRange(Constants.METADATA_KEYSPACE);
     metadata.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);
     int count = 0;
     int missing = 0;
-    Writer writer = MetadataTable.getMetadataTable(SecurityConstants.getSystemCredentials());
+    BatchWriter writer = null; 
+    if (opts.fix)
+      writer = connector.createBatchWriter(Constants.METADATA_TABLE_NAME, bwOpts.getBatchWriterConfig());
     for (Entry<Key,Value> entry : metadata) {
       count++;
       Key key = entry.getKey();
       String table = new String(KeyExtent.tableOfMetadataRow(entry.getKey().getRow()));
-      Path map = new Path(ServerConstants.getTablesDir() + "/" + table + key.getColumnQualifier().toString());
+      String file = key.getColumnQualifier().toString();
+      if (!file.startsWith("/"))
+        file = "/" + file;
+      Path map = new Path(ServerConstants.getTablesDir() + "/" + table + file);
       if (!fs.exists(map)) {
         missing++;
         log.info("File " + map + " is missing");
         Mutation m = new Mutation(key.getRow());
         m.putDelete(key.getColumnFamily(), key.getColumnQualifier());
-        if (args.length > 4) {
-          writer.update(m);
+        if (writer != null) {
+          writer.addMutation(m);
           log.info("entry removed from metadata table: " + m);
         }
       }
     }
+    if (writer != null && missing > 0)
+      writer.close();
     log.info(String.format("%d files of %d missing", missing, count));
   }
 }

Modified: accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java
URL: http://svn.apache.org/viewvc/accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java?rev=1433166&r1=1433165&r2=1433166&view=diff
==============================================================================
--- accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java (original)
+++ accumulo/branches/ACCUMULO-259/server/src/main/java/org/apache/accumulo/server/util/RestoreZookeeper.java Mon Jan 14 22:03:24 2013
@@ -18,12 +18,12 @@ package org.apache.accumulo.server.util;
 
 import java.io.FileInputStream;
 import java.io.InputStream;
-import java.nio.charset.Charset;
 import java.util.Stack;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import org.apache.accumulo.core.cli.Help;
 import org.apache.accumulo.core.zookeeper.ZooUtil;
 import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
 import org.apache.commons.codec.binary.Base64;
@@ -37,9 +37,9 @@ import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
-public class RestoreZookeeper {
+import com.beust.jcommander.Parameter;
 
-  private static final Charset utf8 = Charset.forName("UTF8");
+public class RestoreZookeeper {
   
   private static class Restore extends DefaultHandler {
     ZooKeeper zk = null;
@@ -77,9 +77,9 @@ public class RestoreZookeeper {
     }
     
     private void create(String path, String value, String encoding) {
-      byte[] data = value.getBytes(utf8);
+      byte[] data = value.getBytes();
       if ("base64".equals(encoding))
-        data = Base64.decodeBase64(value.getBytes(utf8));
+        data = Base64.decodeBase64(value.getBytes());
       try {
         try {
           ZooUtil.putPersistentData(zk, path, data, overwrite ? NodeExistsPolicy.OVERWRITE : NodeExistsPolicy.FAIL);
@@ -94,32 +94,37 @@ public class RestoreZookeeper {
     }
   }
   
+  static class Opts extends Help {
+    @Parameter(names={"-z", "--keepers"})
+    String keepers = "localhost:2181";
+    @Parameter(names="--overwrite")
+    boolean overwrite = false;
+    @Parameter(names="--file")
+    String file;
+  }
+  
   /**
    * @param args
    * @throws Exception
    */
   public static void main(String[] args) throws Exception {
     Logger.getRootLogger().setLevel(Level.WARN);
+    Opts opts = new Opts();
+    opts.parseArgs(RestoreZookeeper.class.getName(), args);
     
-    String server = args[0];
     int timeout = 30 * 1000;
     InputStream in = System.in;
-    boolean overwrite = false;
-    if (args.length > 1) {
-      in = new FileInputStream(args[1]);
+    if (opts.file != null) {
+      in = new FileInputStream(opts.file);
     }
-    for (String arg : args)
-      if (arg.equals("--overwrite"))
-        overwrite = true;
-    
-    ZooKeeper zk = new ZooKeeper(server, timeout, new Watcher() {
+    ZooKeeper zk = new ZooKeeper(opts.keepers, timeout, new Watcher() {
       @Override
       public void process(WatchedEvent event) {}
     });
     
     SAXParserFactory factory = SAXParserFactory.newInstance();
     SAXParser parser = factory.newSAXParser();
-    parser.parse(in, new Restore(zk, overwrite));
+    parser.parse(in, new Restore(zk, opts.overwrite));
     in.close();
   }
 }



Mime
View raw message