use of org.apache.accumulo.shell.commands.ListTabletsCommand 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 LineReader
*/
public boolean config(String... args) throws IOException {
if (this.terminal == null)
this.terminal = TerminalBuilder.builder().jansi(false).build();
if (this.reader == null)
this.reader = LineReaderBuilder.builder().terminal(this.terminal).build();
this.writer = this.terminal.writer();
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());
jc.usage();
exitCode = 1;
return false;
}
if (options.isDebugEnabled()) {
log.warn("Configure debugging through your logging configuration file");
}
authTimeout = TimeUnit.MINUTES.toNanos(options.getAuthTimeout());
disableAuthTimeout = options.isAuthTimeoutDisabled();
clientProperties = options.getClientProperties();
if (ClientProperty.SASL_ENABLED.getBoolean(clientProperties)) {
log.debug("SASL is enabled, disabling authorization timeout");
disableAuthTimeout = true;
}
tabCompletion = !options.isTabCompletionDisabled();
this.setTableName("");
if (accumuloClient == null) {
if (ClientProperty.INSTANCE_ZOOKEEPERS.isEmpty(clientProperties)) {
throw new IllegalArgumentException("ZooKeepers must be set using -z or -zh on command line" + " or in accumulo-client.properties");
}
if (ClientProperty.INSTANCE_NAME.isEmpty(clientProperties)) {
throw new IllegalArgumentException("Instance name must be set using -z or -zi on command " + "line or in accumulo-client.properties");
}
final String principal;
try {
principal = options.getUsername();
} catch (Exception e) {
logError(e.getMessage());
exitCode = 1;
return false;
}
String password = options.getPassword();
AuthenticationToken token = null;
if (password == null && clientProperties.containsKey(ClientProperty.AUTH_TOKEN.getKey()) && principal.equals(ClientProperty.AUTH_PRINCIPAL.getValue(clientProperties))) {
token = ClientProperty.getAuthenticationToken(clientProperties);
}
if (token == null) {
// Read password if the user explicitly asked for it, or didn't specify anything at all
if (PasswordConverter.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 {
token = new PasswordToken(password);
}
}
try {
this.setTableName("");
accumuloClient = Accumulo.newClient().from(clientProperties).as(principal, token).build();
context = (ClientContext) accumuloClient;
} 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() };
@SuppressWarnings("deprecation") Command[] debuggingCommands = { new ClasspathCommand(), new org.apache.accumulo.shell.commands.DebugCommand(), new ListScansCommand(), new ListCompactionsCommand(), new TraceCommand(), new PingCommand(), new ListBulkCommand(), new ListTabletsCommand() };
@SuppressWarnings("deprecation") Command[] execCommands = { new ExecfileCommand(), new HistoryCommand(), new ExtensionCommand(), new org.apache.accumulo.shell.commands.ScriptCommand() };
Command[] exitCommands = { new ByeCommand(), new ExitCommand(), new QuitCommand() };
Command[] helpCommands = { new AboutCommand(), new HelpCommand(), new InfoCommand(), new QuestionCommand() };
@SuppressWarnings("deprecation") Command[] iteratorCommands = { new DeleteIterCommand(), new org.apache.accumulo.shell.commands.DeleteScanIterCommand(), new ListIterCommand(), new SetIterCommand(), new org.apache.accumulo.shell.commands.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