accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [4/6] git commit: Merge branch '1.5' into 1.6
Date Fri, 10 Oct 2014 22:19:00 GMT
Merge branch '1.5' into 1.6


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

Branch: refs/heads/master
Commit: 3a73e25f2fd19286aca2390e4bc88623fdb0e0ab
Parents: a269f75 085c5b7
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Fri Oct 10 18:05:31 2014 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Fri Oct 10 18:05:31 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/accumulo/core/util/shell/Shell.java | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/3a73e25f/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index 7775567,bb3c06e..011ae93
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@@ -36,10 -36,10 +36,11 @@@ import java.util.Map.Entry
  import java.util.Set;
  import java.util.TreeMap;
  import java.util.UUID;
+ import java.util.concurrent.TimeUnit;
  
 -import jline.ConsoleReader;
 -import jline.History;
 +import jline.console.ConsoleReader;
 +import jline.console.UserInterruptException;
 +import jline.console.history.FileHistory;
  
  import org.apache.accumulo.core.Constants;
  import org.apache.accumulo.core.client.AccumuloException;
@@@ -236,97 -213,102 +237,97 @@@ public class Shell extends ShellOption
      this.reader = reader;
      this.writer = writer;
    }
 -  
 +
    // Not for client use
    public boolean config(String... args) {
 -    
 -    CommandLine cl;
 +    ShellOptionsJC options = new ShellOptionsJC();
 +    JCommander jc = new JCommander();
 +
 +    jc.setProgramName("accumulo shell");
 +    jc.addObject(options);
      try {
 -      cl = new BasicParser().parse(opts, args);
 -      if (cl.getArgs().length > 0)
 -        throw new ParseException("Unrecognized arguments: " + cl.getArgList());
 -      
 -      if (cl.hasOption(helpOpt.getOpt())) {
 -        configError = true;
 -        printHelp("shell", SHELL_DESCRIPTION, opts);
 -        return true;
 -      }
 -      
 -      setDebugging(cl.hasOption(debugOption.getLongOpt()));
 -      authTimeout = TimeUnit.MINUTES.toNanos(Integer.parseInt(cl.getOptionValue(authTimeoutOpt.getLongOpt(),
DEFAULT_AUTH_TIMEOUT)));
 -      disableAuthTimeout = cl.hasOption(disableAuthTimeoutOpt.getLongOpt());
 -      
 -      if (cl.hasOption(zooKeeperInstance.getOpt()) && cl.getOptionValues(zooKeeperInstance.getOpt()).length
!= 2)
 -        throw new MissingArgumentException(zooKeeperInstance);
 -      
 -    } catch (Exception e) {
 +      jc.parse(args);
 +    } catch (ParameterException e) {
        configError = true;
 -      printException(e);
 -      printHelp("shell", SHELL_DESCRIPTION, opts);
 +    }
 +
 +    if (options.isHelpEnabled()) {
 +      configError = true;
 +    }
 +
 +    if (!configError && options.getUnrecognizedOptions() != null) {
 +      configError = true;
 +      logError("Unrecognized Options: " + options.getUnrecognizedOptions().toString());
 +    }
 +
 +    if (configError) {
 +      jc.usage();
        return true;
      }
 -    
 +
 +    setDebugging(options.isDebugEnabled());
-     authTimeout = options.getAuthTimeout() * 60 * 1000l; // convert minutes to milliseconds
++    authTimeout = TimeUnit.MINUTES.toNanos(options.getAuthTimeout());
 +    disableAuthTimeout = options.isAuthTimeoutDisabled();
 +
      // get the options that were parsed
 -    String sysUser = System.getProperty("user.name");
 -    if (sysUser == null)
 -      sysUser = "root";
 -    String user = cl.getOptionValue(usernameOption.getOpt(), sysUser);
 -    
 -    String passw = cl.getOptionValue(passwOption.getOpt(), null);
 -    tabCompletion = !cl.hasOption(tabCompleteOption.getLongOpt());
 -    String[] loginOptions = cl.getOptionValues(loginOption.getOpt());
 -    
 +    String user = options.getUsername();
 +    String password = options.getPassword();
 +
 +    tabCompletion = !options.isTabCompletionDisabled();
 +
      // Use a fake (Mock), ZK, or HdfsZK Accumulo instance
 -    setInstance(cl);
 -    
 +    setInstance(options);
 +
 +    // AuthenticationToken options
 +    token = options.getAuthenticationToken();
 +    Map<String,String> loginOptions = options.getTokenProperties();
 +
      // process default parameters if unspecified
      try {
 -      if (loginOptions != null && !cl.hasOption(tokenOption.getOpt()))
 -        throw new IllegalArgumentException("Must supply '-" + tokenOption.getOpt() + "'
option with '-" + loginOption.getOpt() + "' option");
 -      
 -      if (loginOptions == null && cl.hasOption(tokenOption.getOpt()))
 -        throw new IllegalArgumentException("Must supply '-" + loginOption.getOpt() + "'
option with '-" + tokenOption.getOpt() + "' option");
 -      
 -      if (passw != null && cl.hasOption(tokenOption.getOpt()))
 -        throw new IllegalArgumentException("Can not supply '-" + passwOption.getOpt() +
"' option with '-" + tokenOption.getOpt() + "' option");
 -      
 -      if (user == null)
 -        throw new MissingArgumentException(usernameOption);
 -      
 -      if (loginOptions != null && cl.hasOption(tokenOption.getOpt())) {
 -        Properties props = new Properties();
 -        for (String loginOption : loginOptions)
 -          for (String lo : loginOption.split(",")) {
 -            String[] split = lo.split("=");
 -            props.put(split[0], split[1]);
 -          }
 -        
 -        this.token = Class.forName(cl.getOptionValue(tokenOption.getOpt())).asSubclass(AuthenticationToken.class).newInstance();
 -        this.token.init(props);
 -      }
 -      
 -      if (!cl.hasOption(fakeOption.getLongOpt())) {
 -        DistributedTrace.enable(instance, new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()),
"shell", InetAddress.getLocalHost()
 -            .getHostName());
 +      boolean hasToken = (token != null);
 +      boolean hasTokenOptions = !loginOptions.isEmpty();
 +
 +      if (hasToken && password != null) {
 +        throw new ParameterException("Can not supply '--pass' option with '--tokenClass'
option");
        }
 -      
 +
        Runtime.getRuntime().addShutdownHook(new Thread() {
          @Override
 -        public void start() {
 -          reader.getTerminal().enableEcho();
 +        public void run() {
 +          reader.getTerminal().setEchoEnabled(true);
          }
        });
 -      
 -      if (passw != null) {
 -        this.token = new PasswordToken(passw);
 +
 +      // Need either both a token and options, or neither, but not just one.
 +      if (hasToken != hasTokenOptions) {
 +        throw new ParameterException("Must supply either both or neither of '--tokenClass'
and '--tokenProperty'");
 +      } else if (hasToken) { // implied hasTokenOptions
 +        // Fully qualified name so we don't shadow java.util.Properties
 +        org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties props;
 +        // and line wrap it because the package name is so long
 +        props = new org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties();
 +
 +        props.putAllStrings(loginOptions);
 +        token.init(props);
 +      } else {
 +        // Read password if the user explicitly asked for it, or didn't specify anything
at all
 +        if ("stdin".equals(password) || password == null) {
 +          password = reader.readLine("Password: ", '*');
 +        }
 +
 +        if (password == null) {
 +          // User cancel, e.g. Ctrl-D pressed
 +          throw new ParameterException("No password or token option supplied");
 +        } else {
 +          this.token = new PasswordToken(password);
 +        }
        }
 -      
 -      if (this.token == null) {
 -        passw = readMaskedLine("Password: ", '*');
 -        if (passw != null)
 -          this.token = new PasswordToken(passw);
 +
 +      if (!options.isFake()) {
 +        ZooReader zr = new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
 +        DistributedTrace.enable(instance, zr, "shell", InetAddress.getLocalHost().getHostName());
        }
 -      
 -      if (this.token == null) {
 -        reader.printNewline();
 -        throw new MissingArgumentException("No password or token option supplied");
 -      } // user canceled
 -      
 +
        this.setTableName("");
        this.principal = user;
        connector = instance.getConnector(this.principal, token);
@@@ -690,13 -544,14 +691,14 @@@
          // Obtain the command from the command table
          sc = commandFactory.get(command);
          if (sc == null) {
 -          reader.printString(String.format("Unknown command \"%s\".  Enter \"help\" for
a list possible commands.%n", command));
 -          reader.flushConsole();
 +          reader.println(String.format("Unknown command \"%s\".  Enter \"help\" for a list
possible commands.", command));
 +          reader.flush();
            return;
          }
 -        
 +
-         if (!(sc instanceof ExitCommand) && !ignoreAuthTimeout && System.currentTimeMillis()
- lastUserActivity > authTimeout) {
+         long duration = System.nanoTime() - lastUserActivity;
+         if (!(sc instanceof ExitCommand) && !ignoreAuthTimeout && (duration
< 0 || duration > authTimeout)) {
 -          reader.printString("Shell has been idle for too long. Please re-authenticate.\n");
 +          reader.println("Shell has been idle for too long. Please re-authenticate.");
            boolean authFailed = true;
            do {
              String pwd = readMaskedLine("Enter current password for '" + connector.whoami()
+ "': ", '*');
@@@ -711,19 -566,19 +713,19 @@@
                ++exitCode;
                printException(e);
              }
 -            
 +
              if (authFailed)
 -              reader.printString("Invalid password. ");
 +              reader.print("Invalid password. ");
            } while (authFailed);
-           lastUserActivity = System.currentTimeMillis();
+           lastUserActivity = System.nanoTime();
          }
 -        
 +
          // Get the options from the command on how to parse the string
          Options parseOpts = sc.getOptionsWithHelp();
 -        
 +
          // Parse the string using the given options
          CommandLine cl = new BasicParser().parse(parseOpts, fields);
 -        
 +
          int actualArgLen = cl.getArgs().length;
          int expectedArgLen = sc.numArgs();
          if (cl.hasOption(helpOption)) {


Mime
View raw message