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 2013/12/05 00:58:20 UTC
[28/50] [abbrv] git commit: ACCUMULO-1906 Drop clone namespace feature
ACCUMULO-1906 Drop clone namespace feature
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/71bed4df
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/71bed4df
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/71bed4df
Branch: refs/heads/1.6.0-SNAPSHOT
Commit: 71bed4df6bd76578449b27b52c65fa4fc8222f63
Parents: 4a7c614
Author: Christopher Tubbs <ct...@apache.org>
Authored: Thu Nov 14 16:03:01 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Dec 4 18:46:11 2013 -0500
----------------------------------------------------------------------
.../client/admin/TableNamespaceOperations.java | 28 --
.../admin/TableNamespaceOperationsImpl.java | 67 ----
.../mock/MockTableNamespaceOperations.java | 9 -
.../apache/accumulo/core/util/shell/Shell.java | 302 +++++++++----------
.../shell/commands/CloneNamespaceCommand.java | 113 -------
.../java/org/apache/accumulo/master/Master.java | 31 +-
.../master/tableOps/CloneTableNamespace.java | 201 ------------
.../concurrent/CloneTableNamespace.java | 55 ----
.../apache/accumulo/test/TableNamespacesIT.java | 253 +++++++---------
.../randomwalk/conf/modules/Concurrent.xml | 5 -
10 files changed, 256 insertions(+), 808 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
index 313a899..d966f3c 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperations.java
@@ -20,7 +20,6 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.SortedSet;
import org.apache.accumulo.core.client.AccumuloException;
@@ -249,33 +248,6 @@ public interface TableNamespaceOperations {
public List<DiskUsage> getDiskUsage(String namespace) throws AccumuloException, AccumuloSecurityException, TableNamespaceNotFoundException;
/**
- * Clone a all the tables in a table namespace to a new table namespace. Optionally copy all their properties as well.
- *
- * @param srcName
- * The table namespace to clone
- * @param newName
- * The new table namespace to clone to
- * @param flush
- * Whether to flush each table before cloning
- * @param propertiesToSet
- * Which table namespace properties to set
- * @param propertiesToExclude
- * Which table namespace properties to exclude
- * @param copyTableProps
- * Whether to copy each table's properties
- * @throws AccumuloSecurityException
- * when the user does not have the proper permissions
- * @throws AccumuloException
- * when there is a general accumulo error
- * @throws TableNamespaceNotFoundException
- * If the old table namespace doesn't exist
- * @throws TableNamespaceExistsException
- * If the new table namespace already exists
- */
- public void clone(String srcName, String newName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, Boolean copyTableProps)
- throws AccumuloSecurityException, AccumuloException, TableNamespaceNotFoundException, TableNamespaceExistsException;
-
- /**
* Add an iterator to a table namespace on all scopes.
*
* @param tableNamespace
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
index 602110b..a7d0c34 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableNamespaceOperationsImpl.java
@@ -18,7 +18,6 @@ package org.apache.accumulo.core.client.admin;
import java.nio.ByteBuffer;
import java.util.Arrays;
-import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
@@ -36,7 +35,6 @@ import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.TableExistsException;
import org.apache.accumulo.core.client.TableNamespaceExistsException;
import org.apache.accumulo.core.client.TableNamespaceNotEmptyException;
import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
@@ -362,71 +360,6 @@ public class TableNamespaceOperationsImpl extends TableNamespaceOperationsHelper
}
/**
- * Clone a all the tables in a table namespace to a new table namespace. Optionally copy all their properties as well.
- *
- * @param srcName
- * The table namespace to clone
- * @param newName
- * The new table namespace to clone to
- * @param flush
- * Whether to flush each table before cloning
- * @param propertiesToSet
- * Which table namespace properties to set
- * @param propertiesToExclude
- * Which table namespace properties to exclude
- * @param copyTableProps
- * Whether to copy each table's properties
- * @throws AccumuloSecurityException
- * when the user does not have the proper permissions
- * @throws AccumuloException
- * when there is a general accumulo error
- * @throws TableNamespaceNotFoundException
- * If the old table namespace doesn't exist
- * @throws TableNamespaceExistsException
- * If the new table namespace already exists
- */
- @Override
- public void clone(String srcName, String newName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, Boolean copyTableProps)
- throws AccumuloSecurityException, AccumuloException, TableNamespaceNotFoundException, TableNamespaceExistsException {
-
- ArgumentChecker.notNull(srcName, newName);
-
- String namespaceId = TableNamespaces.getNamespaceId(instance, srcName);
-
- if (propertiesToExclude == null)
- propertiesToExclude = Collections.emptySet();
-
- if (propertiesToSet == null)
- propertiesToSet = Collections.emptyMap();
-
- if (!Collections.disjoint(propertiesToExclude, propertiesToSet.keySet()))
- throw new IllegalArgumentException("propertiesToSet and propertiesToExclude not disjoint");
-
- String srcNamespaceId = TableNamespaces.getNamespaceId(instance, srcName);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(srcNamespaceId.getBytes()), ByteBuffer.wrap(newName.getBytes()));
- Map<String,String> opts = new HashMap<String,String>();
- opts.putAll(propertiesToSet);
- for (String prop : propertiesToExclude)
- opts.put(prop, "");
- doTableNamespaceOperation(TableOperation.CLONE, args, opts);
-
- for (String tableId : TableNamespaces.getTableIds(instance, namespaceId)) {
- try {
- String tableName = Tables.getTableName(instance, tableId);
-
- String newTableName = newName + "." + Tables.extractTableName(tableName);
- getTableOperations().clone(tableName, newTableName, flush, null, null);
- } catch (TableNotFoundException e) {
- String why = "Table (" + tableId + ") dissappeared while cloning namespace (" + srcName + ")";
- throw new IllegalStateException(why);
- } catch (TableExistsException e) {
- String why = "Table somehow already existed in the newly created namespace (" + newName + ")";
- throw new IllegalStateException(why);
- }
- }
- }
-
- /**
* Rename a table namespace
*
* @param oldNamespaceName
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
index 28fff21..c04c522 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableNamespaceOperations.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -37,7 +36,6 @@ import org.apache.accumulo.core.client.admin.TableNamespaceOperationsHelper;
import org.apache.accumulo.core.client.admin.TimeType;
import org.apache.accumulo.core.client.impl.Tables;
import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
-import org.apache.commons.lang.NotImplementedException;
public class MockTableNamespaceOperations extends TableNamespaceOperationsHelper {
@@ -176,13 +174,6 @@ public class MockTableNamespaceOperations extends TableNamespaceOperationsHelper
}
@Override
- public void clone(String srcName, String newName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude, Boolean copyTableProps)
- throws AccumuloSecurityException, AccumuloException, TableNamespaceNotFoundException, TableNamespaceExistsException {
- // TODO Implement clone in Mock
- throw new NotImplementedException();
- }
-
- @Override
public boolean testClassLoad(String namespace, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
TableNamespaceNotFoundException {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index c19e84a..7d13d5f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -73,7 +73,6 @@ import org.apache.accumulo.core.util.shell.commands.AuthenticateCommand;
import org.apache.accumulo.core.util.shell.commands.ByeCommand;
import org.apache.accumulo.core.util.shell.commands.ClasspathCommand;
import org.apache.accumulo.core.util.shell.commands.ClearCommand;
-import org.apache.accumulo.core.util.shell.commands.CloneNamespaceCommand;
import org.apache.accumulo.core.util.shell.commands.CloneTableCommand;
import org.apache.accumulo.core.util.shell.commands.ClsCommand;
import org.apache.accumulo.core.util.shell.commands.CompactCommand;
@@ -174,14 +173,14 @@ import com.beust.jcommander.ParameterException;
public class Shell extends ShellOptions {
public static final Logger log = Logger.getLogger(Shell.class);
private static final Logger audit = Logger.getLogger(Shell.class.getName() + ".audit");
-
+
public static final String CHARSET = "ISO-8859-1";
public static final int NO_FIXED_ARG_LENGTH_CHECK = -1;
public static final String COMMENT_PREFIX = "#";
public static final String HISTORY_DIR_NAME = ".accumulo";
public static final String HISTORY_FILE_NAME = "shell_history.txt";
private static final String SHELL_DESCRIPTION = "Shell - Apache Accumulo Interactive Shell";
-
+
protected int exitCode = 0;
private String tableName;
protected Instance instance;
@@ -193,21 +192,21 @@ public class Shell extends ShellOptions {
private final Class<? extends Formatter> binaryFormatterClass = BinaryFormatter.class;
public Map<String,List<IteratorSetting>> scanIteratorOptions = new HashMap<String,List<IteratorSetting>>();
public Map<String,List<IteratorSetting>> iteratorProfiles = new HashMap<String,List<IteratorSetting>>();
-
+
private Token rootToken;
public final Map<String,Command> commandFactory = new TreeMap<String,Command>();
public final Map<String,Command[]> commandGrouping = new TreeMap<String,Command[]>();
protected boolean configError = false;
-
+
// exit if true
private boolean exit = false;
-
+
// file to execute commands from
protected File execFile = null;
// single command to execute from the command line
protected String execCommand = null;
protected boolean verbose = true;
-
+
private boolean tabCompletion;
private boolean disableAuthTimeout;
private long authTimeout;
@@ -215,26 +214,26 @@ public class Shell extends ShellOptions {
private boolean logErrorsToConsole = false;
private PrintWriter writer = null;
private boolean masking = false;
-
+
public Shell() throws IOException {
this(new ConsoleReader());
}
-
+
public Shell(ConsoleReader reader) {
super();
this.reader = reader;
}
-
+
public Shell(ConsoleReader reader, PrintWriter writer) {
this(reader);
this.writer = writer;
}
-
+
// Not for client use
public boolean config(String... args) {
ShellOptionsJC options = new ShellOptionsJC();
JCommander jc = new JCommander();
-
+
jc.setProgramName("accumulo shell");
jc.addObject(options);
try {
@@ -242,47 +241,47 @@ public class Shell extends ShellOptions {
} catch (ParameterException e) {
configError = true;
}
-
+
if (options.isHelpEnabled()) {
configError = true;
}
-
+
if (!configError && options.getUnrecognizedOptions() != null) {
configError = true;
logError("Unrecognized Options: " + options.getUnrecognizedOptions().toString());
}
-
+
if (configError) {
jc.usage();
return true;
}
-
+
setDebugging(options.isDebugEnabled());
authTimeout = options.getAuthTimeout() * 60 * 1000; // convert minutes to milliseconds
disableAuthTimeout = options.isAuthTimeoutDisabled();
-
+
// get the options that were parsed
String user = options.getUsername();
String password = options.getPassword();
-
+
tabCompletion = !options.isTabCompletionDisabled();
-
+
// Use a fake (Mock), ZK, or HdfsZK Accumulo instance
setInstance(options);
-
+
// AuthenticationToken options
token = options.getAuthenticationToken();
Map<String,String> loginOptions = options.getTokenProperties();
-
+
// process default parameters if unspecified
try {
boolean hasToken = (token != null);
boolean hasTokenOptions = !loginOptions.isEmpty();
-
+
if (hasToken && password != null) {
throw new ParameterException("Can not supply '--pass' option with '--tokenClass' option");
}
-
+
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
@@ -298,7 +297,7 @@ public class Shell extends ShellOptions {
org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties props;
// and line wrap it because the package name is so long
props = new org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties();
-
+
props.putAllStrings(loginOptions);
token.init(props);
} else {
@@ -306,7 +305,7 @@ public class Shell extends ShellOptions {
if ("stdin".equals(password) || password == null) {
password = reader.readLine("Password: ", '*');
}
-
+
if (password == null) {
// User cancel, e.g. Ctrl-D pressed
throw new ParameterException("No password or token option supplied");
@@ -314,21 +313,21 @@ public class Shell extends ShellOptions {
this.token = new PasswordToken(password);
}
}
-
+
if (!options.isFake()) {
ZooReader zr = new ZooReader(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
DistributedTrace.enable(instance, zr, "shell", InetAddress.getLocalHost().getHostName());
}
-
+
this.setTableName("");
this.principal = user;
connector = instance.getConnector(this.principal, token);
-
+
} catch (Exception e) {
printException(e);
configError = true;
}
-
+
// decide whether to execute commands from a file and quit
if (options.getExecFile() != null) {
execFile = options.getExecFile();
@@ -341,9 +340,9 @@ public class Shell extends ShellOptions {
if (execCommand != null) {
verbose = false;
}
-
+
rootToken = new Token();
-
+
Command[] dataCommands = {new DeleteCommand(), new DeleteManyCommand(), new DeleteRowsCommand(), new EGrepCommand(), new FormatterCommand(),
new InterpreterCommand(), new GrepCommand(), new ImportDirectoryCommand(), new InsertCommand(), new MaxRowCommand(), new ScanCommand()};
Command[] debuggingCommands = {new ClasspathCommand(), new DebugCommand(), new ListScansCommand(), new ListCompactionsCommand(), new TraceCommand(),
@@ -360,7 +359,7 @@ public class Shell extends ShellOptions {
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 CloneNamespaceCommand()};
+ new TablesCommand(), new NamespacesCommand(), new CreateNamespaceCommand(), new DeleteNamespaceCommand(), new RenameNamespaceCommand()};
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(),
@@ -376,7 +375,7 @@ public class Shell extends ShellOptions {
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);
@@ -386,11 +385,12 @@ public class Shell extends ShellOptions {
}
return configError;
}
-
+
/**
* Sets the instance used by the shell based on the given options.
- *
- * @param options shell options
+ *
+ * @param options
+ * shell options
*/
protected void setInstance(ShellOptionsJC options) {
// should only be one set of instance options set
@@ -416,7 +416,7 @@ public class Shell extends ShellOptions {
}
}
}
-
+
/*
* Takes instanceName and keepers as separate arguments, rather than just packaged into the clientConfig,
* so that we can fail over to accumulo-site.xml or HDFS config if they're unspecified.
@@ -443,30 +443,30 @@ public class Shell extends ShellOptions {
return new ZooKeeperInstance(clientConfig.withInstance(instanceName).withZkHosts(keepers));
}
}
-
+
public Connector getConnector() {
return connector;
}
-
+
public Instance getInstance() {
return instance;
}
-
+
public static void main(String args[]) throws IOException {
Shell shell = new Shell();
shell.config(args);
-
+
System.exit(shell.start());
}
-
+
public int start() throws IOException {
if (configError)
return 1;
-
+
String input;
if (isVerbose())
printInfo();
-
+
String home = System.getProperty("HOME");
if (home == null)
home = System.getenv("HOME");
@@ -492,15 +492,15 @@ public class Shell extends ShellOptions {
} catch (IOException e) {
log.warn("Unable to load history file at " + historyPath);
}
-
+
// This would be a nice feature but !METADATA screws it up
reader.setExpandEvents(false);
-
+
// Turn Ctrl+C into Exception instead of JVM exit
reader.setHandleUserInterrupt(true);
-
+
ShellCompletor userCompletor = null;
-
+
if (execFile != null) {
java.util.Scanner scanner = new java.util.Scanner(execFile);
try {
@@ -516,33 +516,33 @@ public class Shell extends ShellOptions {
}
return exitCode;
}
-
+
while (true) {
try {
if (hasExited())
return exitCode;
-
+
// If tab completion is true we need to reset
if (tabCompletion) {
if (userCompletor != null)
reader.removeCompleter(userCompletor);
-
+
userCompletor = setupCompletion();
reader.addCompleter(userCompletor);
}
-
+
reader.setPrompt(getDefaultPrompt());
input = reader.readLine();
if (input == null) {
reader.println();
return exitCode;
} // User Canceled (Ctrl+D)
-
+
execCommand(input, disableAuthTimeout, false);
} catch (UserInterruptException uie) {
// User Cancelled (Ctrl+C)
reader.println();
-
+
String partialLine = uie.getPartialLine();
if (partialLine == null || "".equals(uie.getPartialLine().trim())) {
// No content, actually exit
@@ -553,14 +553,14 @@ public class Shell extends ShellOptions {
}
}
}
-
+
public void printInfo() throws IOException {
reader.print("\n" + SHELL_DESCRIPTION + "\n" + "- \n" + "- version: " + Constants.VERSION + "\n" + "- instance name: "
+ connector.getInstance().getInstanceName() + "\n" + "- instance id: " + connector.getInstance().getInstanceID() + "\n" + "- \n"
+ "- type 'help' for a list of available commands\n" + "- \n");
reader.flush();
}
-
+
public void printVerboseInfo() throws IOException {
StringBuilder sb = new StringBuilder("-\n");
sb.append("- Current user: ").append(connector.whoami()).append("\n");
@@ -587,22 +587,22 @@ public class Shell extends ShellOptions {
sb.append("-\n");
reader.print(sb.toString());
}
-
+
public String getDefaultPrompt() {
return connector.whoami() + "@" + connector.getInstance().getInstanceName() + (getTableName().isEmpty() ? "" : " ") + getTableName() + "> ";
}
-
+
public void execCommand(String input, boolean ignoreAuthTimeout, boolean echoPrompt) throws IOException {
audit.log(Level.INFO, getDefaultPrompt() + input);
if (echoPrompt) {
reader.print(getDefaultPrompt());
reader.println(input);
}
-
+
if (input.startsWith(COMMENT_PREFIX)) {
return;
}
-
+
String fields[];
try {
fields = new QuotedStringTokenizer(input).getTokens();
@@ -613,10 +613,10 @@ public class Shell extends ShellOptions {
}
if (fields.length == 0)
return;
-
+
String command = fields[0];
fields = fields.length > 1 ? Arrays.copyOfRange(fields, 1, fields.length) : new String[] {};
-
+
Command sc = null;
if (command.length() > 0) {
try {
@@ -627,7 +627,7 @@ public class Shell extends ShellOptions {
reader.flush();
return;
}
-
+
if (!(sc instanceof ExitCommand) && !ignoreAuthTimeout && System.currentTimeMillis() - lastUserActivity > authTimeout) {
reader.println("Shell has been idle for too long. Please re-authenticate.");
boolean authFailed = true;
@@ -637,26 +637,26 @@ public class Shell extends ShellOptions {
reader.println();
return;
} // user canceled
-
+
try {
authFailed = !connector.securityOperations().authenticateUser(connector.whoami(), new PasswordToken(pwd));
} catch (Exception e) {
++exitCode;
printException(e);
}
-
+
if (authFailed)
reader.print("Invalid password. ");
} while (authFailed);
lastUserActivity = System.currentTimeMillis();
}
-
+
// Get the options from the command on how to parse the string
Options parseOpts = sc.getOptionsWithHelp();
-
+
// Parse the string using the given options
CommandLine cl = new BasicParser().parse(parseOpts, fields);
-
+
int actualArgLen = cl.getArgs().length;
int expectedArgLen = sc.numArgs();
if (cl.hasOption(helpOption)) {
@@ -675,7 +675,7 @@ public class Shell extends ShellOptions {
exitCode += tmpCode;
reader.flush();
}
-
+
} catch (ConstraintViolationException e) {
++exitCode;
printConstraintViolationException(e);
@@ -703,14 +703,14 @@ public class Shell extends ShellOptions {
}
reader.flush();
}
-
+
/**
* The command tree is built in reverse so that the references are more easily linked up. There is some code in token to allow forward building of the command
* tree.
*/
private ShellCompletor setupCompletion() {
rootToken = new Token();
-
+
Set<String> tableNames = null;
try {
tableNames = connector.tableOperations().list();
@@ -718,7 +718,7 @@ public class Shell extends ShellOptions {
log.debug("Unable to obtain list of tables", e);
tableNames = Collections.emptySet();
}
-
+
Set<String> userlist = null;
try {
userlist = connector.securityOperations().listLocalUsers();
@@ -726,7 +726,7 @@ public class Shell extends ShellOptions {
log.debug("Unable to obtain list of users", e);
userlist = Collections.emptySet();
}
-
+
Set<String> tableNamespaces = null;
try {
tableNamespaces = connector.tableNamespaceOperations().list();
@@ -734,29 +734,29 @@ public class Shell extends ShellOptions {
log.debug("Unable to obtain list of table namespaces", e);
tableNamespaces = Collections.emptySet();
}
-
+
Map<Command.CompletionSet,Set<String>> options = new HashMap<Command.CompletionSet,Set<String>>();
-
+
Set<String> commands = new HashSet<String>();
for (String a : commandFactory.keySet())
commands.add(a);
-
+
Set<String> modifiedUserlist = new HashSet<String>();
Set<String> modifiedTablenames = new HashSet<String>();
Set<String> modifiedTableNamespaces = new HashSet<String>();
-
+
for (String a : tableNames)
modifiedTablenames.add(a.replaceAll("([\\s'\"])", "\\\\$1"));
for (String a : userlist)
modifiedUserlist.add(a.replaceAll("([\\s'\"])", "\\\\$1"));
for (String a : tableNamespaces)
modifiedTableNamespaces.add(a.replaceAll("([\\s'\"])", "\\\\$1"));
-
+
options.put(Command.CompletionSet.USERNAMES, modifiedUserlist);
options.put(Command.CompletionSet.TABLENAMES, modifiedTablenames);
options.put(Command.CompletionSet.TABLENAMESPACES, modifiedTableNamespaces);
options.put(Command.CompletionSet.COMMANDS, commands);
-
+
for (Command[] cmdGroup : commandGrouping.values()) {
for (Command c : cmdGroup) {
c.getOptionsWithHelp(); // prep the options for the command
@@ -767,7 +767,7 @@ public class Shell extends ShellOptions {
}
return new ShellCompletor(rootToken, options);
}
-
+
/**
* The Command class represents a command to be run in the shell. It contains the methods to execute along with some methods to help tab completion, and
* return the command name, help, and usage.
@@ -777,62 +777,62 @@ public class Shell extends ShellOptions {
public enum CompletionSet {
TABLENAMES, USERNAMES, COMMANDS, TABLENAMESPACES
}
-
+
static Set<String> getCommandNames(Map<CompletionSet,Set<String>> objects) {
return objects.get(CompletionSet.COMMANDS);
}
-
+
static Set<String> getTableNames(Map<CompletionSet,Set<String>> objects) {
return objects.get(CompletionSet.TABLENAMES);
}
-
+
static Set<String> getUserNames(Map<CompletionSet,Set<String>> objects) {
return objects.get(CompletionSet.USERNAMES);
}
-
+
static Set<String> getTableNamespaces(Map<CompletionSet,Set<String>> objects) {
return objects.get(CompletionSet.TABLENAMESPACES);
}
-
+
public void registerCompletionGeneral(Token root, Set<String> args, boolean caseSens) {
Token t = new Token(args);
t.setCaseSensitive(caseSens);
-
+
Token command = new Token(getName());
command.addSubcommand(t);
-
+
root.addSubcommand(command);
}
-
+
public void registerCompletionForTables(Token root, Map<CompletionSet,Set<String>> completionSet) {
registerCompletionGeneral(root, completionSet.get(CompletionSet.TABLENAMES), true);
}
-
+
public void registerCompletionForUsers(Token root, Map<CompletionSet,Set<String>> completionSet) {
registerCompletionGeneral(root, completionSet.get(CompletionSet.USERNAMES), true);
}
-
+
public void registerCompletionForCommands(Token root, Map<CompletionSet,Set<String>> completionSet) {
registerCompletionGeneral(root, completionSet.get(CompletionSet.COMMANDS), false);
}
-
+
public void registerCompletionForTableNamespaces(Token root, Map<CompletionSet,Set<String>> completionSet) {
registerCompletionGeneral(root, completionSet.get(CompletionSet.TABLENAMESPACES), true);
}
-
+
// abstract methods to override
public abstract int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception;
-
+
public abstract String description();
-
+
/**
* If the number of arguments is not always zero (not including those arguments handled through Options), make sure to override the {@link #usage()} method.
* Otherwise, {@link #usage()} does need to be overridden.
*/
public abstract int numArgs();
-
+
// OPTIONAL methods to override:
-
+
// the general version of getname uses reflection to get the class name
// and then cuts off the suffix -Command to get the name of the command
public String getName() {
@@ -841,54 +841,54 @@ public class Shell extends ShellOptions {
int i = s.indexOf("Command");
return i > 0 ? s.substring(st + 1, i).toLowerCase(Locale.ENGLISH) : null;
}
-
+
// The general version of this method adds the name
// of the command to the completion tree
public void registerCompletion(Token root, Map<CompletionSet,Set<String>> completion_set) {
root.addSubcommand(new Token(getName()));
}
-
+
// The general version of this method uses the HelpFormatter
// that comes with the apache Options package to print out the help
public final void printHelp(Shell shellState) {
shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp());
}
-
+
public final void printHelp(Shell shellState, int width) {
shellState.printHelp(usage(), "description: " + this.description(), getOptionsWithHelp(), width);
}
-
+
// Get options with help
public final Options getOptionsWithHelp() {
Options opts = getOptions();
opts.addOption(new Option(helpOption, helpLongOption, false, "display this help"));
return opts;
}
-
+
// General usage is just the command
public String usage() {
return getName();
}
-
+
// General Options are empty
public Options getOptions() {
return new Options();
}
}
-
+
public interface PrintLine {
public void print(String s);
-
+
public void close();
}
-
+
public static class PrintShell implements PrintLine {
ConsoleReader reader;
-
+
public PrintShell(ConsoleReader reader) {
this.reader = reader;
}
-
+
@Override
public void print(String s) {
try {
@@ -897,40 +897,40 @@ public class Shell extends ShellOptions {
throw new RuntimeException(ex);
}
}
-
+
@Override
public void close() {}
};
-
+
public static class PrintFile implements PrintLine {
PrintWriter writer;
-
+
public PrintFile(String filename) throws FileNotFoundException {
writer = new PrintWriter(filename);
}
-
+
@Override
public void print(String s) {
writer.println(s);
}
-
+
@Override
public void close() {
writer.close();
}
};
-
+
public final void printLines(Iterator<String> lines, boolean paginate) throws IOException {
printLines(lines, paginate, null);
}
-
+
public final void printLines(Iterator<String> lines, boolean paginate, PrintLine out) throws IOException {
int linesPrinted = 0;
String prompt = "-- hit any key to continue or 'q' to quit --";
int lastPromptLength = prompt.length();
int termWidth = reader.getTerminal().getWidth();
int maxLines = reader.getTerminal().getHeight();
-
+
String peek = null;
while (lines.hasNext()) {
String nextLine = lines.next();
@@ -942,7 +942,7 @@ public class Shell extends ShellOptions {
reader.println(peek);
if (paginate) {
linesPrinted += peek.length() == 0 ? 0 : Math.ceil(peek.length() * 1.0 / termWidth);
-
+
// check if displaying the next line would result in
// scrolling off the screen
if (linesPrinted + Math.ceil(lastPromptLength * 1.0 / termWidth) + Math.ceil(prompt.length() * 1.0 / termWidth)
@@ -953,7 +953,7 @@ public class Shell extends ShellOptions {
lastPromptLength = nextPrompt.length();
reader.print(nextPrompt);
reader.flush();
-
+
if (Character.toUpperCase((char) reader.readCharacter()) == 'Q') {
reader.println();
return;
@@ -974,38 +974,38 @@ public class Shell extends ShellOptions {
reader.println(peek);
}
}
-
+
public final void printRecords(Iterable<Entry<Key,Value>> scanner, boolean printTimestamps, boolean paginate, Class<? extends Formatter> formatterClass,
PrintLine outFile) throws IOException {
printLines(FormatterFactory.getFormatter(formatterClass, scanner, printTimestamps), paginate, outFile);
}
-
+
public final void printRecords(Iterable<Entry<Key,Value>> scanner, boolean printTimestamps, boolean paginate, Class<? extends Formatter> formatterClass)
throws IOException {
printLines(FormatterFactory.getFormatter(formatterClass, scanner, printTimestamps), paginate);
}
-
+
public final void printBinaryRecords(Iterable<Entry<Key,Value>> scanner, boolean printTimestamps, boolean paginate, PrintLine outFile) throws IOException {
printLines(FormatterFactory.getFormatter(binaryFormatterClass, scanner, printTimestamps), paginate, outFile);
}
-
+
public final void printBinaryRecords(Iterable<Entry<Key,Value>> scanner, boolean printTimestamps, boolean paginate) throws IOException {
printLines(FormatterFactory.getFormatter(binaryFormatterClass, scanner, printTimestamps), paginate);
}
-
+
public static String repeat(String s, int c) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < c; i++)
sb.append(s);
return sb.toString();
}
-
+
public void checkTableState() {
if (getTableName().isEmpty())
throw new IllegalStateException(
"Not in a table context. Please use 'table <tableName>' to switch to a table, or use '-t' to specify a table if option is available.");
}
-
+
private final void printConstraintViolationException(ConstraintViolationException cve) {
printException(cve, "");
int COL1 = 50, COL2 = 14;
@@ -1017,28 +1017,28 @@ public class Shell extends ShellOptions {
logError(String.format("%-" + COL1 + "s | %" + COL2 + "d | %-" + col3 + "s%n", cvs.constrainClass, cvs.violationCode, cvs.violationDescription));
logError(String.format("%" + COL1 + "s-+-%" + COL2 + "s-+-%" + col3 + "s%n", repeat("-", COL1), repeat("-", COL2), repeat("-", col3)));
}
-
+
public final void printException(Exception e) {
printException(e, e.getMessage());
}
-
+
private final void printException(Exception e, String msg) {
logError(e.getClass().getName() + (msg != null ? ": " + msg : ""));
log.debug(e.getClass().getName() + (msg != null ? ": " + msg : ""), e);
}
-
+
public static final void setDebugging(boolean debuggingEnabled) {
Logger.getLogger(Constants.CORE_PACKAGE_NAME).setLevel(debuggingEnabled ? Level.TRACE : Level.INFO);
}
-
+
public static final boolean isDebuggingEnabled() {
return Logger.getLogger(Constants.CORE_PACKAGE_NAME).isTraceEnabled();
}
-
+
private final void printHelp(String usage, String description, Options opts) {
printHelp(usage, description, opts, Integer.MAX_VALUE);
}
-
+
private final void printHelp(String usage, String description, Options opts, int width) {
PrintWriter pw = new PrintWriter(System.err);
new HelpFormatter().printHelp(pw, width, usage, description, opts, 2, 5, null, true);
@@ -1048,53 +1048,53 @@ public class Shell extends ShellOptions {
writer.flush();
}
}
-
+
public int getExitCode() {
return exitCode;
}
-
+
public void resetExitCode() {
exitCode = 0;
}
-
+
public void setExit(boolean exit) {
this.exit = exit;
}
-
+
public boolean getExit() {
return this.exit;
}
-
+
public boolean isVerbose() {
return verbose;
}
-
+
public void setTableName(String tableName) {
this.tableName = tableName;
}
-
+
public String getTableName() {
return tableName;
}
-
+
public ConsoleReader getReader() {
return reader;
}
-
+
public void updateUser(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
connector = instance.getConnector(principal, token);
this.principal = principal;
this.token = token;
}
-
+
public String getPrincipal() {
return principal;
}
-
+
public AuthenticationToken getToken() {
return token;
}
-
+
/**
* Return the formatter for the current table.
*
@@ -1103,7 +1103,7 @@ public class Shell extends ShellOptions {
public Class<? extends Formatter> getFormatter() {
return getFormatter(this.tableName);
}
-
+
/**
* Return the formatter for the given table.
*
@@ -1113,7 +1113,7 @@ public class Shell extends ShellOptions {
*/
public Class<? extends Formatter> getFormatter(String tableName) {
Class<? extends Formatter> formatter = FormatterCommand.getCurrentFormatter(tableName, this);
-
+
if (null == formatter) {
logError("Could not load the specified formatter. Using the DefaultFormatter");
return this.defaultFormatterClass;
@@ -1121,11 +1121,11 @@ public class Shell extends ShellOptions {
return formatter;
}
}
-
+
public void setLogErrorsToConsole() {
this.logErrorsToConsole = true;
}
-
+
private void logError(String s) {
log.error(s);
if (logErrorsToConsole) {
@@ -1135,24 +1135,24 @@ public class Shell extends ShellOptions {
} catch (IOException e) {}
}
}
-
+
public String readMaskedLine(String prompt, Character mask) throws IOException {
this.masking = true;
String s = reader.readLine(prompt, mask);
this.masking = false;
return s;
}
-
+
public boolean isMasking() {
return masking;
}
-
+
public boolean hasExited() {
return exit;
}
-
+
public boolean isTabCompletion() {
return tabCompletion;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CloneNamespaceCommand.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CloneNamespaceCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CloneNamespaceCommand.java
deleted file mode 100644
index dade389..0000000
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CloneNamespaceCommand.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.HashMap;
-import java.util.HashSet;
-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.TableNamespaceExistsException;
-import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
-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;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-
-public class CloneNamespaceCommand extends Command {
-
- private Option setPropsOption;
- private Option excludePropsOption;
- private Option noFlushOption;
- private Option copyTablePropsOption;
-
- @Override
- public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException,
- TableNotFoundException, TableExistsException, TableNamespaceNotFoundException, TableNamespaceExistsException {
-
- final HashMap<String,String> props = new HashMap<String,String>();
- final HashSet<String> exclude = new HashSet<String>();
- boolean flush = true;
- boolean copyTableProps = false;
-
- if (cl.hasOption(setPropsOption.getOpt())) {
- String[] keyVals = cl.getOptionValue(setPropsOption.getOpt()).split(",");
- for (String keyVal : keyVals) {
- String[] sa = keyVal.split("=");
- props.put(sa[0], sa[1]);
- }
- }
-
- if (cl.hasOption(excludePropsOption.getOpt())) {
- String[] keys = cl.getOptionValue(excludePropsOption.getOpt()).split(",");
- for (String key : keys) {
- exclude.add(key);
- }
- }
-
- if (cl.hasOption(noFlushOption.getOpt())) {
- flush = false;
- }
-
- if (cl.hasOption(noFlushOption.getOpt())) {
- copyTableProps = true;
- }
-
- shellState.getConnector().tableNamespaceOperations().clone(cl.getArgs()[0], cl.getArgs()[1], flush, props, exclude, copyTableProps);
- return 0;
- }
-
- @Override
- public String usage() {
- return getName() + " <current name> <new name>";
- }
-
- @Override
- public String description() {
- return "clones a table namespace";
- }
-
- @Override
- public void registerCompletion(final Token root, final Map<Command.CompletionSet,Set<String>> completionSet) {
- registerCompletionForTableNamespaces(root, completionSet);
- }
-
- @Override
- public Options getOptions() {
- final Options o = new Options();
- setPropsOption = new Option("s", "set", true, "set initial properties. Expects <prop>=<value>{,<prop>=<value>}");
- o.addOption(setPropsOption);
- excludePropsOption = new Option("e", "exclude", true, "exclude properties that should not be copied from source. Expects <prop>{,<prop>}");
- o.addOption(excludePropsOption);
- noFlushOption = new Option("nf", "noFlush", false, "do not flush table data in memory before cloning.");
- o.addOption(noFlushOption);
- copyTablePropsOption = new Option("tp", "copyTableProps", false, "copy each table's properties to the cloned table in the new namespace.");
- o.addOption(copyTablePropsOption);
- return o;
- }
-
- @Override
- public int numArgs() {
- return 2;
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/server/master/src/main/java/org/apache/accumulo/master/Master.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java
index e0c1398..64c6340 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/Master.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java
@@ -99,7 +99,6 @@ import org.apache.accumulo.master.tableOps.BulkImport;
import org.apache.accumulo.master.tableOps.CancelCompactions;
import org.apache.accumulo.master.tableOps.ChangeTableState;
import org.apache.accumulo.master.tableOps.CloneTable;
-import org.apache.accumulo.master.tableOps.CloneTableNamespace;
import org.apache.accumulo.master.tableOps.CompactRange;
import org.apache.accumulo.master.tableOps.CreateTable;
import org.apache.accumulo.master.tableOps.CreateTableNamespace;
@@ -951,7 +950,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
} catch (TableNamespaceNotFoundException e) {
throw new TException(e.getMessage(), e);
}
-
+
break;
}
case CLONE: {
@@ -1190,34 +1189,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver, CurrentSt
fate.seedTransaction(opid, new TraceRepo<Master>(new DeleteTableNamespace(namespaceId)), autoCleanup);
break;
}
- case CLONE: {
- String namespaceId = ByteBufferUtil.toString(arguments.get(0));
- String namespace = ByteBufferUtil.toString(arguments.get(1));
- checkNotSystemNamespace(namespace, TableOperation.CLONE);
- checkTableNamespaceName(namespace, TableOperation.CLONE);
- if (!security.canCloneNamespace(c, namespaceId, namespace))
- throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
-
- Map<String,String> propertiesToSet = new HashMap<String,String>();
- Set<String> propertiesToExclude = new HashSet<String>();
-
- for (Entry<String,String> entry : options.entrySet()) {
- if (entry.getValue() == null || entry.getValue().isEmpty()) {
- propertiesToExclude.add(entry.getKey());
- continue;
- }
- if (!TablePropUtil.isPropertyValid(entry.getKey(), entry.getValue())) {
- throw new ThriftTableOperationException(null, namespace, TableOperation.CLONE, TableOperationExceptionType.OTHER, "Property or value not valid "
- + entry.getKey() + "=" + entry.getValue());
- }
- propertiesToSet.put(entry.getKey(), entry.getValue());
- }
-
- fate.seedTransaction(opid, new TraceRepo<Master>(new CloneTableNamespace(c.getPrincipal(), namespaceId, namespace, propertiesToSet,
- propertiesToExclude)), autoCleanup);
-
- break;
- }
default:
throw new UnsupportedOperationException();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTableNamespace.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTableNamespace.java b/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTableNamespace.java
deleted file mode 100644
index ffa1448..0000000
--- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/CloneTableNamespace.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * 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.master.tableOps;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.impl.Tables;
-import org.apache.accumulo.core.client.impl.thrift.TableOperation;
-import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.security.TableNamespacePermission;
-import org.apache.accumulo.fate.Repo;
-import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy;
-import org.apache.accumulo.master.Master;
-import org.apache.accumulo.server.client.HdfsZooInstance;
-import org.apache.accumulo.server.security.AuditedSecurityOperation;
-import org.apache.accumulo.server.security.SystemCredentials;
-import org.apache.accumulo.server.tables.TableManager;
-import org.apache.log4j.Logger;
-
-class CloneNamespaceInfo implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- String srcId;
- String namespace;
- String newId;
- Map<String,String> propertiesToSet;
- Set<String> propertiesToExclude;
-
- public String user;
-}
-
-class FinishCloneTableNamespace extends MasterRepo {
-
- private static final long serialVersionUID = 1L;
- private CloneNamespaceInfo cloneInfo;
-
- public FinishCloneTableNamespace(CloneNamespaceInfo cloneInfo) {
- this.cloneInfo = cloneInfo;
- }
-
- @Override
- public long isReady(long tid, Master environment) throws Exception {
- return 0;
- }
-
- @Override
- public Repo<Master> call(long tid, Master environment) throws Exception {
- Utils.unreserveTableNamespace(cloneInfo.srcId, tid, false);
- Utils.unreserveTableNamespace(cloneInfo.newId, tid, true);
-
- environment.getEventCoordinator().event("Cloned table namespace %s from %s", cloneInfo.namespace, cloneInfo.srcId);
-
- Logger.getLogger(FinishCloneTableNamespace.class).debug("Cloned table namespace " + cloneInfo.srcId + " " + cloneInfo.newId + " " + cloneInfo.namespace);
-
- return null;
- }
-
- @Override
- public void undo(long tid, Master environment) throws Exception {}
-}
-
-class CloneNamespaceZookeeper extends MasterRepo {
-
- private static final long serialVersionUID = 1L;
-
- private CloneNamespaceInfo cloneInfo;
-
- public CloneNamespaceZookeeper(CloneNamespaceInfo cloneInfo) {
- this.cloneInfo = cloneInfo;
- }
-
- @Override
- public long isReady(long tid, Master environment) throws Exception {
- return Utils.reserveTableNamespace(cloneInfo.newId, tid, true, false, TableOperation.CLONE);
- }
-
- @Override
- public Repo<Master> call(long tid, Master environment) throws Exception {
- Utils.tableNameLock.lock();
- try {
- // write namespace to zookeeper
- Instance instance = HdfsZooInstance.getInstance();
-
- Utils.checkTableNamespaceDoesNotExist(instance, cloneInfo.namespace, cloneInfo.newId, TableOperation.CLONE);
-
- TableManager.getInstance().addNamespace(cloneInfo.newId, cloneInfo.namespace, NodeExistsPolicy.FAIL);
- TableManager.getInstance().cloneNamespace(cloneInfo.srcId, cloneInfo.newId, cloneInfo.namespace, cloneInfo.propertiesToSet,
- cloneInfo.propertiesToExclude, NodeExistsPolicy.OVERWRITE);
- Tables.clearCache(instance);
-
- return new FinishCloneTableNamespace(cloneInfo);
- } finally {
- Utils.tableNameLock.unlock();
- }
- }
-
- @Override
- public void undo(long tid, Master environment) throws Exception {
- Instance instance = HdfsZooInstance.getInstance();
- TableManager.getInstance().removeNamespace(cloneInfo.newId);
- Utils.unreserveTableNamespace(cloneInfo.newId, tid, true);
- Tables.clearCache(instance);
- }
-}
-
-class CloneNamespacePermissions extends MasterRepo {
-
- private static final long serialVersionUID = 1L;
-
- private CloneNamespaceInfo cloneInfo;
-
- public CloneNamespacePermissions(CloneNamespaceInfo cloneInfo) {
- this.cloneInfo = cloneInfo;
- }
-
- @Override
- public long isReady(long tid, Master environment) throws Exception {
- return 0;
- }
-
- @Override
- public Repo<Master> call(long tid, Master environment) throws Exception {
- // give all table namespace permissions to the creator
- for (TableNamespacePermission permission : TableNamespacePermission.values()) {
- try {
- AuditedSecurityOperation.getInstance().grantTableNamespacePermission(SystemCredentials.get().toThrift(environment.getInstance()), cloneInfo.user,
- cloneInfo.newId, permission);
- } catch (ThriftSecurityException e) {
- Logger.getLogger(FinishCloneTableNamespace.class).error(e.getMessage(), e);
- throw e;
- }
- }
-
- // setup permissions in zookeeper before table namespace info in zookeeper
- // this way concurrent users will not get a spurious pemission denied
- // error
- return new CloneNamespaceZookeeper(cloneInfo);
- }
-
- @Override
- public void undo(long tid, Master environment) throws Exception {
-
- }
-}
-
-public class CloneTableNamespace extends MasterRepo {
-
- private static final long serialVersionUID = 1L;
- private CloneNamespaceInfo cloneInfo;
-
- public CloneTableNamespace(String user, String srcId, String namespace, Map<String,String> propertiesToSet, Set<String> propertiesToExclude) {
- cloneInfo = new CloneNamespaceInfo();
- cloneInfo.user = user;
- cloneInfo.srcId = srcId;
- cloneInfo.namespace = namespace;
- cloneInfo.propertiesToExclude = propertiesToExclude;
- cloneInfo.propertiesToSet = propertiesToSet;
- }
-
- @Override
- public long isReady(long tid, Master environment) throws Exception {
- return Utils.reserveTableNamespace(cloneInfo.srcId, tid, false, true, TableOperation.CLONE);
- }
-
- @Override
- public Repo<Master> call(long tid, Master environment) throws Exception {
-
- Utils.idLock.lock();
- try {
- Instance instance = HdfsZooInstance.getInstance();
- cloneInfo.newId = Utils.getNextTableId(cloneInfo.namespace, instance);
- return new CloneNamespacePermissions(cloneInfo);
- } finally {
- Utils.idLock.unlock();
- }
- }
-
- @Override
- public void undo(long tid, Master environment) throws Exception {
- Utils.unreserveTableNamespace(cloneInfo.srcId, tid, false);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CloneTableNamespace.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CloneTableNamespace.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CloneTableNamespace.java
deleted file mode 100644
index 2c35173..0000000
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/concurrent/CloneTableNamespace.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.test.randomwalk.concurrent;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.TableNamespaceExistsException;
-import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
-import org.apache.accumulo.test.randomwalk.State;
-import org.apache.accumulo.test.randomwalk.Test;
-
-public class CloneTableNamespace extends Test {
-
- @Override
- public void visit(State state, Properties props) throws Exception {
- Connector conn = state.getConnector();
-
- Random rand = (Random) state.get("rand");
-
- @SuppressWarnings("unchecked")
- List<String> namespaces = (List<String>) state.get("namespaces");
-
- String srcName = namespaces.get(rand.nextInt(namespaces.size()));
- String newName = namespaces.get(rand.nextInt(namespaces.size()));
- boolean flush = rand.nextBoolean();
-
- try {
- log.debug("Cloning table namespace " + srcName + " " + newName + " " + flush);
- conn.tableNamespaceOperations().clone(srcName, newName, flush, new HashMap<String,String>(), new HashSet<String>(), true);
- } catch (TableNamespaceExistsException e) {
- log.debug("Clone namespace " + srcName + " failed, " + newName + " exists");
- } catch (TableNamespaceNotFoundException e) {
- log.debug("Clone namespace " + srcName + " failed, doesnt exist");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java b/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
index 5705044..6cb2568 100644
--- a/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
@@ -21,13 +21,10 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.EnumSet;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
-import java.util.Set;
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloException;
@@ -63,25 +60,25 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class TableNamespacesIT {
-
+
Random random = new Random();
public static TemporaryFolder folder = new TemporaryFolder();
static private MiniAccumuloCluster accumulo;
static private String secret = "secret";
-
+
@BeforeClass
static public void setUp() throws Exception {
folder.create();
accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
accumulo.start();
}
-
+
@AfterClass
static public void tearDown() throws Exception {
accumulo.stop();
folder.delete();
}
-
+
/**
* This test creates a table without specifying a namespace. In this case, it puts the table into the default namespace.
*/
@@ -89,12 +86,12 @@ public class TableNamespacesIT {
public void testDefaultNamespace() throws Exception {
String tableName = "test";
Connector c = accumulo.getConnector("root", secret);
-
+
assertTrue(c.tableNamespaceOperations().exists(Constants.DEFAULT_TABLE_NAMESPACE));
c.tableOperations().create(tableName);
assertTrue(c.tableOperations().exists(tableName));
}
-
+
/**
* This test creates a new namespace "testing" and a table "testing.table1" which puts "table1" into the "testing" namespace. Then we create "testing.table2"
* which creates "table2" and puts it into "testing" as well. Then we make sure that you can't delete a namespace with tables in it, and then we delete the
@@ -105,18 +102,18 @@ public class TableNamespacesIT {
String namespace = "testing";
String tableName1 = namespace + ".table1";
String tableName2 = namespace + ".table2";
-
+
Connector c = accumulo.getConnector("root", secret);
-
+
c.tableNamespaceOperations().create(namespace);
assertTrue(c.tableNamespaceOperations().exists(namespace));
-
+
c.tableOperations().create(tableName1);
assertTrue(c.tableOperations().exists(tableName1));
-
+
c.tableOperations().create(tableName2);
assertTrue(c.tableOperations().exists(tableName2));
-
+
// deleting
try {
// can't delete a namespace with tables in it
@@ -128,17 +125,17 @@ public class TableNamespacesIT {
assertTrue(c.tableNamespaceOperations().exists(namespace));
assertTrue(c.tableOperations().exists(tableName1));
assertTrue(c.tableOperations().exists(tableName2));
-
+
c.tableOperations().delete(tableName2);
assertTrue(!c.tableOperations().exists(tableName2));
assertTrue(c.tableNamespaceOperations().exists(namespace));
-
+
c.tableOperations().delete(tableName1);
assertTrue(!c.tableOperations().exists(tableName1));
c.tableNamespaceOperations().delete(namespace);
assertTrue(!c.tableNamespaceOperations().exists(namespace));
}
-
+
/**
* This test creates a namespace, modifies it's properties, and checks to make sure that those properties are applied to its tables. To do something on a
* namespace-wide level, use TableNamespaceOperations.
@@ -147,70 +144,70 @@ public class TableNamespacesIT {
*
* Checks to see if the default namespace's properties work as well.
*/
-
+
@Test
public void testNamespaceProperties() throws Exception {
String namespace = "propchange";
String tableName1 = namespace + ".table1";
String tableName2 = namespace + ".table2";
-
+
String propKey = Property.TABLE_SCAN_MAXMEM.getKey();
String propVal = "42K";
-
+
Connector c = accumulo.getConnector("root", secret);
-
+
c.tableNamespaceOperations().create(namespace);
c.tableOperations().create(tableName1);
c.tableNamespaceOperations().setProperty(namespace, propKey, propVal);
-
+
// check the namespace has the property
assertTrue(checkTableNamespaceHasProp(c, namespace, propKey, propVal));
-
+
// check that the table gets it from the namespace
assertTrue(checkTableHasProp(c, tableName1, propKey, propVal));
-
+
// test a second table to be sure the first wasn't magical
// (also, changed the order, the namespace has the property already)
c.tableOperations().create(tableName2);
assertTrue(checkTableHasProp(c, tableName2, propKey, propVal));
-
+
// test that table properties override namespace properties
String propKey2 = Property.TABLE_FILE_MAX.getKey();
String propVal2 = "42";
String tablePropVal = "13";
-
+
c.tableOperations().setProperty(tableName2, propKey2, tablePropVal);
c.tableNamespaceOperations().setProperty("propchange", propKey2, propVal2);
-
+
assertTrue(checkTableHasProp(c, tableName2, propKey2, tablePropVal));
-
+
// now check that you can change the default namespace's properties
propVal = "13K";
String tableName = "some_table";
c.tableOperations().create(tableName);
c.tableNamespaceOperations().setProperty(Constants.DEFAULT_TABLE_NAMESPACE, propKey, propVal);
-
+
assertTrue(checkTableHasProp(c, tableName, propKey, propVal));
-
+
// test the properties server-side by configuring an iterator.
// should not show anything with column-family = 'a'
String tableName3 = namespace + ".table3";
c.tableOperations().create(tableName3);
-
+
IteratorSetting setting = new IteratorSetting(250, "thing", SimpleFilter.class.getName());
c.tableNamespaceOperations().attachIterator(namespace, setting);
-
+
BatchWriter bw = c.createBatchWriter(tableName3, new BatchWriterConfig());
Mutation m = new Mutation("r");
m.put("a", "b", new Value("abcde".getBytes()));
bw.addMutation(m);
bw.flush();
bw.close();
-
+
Scanner s = c.createScanner(tableName3, Authorizations.EMPTY);
assertTrue(!s.iterator().hasNext());
}
-
+
/**
* This test renames and clones two separate table into different namespaces. different namespace.
*
@@ -222,25 +219,25 @@ public class TableNamespacesIT {
String tableName = "table";
String tableName1 = "renamed.table1";
String tableName2 = "cloned.table2";
-
+
Connector c = accumulo.getConnector("root", secret);
-
+
c.tableOperations().create(tableName);
c.tableNamespaceOperations().create(namespace1);
c.tableNamespaceOperations().create(namespace2);
-
+
c.tableOperations().rename(tableName, tableName1);
-
+
assertTrue(c.tableOperations().exists(tableName1));
assertTrue(!c.tableOperations().exists(tableName));
-
+
c.tableOperations().clone(tableName1, tableName2, false, null, null);
-
+
assertTrue(c.tableOperations().exists(tableName1));
assertTrue(c.tableOperations().exists(tableName2));
return;
}
-
+
/**
* This test renames a table namespace and ensures that its tables are still correct
*/
@@ -249,15 +246,15 @@ public class TableNamespacesIT {
String namespace1 = "n1";
String namespace2 = "n2";
String table = "t";
-
+
Connector c = accumulo.getConnector("root", secret);
Instance instance = c.getInstance();
-
+
c.tableNamespaceOperations().create(namespace1);
c.tableOperations().create(namespace1 + "." + table);
-
+
c.tableNamespaceOperations().rename(namespace1, namespace2);
-
+
assertTrue(!c.tableNamespaceOperations().exists(namespace1));
assertTrue(c.tableNamespaceOperations().exists(namespace2));
assertTrue(c.tableOperations().exists(namespace2 + "." + table));
@@ -266,7 +263,7 @@ public class TableNamespacesIT {
String tnamespace = TableNamespaces.getNamespaceName(instance, tnid);
assertTrue(namespace2.equals(tnamespace));
}
-
+
/**
* This test clones a table to a different namespace and ensures it's properties are correct
*/
@@ -276,110 +273,67 @@ public class TableNamespacesIT {
String n2 = "namespace2";
String t1 = n1 + ".table";
String t2 = n2 + ".table";
-
+
String propKey = Property.TABLE_FILE_MAX.getKey();
String propVal1 = "55";
String propVal2 = "66";
-
+
Connector c = accumulo.getConnector("root", secret);
-
+
c.tableNamespaceOperations().create(n1);
c.tableOperations().create(t1);
-
+
c.tableOperations().removeProperty(t1, Property.TABLE_FILE_MAX.getKey());
c.tableNamespaceOperations().setProperty(n1, propKey, propVal1);
-
+
assertTrue(checkTableHasProp(c, t1, propKey, propVal1));
-
+
c.tableNamespaceOperations().create(n2);
c.tableNamespaceOperations().setProperty(n2, propKey, propVal2);
c.tableOperations().clone(t1, t2, true, null, null);
c.tableOperations().removeProperty(t2, propKey);
-
+
assertTrue(checkTableHasProp(c, t2, propKey, propVal2));
-
+
c.tableNamespaceOperations().delete(n1, true);
c.tableNamespaceOperations().delete(n2, true);
}
-
- /**
- * This test clones namespaces. First checks to see that the properties were correctly copied over, then checks to see that the correct properties were set
- * when given that option and that table properties copy successfully.
- */
- @Test
- public void testCloneNamespace() throws Exception {
- String n1 = "nspace1";
- String n2 = "nspace2";
- String n3 = "nspace3";
- String t = ".table";
-
- String propKey1 = Property.TABLE_FILE_MAX.getKey();
- String propKey2 = Property.TABLE_SCAN_MAXMEM.getKey();
- String propVal1 = "55";
- String propVal2 = "66";
- String propVal3 = "77K";
-
- Connector c = accumulo.getConnector("root", secret);
- c.tableNamespaceOperations().create(n1);
- c.tableOperations().create(n1 + t);
-
- c.tableNamespaceOperations().setProperty(n1, propKey1, propVal1);
- c.tableOperations().setProperty(n1 + t, propKey1, propVal2);
- c.tableNamespaceOperations().setProperty(n1, propKey2, propVal3);
-
- c.tableNamespaceOperations().clone(n1, n2, false, null, null, false);
- assertTrue(c.tableNamespaceOperations().exists(n2));
- assertTrue(checkTableNamespaceHasProp(c, n2, propKey1, propVal1));
- assertTrue(checkTableHasProp(c, n2 + t, propKey1, propVal2));
- assertTrue(checkTableNamespaceHasProp(c, n2, propKey2, propVal3));
-
- Map<String,String> propsToSet = new HashMap<String,String>();
- propsToSet.put(propKey1, propVal1);
- Set<String> propsToExclude = new HashSet<String>();
- propsToExclude.add(propKey2);
- c.tableNamespaceOperations().clone(n1, n3, true, propsToSet, propsToExclude, true);
-
- assertTrue(checkTableNamespaceHasProp(c, n3, propKey1, propVal1));
- assertTrue(checkTableHasProp(c, n3 + t, propKey1, propVal2));
- assertTrue(!checkTableNamespaceHasProp(c, n3, propKey2, propVal3));
- assertTrue(!checkTableHasProp(c, n3 + t, propKey2, propVal3));
- }
-
+
/**
* This tests adding iterators to a namespace, listing them, and removing them as well as adding and removing constraints
*/
@Test
public void testNamespaceIteratorsAndConstraints() throws Exception {
Connector c = accumulo.getConnector("root", secret);
-
+
String namespace = "iterator";
String tableName = namespace + ".table";
String iter = "thing";
-
+
c.tableNamespaceOperations().create(namespace);
c.tableOperations().create(tableName);
-
+
IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
HashSet<IteratorScope> scope = new HashSet<IteratorScope>();
scope.add(IteratorScope.scan);
c.tableNamespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
-
+
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m = new Mutation("r");
m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
bw.addMutation(m);
bw.flush();
-
+
Scanner s = c.createScanner(tableName, Authorizations.EMPTY);
assertTrue(!s.iterator().hasNext());
-
+
assertTrue(c.tableNamespaceOperations().listIterators(namespace).containsKey(iter));
c.tableNamespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
-
+
c.tableNamespaceOperations().addConstraint(namespace, NumericValueConstraint.class.getName());
// doesn't take effect immediately, needs time to propagate
UtilWaitThread.sleep(250);
-
+
m = new Mutation("rowy");
m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
try {
@@ -393,26 +347,26 @@ public class TableNamespacesIT {
int num = c.tableNamespaceOperations().listConstraints(namespace).get(NumericValueConstraint.class.getName());
c.tableNamespaceOperations().removeConstraint(namespace, num);
}
-
+
/**
* Tests that when a table moves to a new namespace that it's properties inherit from the new namespace and not the old one
*/
@Test
public void testRenameToNewNamespaceProperties() throws Exception {
Connector c = accumulo.getConnector("root", secret);
-
+
String namespace1 = "moveToNewNamespace1";
String namespace2 = "moveToNewNamespace2";
String tableName1 = namespace1 + ".table";
String tableName2 = namespace2 + ".table";
-
+
String propKey = Property.TABLE_FILE_MAX.getKey();
String propVal = "42";
-
+
c.tableNamespaceOperations().create(namespace1);
c.tableNamespaceOperations().create(namespace2);
c.tableOperations().create(tableName1);
-
+
c.tableNamespaceOperations().setProperty(namespace1, propKey, propVal);
boolean hasProp = false;
for (Entry<String,String> p : c.tableOperations().getProperties(tableName1)) {
@@ -421,9 +375,9 @@ public class TableNamespacesIT {
}
}
assertTrue(hasProp);
-
+
c.tableOperations().rename(tableName1, tableName2);
-
+
hasProp = false;
for (Entry<String,String> p : c.tableOperations().getProperties(tableName2)) {
if (p.getKey().equals(propKey) && p.getValue().equals(propVal)) {
@@ -432,7 +386,7 @@ public class TableNamespacesIT {
}
assertTrue(!hasProp);
}
-
+
/**
* Tests new Namespace permissions as well as modifications to Table permissions because of namespaces. Checks each permission to first make sure the user
* doesn't have permission to perform the action, then root grants them the permission and we check to make sure they could perform the action.
@@ -440,51 +394,51 @@ public class TableNamespacesIT {
@Test
public void testPermissions() throws Exception {
Connector c = accumulo.getConnector("root", secret);
-
+
PasswordToken pass = new PasswordToken(secret);
-
+
String n1 = "spaceOfTheName";
-
+
String user1 = "dude";
-
+
c.tableNamespaceOperations().create(n1);
c.tableOperations().create(n1 + ".table1");
-
+
c.securityOperations().createLocalUser(user1, pass);
-
+
Connector user1Con = accumulo.getConnector(user1, secret);
-
+
try {
user1Con.tableOperations().create(n1 + ".table2");
fail();
} catch (AccumuloSecurityException e) {
// supposed to happen
}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.CREATE_TABLE);
user1Con.tableOperations().create(n1 + ".table2");
assertTrue(c.tableOperations().list().contains(n1 + ".table2"));
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.CREATE_TABLE);
-
+
try {
user1Con.tableOperations().delete(n1 + ".table1");
fail();
} catch (AccumuloSecurityException e) {
// should happen
}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.DROP_TABLE);
user1Con.tableOperations().delete(n1 + ".table1");
assertTrue(!c.tableOperations().list().contains(n1 + ".table1"));
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.DROP_TABLE);
-
+
c.tableOperations().create(n1 + ".t");
BatchWriter bw = c.createBatchWriter(n1 + ".t", null);
Mutation m = new Mutation("row");
m.put("cf", "cq", "value");
bw.addMutation(m);
bw.close();
-
+
Iterator<Entry<Key,Value>> i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
try {
i.next();
@@ -492,7 +446,7 @@ public class TableNamespacesIT {
} catch (RuntimeException e) {
// yup
}
-
+
m = new Mutation("user1");
m.put("cf", "cq", "turtles");
bw = user1Con.createBatchWriter(n1 + ".t", null);
@@ -503,12 +457,12 @@ public class TableNamespacesIT {
} catch (MutationsRejectedException e) {
// good
}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.READ);
i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
assertTrue(i.hasNext());
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.READ);
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.WRITE);
m = new Mutation("user1");
m.put("cf", "cq", "turtles");
@@ -516,91 +470,91 @@ public class TableNamespacesIT {
bw.addMutation(m);
bw.close();
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.WRITE);
-
+
try {
user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_TABLE);
user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
user1Con.tableOperations().removeProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey());
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_TABLE);
-
+
try {
user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "55");
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_NAMESPACE);
user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "42");
user1Con.tableNamespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_NAMESPACE);
-
+
String user2 = "guy";
c.securityOperations().createLocalUser(user2, pass);
try {
user1Con.securityOperations().grantTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.GRANT);
user1Con.securityOperations().grantTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
user1Con.securityOperations().revokeTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.GRANT);
-
+
String n2 = "namespace2";
try {
user1Con.tableNamespaceOperations().create(n2);
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
user1Con.tableNamespaceOperations().create(n2);
c.securityOperations().revokeSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
-
+
try {
user1Con.tableNamespaceOperations().delete(n2);
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
user1Con.tableNamespaceOperations().delete(n2);
c.securityOperations().revokeSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
-
+
try {
user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
fail();
} catch (AccumuloSecurityException e) {}
-
+
c.securityOperations().grantSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
user1Con.tableNamespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
c.securityOperations().revokeSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
}
-
+
/**
* This test makes sure that system-level iterators and constraints are ignored by the system namespace so that the metadata and root tables aren't affected
*/
@Test
public void excludeSystemIterConst() throws Exception {
Connector c = accumulo.getConnector("root", secret);
-
+
c.instanceOperations().setProperty("table.iterator.scan.sum", "20," + SimpleFilter.class.getName());
assertTrue(c.instanceOperations().getSystemConfiguration().containsValue("20," + SimpleFilter.class.getName()));
-
+
assertTrue(checkTableNamespaceHasProp(c, Constants.DEFAULT_TABLE_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
assertTrue(!checkTableNamespaceHasProp(c, Constants.SYSTEM_TABLE_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
c.instanceOperations().removeProperty("table.iterator.scan.sum");
-
+
c.instanceOperations().setProperty("table.constraint.42", NumericValueConstraint.class.getName());
assertTrue(c.instanceOperations().getSystemConfiguration().containsValue(NumericValueConstraint.class.getName()));
-
+
assertTrue(checkTableNamespaceHasProp(c, Constants.DEFAULT_TABLE_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
assertTrue(!checkTableNamespaceHasProp(c, Constants.SYSTEM_TABLE_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
c.instanceOperations().removeProperty("table.constraint.42");
}
-
+
private boolean checkTableHasProp(Connector c, String t, String propKey, String propVal) throws AccumuloException, TableNotFoundException {
for (Entry<String,String> e : c.tableOperations().getProperties(t)) {
if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
@@ -609,7 +563,7 @@ public class TableNamespacesIT {
}
return false;
}
-
+
private boolean checkTableNamespaceHasProp(Connector c, String n, String propKey, String propVal) throws AccumuloException, TableNamespaceNotFoundException {
for (Entry<String,String> e : c.tableNamespaceOperations().getProperties(n)) {
if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
@@ -618,8 +572,9 @@ public class TableNamespacesIT {
}
return false;
}
-
+
public static class SimpleFilter extends Filter {
+ @Override
public boolean accept(Key k, Value v) {
if (k.getColumnFamily().toString().equals("a"))
return false;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/71bed4df/test/system/randomwalk/conf/modules/Concurrent.xml
----------------------------------------------------------------------
diff --git a/test/system/randomwalk/conf/modules/Concurrent.xml b/test/system/randomwalk/conf/modules/Concurrent.xml
index cb057c2..3768878 100644
--- a/test/system/randomwalk/conf/modules/Concurrent.xml
+++ b/test/system/randomwalk/conf/modules/Concurrent.xml
@@ -52,7 +52,6 @@
<edge id="ct.CreateTableNamespace" weight="1000"/>
<edge id="ct.DeleteTableNamespace" weight="100"/>
<edge id="ct.RenameTableNamespace" weight="100"/>
- <edge id="ct.CloneTableNamespace" weight="100"/>
<edge id="ct.OfflineTableNamespace" weight="100"/>
<edge id="ct.Apocalypse" weight="10"/>
<edge id="END" weight="1"/>
@@ -180,10 +179,6 @@
<edge id="ct.StartAll" weight="1"/>
</node>
-<node id="ct.CloneTableNamespace">
- <edge id="ct.StartAll" weight="1"/>
-</node>
-
<node id="ct.OfflineTableNamespace">
<edge id="ct.StartAll" weight="1"/>
</node>