use of org.apache.accumulo.shell.commands.UserCommand in project accumulo by apache.
the class Shell method config.
/**
* Configures the shell using the provided options. Not for client use.
*
* @return true if the shell was successfully configured, false otherwise.
* @throws IOException
* if problems occur creating the ConsoleReader
*/
public boolean config(String... args) throws IOException {
if (this.reader == null)
this.reader = new ConsoleReader();
ShellOptionsJC options = new ShellOptionsJC();
JCommander jc = new JCommander();
jc.setProgramName("accumulo shell");
jc.addObject(options);
try {
jc.parse(args);
} catch (ParameterException e) {
jc.usage();
exitCode = 1;
return false;
}
if (options.isHelpEnabled()) {
jc.usage();
// Not an error
exitCode = 0;
return false;
}
if (options.getUnrecognizedOptions() != null) {
logError("Unrecognized Options: " + options.getUnrecognizedOptions().toString());
jc.usage();
exitCode = 1;
return false;
}
setDebugging(options.isDebugEnabled());
authTimeout = TimeUnit.MINUTES.toNanos(options.getAuthTimeout());
disableAuthTimeout = options.isAuthTimeoutDisabled();
ClientConfiguration clientConf;
try {
clientConf = options.getClientConfiguration();
} catch (Exception e) {
printException(e);
return true;
}
if (Boolean.parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED))) {
log.debug("SASL is enabled, disabling authorization timeout");
disableAuthTimeout = true;
}
// get the options that were parsed
final String user;
try {
user = options.getUsername();
} catch (Exception e) {
printException(e);
return true;
}
String password = options.getPassword();
tabCompletion = !options.isTabCompletionDisabled();
// Use a ZK, or HdfsZK Accumulo instance
setInstance(options);
// AuthenticationToken options
try {
token = options.getAuthenticationToken();
} catch (Exception e) {
printException(e);
return true;
}
Map<String, String> loginOptions = options.getTokenProperties();
// process default parameters if unspecified
try {
final boolean hasToken = (token != null);
if (hasToken && password != null) {
throw new ParameterException("Can not supply '--pass' option with '--tokenClass' option");
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
reader.getTerminal().setEchoEnabled(true);
}
});
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();
if (!loginOptions.isEmpty()) {
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 (!options.isFake()) {
DistributedTrace.enable(InetAddress.getLocalHost().getHostName(), "shell", clientConf);
}
this.setTableName("");
connector = instance.getConnector(user, token);
} catch (Exception e) {
printException(e);
exitCode = 1;
return false;
}
// decide whether to execute commands from a file and quit
if (options.getExecFile() != null) {
execFile = options.getExecFile();
verbose = false;
} else if (options.getExecFileVerbose() != null) {
execFile = options.getExecFileVerbose();
verbose = true;
}
execCommand = options.getExecCommand();
if (execCommand != null) {
verbose = false;
}
rootToken = new Token();
Command[] dataCommands = { new DeleteCommand(), new DeleteManyCommand(), new DeleteRowsCommand(), new EGrepCommand(), new FormatterCommand(), new InterpreterCommand(), new GrepCommand(), new ImportDirectoryCommand(), new InsertCommand(), new MaxRowCommand(), new ScanCommand() };
Command[] debuggingCommands = { new ClasspathCommand(), new DebugCommand(), new ListScansCommand(), new ListCompactionsCommand(), new TraceCommand(), new PingCommand(), new ListBulkCommand() };
Command[] execCommands = { new ExecfileCommand(), new HistoryCommand(), new ExtensionCommand(), new ScriptCommand() };
Command[] exitCommands = { new ByeCommand(), new ExitCommand(), new QuitCommand() };
Command[] helpCommands = { new AboutCommand(), new HelpCommand(), new InfoCommand(), new QuestionCommand() };
Command[] iteratorCommands = { new DeleteIterCommand(), new DeleteScanIterCommand(), new ListIterCommand(), new SetIterCommand(), new SetScanIterCommand(), new SetShellIterCommand(), new ListShellIterCommand(), new DeleteShellIterCommand() };
Command[] otherCommands = { new HiddenCommand() };
Command[] permissionsCommands = { new GrantCommand(), new RevokeCommand(), new SystemPermissionsCommand(), new TablePermissionsCommand(), new UserPermissionsCommand(), new NamespacePermissionsCommand() };
Command[] stateCommands = { new AuthenticateCommand(), new ClsCommand(), new ClearCommand(), new FateCommand(), new NoTableCommand(), new SleepCommand(), new TableCommand(), new UserCommand(), new WhoAmICommand() };
Command[] tableCommands = { new CloneTableCommand(), new ConfigCommand(), new CreateTableCommand(), new DeleteTableCommand(), new DropTableCommand(), new DUCommand(), new ExportTableCommand(), new ImportTableCommand(), new OfflineCommand(), new OnlineCommand(), new RenameTableCommand(), new TablesCommand(), new NamespacesCommand(), new CreateNamespaceCommand(), new DeleteNamespaceCommand(), new RenameNamespaceCommand(), new SummariesCommand() };
Command[] tableControlCommands = { new AddSplitsCommand(), new CompactCommand(), new ConstraintCommand(), new FlushCommand(), new GetGroupsCommand(), new GetSplitsCommand(), new MergeCommand(), new SetGroupsCommand() };
Command[] userCommands = { new AddAuthsCommand(), new CreateUserCommand(), new DeleteUserCommand(), new DropUserCommand(), new GetAuthsCommand(), new PasswdCommand(), new SetAuthsCommand(), new UsersCommand(), new DeleteAuthsCommand() };
commandGrouping.put("-- Writing, Reading, and Removing Data --", dataCommands);
commandGrouping.put("-- Debugging Commands -------------------", debuggingCommands);
commandGrouping.put("-- Shell Execution Commands -------------", execCommands);
commandGrouping.put("-- Exiting Commands ---------------------", exitCommands);
commandGrouping.put("-- Help Commands ------------------------", helpCommands);
commandGrouping.put("-- Iterator Configuration ---------------", iteratorCommands);
commandGrouping.put("-- Permissions Administration Commands --", permissionsCommands);
commandGrouping.put("-- Shell State Commands -----------------", stateCommands);
commandGrouping.put("-- Table Administration Commands --------", tableCommands);
commandGrouping.put("-- Table Control Commands ---------------", tableControlCommands);
commandGrouping.put("-- User Administration Commands ---------", userCommands);
for (Command[] cmds : commandGrouping.values()) {
for (Command cmd : cmds) commandFactory.put(cmd.getName(), cmd);
}
for (Command cmd : otherCommands) {
commandFactory.put(cmd.getName(), cmd);
}
return true;
}
Aggregations