You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2016/03/03 22:59:28 UTC
[03/61] [abbrv] [partial] accumulo git commit: ACCUMULO-722 put trunk
in my sandbox
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java
new file mode 100644
index 0000000..9402dcc
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.accumulo.core.util.LocalityGroupUtil;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.apache.hadoop.io.Text;
+
+public class GetGroupsCommand extends Command {
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+ String tableName = OptUtil.getTableOpt(cl, shellState);
+
+ Map<String,Set<Text>> groups = shellState.getConnector().tableOperations().getLocalityGroups(tableName);
+
+ for (Entry<String,Set<Text>> entry : groups.entrySet())
+ shellState.getReader().printString(entry.getKey() + "=" + LocalityGroupUtil.encodeColumnFamilies(entry.getValue()) + "\n");
+
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "gets the locality groups for a given table";
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options opts = new Options();
+ opts.addOption(OptUtil.tableOpt("table to fetch locality groups from"));
+ return opts;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
new file mode 100644
index 0000000..2a239e3
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.KeyExtent;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.util.TextUtil;
+import org.apache.accumulo.core.util.format.BinaryFormatter;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Shell.PrintFile;
+import org.apache.accumulo.core.util.shell.Shell.PrintLine;
+import org.apache.accumulo.core.util.shell.Shell.PrintShell;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.hadoop.io.Text;
+
+public class GetSplitsCommand extends Command {
+
+ private Option outputFileOpt, maxSplitsOpt, base64Opt, verboseOpt;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws IOException, AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+ 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());
+
+ PrintLine p = outputFile == null ? new PrintShell(shellState.getReader()) : new PrintFile(outputFile);
+
+ try {
+ if (!verbose) {
+ for (Text row : maxSplits > 0 ? shellState.getConnector().tableOperations().getSplits(tableName, maxSplits) : shellState.getConnector()
+ .tableOperations().getSplits(tableName)) {
+ p.print(encode(encode, row));
+ }
+ } else {
+ final Scanner scanner = shellState.getConnector().createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS);
+ Constants.METADATA_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 (Constants.METADATA_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);
+ }
+ }
+ }
+
+ } finally {
+ p.close();
+ }
+
+ return 0;
+ }
+
+ private static String encode(boolean encode, Text text) {
+ if (text == null)
+ return null;
+ BinaryFormatter.getlength(text.getLength());
+ return encode ? new String(Base64.encodeBase64(TextUtil.getBytes(text))) : BinaryFormatter.appendText(new StringBuilder(), text).toString();
+ }
+
+ private static String obscuredTabletName(KeyExtent extent) {
+ MessageDigest digester;
+ try {
+ digester = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException(e);
+ }
+ if (extent.getEndRow() != null && extent.getEndRow().getLength() > 0) {
+ digester.update(extent.getEndRow().getBytes(), 0, extent.getEndRow().getLength());
+ }
+ return new String(Base64.encodeBase64(digester.digest()));
+ }
+
+ @Override
+ public String description() {
+ return "retrieves the current split points for tablets in the current table";
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options opts = new Options();
+
+ outputFileOpt = new Option("o", "output", true, "local file to write the splits to");
+ outputFileOpt.setArgName("file");
+
+ maxSplitsOpt = new Option("m", "max", true, "maximum number of splits to return (evenly spaced)");
+ maxSplitsOpt.setArgName("num");
+
+ base64Opt = new Option("b64", "base64encoded", false, "encode the split points");
+
+ verboseOpt = new Option("v", "verbose", false, "print out the tablet information with start/end rows");
+
+ opts.addOption(outputFileOpt);
+ opts.addOption(maxSplitsOpt);
+ opts.addOption(base64Opt);
+ opts.addOption(verboseOpt);
+ opts.addOption(OptUtil.tableOpt("table to get splits for"));
+
+ return opts;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java
new file mode 100644
index 0000000..2ccb002
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.util.BadArgumentException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Token;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+public class GrantCommand extends TableOperation {
+ {
+ disableUnflaggedTableOptions();
+ }
+
+ private Option systemOpt, userOpt;
+ private String user;
+ private String[] permission;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+ user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
+
+ permission = cl.getArgs()[0].split("\\.", 2);
+ if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
+ try {
+ shellState.getConnector().securityOperations().grantSystemPermission(user, SystemPermission.valueOf(permission[1]));
+ Shell.log.debug("Granted " + user + " the " + permission[1] + " permission");
+ } catch (IllegalArgumentException e) {
+ throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
+ }
+ } else if (permission[0].equalsIgnoreCase("Table")) {
+ super.execute(fullCommand, cl, shellState);
+ } else {
+ throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
+ }
+ return 0;
+ }
+
+ @Override
+ protected void doTableOp(Shell shellState, String tableName) throws Exception {
+ try {
+ shellState.getConnector().securityOperations().grantTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
+ Shell.log.debug("Granted " + user + " the " + permission[1] + " permission on table " + tableName);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("No such table permission", e);
+ }
+ }
+
+ @Override
+ public String description() {
+ return "grants system or table permissions for a user";
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <permission>";
+ }
+
+ @Override
+ public void registerCompletion(Token root, Map<Command.CompletionSet,Set<String>> completionSet) {
+ Token cmd = new Token(getName());
+ cmd.addSubcommand(new Token(TablePermission.printableValues()));
+ cmd.addSubcommand(new Token(SystemPermission.printableValues()));
+ root.addSubcommand(cmd);
+ }
+
+ @Override
+ public Options getOptions() {
+ super.getOptions();
+ Options o = new Options();
+
+ OptionGroup group = new OptionGroup();
+
+ systemOpt = new Option("s", "system", false, "grant a system permission");
+
+ group.addOption(systemOpt);
+ group.addOption(optTableName);
+ group.addOption(optTablePattern);
+
+ o.addOptionGroup(group);
+ userOpt = new Option(Shell.userOption, "user", true, "user to operate on");
+ userOpt.setArgName("username");
+ userOpt.setRequired(true);
+ o.addOption(userOpt);
+
+ return o;
+ }
+
+ @Override
+ public int numArgs() {
+ return 1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
new file mode 100644
index 0000000..6873e4b
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.iterators.user.GrepIterator;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.MissingArgumentException;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class GrepCommand extends ScanCommand {
+
+ private Option numThreadsOpt;
+
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
+ IOException, MissingArgumentException {
+
+ String tableName = OptUtil.getTableOpt(cl, shellState);
+
+ if (cl.getArgList().isEmpty())
+ throw new MissingArgumentException("No terms specified");
+
+ // handle first argument, if present, the authorizations list to
+ // scan with
+ int numThreads = 20;
+ if (cl.hasOption(numThreadsOpt.getOpt())) {
+ numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
+ }
+ Authorizations auths = getAuths(cl, shellState);
+ BatchScanner scanner = shellState.getConnector().createBatchScanner(tableName, auths, numThreads);
+ scanner.setRanges(Collections.singletonList(getRange(cl)));
+
+ for (int i = 0; i < cl.getArgs().length; i++)
+ setUpIterator(Integer.MAX_VALUE - cl.getArgs().length + i, "grep" + i, cl.getArgs()[i], scanner);
+
+ try {
+ // handle columns
+ fetchColumns(cl, scanner);
+
+ // output the records
+ printRecords(cl, shellState, scanner);
+ } finally {
+ scanner.close();
+ }
+
+ return 0;
+ }
+
+ protected void setUpIterator(int prio, String name, String term, BatchScanner scanner) throws IOException {
+ if (prio < 0)
+ throw new IllegalArgumentException("Priority < 0 " + prio);
+
+ IteratorSetting grep = new IteratorSetting(prio, name, GrepIterator.class);
+ GrepIterator.setTerm(grep, term);
+ scanner.addScanIterator(grep);
+ }
+
+ @Override
+ public String description() {
+ return "searches each row, column family, column qualifier and value in a table for a substring (not a regular expression), in parallel, on the server side";
+ }
+
+ @Override
+ public Options getOptions() {
+ Options opts = super.getOptions();
+ numThreadsOpt = new Option("nt", "num-threads", true, "number of threads to use");
+ opts.addOption(numThreadsOpt);
+ return opts;
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <term>{ <term>}";
+ }
+
+ @Override
+ public int numArgs() {
+ return Shell.NO_FIXED_ARG_LENGTH_CHECK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
new file mode 100644
index 0000000..ad1dc4b
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.ShellCommandException;
+import org.apache.accumulo.core.util.shell.Token;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class HelpCommand extends Command {
+ private Option disablePaginationOpt;
+ private Option noWrapOpt;
+
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws ShellCommandException, IOException {
+ int numColumns = shellState.getReader().getTermwidth();
+ if (cl.hasOption(noWrapOpt.getOpt()))
+ numColumns = Integer.MAX_VALUE;
+
+ // print help summary
+ if (cl.getArgs().length == 0) {
+ int i = 0;
+ for (String cmd : shellState.commandFactory.keySet())
+ i = Math.max(i, cmd.length());
+ if (numColumns < 40)
+ throw new IllegalArgumentException("numColumns must be at least 40 (was " + numColumns + ")");
+ ArrayList<String> output = new ArrayList<String>();
+ for (Entry<String,Command[]> cmdGroup : shellState.commandGrouping.entrySet()) {
+ output.add(cmdGroup.getKey());
+ for (Command c : cmdGroup.getValue()) {
+ String n = c.getName();
+ String s = c.description();
+ if (s == null)
+ s = "";
+ int beginIndex = 0;
+ int endIndex = s.length();
+ while (beginIndex < endIndex && s.charAt(beginIndex) == ' ')
+ beginIndex++;
+ String dash = "-";
+ while (endIndex > beginIndex && endIndex - beginIndex + i + 5 > numColumns) {
+ endIndex = s.lastIndexOf(" ", numColumns + beginIndex - i - 5);
+ if (endIndex == -1 || endIndex < beginIndex) {
+ endIndex = numColumns + beginIndex - i - 5 - 1;
+ output.add(String.format("%-" + i + "s %s %s-", n, dash, s.substring(beginIndex, endIndex)));
+ dash = " ";
+ beginIndex = endIndex;
+ } else {
+ output.add(String.format("%-" + i + "s %s %s", n, dash, s.substring(beginIndex, endIndex)));
+ dash = " ";
+ beginIndex = endIndex + 1;
+ }
+ n = "";
+ endIndex = s.length();
+ while (beginIndex < endIndex && s.charAt(beginIndex) == ' ')
+ beginIndex++;
+ }
+ output.add(String.format("%-" + i + "s %s %s", n, dash, s.substring(beginIndex, endIndex)));
+ }
+ output.add("");
+ }
+ shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()));
+ }
+
+ // print help for every command on command line
+ for (String cmd : cl.getArgs()) {
+ Command c = shellState.commandFactory.get(cmd);
+ if (c == null)
+ shellState.getReader().printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.\n", cmd));
+ else
+ c.printHelp(shellState, numColumns);
+ }
+ return 0;
+ }
+
+ public String description() {
+ return "provides information about the available commands";
+ }
+
+ public void registerCompletion(Token root, Map<Command.CompletionSet,Set<String>> special) {
+ registerCompletionForCommands(root, special);
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+ disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output");
+ o.addOption(disablePaginationOpt);
+ noWrapOpt = new Option("nw", "no-wrap", false, "disable wrapping of output");
+ o.addOption(noWrapOpt);
+ return o;
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " [ <command>{ <command>} ]";
+ }
+
+ @Override
+ public int numArgs() {
+ return Shell.NO_FIXED_ARG_LENGTH_CHECK;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
new file mode 100644
index 0000000..59eda63
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.security.SecureRandom;
+import java.util.Random;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.ShellCommandException;
+import org.apache.accumulo.core.util.shell.ShellCommandException.ErrorCode;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.codec.binary.Base64;
+
+public class HiddenCommand extends Command {
+ private static Random rand = new SecureRandom();
+
+ @Override
+ public String description() {
+ return "The first rule of Accumulo is: \"You don't talk about Accumulo.\"";
+ }
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+ if (rand.nextInt(10) == 0) {
+ shellState.getReader().beep();
+ shellState.getReader().printNewline();
+ shellState.getReader().printString(
+ new String(Base64.decodeBase64(("ICAgICAgIC4tLS4KICAgICAgLyAvXCBcCiAgICAgKCAvLS1cICkKICAgICAuPl8gIF88LgogICAgLyB8ICd8ICcgXAog"
+ + "ICAvICB8Xy58Xy4gIFwKICAvIC98ICAgICAgfFwgXAogfCB8IHwgfFwvfCB8IHwgfAogfF98IHwgfCAgfCB8IHxffAogICAgIC8gIF9fICBcCiAgICAvICAv"
+ + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK").getBytes())));
+ shellState.getReader().printNewline();
+ } else
+ throw new ShellCommandException(ErrorCode.UNRECOGNIZED_COMMAND, getName());
+
+ return 0;
+ }
+
+ @Override
+ public int numArgs() {
+ return Shell.NO_FIXED_ARG_LENGTH_CHECK;
+ }
+
+ @Override
+ public String getName() {
+ return new String("accvmvlo");
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
new file mode 100644
index 0000000..0d7c3a5
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class HistoryCommand extends Command {
+
+ private Option clearHist;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+
+ String histDir = System.getenv("HOME") + "/.accumulo";
+ int counter = 0;
+
+ if (cl.hasOption(clearHist.getOpt())) {
+
+ try {
+
+ FileWriter outFile = new FileWriter(histDir + "/shell_history.txt");
+ PrintWriter out = new PrintWriter(outFile);
+ out.close();
+
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ else {
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(histDir + "/shell_history.txt"));
+ String Line;
+ try {
+ Line = in.readLine();
+ while (Line != null) {
+ shellState.getReader().printString(counter + " " + Line);
+ shellState.getReader().printNewline();
+ counter++;
+ Line = in.readLine();
+ }
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ }
+ } catch (FileNotFoundException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return ("generates a list of commands previously executed");
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+
+ clearHist = new Option("c", "clear", false, "clear history file");
+ clearHist.setRequired(false);
+
+ o.addOption(clearHist);
+
+ return o;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportDirectoryCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportDirectoryCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportDirectoryCommand.java
new file mode 100644
index 0000000..0c85586
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportDirectoryCommand.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.CachedConfiguration;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class ImportDirectoryCommand extends Command {
+
+ @Override
+ public String description() {
+ return "bulk imports an entire directory of data files to the current table. The boolean argument determines if accumulo sets the time.";
+ }
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws IOException, AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+ shellState.checkTableState();
+
+ String dir = cl.getArgs()[0];
+ String failureDir = cl.getArgs()[1];
+ boolean setTime = Boolean.parseBoolean(cl.getArgs()[2]);
+
+ FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
+ FileStatus failStatus = fs.getFileStatus(new Path(failureDir));
+ if (failStatus == null || !failStatus.isDir() || fs.listStatus(new Path(failureDir)).length != 0)
+ throw new AccumuloException(failureDir + " is not an empty directory");
+ shellState.getConnector().tableOperations().importDirectory(shellState.getTableName(), dir, failureDir, setTime);
+ return 0;
+ }
+
+ @Override
+ public int numArgs() {
+ return 3;
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <directory> <failureDirectory> true|false";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportTableCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportTableCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportTableCommand.java
new file mode 100644
index 0000000..487b322
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ImportTableCommand.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+
+public class ImportTableCommand extends Command {
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
+ TableExistsException {
+
+ shellState.getConnector().tableOperations().importTable(cl.getArgs()[0], cl.getArgs()[1]);
+ return 0;
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <table name> <import dir>";
+ }
+
+ @Override
+ public String description() {
+ return "imports a table";
+ }
+
+ @Override
+ public int numArgs() {
+ return 2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InfoCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InfoCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InfoCommand.java
new file mode 100644
index 0000000..57de6b1
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InfoCommand.java
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+public class InfoCommand extends AboutCommand {}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java
new file mode 100644
index 0000000..49f1daf
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.ConstraintViolationSummary;
+import org.apache.accumulo.core.data.KeyExtent;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.ColumnVisibility;
+import org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.hadoop.io.Text;
+
+public class InsertCommand extends Command {
+ private Option insertOptAuths, timestampOpt;
+
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
+ IOException, ConstraintViolationException {
+ shellState.checkTableState();
+
+ Mutation m = new Mutation(new Text(cl.getArgs()[0].getBytes(Shell.CHARSET)));
+ Text colf = new Text(cl.getArgs()[1].getBytes(Shell.CHARSET));
+ Text colq = new Text(cl.getArgs()[2].getBytes(Shell.CHARSET));
+ Value val = new Value(cl.getArgs()[3].getBytes(Shell.CHARSET));
+
+ if (cl.hasOption(insertOptAuths.getOpt())) {
+ ColumnVisibility le = new ColumnVisibility(cl.getOptionValue(insertOptAuths.getOpt()));
+ Shell.log.debug("Authorization label will be set to: " + le.toString());
+
+ if (cl.hasOption(timestampOpt.getOpt()))
+ m.put(colf, colq, le, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
+ else
+ m.put(colf, colq, le, val);
+ } else if (cl.hasOption(timestampOpt.getOpt()))
+ m.put(colf, colq, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
+ else
+ m.put(colf, colq, val);
+
+ BatchWriter bw = shellState.getConnector().createBatchWriter(shellState.getTableName(), m.estimatedMemoryUsed() + 0L, 0L, 1);
+ bw.addMutation(m);
+ try {
+ bw.close();
+ } catch (MutationsRejectedException e) {
+ ArrayList<String> lines = new ArrayList<String>();
+ if (e.getAuthorizationFailures().isEmpty() == false)
+ lines.add(" Authorization Failures:");
+ for (KeyExtent extent : e.getAuthorizationFailures()) {
+ lines.add(" " + extent);
+ }
+ if (e.getConstraintViolationSummaries().isEmpty() == false)
+ lines.add(" Constraint Failures:");
+ for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) {
+ lines.add(" " + cvs.toString());
+ }
+ shellState.printLines(lines.iterator(), false);
+ }
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "inserts a record";
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <row> <colfamily> <colqualifier> <value>";
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+ insertOptAuths = new Option("l", "visibility-label", true, "formatted visibility");
+ insertOptAuths.setArgName("expression");
+ o.addOption(insertOptAuths);
+
+ timestampOpt = new Option("ts", "timestamp", true, "timestamp to use for insert");
+ timestampOpt.setArgName("timestamp");
+ o.addOption(timestampOpt);
+
+ return o;
+ }
+
+ @Override
+ public int numArgs() {
+ return 4;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
new file mode 100644
index 0000000..27a579f
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class ListIterCommand extends Command {
+ private Option nameOpt;
+ private Map<IteratorScope,Option> scopeOpts;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+ String tableName = OptUtil.getTableOpt(cl, shellState);
+
+ Map<String,EnumSet<IteratorScope>> iterators = shellState.getConnector().tableOperations().listIterators(tableName);
+
+ if (cl.hasOption(nameOpt.getOpt())) {
+ String name = cl.getOptionValue(nameOpt.getOpt());
+ if (!iterators.containsKey(name)) {
+ Shell.log.warn("no iterators found that match your criteria");
+ return 0;
+ }
+ EnumSet<IteratorScope> scopes = iterators.get(name);
+ iterators.clear();
+ iterators.put(name, scopes);
+ }
+
+ boolean hasScope = false;
+ for (IteratorScope scope : IteratorScope.values()) {
+ if (cl.hasOption(scopeOpts.get(scope).getOpt()))
+ hasScope = true;
+ }
+ if (!hasScope)
+ throw new IllegalArgumentException("You must select at least one scope to configure");
+
+ StringBuilder sb = new StringBuilder("-\n");
+ for (String name : iterators.keySet()) {
+ for (IteratorScope scope : iterators.get(name)) {
+ if (cl.hasOption(scopeOpts.get(scope).getOpt())) {
+ IteratorSetting setting = shellState.getConnector().tableOperations().getIteratorSetting(tableName, name, scope);
+ sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope).append(" scope options:\n");
+ sb.append("- ").append("iteratorPriority").append(" = ").append(setting.getPriority()).append("\n");
+ sb.append("- ").append("iteratorClassName").append(" = ").append(setting.getIteratorClass()).append("\n");
+ for (Entry<String,String> optEntry : setting.getOptions().entrySet()) {
+ sb.append("- ").append(optEntry.getKey()).append(" = ").append(optEntry.getValue()).append("\n");
+ }
+ }
+ }
+ }
+ sb.append("-\n");
+ shellState.getReader().printString(sb.toString());
+
+ return 0;
+ }
+
+ public String description() {
+ return "lists table-specific iterators";
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+
+ nameOpt = new Option("n", "name", true, "iterator to list");
+ nameOpt.setArgName("itername");
+
+ scopeOpts = new EnumMap<IteratorScope,Option>(IteratorScope.class);
+ scopeOpts.put(IteratorScope.minc, new Option(IteratorScope.minc.name(), "minor-compaction", false, "list iterator for minor compaction scope"));
+ scopeOpts.put(IteratorScope.majc, new Option(IteratorScope.majc.name(), "major-compaction", false, "list iterator for major compaction scope"));
+ scopeOpts.put(IteratorScope.scan, new Option(IteratorScope.scan.name(), "scan-time", false, "list iterator for scan scope"));
+
+ o.addOption(OptUtil.tableOpt("table to list the configured iterators on"));
+ o.addOption(nameOpt);
+
+ for (Option opt : scopeOpts.values()) {
+ o.addOption(opt);
+ }
+
+ return o;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListScansCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListScansCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListScansCommand.java
new file mode 100644
index 0000000..ed2bffc
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListScansCommand.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.accumulo.core.client.admin.InstanceOperations;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class ListScansCommand extends Command {
+
+ private Option tserverOption, disablePaginationOpt;
+
+ @Override
+ public String description() {
+ return "lists what scans are currently running in accumulo. See the accumulo.core.client.admin.ActiveScan javadoc for more information about columns.";
+ }
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+
+ List<String> tservers;
+
+ InstanceOperations instanceOps = shellState.getConnector().instanceOperations();
+
+ boolean paginate = !cl.hasOption(disablePaginationOpt.getOpt());
+
+ if (cl.hasOption(tserverOption.getOpt())) {
+ tservers = new ArrayList<String>();
+ tservers.add(cl.getOptionValue(tserverOption.getOpt()));
+ } else {
+ tservers = instanceOps.getTabletServers();
+ }
+
+ shellState.printLines(new ActiveScanIterator(tservers, instanceOps), paginate);
+
+ return 0;
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options opts = new Options();
+
+ tserverOption = new Option("ts", "tabletServer", true, "tablet server to list scans for");
+ tserverOption.setArgName("tablet server");
+ opts.addOption(tserverOption);
+
+ disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output");
+ opts.addOption(disablePaginationOpt);
+
+ return opts;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java
new file mode 100644
index 0000000..12ea807
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+import org.apache.hadoop.io.Text;
+
+public class MaxRowCommand extends ScanCommand {
+
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
+ IOException, ParseException {
+ String tableName = OptUtil.getTableOpt(cl, shellState);
+ Range range = getRange(cl);
+ Authorizations auths = getAuths(cl, shellState);
+ Text startRow = range.getStartKey() == null ? null : range.getStartKey().getRow();
+ Text endRow = range.getEndKey() == null ? null : range.getEndKey().getRow();
+
+ try {
+ Text max = shellState.getConnector().tableOperations()
+ .getMaxRow(tableName, auths, startRow, range.isStartKeyInclusive(), endRow, range.isEndKeyInclusive());
+ if (max != null)
+ shellState.getReader().printString(max.toString() + "\n");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "finds the max row in a table within a given range";
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java
new file mode 100644
index 0000000..ad8ff8b
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.util.Merge;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.hadoop.io.Text;
+
+public class MergeCommand extends Command {
+ private Option verboseOpt, forceOpt, sizeOpt;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws Exception {
+ boolean verbose = shellState.isVerbose();
+ boolean force = false;
+ long size = -1;
+ String tableName = OptUtil.getTableOpt(cl, shellState);
+ Text startRow = OptUtil.getStartRow(cl);
+ Text endRow = OptUtil.getEndRow(cl);
+ if (cl.hasOption(verboseOpt.getOpt()))
+ verbose = true;
+ if (cl.hasOption(forceOpt.getOpt()))
+ force = true;
+ if (cl.hasOption(sizeOpt.getOpt())) {
+ size = AccumuloConfiguration.getMemoryInBytes(cl.getOptionValue(sizeOpt.getOpt()));
+ }
+ if (size < 0)
+ shellState.getConnector().tableOperations().merge(tableName, startRow, endRow);
+ else {
+ final boolean finalVerbose = verbose;
+ Merge merge = new Merge() {
+ protected void message(String fmt, Object... args) {
+ if (finalVerbose) {
+ try {
+ shellState.getReader().printString(String.format(fmt, args));
+ shellState.getReader().printNewline();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ };
+ merge.mergomatic(shellState.getConnector(), tableName, startRow, endRow, size, force);
+ }
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "merges tablets in a table";
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+ verboseOpt = new Option("v", "verbose", false, "verbose output during merge");
+ sizeOpt = new Option("s", "size", true, "merge tablets to the given size over the entire table");
+ forceOpt = new Option("f", "force", false, "merge small tablets to large tablets, even if it goes over the given size");
+ o.addOption(OptUtil.startRowOpt());
+ o.addOption(OptUtil.endRowOpt());
+ o.addOption(OptUtil.tableOpt("table to be merged"));
+ o.addOption(verboseOpt);
+ o.addOption(sizeOpt);
+ o.addOption(forceOpt);
+ return o;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java
new file mode 100644
index 0000000..c9b458f
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+
+public class NoTableCommand extends Command {
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+ shellState.setTableName("");
+
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "returns to a tableless shell state";
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
new file mode 100644
index 0000000..27d6ee5
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+
+public class OfflineCommand extends TableOperation {
+ @Override
+ public String description() {
+ return "starts the process of taking table offline";
+ }
+
+ protected void doTableOp(Shell shellState, String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (tableName.equals(Constants.METADATA_TABLE_NAME)) {
+ Shell.log.info(" You cannot take the " + Constants.METADATA_TABLE_NAME + " offline.");
+ } else {
+ Shell.log.info("Attempting to begin taking " + tableName + " offline");
+ shellState.getConnector().tableOperations().offline(tableName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
new file mode 100644
index 0000000..a9d1d88
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+
+public class OnlineCommand extends TableOperation {
+ @Override
+ public String description() {
+ return "starts the process of putting a table online";
+ }
+
+ protected void doTableOp(Shell shellState, String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (tableName.equals(Constants.METADATA_TABLE_NAME)) {
+ Shell.log.info(" The " + Constants.METADATA_TABLE_NAME + " is always online.");
+ } else {
+ Shell.log.info("Attempting to begin bringing " + tableName + " online");
+ shellState.getConnector().tableOperations().online(tableName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java
new file mode 100644
index 0000000..8207995
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.hadoop.io.Text;
+
+public abstract class OptUtil {
+ public static final String START_ROW_OPT = "b";
+ public static final String END_ROW_OPT = "e";
+
+ public static String getTableOpt(CommandLine cl, Shell shellState) throws TableNotFoundException {
+ String tableName;
+
+ if (cl.hasOption(Shell.tableOption)) {
+ tableName = cl.getOptionValue(Shell.tableOption);
+ if (!shellState.getConnector().tableOperations().exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "specified table that doesn't exist");
+ } else {
+ shellState.checkTableState();
+ tableName = shellState.getTableName();
+ }
+
+ return tableName;
+ }
+
+ public static Option tableOpt() {
+ return tableOpt("tableName");
+ }
+
+ public static Option tableOpt(String description) {
+ Option tableOpt = new Option(Shell.tableOption, "table", true, description);
+ tableOpt.setArgName("table");
+ tableOpt.setRequired(false);
+ return tableOpt;
+ }
+
+ public static enum AdlOpt {
+ ADD("a"), DELETE("d"), LIST("l");
+
+ public final String opt;
+
+ private AdlOpt(String opt) {
+ this.opt = opt;
+ }
+ }
+
+ public static AdlOpt getAldOpt(CommandLine cl) {
+ if (cl.hasOption(AdlOpt.ADD.opt)) {
+ return AdlOpt.ADD;
+ } else if (cl.hasOption(AdlOpt.DELETE.opt)) {
+ return AdlOpt.DELETE;
+ } else {
+ return AdlOpt.LIST;
+ }
+ }
+
+ public static OptionGroup addListDeleteGroup(String name) {
+ Option addOpt = new Option(AdlOpt.ADD.opt, "add", false, "add " + name);
+ Option deleteOpt = new Option(AdlOpt.DELETE.opt, "delete", false, "delete " + name);
+ Option listOpt = new Option(AdlOpt.LIST.opt, "list", false, "list " + name + "(s)");
+ OptionGroup og = new OptionGroup();
+ og.addOption(addOpt);
+ og.addOption(deleteOpt);
+ og.addOption(listOpt);
+ og.setRequired(true);
+ return og;
+ }
+
+ public static Option startRowOpt() {
+ Option o = new Option(START_ROW_OPT, "begin-row", true, "begin row (inclusive)");
+ o.setArgName("begin-row");
+ return o;
+ }
+
+ public static Option endRowOpt() {
+ Option o = new Option(END_ROW_OPT, "end-row", true, "end row (inclusive)");
+ o.setArgName("end-row");
+ return o;
+ }
+
+ public static Text getStartRow(CommandLine cl) throws UnsupportedEncodingException {
+ if (cl.hasOption(START_ROW_OPT))
+ return new Text(cl.getOptionValue(START_ROW_OPT).getBytes(Shell.CHARSET));
+ else
+ return null;
+ }
+
+ public static Text getEndRow(CommandLine cl) throws UnsupportedEncodingException {
+ if (cl.hasOption(END_ROW_OPT))
+ return new Text(cl.getOptionValue(END_ROW_OPT).getBytes(Shell.CHARSET));
+ else
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
new file mode 100644
index 0000000..32703d9
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.security.thrift.AuthInfo;
+import org.apache.accumulo.core.security.thrift.SecurityErrorCode;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+
+public class PasswdCommand extends Command {
+ private Option userOpt;
+
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException {
+ String currentUser = shellState.getConnector().whoami();
+ String user = cl.getOptionValue(userOpt.getOpt(), currentUser);
+
+ String password = null;
+ String passwordConfirm = null;
+ String oldPassword = null;
+
+ oldPassword = shellState.readMaskedLine("Enter current password for '" + currentUser + "': ", '*');
+ if (oldPassword == null) {
+ shellState.getReader().printNewline();
+ return 0;
+ } // user canceled
+
+ if (!shellState.getConnector().securityOperations().authenticateUser(currentUser, oldPassword.getBytes()))
+ throw new AccumuloSecurityException(user, SecurityErrorCode.BAD_CREDENTIALS);
+
+ password = shellState.readMaskedLine("Enter new password for '" + user + "': ", '*');
+ if (password == null) {
+ shellState.getReader().printNewline();
+ return 0;
+ } // user canceled
+ passwordConfirm = shellState.readMaskedLine("Please confirm new password for '" + user + "': ", '*');
+ if (passwordConfirm == null) {
+ shellState.getReader().printNewline();
+ return 0;
+ } // user canceled
+
+ if (!password.equals(passwordConfirm))
+ throw new IllegalArgumentException("Passwords do not match");
+
+ byte[] pass = password.getBytes();
+ shellState.getConnector().securityOperations().changeUserPassword(user, pass);
+ // update the current credentials if the password changed was for
+ // the current user
+ if (shellState.getConnector().whoami().equals(user))
+ shellState.updateUser(new AuthInfo(user, ByteBuffer.wrap(pass), shellState.getConnector().getInstance().getInstanceID()));
+ Shell.log.debug("Changed password for user " + user);
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "changes a user's password";
+ }
+
+ @Override
+ public Options getOptions() {
+ Options o = new Options();
+ userOpt = new Option(Shell.userOption, "user", true, "user to operate on");
+ userOpt.setArgName("user");
+ o.addOption(userOpt);
+ return o;
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuestionCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuestionCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuestionCommand.java
new file mode 100644
index 0000000..b12c2cb
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuestionCommand.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+public class QuestionCommand extends HelpCommand {
+ @Override
+ public String getName() {
+ return "?";
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuitCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuitCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuitCommand.java
new file mode 100644
index 0000000..8aa95f5
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuitCommand.java
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+public class QuitCommand extends ExitCommand {}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
new file mode 100644
index 0000000..dfee8b9
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.accumulo.core.util.BadArgumentException;
+import org.apache.accumulo.core.util.shell.Shell;
+
+/**
+ * A basic tokenizer for generating tokens from a string. It understands quoted strings and escaped quote characters.
+ *
+ * You can use the escape sequence '\' to escape single quotes, double quotes, and spaces only, in addition to the escape character itself.
+ *
+ * The behavior is the same for single and double quoted strings. (i.e. '\'' is the same as "\'")
+ */
+
+public class QuotedStringTokenizer implements Iterable<String> {
+ private ArrayList<String> tokens;
+ private String input;
+
+ public QuotedStringTokenizer(String t) throws BadArgumentException {
+ tokens = new ArrayList<String>();
+ this.input = t;
+ try {
+ createTokens();
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ }
+
+ public String[] getTokens() {
+ return tokens.toArray(new String[tokens.size()]);
+ }
+
+ private void createTokens() throws BadArgumentException, UnsupportedEncodingException {
+ boolean inQuote = false;
+ boolean inEscapeSequence = false;
+ String hexChars = null;
+ char inQuoteChar = '"';
+
+ byte[] token = new byte[input.length()];
+ int tokenLength = 0;
+ byte[] inputBytes = input.getBytes();
+ for (int i = 0; i < input.length(); ++i) {
+ char ch = input.charAt(i);
+
+ // if I ended up in an escape sequence, check for valid escapable character, and add it as a literal
+ if (inEscapeSequence) {
+ inEscapeSequence = false;
+ if (ch == 'x')
+ hexChars = "";
+ else if (ch == ' ' || ch == '\'' || ch == '"' || ch == '\\')
+ token[tokenLength++] = inputBytes[i];
+ else
+ throw new BadArgumentException("can only escape single quotes, double quotes, the space character, the backslash, and hex input", input, i);
+ }
+ // in a hex escape sequence
+ else if (hexChars != null) {
+ int digit = Character.digit(ch, 16);
+ if (digit < 0)
+ throw new BadArgumentException("expected hex character", input, i);
+ hexChars += ch;
+ if (hexChars.length() == 2) {
+ byte b;
+ try {
+ b = (byte) (0xff & Short.parseShort(hexChars, 16));
+ if (!Character.isValidCodePoint(0xff & b))
+ throw new NumberFormatException();
+ } catch (NumberFormatException e) {
+ throw new BadArgumentException("unsupported non-ascii character", input, i);
+ }
+ token[tokenLength++] = b;
+ hexChars = null;
+ }
+ }
+ // in a quote, either end the quote, start escape, or continue a token
+ else if (inQuote) {
+ if (ch == inQuoteChar) {
+ inQuote = false;
+ tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
+ tokenLength = 0;
+ } else if (ch == '\\')
+ inEscapeSequence = true;
+ else
+ token[tokenLength++] = inputBytes[i];
+ }
+ // not in a quote, either enter a quote, end a token, start escape, or continue a token
+ else {
+ if (ch == '\'' || ch == '"') {
+ if (tokenLength > 0) {
+ tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
+ tokenLength = 0;
+ }
+ inQuote = true;
+ inQuoteChar = ch;
+ } else if (ch == ' ' && tokenLength > 0) {
+ tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
+ tokenLength = 0;
+ } else if (ch == '\\')
+ inEscapeSequence = true;
+ else if (ch != ' ')
+ token[tokenLength++] = inputBytes[i];
+ }
+ }
+ if (inQuote)
+ throw new BadArgumentException("missing terminating quote", input, input.length());
+ else if (inEscapeSequence || hexChars != null)
+ throw new BadArgumentException("escape sequence not complete", input, input.length());
+ if (tokenLength > 0)
+ tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+ return tokens.iterator();
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/7bdbfccb/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RenameTableCommand.java
----------------------------------------------------------------------
diff --git a/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RenameTableCommand.java b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RenameTableCommand.java
new file mode 100644
index 0000000..2e7e880
--- /dev/null
+++ b/1.5/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RenameTableCommand.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Token;
+import org.apache.commons.cli.CommandLine;
+
+public class RenameTableCommand extends Command {
+ @Override
+ public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
+ TableExistsException {
+ shellState.getConnector().tableOperations().rename(cl.getArgs()[0], cl.getArgs()[1]);
+ if (shellState.getTableName().equals(cl.getArgs()[0]))
+ shellState.setTableName(cl.getArgs()[1]);
+ return 0;
+ }
+
+ @Override
+ public String usage() {
+ return getName() + " <current table name> <new table name>";
+ }
+
+ @Override
+ public String description() {
+ return "renames a table";
+ }
+
+ public void registerCompletion(Token root, Map<Command.CompletionSet,Set<String>> completionSet) {
+ registerCompletionForTables(root, completionSet);
+ }
+
+ @Override
+ public int numArgs() {
+ return 2;
+ }
+}