use of org.apache.accumulo.shell.Shell.PrintShell in project accumulo by apache.
the class GetSplitsCommand method execute.
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
final String tableName = OptUtil.getTableOpt(cl, shellState);
final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
final String m = cl.getOptionValue(maxSplitsOpt.getOpt());
final int maxSplits = m == null ? 0 : Integer.parseInt(m);
final boolean encode = cl.hasOption(base64Opt.getOpt());
final boolean verbose = cl.hasOption(verboseOpt.getOpt());
try (PrintLine p = outputFile == null ? new PrintShell(shellState.getReader()) : new PrintFile(outputFile)) {
if (!verbose) {
for (Text row : maxSplits > 0 ? shellState.getConnector().tableOperations().listSplits(tableName, maxSplits) : shellState.getConnector().tableOperations().listSplits(tableName)) {
p.print(encode(encode, row));
}
} else {
String systemTableToCheck = MetadataTable.NAME.equals(tableName) ? RootTable.NAME : MetadataTable.NAME;
final Scanner scanner = shellState.getConnector().createScanner(systemTableToCheck, Authorizations.EMPTY);
TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
final Text start = new Text(shellState.getConnector().tableOperations().tableIdMap().get(tableName));
final Text end = new Text(start);
end.append(new byte[] { '<' }, 0, 1);
scanner.setRange(new Range(start, end));
for (Iterator<Entry<Key, Value>> iterator = scanner.iterator(); iterator.hasNext(); ) {
final Entry<Key, Value> next = iterator.next();
if (TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.hasColumns(next.getKey())) {
KeyExtent extent = new KeyExtent(next.getKey().getRow(), next.getValue());
final String pr = encode(encode, extent.getPrevEndRow());
final String er = encode(encode, extent.getEndRow());
final String line = String.format("%-26s (%s, %s%s", obscuredTabletName(extent), pr == null ? "-inf" : pr, er == null ? "+inf" : er, er == null ? ") Default Tablet " : "]");
p.print(line);
}
}
}
}
return 0;
}
Aggregations