setDebugging(cl.hasOption(debugOption.getLongOpt()));
authTimeout = Integer.parseInt(cl.getOptionValue(authTimeoutOpt.getLongOpt(), DEFAULT_AUTH_TIMEOUT)) * 60 * 1000;
disableAuthTimeout = cl.hasOption(disableAuthTimeoutOpt.getLongOpt());
if (cl.hasOption(zooKeeperInstance.getOpt()) && cl.getOptionValues(zooKeeperInstance.getOpt()).length != 2)
throw new MissingArgumentException(zooKeeperInstance);
} catch (Exception e) {
configError = true;
printException(e);
printHelp("shell", SHELL_DESCRIPTION, opts);
return true;
}
// 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());
// Use a fake (Mock), ZK, or HdfsZK Accumulo instance
setInstance(cl);
// 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());
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void start() {
reader.getTerminal().enableEcho();
}
});
if (passw != null) {
this.token = new PasswordToken(passw);
}
if (this.token == null) {
passw = readMaskedLine("Password: ", '*');
if (passw != null)
this.token = new PasswordToken(passw);
}
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);