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/08/22 22:07:10 UTC
[1/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Repository: accumulo
Updated Branches:
refs/heads/master 5ead817bc -> 4f2e64728
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/test/resources/shelltest.txt
----------------------------------------------------------------------
diff --git a/shell/src/test/resources/shelltest.txt b/shell/src/test/resources/shelltest.txt
new file mode 100644
index 0000000..d2eb955
--- /dev/null
+++ b/shell/src/test/resources/shelltest.txt
@@ -0,0 +1,16 @@
+# 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.
+exit
+foo
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/BulkImportDirectory.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/BulkImportDirectory.java b/test/src/main/java/org/apache/accumulo/test/BulkImportDirectory.java
index 1022f6a..4cbba8e 100644
--- a/test/src/main/java/org/apache/accumulo/test/BulkImportDirectory.java
+++ b/test/src/main/java/org/apache/accumulo/test/BulkImportDirectory.java
@@ -16,6 +16,8 @@
*/
package org.apache.accumulo.test;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -23,8 +25,10 @@ import java.util.List;
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.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.util.CachedConfiguration;
import org.apache.accumulo.server.cli.ClientOnRequiredTable;
+import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -43,9 +47,22 @@ public class BulkImportDirectory {
public static void main(String[] args) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
final FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
Opts opts = new Opts();
- opts.parseArgs(BulkImportDirectory.class.getName(), args);
- fs.delete(new Path(opts.failures), true);
- fs.mkdirs(new Path(opts.failures));
- opts.getConnector().tableOperations().importDirectory(opts.getTableName(), opts.source, opts.failures, false);
+ if (args.length == 5) {
+ System.err.println("Deprecated syntax for BulkImportDirectory, please use the new style (see --help)");
+ final String user = args[0];
+ final byte[] pass = args[1].getBytes(UTF_8);
+ final String tableName = args[2];
+ final String dir = args[3];
+ final String failureDir = args[4];
+ final Path failureDirPath = new Path(failureDir);
+ fs.delete(failureDirPath, true);
+ fs.mkdirs(failureDirPath);
+ HdfsZooInstance.getInstance().getConnector(user, new PasswordToken(pass)).tableOperations().importDirectory(tableName, dir, failureDir, false);
+ } else {
+ opts.parseArgs(BulkImportDirectory.class.getName(), args);
+ fs.delete(new Path(opts.failures), true);
+ fs.mkdirs(new Path(opts.failures));
+ opts.getConnector().tableOperations().importDirectory(opts.getTableName(), opts.source, opts.failures, false);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/CreateTableWithNewTableConfigIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/CreateTableWithNewTableConfigIT.java b/test/src/main/java/org/apache/accumulo/test/CreateTableWithNewTableConfigIT.java
index eefa604..7fd2dd1 100644
--- a/test/src/main/java/org/apache/accumulo/test/CreateTableWithNewTableConfigIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/CreateTableWithNewTableConfigIT.java
@@ -102,6 +102,7 @@ public class CreateTableWithNewTableConfigIT extends SharedMiniClusterBase {
return false;
}
+ @SuppressWarnings("deprecation")
@Test
public void tableNameOnly() throws Exception {
log.info("Starting tableNameOnly");
@@ -112,7 +113,7 @@ public class CreateTableWithNewTableConfigIT extends SharedMiniClusterBase {
connector.tableOperations().create(tableName, new NewTableConfiguration());
String tableNameOrig = "original";
- connector.tableOperations().create(tableNameOrig);
+ connector.tableOperations().create(tableNameOrig, true);
int countNew = numProperties(connector, tableName);
int countOrig = compareProperties(connector, tableNameOrig, tableName, null);
@@ -121,6 +122,50 @@ public class CreateTableWithNewTableConfigIT extends SharedMiniClusterBase {
Assert.assertTrue("Wrong TimeType", checkTimeType(connector, tableName, TimeType.MILLIS));
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void tableNameAndLimitVersion() throws Exception {
+ log.info("Starting tableNameAndLimitVersion");
+
+ // Create a table with the initial properties
+ Connector connector = getConnector();
+ String tableName = getUniqueNames(2)[0];
+ boolean limitVersion = false;
+ connector.tableOperations().create(tableName, new NewTableConfiguration().withoutDefaultIterators());
+
+ String tableNameOrig = "originalWithLimitVersion";
+ connector.tableOperations().create(tableNameOrig, limitVersion);
+
+ int countNew = numProperties(connector, tableName);
+ int countOrig = compareProperties(connector, tableNameOrig, tableName, null);
+
+ Assert.assertEquals("Extra properties using the new create method", countOrig, countNew);
+ Assert.assertTrue("Wrong TimeType", checkTimeType(connector, tableName, TimeType.MILLIS));
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void tableNameLimitVersionAndTimeType() throws Exception {
+ log.info("Starting tableNameLimitVersionAndTimeType");
+
+ // Create a table with the initial properties
+ Connector connector = getConnector();
+ String tableName = getUniqueNames(2)[0];
+ boolean limitVersion = false;
+ TimeType tt = TimeType.LOGICAL;
+ connector.tableOperations().create(tableName, new NewTableConfiguration().withoutDefaultIterators().setTimeType(tt));
+
+ String tableNameOrig = "originalWithLimitVersionAndTimeType";
+ connector.tableOperations().create(tableNameOrig, limitVersion, tt);
+
+ int countNew = numProperties(connector, tableName);
+ int countOrig = compareProperties(connector, tableNameOrig, tableName, null);
+
+ Assert.assertEquals("Extra properties using the new create method", countOrig, countNew);
+ Assert.assertTrue("Wrong TimeType", checkTimeType(connector, tableName, tt));
+ }
+
+ @SuppressWarnings("deprecation")
@Test
public void addCustomPropAndChangeExisting() throws Exception {
log.info("Starting addCustomPropAndChangeExisting");
@@ -141,7 +186,7 @@ public class CreateTableWithNewTableConfigIT extends SharedMiniClusterBase {
connector.tableOperations().create(tableName, new NewTableConfiguration().setProperties(properties));
String tableNameOrig = "originalWithTableName";
- connector.tableOperations().create(tableNameOrig);
+ connector.tableOperations().create(tableNameOrig, true);
int countNew = numProperties(connector, tableName);
int countOrig = compareProperties(connector, tableNameOrig, tableName, propertyName);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
index d6cfa79..78ad958 100644
--- a/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/ShellServerIT.java
@@ -40,7 +40,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Stream;
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.ClientConfiguration;
@@ -153,7 +152,7 @@ public class ShellServerIT extends SharedMiniClusterBase {
public StringInputStream input;
public Shell shell;
- TestShell(String user, String rootPass, String instanceName, String zookeepers, File configFile, String... extraArgs) throws IOException {
+ TestShell(String user, String rootPass, String instanceName, String zookeepers, File configFile) throws IOException {
ClientConfiguration clientConf;
try {
clientConf = new ClientConfiguration(configFile);
@@ -165,14 +164,12 @@ public class ShellServerIT extends SharedMiniClusterBase {
input = new StringInputStream();
shell = new Shell(new ConsoleReader(input, output));
shell.setLogErrorsToConsole();
- String[] shellArgs = null;
if (clientConf.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
// Pull the kerberos principal out when we're using SASL
- shellArgs = new String[] {"-u", user, "-z", instanceName, zookeepers, "--config-file", configFile.getAbsolutePath()};
+ shell.config("-u", user, "-z", instanceName, zookeepers, "--config-file", configFile.getAbsolutePath());
} else {
- shellArgs = new String[] {"-u", user, "-p", rootPass, "-z", instanceName, zookeepers, "--config-file", configFile.getAbsolutePath()};
+ shell.config("-u", user, "-p", rootPass, "-z", instanceName, zookeepers, "--config-file", configFile.getAbsolutePath());
}
- shell.config(Stream.concat(Arrays.stream(shellArgs), Arrays.stream(extraArgs)).toArray(String[]::new));
exec("quit", true);
shell.start();
shell.setExit(false);
@@ -233,10 +230,6 @@ public class ShellServerIT extends SharedMiniClusterBase {
assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
}
- void assertBadExit(String s, boolean stringPresent) {
- assertBadExit(s, stringPresent, noop);
- }
-
void assertBadExit(String s, boolean stringPresent, ErrorMessageCallback callback) {
shellLog.debug(output.get());
if (0 == shell.getExitCode()) {
@@ -248,19 +241,6 @@ public class ShellServerIT extends SharedMiniClusterBase {
assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
shell.resetExitCode();
}
-
- void execExpectList(String cmd, boolean expecteGoodExit, List<String> expectedStrings) throws IOException {
- exec(cmd);
- if (expecteGoodExit) {
- assertGoodExit("", true);
- } else {
- assertBadExit("", true);
- }
-
- for (String expectedString : expectedStrings) {
- assertTrue(expectedString + " was not present in " + output.get(), output.get().contains(expectedString));
- }
- }
}
private static final NoOpErrorMessageCallback noop = new NoOpErrorMessageCallback();
@@ -414,6 +394,24 @@ public class ShellServerIT extends SharedMiniClusterBase {
}
@Test
+ public void setscaniterDeletescaniter() throws Exception {
+ final String table = name.getMethodName();
+
+ // setscaniter, deletescaniter
+ ts.exec("createtable " + table);
+ ts.exec("insert a cf cq 1");
+ ts.exec("insert a cf cq 1");
+ ts.exec("insert a cf cq 1");
+ ts.input.set("true\n\n\n\nSTRING");
+ ts.exec("setscaniter -class org.apache.accumulo.core.iterators.user.SummingCombiner -p 10 -n name", true);
+ ts.exec("scan", true, "3", true);
+ ts.exec("deletescaniter -n name", true);
+ ts.exec("scan", true, "1", true);
+ ts.exec("deletetable -f " + table);
+
+ }
+
+ @Test
public void execfile() throws Exception {
// execfile
File file = File.createTempFile("ShellServerIT.execfile", ".conf", new File(rootPath));
@@ -1307,7 +1305,7 @@ public class ShellServerIT extends SharedMiniClusterBase {
public void help() throws Exception {
ts.exec("help -np", true, "Help Commands", true);
ts.exec("?", true, "Help Commands", true);
- for (String c : ("bye exit quit " + "about help info ? " + "deleteiter listiter setiter "
+ for (String c : ("bye exit quit " + "about help info ? " + "deleteiter deletescaniter listiter setiter setscaniter "
+ "grant revoke systempermissions tablepermissions userpermissions " + "execfile history " + "authenticate cls clear notable sleep table user whoami "
+ "clonetable config createtable deletetable droptable du exporttable importtable offline online renametable tables "
+ "addsplits compact constraint flush getgropus getsplits merge setgroups " + "addauths createuser deleteuser dropuser getauths passwd setauths users "
@@ -1846,204 +1844,6 @@ public class ShellServerIT extends SharedMiniClusterBase {
}
}
- @Test
- public void aboutTest() throws IOException {
- ts.exec("about", true, "Shell - Apache Accumulo Interactive Shell");
- ts.exec("about -v", true, "Current user:");
- ts.exec("about arg", false, "java.lang.IllegalArgumentException: Expected 0 arguments");
- }
-
- @Test
- public void addGetSplitsTest() throws IOException {
- ts.exec("addsplits arg", false, "java.lang.IllegalStateException: Not in a table context");
- ts.exec("createtable test", true);
- ts.exec("addsplits 1 \\x80", true);
- ts.exec("getsplits", true, "1\n\\x80");
- ts.exec("getsplits -m 1", true, "1");
- ts.exec("getsplits -b64", true, "MQ==\ngA==");
- ts.exec("deletetable test -f", true, "Table: [test] has been deleted");
- }
-
- @Test
- public void insertDeleteScanTest() throws IOException {
- ts.exec("insert r f q v", false, "java.lang.IllegalStateException: Not in a table context");
- ts.exec("delete r f q", false, "java.lang.IllegalStateException: Not in a table context");
- ts.exec("createtable test", true);
- ts.exec("insert r f q v", true);
- ts.exec("scan", true, "r f:q [] v");
- ts.exec("delete r f q", true);
- ts.exec("scan", true, "r f:q [] v", false);
- ts.exec("insert \\x90 \\xa0 \\xb0 \\xc0\\xd0\\xe0\\xf0", true);
- ts.exec("scan", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0");
- ts.exec("scan -f 2", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0");
- ts.exec("scan -f 2", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0\\xE0", false);
- ts.exec("scan -b \\x90 -e \\x90 -c \\xA0", true, "\\x90 \\xA0:\\xB0 [] \\xC0");
- ts.exec("scan -b \\x90 -e \\x90 -c \\xA0:\\xB0", true, "\\x90 \\xA0:\\xB0 [] \\xC0");
- ts.exec("scan -b \\x90 -be", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
- ts.exec("scan -e \\x90 -ee", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
- ts.exec("scan -b \\x90\\x00", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
- ts.exec("scan -e \\x8f", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
- ts.exec("delete \\x90 \\xa0 \\xb0", true);
- ts.exec("scan", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
- ts.exec("deletetable test -f", true, "Table: [test] has been deleted");
- }
-
- @Test
- public void deleteManyTest() throws IOException {
- ts.exec("deletemany", false, "java.lang.IllegalStateException: Not in a table context");
- ts.exec("createtable test", true);
- ts.exec("deletemany", true, "\n");
-
- ts.exec("insert 0 0 0 0 -ts 0");
- ts.exec("insert 0 0 0 0 -l 0 -ts 0");
- ts.exec("insert 1 1 1 1 -ts 1");
- ts.exec("insert 2 2 2 2 -ts 2");
-
- // prompts for delete, and rejects by default
- ts.exec("deletemany", true, "[SKIPPED] 0 0:0 []");
- ts.exec("deletemany -r 0", true, "[SKIPPED] 0 0:0 []");
- ts.exec("deletemany -r 0 -f", true, "[DELETED] 0 0:0 []");
-
- // with auths, can delete the other record
- ts.exec("setauths -s 0");
- ts.exec("deletemany -r 0 -f", true, "[DELETED] 0 0:0 [0]");
-
- // delete will show the timestamp
- ts.exec("deletemany -r 1 -f -st", true, "[DELETED] 1 1:1 [] 1");
-
- // DeleteManyCommand has its own Formatter (DeleterFormatter), so it does not honor the -fm flag
- ts.exec("deletemany -r 2 -f -st -fm org.apache.accumulo.core.util.format.DateStringFormatter", true, "[DELETED] 2 2:2 [] 2");
-
- ts.exec("setauths -c ", true);
- ts.exec("deletetable test -f", true, "Table: [test] has been deleted");
- }
-
- @Test
- public void authsTest() throws Exception {
- ts.exec("setauths x,y,z", false, "Missing required option");
- ts.exec("setauths -s x,y,z -u notauser", false, "user does not exist");
- ts.exec("setauths -s y,z,x", true);
- ts.exec("getauths -u notauser", false, "user does not exist");
- ts.execExpectList("getauths", true, Arrays.asList("x", "y", "z"));
- ts.exec("addauths -u notauser", false, "Missing required option");
- ts.exec("addauths -u notauser -s foo", false, "user does not exist");
- ts.exec("addauths -s a", true);
- ts.execExpectList("getauths", true, Arrays.asList("x", "y", "z", "a"));
- ts.exec("setauths -c", true);
- }
-
- @Test
- public void duContextTest() throws Exception {
- ts.exec("createtable t", true);
- ts.exec("du", true, "0 [t]");
- ts.exec("deletetable t -f", true, "Table: [t] has been deleted");
- }
-
- @Test
- public void duTest() throws IOException {
- ts.exec("createtable t", true);
- ts.exec("du t", true, "0 [t]");
- ts.exec("deletetable t -f", true, "Table: [t] has been deleted");
- }
-
- @Test
- public void duPatternTest() throws IOException {
- ts.exec("createnamespace n", true);
- ts.exec("createtable n.t", true);
- ts.exec("createtable n.tt", true);
- ts.exec("du -p n[.]t.*", true, "0 [n.t, n.tt]");
- ts.exec("deletetable n.t -f", true, "Table: [n.t] has been deleted");
- ts.exec("deletetable n.tt -f", true, "Table: [n.tt] has been deleted");
- ts.exec("deletenamespace -f n", true);
- }
-
- @Test
- public void scanTimestampTest() throws IOException {
- ts.exec("createtable test", true);
- ts.exec("insert r f q v -ts 0", true);
- ts.exec("scan -st", true, "r f:q [] 0 v");
- ts.exec("scan -st -f 0", true, " : [] 0 ");
- ts.exec("deletemany -f", true);
- ts.exec("deletetable test -f", true, "Table: [test] has been deleted");
- }
-
- @Test
- public void scanFewTest() throws IOException {
- ts.exec("createtable test", true);
- // historically, showing few did not pertain to ColVis or Timestamp
- ts.exec("insert 1 123 123456 -l '12345678' -ts 123456789 1234567890", true);
- ts.exec("setauths -s 12345678", true);
- String expected = "1 123:123456 [12345678] 123456789 1234567890";
- String expectedFew = "1 123:12345 [12345678] 123456789 12345";
- ts.exec("scan -st", true, expected);
- ts.exec("scan -st -f 5", true, expectedFew);
- // also prove that BinaryFormatter behaves same as the default
- ts.exec("scan -st -fm org.apache.accumulo.core.util.format.BinaryFormatter", true, expected);
- ts.exec("scan -st -f 5 -fm org.apache.accumulo.core.util.format.BinaryFormatter", true, expectedFew);
- ts.exec("setauths -c", true);
- ts.exec("deletetable test -f", true, "Table: [test] has been deleted");
- }
-
- @Test
- public void grepTest() throws IOException {
- ts.exec("grep", false, "java.lang.IllegalStateException: Not in a table context");
- ts.exec("createtable t", true);
- ts.exec("setauths -s vis", true);
- ts.exec("insert r f q v -ts 0 -l vis", true);
-
- String expected = "r f:q [vis] v";
- String expectedTimestamp = "r f:q [vis] 0 v";
- ts.exec("grep", false, "No terms specified");
- ts.exec("grep non_matching_string", true, "");
- // historically, showing few did not pertain to ColVis or Timestamp
- ts.exec("grep r", true, expected);
- ts.exec("grep r -f 1", true, expected);
- ts.exec("grep r -st", true, expectedTimestamp);
- ts.exec("grep r -st -f 1", true, expectedTimestamp);
- ts.exec("setauths -c", true);
- ts.exec("deletetable t -f", true, "Table: [t] has been deleted");
- }
-
- @Test
- public void commentTest() throws IOException {
- ts.exec("#", true, "Unknown command", false);
- ts.exec("# foo", true, "Unknown command", false);
- ts.exec("- foo", true, "Unknown command", true);
- }
-
- @Test
- public void execFileTest() throws IOException {
- TestShell configTestShell = new TestShell(getPrincipal(), getRootPassword(), getCluster().getConfig().getInstanceName(), getCluster().getConfig()
- .getZooKeepers(), getCluster().getConfig().getClientConfFile(), "-f", "src/test/resources/shelltest.txt");
- configTestShell.assertGoodExit("Unknown command", false);
- }
-
- @Test
- public void setIterTest() throws IOException {
- ts.exec("createtable t", true);
-
- String cmdJustClass = "setiter -class VersioningIterator -p 1";
- ts.exec(cmdJustClass, false, "java.lang.IllegalArgumentException", false);
- ts.exec(cmdJustClass, false, "fully qualified package name", true);
-
- String cmdFullPackage = "setiter -class o.a.a.foo -p 1";
- ts.exec(cmdFullPackage, false, "java.lang.IllegalArgumentException", false);
- ts.exec(cmdFullPackage, false, "class not found", true);
-
- String cmdNoOption = "setiter -class java.lang.String -p 1";
- ts.exec(cmdNoOption, false, "loaded successfully but does not implement SortedKeyValueIterator", true);
-
- ts.input.set("\n\n");
- ts.exec("setiter -scan -class org.apache.accumulo.core.iterators.ColumnFamilyCounter -p 30 -name foo", true);
-
- ts.input.set("bar\nname value\n");
- ts.exec("setiter -scan -class org.apache.accumulo.core.iterators.ColumnFamilyCounter -p 31", true);
-
- // TODO can't verify this as config -t fails, functionality verified in ShellServerIT
-
- ts.exec("deletetable t -f", true, "Table: [t] has been deleted");
- }
-
private void make10() throws IOException {
for (int i = 0; i < 10; i++) {
ts.exec(String.format("insert row%d cf col%d value", i, i));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/VolumeIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/VolumeIT.java b/test/src/main/java/org/apache/accumulo/test/VolumeIT.java
index 553cb14..f9a6a326 100644
--- a/test/src/main/java/org/apache/accumulo/test/VolumeIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/VolumeIT.java
@@ -82,11 +82,6 @@ import org.junit.Test;
public class VolumeIT extends ConfigurableMacBase {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
-
private static final Text EMPTY = new Text();
private static final Value EMPTY_VALUE = new Value(new byte[] {});
private File volDirBase;
@@ -97,6 +92,7 @@ public class VolumeIT extends ConfigurableMacBase {
return 5 * 60;
}
+ @SuppressWarnings("deprecation")
@Override
public void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {
File baseDir = cfg.getDir();
@@ -108,8 +104,8 @@ public class VolumeIT extends ConfigurableMacBase {
// Run MAC on two locations in the local file system
URI v1Uri = v1.toUri();
- cfg.setProperty(INSTANCE_DFS_DIR, v1Uri.getPath());
- cfg.setProperty(INSTANCE_DFS_URI, v1Uri.getScheme() + v1Uri.getHost());
+ cfg.setProperty(Property.INSTANCE_DFS_DIR, v1Uri.getPath());
+ cfg.setProperty(Property.INSTANCE_DFS_URI, v1Uri.getScheme() + v1Uri.getHost());
cfg.setProperty(Property.INSTANCE_VOLUMES, v1.toString() + "," + v2.toString());
cfg.setProperty(Property.INSTANCE_ZK_TIMEOUT, "15s");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/functional/WALSunnyDayIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/functional/WALSunnyDayIT.java b/test/src/main/java/org/apache/accumulo/test/functional/WALSunnyDayIT.java
index 0831812..2f5ee81 100644
--- a/test/src/main/java/org/apache/accumulo/test/functional/WALSunnyDayIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/functional/WALSunnyDayIT.java
@@ -238,7 +238,7 @@ public class WALSunnyDayIT extends ConfigurableMacBase {
}
fail("Unable to get the correct number of WALs, expected " + expectedCount + " but got " + wals.toString());
- return new HashMap<String,Boolean>();
+ return new HashMap<>();
}
private int getWaitFactor() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/main/java/org/apache/accumulo/test/server/security/SystemCredentialsIT.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/server/security/SystemCredentialsIT.java b/test/src/main/java/org/apache/accumulo/test/server/security/SystemCredentialsIT.java
index 150eee4..9752916 100644
--- a/test/src/main/java/org/apache/accumulo/test/server/security/SystemCredentialsIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/server/security/SystemCredentialsIT.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.test.server.security;
import static org.junit.Assert.assertEquals;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map.Entry;
@@ -31,6 +32,7 @@ import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.metadata.RootTable;
@@ -63,6 +65,12 @@ public class SystemCredentialsIT extends ConfigurableMacBase {
if (args[0].equals("bad")) {
Instance inst = new Instance() {
+ @Deprecated
+ @Override
+ public void setConfiguration(AccumuloConfiguration conf) {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public int getZooKeepersSessionTimeOut() {
throw new UnsupportedOperationException();
@@ -98,6 +106,30 @@ public class SystemCredentialsIT extends ConfigurableMacBase {
throw new UnsupportedOperationException();
}
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
};
creds = SystemCredentials.get(inst);
} else if (args[0].equals("good")) {
@@ -140,6 +172,36 @@ public class SystemCredentialsIT extends ConfigurableMacBase {
throw new UnsupportedOperationException();
}
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public void setConfiguration(AccumuloConfiguration conf) {
+ throw new UnsupportedOperationException();
+ }
+
};
creds = new SystemCredentials(inst, "!SYSTEM", new PasswordToken("fake"));
} else {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/test/src/test/resources/shelltest.txt
----------------------------------------------------------------------
diff --git a/test/src/test/resources/shelltest.txt b/test/src/test/resources/shelltest.txt
deleted file mode 100644
index d2eb955..0000000
--- a/test/src/test/resources/shelltest.txt
+++ /dev/null
@@ -1,16 +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.
-exit
-foo
[8/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
Revert "ACCUMULO-2589 Drop deprecated code from 1.x"
Restore all of the aggressively removed deprecated code, except the
trace module, which is no longer needed.
This reverts commit b69291a3453fd0e6091586cf37fb1636a356caa9.
Conflicts:
minicluster/src/test/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImplTest.java
server/base/src/test/java/org/apache/accumulo/server/util/FileUtilTest.java
shell/src/main/java/org/apache/accumulo/shell/Shell.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/4f2e6472
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/4f2e6472
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/4f2e6472
Branch: refs/heads/master
Commit: 4f2e64728292af22d07b1907b6ec2d432f8564e2
Parents: 5ead817
Author: Christopher Tubbs <ct...@apache.org>
Authored: Mon Aug 22 18:04:34 2016 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Mon Aug 22 18:04:34 2016 -0400
----------------------------------------------------------------------
.../org/apache/accumulo/core/Constants.java | 8 +
.../apache/accumulo/core/cli/ClientOpts.java | 6 +
.../core/client/ClientConfiguration.java | 17 +-
.../core/client/ClientSideIteratorScanner.java | 33 ++
.../apache/accumulo/core/client/Connector.java | 67 +++
.../apache/accumulo/core/client/Instance.java | 75 +++
.../accumulo/core/client/IsolatedScanner.java | 18 +
.../core/client/MutationsRejectedException.java | 77 +++
.../apache/accumulo/core/client/Scanner.java | 19 +
.../accumulo/core/client/ZooKeeperInstance.java | 91 ++++
.../core/client/admin/ActiveCompaction.java | 7 +
.../accumulo/core/client/admin/ActiveScan.java | 7 +
.../core/client/admin/SecurityOperations.java | 79 +++
.../core/client/admin/TableOperations.java | 71 +++
.../core/client/impl/ActiveCompactionImpl.java | 9 +
.../core/client/impl/ActiveScanImpl.java | 7 +
.../core/client/impl/ConnectorImpl.java | 27 +
.../core/client/impl/OfflineScanner.java | 13 +
.../accumulo/core/client/impl/ScannerImpl.java | 20 +-
.../core/client/impl/ScannerIterator.java | 6 +-
.../client/impl/SecurityOperationsImpl.java | 31 ++
.../core/client/impl/TableOperationsImpl.java | 51 ++
.../core/client/impl/ThriftScanner.java | 2 +-
.../core/client/mapred/AbstractInputFormat.java | 95 +++-
.../client/mapred/AccumuloFileOutputFormat.java | 15 +
.../client/mapred/AccumuloOutputFormat.java | 56 ++
.../core/client/mapred/InputFormatBase.java | 69 +++
.../client/mapreduce/AbstractInputFormat.java | 119 ++++-
.../mapreduce/AccumuloFileOutputFormat.java | 16 +
.../client/mapreduce/AccumuloOutputFormat.java | 54 ++
.../core/client/mapreduce/InputFormatBase.java | 66 +++
.../core/client/mapreduce/RangeInputSplit.java | 62 ++-
.../core/client/mapreduce/impl/SplitUtils.java | 2 +
.../mapreduce/lib/impl/ConfiguratorBase.java | 28 +-
.../mapreduce/lib/impl/InputConfigurator.java | 69 +++
.../mapreduce/lib/util/ConfiguratorBase.java | 275 ++++++++++
.../lib/util/FileOutputConfigurator.java | 170 +++++++
.../mapreduce/lib/util/InputConfigurator.java | 461 +++++++++++++++++
.../mapreduce/lib/util/OutputConfigurator.java | 196 +++++++
.../client/mapreduce/lib/util/package-info.java | 22 +
.../core/client/mock/IteratorAdapter.java | 33 ++
.../accumulo/core/client/mock/MockAccumulo.java | 148 ++++++
.../core/client/mock/MockBatchDeleter.java | 76 +++
.../core/client/mock/MockBatchScanner.java | 79 +++
.../core/client/mock/MockBatchWriter.java | 59 +++
.../core/client/mock/MockConfiguration.java | 54 ++
.../core/client/mock/MockConnector.java | 162 ++++++
.../accumulo/core/client/mock/MockInstance.java | 163 ++++++
.../client/mock/MockInstanceOperations.java | 97 ++++
.../client/mock/MockMultiTableBatchWriter.java | 60 +++
.../core/client/mock/MockNamespace.java | 58 +++
.../client/mock/MockNamespaceOperations.java | 138 +++++
.../accumulo/core/client/mock/MockScanner.java | 127 +++++
.../core/client/mock/MockScannerBase.java | 159 ++++++
.../client/mock/MockSecurityOperations.java | 236 +++++++++
.../accumulo/core/client/mock/MockTable.java | 212 ++++++++
.../core/client/mock/MockTableOperations.java | 505 +++++++++++++++++++
.../accumulo/core/client/mock/MockUser.java | 41 ++
.../client/mock/impl/MockTabletLocator.java | 75 +++
.../accumulo/core/client/mock/package-info.java | 25 +
.../core/client/rfile/RFileScanner.java | 19 +
.../client/security/tokens/KerberosToken.java | 25 +-
.../org/apache/accumulo/core/conf/Property.java | 13 +
.../accumulo/core/constraints/Constraint.java | 10 +
.../accumulo/core/data/ComparableBytes.java | 58 +++
.../apache/accumulo/core/data/KeyExtent.java | 259 ++++++++++
.../apache/accumulo/core/data/PartialKey.java | 18 +
.../org/apache/accumulo/core/data/Value.java | 36 +-
.../accumulo/core/data/impl/KeyExtent.java | 73 +++
.../accumulo/core/data/impl/TabletIdImpl.java | 31 ++
.../core/iterators/AggregatingIterator.java | 215 ++++++++
.../iterators/FamilyIntersectingIterator.java | 29 ++
.../accumulo/core/iterators/GrepIterator.java | 27 +
.../core/iterators/IntersectingIterator.java | 27 +
.../accumulo/core/iterators/IteratorUtil.java | 11 +
.../accumulo/core/iterators/LargeRowFilter.java | 27 +
.../core/iterators/RowDeletingIterator.java | 27 +
.../core/iterators/VersioningIterator.java | 36 ++
.../core/iterators/WholeRowIterator.java | 27 +
.../core/iterators/aggregation/Aggregator.java | 31 ++
.../iterators/aggregation/LongSummation.java | 76 +++
.../aggregation/NumArraySummation.java | 96 ++++
.../iterators/aggregation/NumSummation.java | 91 ++++
.../core/iterators/aggregation/StringMax.java | 48 ++
.../core/iterators/aggregation/StringMin.java | 48 ++
.../iterators/aggregation/StringSummation.java | 45 ++
.../conf/AggregatorConfiguration.java | 34 ++
.../aggregation/conf/AggregatorSet.java | 41 ++
.../iterators/conf/PerColumnIteratorConfig.java | 81 +++
.../iterators/user/IntersectingIterator.java | 24 +
.../core/replication/ReplicationTable.java | 3 +-
.../core/security/VisibilityConstraint.java | 29 ++
.../CachingHDFSSecretKeyEncryptionStrategy.java | 7 +-
.../NonCachingSecretKeyEncryptionStrategy.java | 19 +-
.../accumulo/core/trace/DistributedTrace.java | 11 +
.../org/apache/accumulo/core/trace/Trace.java | 18 +
.../accumulo/core/util/DeprecationUtil.java | 61 +++
.../core/util/format/BinaryFormatter.java | 66 +++
.../core/util/format/DateStringFormatter.java | 75 +++
.../core/volume/VolumeConfiguration.java | 27 +-
.../accumulo/core/cli/TestClientOpts.java | 10 +-
.../client/impl/TableOperationsHelperTest.java | 27 +
.../core/client/impl/TabletLocatorImplTest.java | 34 +-
.../core/client/mapred/RangeInputSplitTest.java | 3 +
.../client/mapreduce/RangeInputSplitTest.java | 3 +
.../mapreduce/impl/BatchInputSplitTest.java | 3 +
.../lib/impl/ConfiguratorBaseTest.java | 14 +
.../core/client/mock/MockConnectorTest.java | 375 ++++++++++++++
.../core/client/mock/MockNamespacesTest.java | 297 +++++++++++
.../client/mock/MockTableOperationsTest.java | 345 +++++++++++++
.../core/client/mock/TestBatchScanner821.java | 77 +++
.../accumulo/core/data/KeyExtentTest.java | 58 +++
.../apache/accumulo/core/data/ValueTest.java | 26 +
.../core/iterators/AggregatingIteratorTest.java | 471 +++++++++++++++++
.../iterators/aggregation/NumSummationTest.java | 149 ++++++
.../conf/AggregatorConfigurationTest.java | 72 +++
.../core/iterators/user/FilterTest.java | 4 +-
.../accumulo/core/security/CredentialsTest.java | 21 +
.../util/format/DateStringFormatterTest.java | 80 +++
.../standalone/StandaloneAccumuloCluster.java | 4 +
.../impl/MiniAccumuloClusterImpl.java | 10 +-
pom.xml | 48 --
.../org/apache/accumulo/proxy/ProxyServer.java | 26 +-
.../accumulo/server/AccumuloServerContext.java | 5 +
.../server/cli/ClientOnDefaultTable.java | 3 +
.../server/cli/ClientOnRequiredTable.java | 3 +
.../apache/accumulo/server/cli/ClientOpts.java | 3 +
.../accumulo/server/client/HdfsZooInstance.java | 41 +-
.../server/security/UserImpersonation.java | 68 ++-
.../accumulo/server/init/InitializeTest.java | 24 +-
.../BaseHostRegexTableLoadBalancerTest.java | 29 ++
...redentialsUpdatingInvocationHandlerTest.java | 81 +++
.../server/security/UserImpersonationTest.java | 227 +++++++++
.../accumulo/server/util/TServerUtilsTest.java | 29 ++
.../java/org/apache/accumulo/master/Master.java | 6 +-
.../apache/accumulo/master/util/FateAdmin.java | 104 ++++
.../accumulo/monitor/servlets/ShellServlet.java | 13 +-
.../monitor/servlets/trace/NullScanner.java | 10 +
.../org/apache/accumulo/tracer/TracerTest.java | 3 +-
.../accumulo/tserver/TservConstraintEnv.java | 14 +
.../accumulo/tserver/log/LocalWALRecovery.java | 5 +-
.../tserver/log/SortedLogRecoveryTest.java | 3 +-
.../accumulo/tserver/tablet/RootFilesTest.java | 9 +-
.../java/org/apache/accumulo/shell/Shell.java | 47 +-
.../apache/accumulo/shell/ShellOptionsJC.java | 4 +
.../shell/commands/DeleteScanIterCommand.java | 103 ++++
.../accumulo/shell/commands/SetIterCommand.java | 27 +-
.../shell/commands/SetScanIterCommand.java | 113 +++++
.../apache/accumulo/shell/mock/MockShell.java | 159 ++++++
.../apache/accumulo/shell/ShellConfigTest.java | 28 +-
.../accumulo/shell/ShellSetInstanceTest.java | 35 +-
.../org/apache/accumulo/shell/ShellTest.java | 394 +++++++++++++++
shell/src/test/resources/shelltest.txt | 16 +
.../accumulo/test/BulkImportDirectory.java | 25 +-
.../test/CreateTableWithNewTableConfigIT.java | 49 +-
.../org/apache/accumulo/test/ShellServerIT.java | 244 +--------
.../java/org/apache/accumulo/test/VolumeIT.java | 10 +-
.../accumulo/test/functional/WALSunnyDayIT.java | 2 +-
.../server/security/SystemCredentialsIT.java | 62 +++
test/src/test/resources/shelltest.txt | 16 -
160 files changed, 10619 insertions(+), 474 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/Constants.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/Constants.java b/core/src/main/java/org/apache/accumulo/core/Constants.java
index 7098d7c..eebd81d 100644
--- a/core/src/main/java/org/apache/accumulo/core/Constants.java
+++ b/core/src/main/java/org/apache/accumulo/core/Constants.java
@@ -22,6 +22,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import org.apache.accumulo.core.security.Authorizations;
+
public class Constants {
public static final String VERSION = FilteredConstants.VERSION;
@@ -107,6 +109,12 @@ public class Constants {
// Security configuration
public static final String PW_HASH_ALGORITHM = "SHA-256";
+ /**
+ * @deprecated since 1.6.0; Use {@link Authorizations#EMPTY} instead
+ */
+ @Deprecated
+ public static final Authorizations NO_AUTHS = Authorizations.EMPTY;
+
public static final int MAX_DATA_TO_PRINT = 64;
public static final String CORE_PACKAGE_NAME = "org.apache.accumulo.core";
public static final String MAPFILE_EXTENSION = "map";
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java
index d78c1b5..a73da7b 100644
--- a/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java
+++ b/core/src/main/java/org/apache/accumulo/core/cli/ClientOpts.java
@@ -45,6 +45,7 @@ import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.accumulo.core.trace.Trace;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.volume.VolumeConfiguration;
import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.hadoop.conf.Configuration;
@@ -162,6 +163,9 @@ public class ClientOpts extends Help {
@Parameter(names = "--debug", description = "turn on TRACE-level log messages")
public boolean debug = false;
+ @Parameter(names = {"-fake", "--mock"}, description = "Use a mock Instance")
+ public boolean mock = false;
+
@Parameter(names = "--site-file", description = "Read the given accumulo site file to find the accumulo instance")
public String siteFile = null;
@@ -255,6 +259,8 @@ public class ClientOpts extends Help {
synchronized public Instance getInstance() {
if (cachedInstance != null)
return cachedInstance;
+ if (mock)
+ return cachedInstance = DeprecationUtil.makeMockInstance(instance);
return cachedInstance = new ZooKeeperInstance(this.getClientConfiguration());
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java b/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
index 09d6b42..1b9b380 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/ClientConfiguration.java
@@ -97,8 +97,11 @@ public class ClientConfiguration extends CompositeConfiguration {
private PropertyType type;
private String description;
+ private Property accumuloProperty = null;
+
private ClientProperty(Property prop) {
this(prop.getKey(), prop.getDefaultValue(), prop.getType(), prop.getDescription());
+ accumuloProperty = prop;
}
private ClientProperty(String key, String defaultValue, PropertyType type, String description) {
@@ -116,7 +119,11 @@ public class ClientConfiguration extends CompositeConfiguration {
return defaultValue;
}
- private PropertyType getType() {
+ /**
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and not guaranteed to be stable.
+ */
+ @Deprecated
+ public PropertyType getType() {
return type;
}
@@ -124,6 +131,14 @@ public class ClientConfiguration extends CompositeConfiguration {
return description;
}
+ /**
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and not guaranteed to be stable.
+ */
+ @Deprecated
+ public Property getAccumuloProperty() {
+ return accumuloProperty;
+ }
+
public static ClientProperty getPropertyByKey(String key) {
for (ClientProperty prop : ClientProperty.values())
if (prop.getKey().equals(key))
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java b/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
index 978d85a..d4622c6 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/ClientSideIteratorScanner.java
@@ -65,6 +65,21 @@ public class ClientSideIteratorScanner extends ScannerOptions implements Scanner
private long readaheadThreshold = Constants.SCANNER_DEFAULT_READAHEAD_THRESHOLD;
private SamplerConfiguration iteratorSamplerConfig;
+ /**
+ * @deprecated since 1.7.0 was never intended for public use. However this could have been used by anything extending this class.
+ */
+ @Deprecated
+ public class ScannerTranslator extends ScannerTranslatorImpl {
+ public ScannerTranslator(Scanner scanner) {
+ super(scanner, scanner.getSamplerConfiguration());
+ }
+
+ @Override
+ public SortedKeyValueIterator<Key,Value> deepCopy(final IteratorEnvironment env) {
+ return new ScannerTranslator(scanner);
+ }
+ }
+
private class ClientSideIteratorEnvironment implements IteratorEnvironment {
private SamplerConfiguration samplerConfig;
@@ -269,6 +284,24 @@ public class ClientSideIteratorScanner extends ScannerOptions implements Scanner
return smi.scanner.getAuthorizations();
}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ if (timeOut == Integer.MAX_VALUE)
+ setTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ else
+ setTimeout(timeOut, TimeUnit.SECONDS);
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ long timeout = getTimeout(TimeUnit.SECONDS);
+ if (timeout >= Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ return (int) timeout;
+ }
+
@Override
public void setRange(final Range range) {
this.range = range;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/Connector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/Connector.java b/core/src/main/java/org/apache/accumulo/core/client/Connector.java
index 95cfd10..e36cc82 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/Connector.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/Connector.java
@@ -50,6 +50,33 @@ public abstract class Connector {
public abstract BatchScanner createBatchScanner(String tableName, Authorizations authorizations, int numQueryThreads) throws TableNotFoundException;
/**
+ * Factory method to create a BatchDeleter connected to Accumulo.
+ *
+ * @param tableName
+ * the name of the table to query and delete from
+ * @param authorizations
+ * A set of authorization labels that will be checked against the column visibility of each key in order to filter data. The authorizations passed in
+ * must be a subset of the accumulo user's set of authorizations. If the accumulo user has authorizations (A1, A2) and authorizations (A2, A3) are
+ * passed, then an exception will be thrown.
+ * @param numQueryThreads
+ * the number of concurrent threads to spawn for querying
+ * @param maxMemory
+ * size in bytes of the maximum memory to batch before writing
+ * @param maxLatency
+ * size in milliseconds; set to 0 or Long.MAX_VALUE to allow the maximum time to hold a batch before writing
+ * @param maxWriteThreads
+ * the maximum number of threads to use for writing data to the tablet servers
+ *
+ * @return BatchDeleter object for configuring and deleting
+ * @throws TableNotFoundException
+ * when the specified table doesn't exist
+ * @deprecated since 1.5.0; Use {@link #createBatchDeleter(String, Authorizations, int, BatchWriterConfig)} instead.
+ */
+ @Deprecated
+ public abstract BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, long maxMemory, long maxLatency,
+ int maxWriteThreads) throws TableNotFoundException;
+
+ /**
*
* @param tableName
* the name of the table to query and delete from
@@ -64,6 +91,7 @@ public abstract class Connector {
* @return BatchDeleter object for configuring and deleting
* @since 1.5.0
*/
+
public abstract BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, BatchWriterConfig config)
throws TableNotFoundException;
@@ -72,14 +100,52 @@ public abstract class Connector {
*
* @param tableName
* the name of the table to insert data into
+ * @param maxMemory
+ * size in bytes of the maximum memory to batch before writing
+ * @param maxLatency
+ * time in milliseconds; set to 0 or Long.MAX_VALUE to allow the maximum time to hold a batch before writing
+ * @param maxWriteThreads
+ * the maximum number of threads to use for writing data to the tablet servers
+ *
+ * @return BatchWriter object for configuring and writing data to
+ * @throws TableNotFoundException
+ * when the specified table doesn't exist
+ * @deprecated since 1.5.0; Use {@link #createBatchWriter(String, BatchWriterConfig)} instead.
+ */
+ @Deprecated
+ public abstract BatchWriter createBatchWriter(String tableName, long maxMemory, long maxLatency, int maxWriteThreads) throws TableNotFoundException;
+
+ /**
+ * Factory method to create a BatchWriter connected to Accumulo.
+ *
+ * @param tableName
+ * the name of the table to insert data into
* @param config
* configuration used to create batch writer
* @return BatchWriter object for configuring and writing data to
* @since 1.5.0
*/
+
public abstract BatchWriter createBatchWriter(String tableName, BatchWriterConfig config) throws TableNotFoundException;
/**
+ * Factory method to create a Multi-Table BatchWriter connected to Accumulo. Multi-table batch writers can queue data for multiple tables, which is good for
+ * ingesting data into multiple tables from the same source
+ *
+ * @param maxMemory
+ * size in bytes of the maximum memory to batch before writing
+ * @param maxLatency
+ * size in milliseconds; set to 0 or Long.MAX_VALUE to allow the maximum time to hold a batch before writing
+ * @param maxWriteThreads
+ * the maximum number of threads to use for writing data to the tablet servers
+ *
+ * @return MultiTableBatchWriter object for configuring and writing data to
+ * @deprecated since 1.5.0; Use {@link #createMultiTableBatchWriter(BatchWriterConfig)} instead.
+ */
+ @Deprecated
+ public abstract MultiTableBatchWriter createMultiTableBatchWriter(long maxMemory, long maxLatency, int maxWriteThreads);
+
+ /**
* Factory method to create a Multi-Table BatchWriter connected to Accumulo. Multi-table batch writers can queue data for multiple tables. Also data for
* multiple tables can be sent to a server in a single batch. Its an efficient way to ingest data into multiple tables from a single process.
*
@@ -88,6 +154,7 @@ public abstract class Connector {
* @return MultiTableBatchWriter object for configuring and writing data to
* @since 1.5.0
*/
+
public abstract MultiTableBatchWriter createMultiTableBatchWriter(BatchWriterConfig config);
/**
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/Instance.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/Instance.java b/core/src/main/java/org/apache/accumulo/core/client/Instance.java
index 3cb8973..8a70d4c 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/Instance.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/Instance.java
@@ -16,10 +16,13 @@
*/
package org.apache.accumulo.core.client;
+import java.nio.ByteBuffer;
import java.util.List;
+import org.apache.accumulo.core.client.admin.InstanceOperations;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
/**
* This class represents the information a client needs to know to connect to an instance of accumulo.
@@ -69,6 +72,78 @@ public interface Instance {
int getZooKeepersSessionTimeOut();
/**
+ * Returns a connection to accumulo.
+ *
+ * @param user
+ * a valid accumulo user
+ * @param pass
+ * A UTF-8 encoded password. The password may be cleared after making this call.
+ * @return the accumulo Connector
+ * @throws AccumuloException
+ * when a generic exception occurs
+ * @throws AccumuloSecurityException
+ * when a user's credentials are invalid
+ * @deprecated since 1.5, use {@link #getConnector(String, AuthenticationToken)} with {@link PasswordToken}
+ */
+ @Deprecated
+ Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Returns a connection to accumulo.
+ *
+ * @param user
+ * a valid accumulo user
+ * @param pass
+ * A UTF-8 encoded password. The password may be cleared after making this call.
+ * @return the accumulo Connector
+ * @throws AccumuloException
+ * when a generic exception occurs
+ * @throws AccumuloSecurityException
+ * when a user's credentials are invalid
+ * @deprecated since 1.5, use {@link #getConnector(String, AuthenticationToken)} with {@link PasswordToken}
+ */
+ @Deprecated
+ Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Returns a connection to this instance of accumulo.
+ *
+ * @param user
+ * a valid accumulo user
+ * @param pass
+ * If a mutable CharSequence is passed in, it may be cleared after this call.
+ * @return the accumulo Connector
+ * @throws AccumuloException
+ * when a generic exception occurs
+ * @throws AccumuloSecurityException
+ * when a user's credentials are invalid
+ * @deprecated since 1.5, use {@link #getConnector(String, AuthenticationToken)} with {@link PasswordToken}
+ */
+ @Deprecated
+ Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Returns the AccumuloConfiguration to use when interacting with this instance.
+ *
+ * @return the AccumuloConfiguration that specifies properties related to interacting with this instance
+ * @deprecated since 1.6.0. This method makes very little sense in the context of the client API and never should have been exposed.
+ * @see InstanceOperations#getSystemConfiguration() for client-side reading of the server-side configuration.
+ */
+ @Deprecated
+ AccumuloConfiguration getConfiguration();
+
+ /**
+ * Set the AccumuloConfiguration to use when interacting with this instance.
+ *
+ * @param conf
+ * accumulo configuration
+ * @deprecated since 1.6.0. This method makes very little sense in the context of the client API and never should have been exposed.
+ * @see InstanceOperations#setProperty(String, String)
+ */
+ @Deprecated
+ void setConfiguration(AccumuloConfiguration conf);
+
+ /**
* Returns a connection to this instance of accumulo.
*
* @param principal
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/IsolatedScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/IsolatedScanner.java b/core/src/main/java/org/apache/accumulo/core/client/IsolatedScanner.java
index 164cb1c..90e8637 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/IsolatedScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/IsolatedScanner.java
@@ -238,6 +238,24 @@ public class IsolatedScanner extends ScannerOptions implements Scanner {
return new RowBufferingIterator(scanner, this, range, timeOut, batchSize, readaheadThreshold, bufferFactory);
}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ if (timeOut == Integer.MAX_VALUE)
+ setTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ else
+ setTimeout(timeOut, TimeUnit.SECONDS);
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ long timeout = getTimeout(TimeUnit.SECONDS);
+ if (timeout >= Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ return (int) timeout;
+ }
+
@Override
public void setRange(Range range) {
this.range = range;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
index 8f8720a..b67a3a0 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
@@ -23,11 +23,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.apache.accumulo.core.client.impl.Tables;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.data.ConstraintViolationSummary;
import org.apache.accumulo.core.data.TabletId;
+import org.apache.accumulo.core.data.impl.TabletIdImpl;
/**
* Communicate the failed mutations of a BatchWriter back to the client.
@@ -41,6 +44,61 @@ public class MutationsRejectedException extends AccumuloException {
private Collection<String> es;
private int unknownErrors;
+ private static <K,V,L> Map<L,V> transformKeys(Map<K,V> map, Function<K,L> keyFunction) {
+ HashMap<L,V> ret = new HashMap<>();
+ for (Entry<K,V> entry : map.entrySet()) {
+ ret.put(keyFunction.apply(entry.getKey()), entry.getValue());
+ }
+
+ return ret;
+ }
+
+ /**
+ * @param cvsList
+ * list of constraint violations
+ * @param hashMap
+ * authorization failures
+ * @param serverSideErrors
+ * server side errors
+ * @param unknownErrors
+ * number of unknown errors
+ *
+ * @deprecated since 1.6.0, see {@link #MutationsRejectedException(Instance, List, Map, Collection, int, Throwable)}
+ */
+ @Deprecated
+ public MutationsRejectedException(List<ConstraintViolationSummary> cvsList, HashMap<org.apache.accumulo.core.data.KeyExtent,Set<SecurityErrorCode>> hashMap,
+ Collection<String> serverSideErrors, int unknownErrors, Throwable cause) {
+ super("# constraint violations : " + cvsList.size() + " security codes: " + hashMap.values() + " # server errors " + serverSideErrors.size()
+ + " # exceptions " + unknownErrors, cause);
+ this.cvsl = cvsList;
+ this.af = transformKeys(hashMap, TabletIdImpl.KE_2_TID_OLD);
+ this.es = serverSideErrors;
+ this.unknownErrors = unknownErrors;
+ }
+
+ /**
+ * @param cvsList
+ * list of constraint violations
+ * @param hashMap
+ * authorization failures
+ * @param serverSideErrors
+ * server side errors
+ * @param unknownErrors
+ * number of unknown errors
+ *
+ * @deprecated since 1.7.0 see {@link #MutationsRejectedException(Instance, List, Map, Collection, int, Throwable)}
+ */
+ @Deprecated
+ public MutationsRejectedException(Instance instance, List<ConstraintViolationSummary> cvsList,
+ HashMap<org.apache.accumulo.core.data.KeyExtent,Set<SecurityErrorCode>> hashMap, Collection<String> serverSideErrors, int unknownErrors, Throwable cause) {
+ super("# constraint violations : " + cvsList.size() + " security codes: " + format(transformKeys(hashMap, TabletIdImpl.KE_2_TID_OLD), instance)
+ + " # server errors " + serverSideErrors.size() + " # exceptions " + unknownErrors, cause);
+ this.cvsl = cvsList;
+ this.af = transformKeys(hashMap, TabletIdImpl.KE_2_TID_OLD);
+ this.es = serverSideErrors;
+ this.unknownErrors = unknownErrors;
+ }
+
/**
*
* @param cvsList
@@ -88,6 +146,25 @@ public class MutationsRejectedException extends AccumuloException {
}
/**
+ * @return the internal list of authorization failures
+ * @deprecated since 1.5, see {@link #getAuthorizationFailuresMap()}
+ */
+ @Deprecated
+ public List<org.apache.accumulo.core.data.KeyExtent> getAuthorizationFailures() {
+ return af.keySet().stream().map(TabletIdImpl.TID_2_KE_OLD).collect(Collectors.toList());
+ }
+
+ /**
+ * @return the internal mapping of keyextent mappings to SecurityErrorCode
+ * @since 1.5.0
+ * @deprecated since 1.7.0 see {@link #getSecurityErrorCodes()}
+ */
+ @Deprecated
+ public Map<org.apache.accumulo.core.data.KeyExtent,Set<SecurityErrorCode>> getAuthorizationFailuresMap() {
+ return transformKeys(af, TabletIdImpl.TID_2_KE_OLD);
+ }
+
+ /**
* @return the internal mapping of TabletID to SecurityErrorCodes
*/
public Map<TabletId,Set<SecurityErrorCode>> getSecurityErrorCodes() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/Scanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/Scanner.java b/core/src/main/java/org/apache/accumulo/core/client/Scanner.java
index 547c89c..372ee42 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/Scanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/Scanner.java
@@ -28,6 +28,25 @@ import org.apache.accumulo.core.data.Range;
public interface Scanner extends ScannerBase {
/**
+ * This setting determines how long a scanner will automatically retry when a failure occurs. By default a scanner will retry forever.
+ *
+ * @param timeOut
+ * in seconds
+ * @deprecated Since 1.5. See {@link ScannerBase#setTimeout(long, java.util.concurrent.TimeUnit)}
+ */
+ @Deprecated
+ void setTimeOut(int timeOut);
+
+ /**
+ * Returns the setting for how long a scanner will automatically retry when a failure occurs.
+ *
+ * @return the timeout configured for this scanner
+ * @deprecated Since 1.5. See {@link ScannerBase#getTimeout(java.util.concurrent.TimeUnit)}
+ */
+ @Deprecated
+ int getTimeOut();
+
+ /**
* Sets the range of keys to scan over.
*
* @param range
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java b/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
index a545c72..4a4dd5f 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.core.client;
import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.charset.StandardCharsets.UTF_8;
+import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -31,13 +32,18 @@ import org.apache.accumulo.core.client.impl.ConnectorImpl;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.impl.InstanceOperationsImpl;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.accumulo.core.util.OpTimer;
+import org.apache.accumulo.core.util.TextUtil;
import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.ZooCache;
import org.apache.accumulo.fate.zookeeper.ZooCacheFactory;
import org.apache.commons.configuration.Configuration;
+import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,6 +73,7 @@ public class ZooKeeperInstance implements Instance {
private final int zooKeepersSessionTimeOut;
+ private AccumuloConfiguration conf;
private ClientConfiguration clientConf;
/**
@@ -81,6 +88,49 @@ public class ZooKeeperInstance implements Instance {
}
/**
+ *
+ * @param instanceName
+ * The name of specific accumulo instance. This is set at initialization time.
+ * @param zooKeepers
+ * A comma separated list of zoo keeper server locations. Each location can contain an optional port, of the format host:port.
+ * @param sessionTimeout
+ * zoo keeper session time out in milliseconds.
+ * @deprecated since 1.6.0; Use {@link #ZooKeeperInstance(Configuration)} instead.
+ */
+ @Deprecated
+ public ZooKeeperInstance(String instanceName, String zooKeepers, int sessionTimeout) {
+ this(ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zooKeepers).withZkTimeout(sessionTimeout));
+ }
+
+ /**
+ *
+ * @param instanceId
+ * The UUID that identifies the accumulo instance you want to connect to.
+ * @param zooKeepers
+ * A comma separated list of zoo keeper server locations. Each location can contain an optional port, of the format host:port.
+ * @deprecated since 1.6.0; Use {@link #ZooKeeperInstance(Configuration)} instead.
+ */
+ @Deprecated
+ public ZooKeeperInstance(UUID instanceId, String zooKeepers) {
+ this(ClientConfiguration.loadDefault().withInstance(instanceId).withZkHosts(zooKeepers));
+ }
+
+ /**
+ *
+ * @param instanceId
+ * The UUID that identifies the accumulo instance you want to connect to.
+ * @param zooKeepers
+ * A comma separated list of zoo keeper server locations. Each location can contain an optional port, of the format host:port.
+ * @param sessionTimeout
+ * zoo keeper session time out in milliseconds.
+ * @deprecated since 1.6.0; Use {@link #ZooKeeperInstance(Configuration)} instead.
+ */
+ @Deprecated
+ public ZooKeeperInstance(UUID instanceId, String zooKeepers, int sessionTimeout) {
+ this(ClientConfiguration.loadDefault().withInstance(instanceId).withZkHosts(zooKeepers).withZkTimeout(sessionTimeout));
+ }
+
+ /**
* @param config
* Client configuration for specifying connection options. See {@link ClientConfiguration} which extends Configuration with convenience methods
* specific to Accumulo.
@@ -204,11 +254,52 @@ public class ZooKeeperInstance implements Instance {
}
@Override
+ @Deprecated
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, TextUtil.getBytes(new Text(pass.toString())));
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, ByteBufferUtil.toBytes(pass));
+ }
+
+ @Override
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
return new ConnectorImpl(new ClientContext(this, new Credentials(principal, token), clientConf));
}
@Override
+ @Deprecated
+ public Connector getConnector(String principal, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(principal, new PasswordToken(pass));
+ }
+
+ @Override
+ @Deprecated
+ public AccumuloConfiguration getConfiguration() {
+ return conf = conf == null ? DefaultConfiguration.getInstance() : ClientContext.convertClientConfig(clientConf);
+ }
+
+ @Override
+ @Deprecated
+ public void setConfiguration(AccumuloConfiguration conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Given a zooCache and instanceId, look up the instance name.
+ *
+ * @deprecated since 1.7.0 {@link ZooCache} is not part of the public API, but its a parameter to this method. Therefore code that uses this method is not
+ * guaranteed to be stable. This method was deprecated to discourage its use.
+ */
+ @Deprecated
+ public static String lookupInstanceName(ZooCache zooCache, UUID instanceId) {
+ return InstanceOperationsImpl.lookupInstanceName(zooCache, instanceId);
+ }
+
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder(64);
sb.append("ZooKeeperInstance: ").append(getInstanceName()).append(" ").append(getZooKeepers());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveCompaction.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveCompaction.java b/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveCompaction.java
index ddb7fa9..5228391 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveCompaction.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveCompaction.java
@@ -78,6 +78,13 @@ public abstract class ActiveCompaction {
/**
* @return tablet thats is compacting
+ * @deprecated since 1.7.0 use {@link #getTablet()}
+ */
+ @Deprecated
+ public abstract org.apache.accumulo.core.data.KeyExtent getExtent();
+
+ /**
+ * @return tablet thats is compacting
* @since 1.7.0
*/
public abstract TabletId getTablet();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveScan.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveScan.java b/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveScan.java
index 9510895..81bb1cc 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveScan.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/ActiveScan.java
@@ -65,6 +65,13 @@ public abstract class ActiveScan {
/**
* @return tablet the scan is running against, if a batch scan may be one of many or null
+ * @deprecated since 1.7.0 use {@link #getTablet()}
+ */
+ @Deprecated
+ public abstract org.apache.accumulo.core.data.KeyExtent getExtent();
+
+ /**
+ * @return tablet the scan is running against, if a batch scan may be one of many or null
* @since 1.7.0
*/
public abstract TabletId getTablet();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperations.java b/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperations.java
index 21d507b..cb916ef 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperations.java
@@ -36,6 +36,24 @@ public interface SecurityOperations {
/**
* Create a user
*
+ * @param user
+ * the name of the user to create
+ * @param password
+ * the plaintext password for the user
+ * @param authorizations
+ * the authorizations that the user has for scanning
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission to create a user
+ * @deprecated since 1.5.0; use {@link #createLocalUser(String, PasswordToken)} or the user management functions of your configured authenticator instead.
+ */
+ @Deprecated
+ void createUser(String user, byte[] password, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Create a user
+ *
* @param principal
* the name of the user to create
* @param password
@@ -51,6 +69,20 @@ public interface SecurityOperations {
/**
* Delete a user
*
+ * @param user
+ * the user name to delete
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission to delete a user
+ * @deprecated since 1.5.0; use {@link #dropUser(String)} or the user management functions of your configured authenticator instead.
+ */
+ @Deprecated
+ void dropUser(String user) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Delete a user
+ *
* @param principal
* the user name to delete
* @throws AccumuloException
@@ -64,6 +96,23 @@ public interface SecurityOperations {
/**
* Verify a username/password combination is valid
*
+ * @param user
+ * the name of the user to authenticate
+ * @param password
+ * the plaintext password for the user
+ * @return true if the user asking is allowed to know and the specified user/password is valid, false otherwise
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission to ask
+ * @deprecated since 1.5.0; use {@link #authenticateUser(String, AuthenticationToken)} instead.
+ */
+ @Deprecated
+ boolean authenticateUser(String user, byte[] password) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Verify a username/password combination is valid
+ *
* @param principal
* the name of the user to authenticate
* @param token
@@ -80,6 +129,23 @@ public interface SecurityOperations {
/**
* Set the user's password
*
+ * @param user
+ * the name of the user to modify
+ * @param password
+ * the plaintext password for the user
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission to modify a user
+ * @deprecated since 1.5.0; use {@link #changeLocalUserPassword(String, PasswordToken)} or the user management functions of your configured authenticator
+ * instead.
+ */
+ @Deprecated
+ void changeUserPassword(String user, byte[] password) throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Set the user's password
+ *
* @param principal
* the name of the user to modify
* @param token
@@ -268,6 +334,19 @@ public interface SecurityOperations {
* if a general error occurs
* @throws AccumuloSecurityException
* if the user does not have permission to query users
+ * @deprecated since 1.5.0; use {@link #listLocalUsers()} or the user management functions of your configured authenticator instead.
+ */
+ @Deprecated
+ Set<String> listUsers() throws AccumuloException, AccumuloSecurityException;
+
+ /**
+ * Return a list of users in accumulo
+ *
+ * @return a set of user names
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission to query users
* @since 1.5.0
*/
Set<String> listLocalUsers() throws AccumuloException, AccumuloSecurityException;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
index a6046c6..3e56736 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperations.java
@@ -79,6 +79,40 @@ public interface TableOperations {
/**
* @param tableName
* the name of the table
+ * @param limitVersion
+ * Enables/disables the versioning iterator, which will limit the number of Key versions kept.
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission
+ * @throws TableExistsException
+ * if the table already exists
+ * @deprecated since 1.7.0; use {@link #create(String, NewTableConfiguration)} instead.
+ */
+ @Deprecated
+ void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException;
+
+ /**
+ * @param tableName
+ * the name of the table
+ * @param versioningIter
+ * Enables/disables the versioning iterator, which will limit the number of Key versions kept.
+ * @param timeType
+ * specifies logical or real-time based time recording for entries in the table
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission
+ * @throws TableExistsException
+ * if the table already exists
+ * @deprecated since 1.7.0; use {@link #create(String, NewTableConfiguration)} instead.
+ */
+ @Deprecated
+ void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException;
+
+ /**
+ * @param tableName
+ * the name of the table
* @param ntc
* specifies the new table's configuration variable, which are: 1. enable/disable the versioning iterator, which will limit the number of Key
* versions kept; 2. specifies logical or real-time based time recording for entries in the table; 3. user defined properties to be merged into the
@@ -156,6 +190,17 @@ public interface TableOperations {
* @return the split points (end-row names) for the table's current split profile
* @throws TableNotFoundException
* if the table does not exist
+ * @deprecated since 1.5.0; use {@link #listSplits(String)} instead.
+ */
+ @Deprecated
+ Collection<Text> getSplits(String tableName) throws TableNotFoundException;
+
+ /**
+ * @param tableName
+ * the name of the table
+ * @return the split points (end-row names) for the table's current split profile
+ * @throws TableNotFoundException
+ * if the table does not exist
* @throws AccumuloException
* if a general error occurs
* @throws AccumuloSecurityException
@@ -169,6 +214,17 @@ public interface TableOperations {
* the name of the table
* @param maxSplits
* specifies the maximum number of splits to return
+ * @return the split points (end-row names) for the table's current split profile, grouped into fewer splits so as not to exceed maxSplits
+ * @deprecated since 1.5.0; use {@link #listSplits(String, int)} instead.
+ */
+ @Deprecated
+ Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException;
+
+ /**
+ * @param tableName
+ * the name of the table
+ * @param maxSplits
+ * specifies the maximum number of splits to return
* @throws AccumuloException
* if a general error occurs
* @throws AccumuloSecurityException
@@ -360,6 +416,21 @@ public interface TableOperations {
void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException, TableExistsException;
/**
+ * Initiate a flush of a table's data that is in memory
+ *
+ * @param tableName
+ * the name of the table
+ * @throws AccumuloException
+ * if a general error occurs
+ * @throws AccumuloSecurityException
+ * if the user does not have permission
+ *
+ * @deprecated since 1.4; use {@link #flush(String, Text, Text, boolean)} instead
+ */
+ @Deprecated
+ void flush(String tableName) throws AccumuloException, AccumuloSecurityException;
+
+ /**
* Flush a table's data that is currently in memory.
*
* @param tableName
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveCompactionImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveCompactionImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveCompactionImpl.java
index a34bcf7..bdd5d51 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveCompactionImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveCompactionImpl.java
@@ -28,6 +28,7 @@ import org.apache.accumulo.core.data.TabletId;
import org.apache.accumulo.core.data.impl.KeyExtent;
import org.apache.accumulo.core.data.impl.TabletIdImpl;
import org.apache.accumulo.core.data.thrift.IterInfo;
+import org.apache.hadoop.io.Text;
/**
*
@@ -49,6 +50,14 @@ public class ActiveCompactionImpl extends ActiveCompaction {
}
@Override
+ @Deprecated
+ public org.apache.accumulo.core.data.KeyExtent getExtent() {
+ KeyExtent ke = new KeyExtent(tac.getExtent());
+ org.apache.accumulo.core.data.KeyExtent oke = new org.apache.accumulo.core.data.KeyExtent(new Text(ke.getTableId()), ke.getEndRow(), ke.getPrevEndRow());
+ return oke;
+ }
+
+ @Override
public TabletId getTablet() {
return new TabletIdImpl(new KeyExtent(tac.getExtent()));
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java
index dd96aa3..9021190 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ActiveScanImpl.java
@@ -32,6 +32,7 @@ import org.apache.accumulo.core.data.impl.TabletIdImpl;
import org.apache.accumulo.core.data.thrift.IterInfo;
import org.apache.accumulo.core.data.thrift.TColumn;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.hadoop.io.Text;
/**
* A class that contains information about an ActiveScan
@@ -119,6 +120,12 @@ public class ActiveScanImpl extends ActiveScan {
}
@Override
+ @Deprecated
+ public org.apache.accumulo.core.data.KeyExtent getExtent() {
+ return new org.apache.accumulo.core.data.KeyExtent(new Text(extent.getTableId()), extent.getEndRow(), extent.getPrevEndRow());
+ }
+
+ @Override
public TabletId getTablet() {
return new TabletIdImpl(extent);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
index 324e11a..b2b02b1 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java
@@ -18,6 +18,8 @@ package org.apache.accumulo.core.client.impl;
import static com.google.common.base.Preconditions.checkArgument;
+import java.util.concurrent.TimeUnit;
+
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.BatchDeleter;
@@ -94,6 +96,16 @@ public class ConnectorImpl extends Connector {
return new TabletServerBatchReader(context, getTableId(tableName), authorizations, numQueryThreads);
}
+ @Deprecated
+ @Override
+ public BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, long maxMemory, long maxLatency,
+ int maxWriteThreads) throws TableNotFoundException {
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(authorizations != null, "authorizations is null");
+ return new TabletServerBatchDeleter(context, getTableId(tableName), authorizations, numQueryThreads, new BatchWriterConfig().setMaxMemory(maxMemory)
+ .setMaxLatency(maxLatency, TimeUnit.MILLISECONDS).setMaxWriteThreads(maxWriteThreads));
+ }
+
@Override
public BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, BatchWriterConfig config)
throws TableNotFoundException {
@@ -102,12 +114,27 @@ public class ConnectorImpl extends Connector {
return new TabletServerBatchDeleter(context, getTableId(tableName), authorizations, numQueryThreads, config);
}
+ @Deprecated
+ @Override
+ public BatchWriter createBatchWriter(String tableName, long maxMemory, long maxLatency, int maxWriteThreads) throws TableNotFoundException {
+ checkArgument(tableName != null, "tableName is null");
+ return new BatchWriterImpl(context, getTableId(tableName), new BatchWriterConfig().setMaxMemory(maxMemory).setMaxLatency(maxLatency, TimeUnit.MILLISECONDS)
+ .setMaxWriteThreads(maxWriteThreads));
+ }
+
@Override
public BatchWriter createBatchWriter(String tableName, BatchWriterConfig config) throws TableNotFoundException {
checkArgument(tableName != null, "tableName is null");
return new BatchWriterImpl(context, getTableId(tableName), config);
}
+ @Deprecated
+ @Override
+ public MultiTableBatchWriter createMultiTableBatchWriter(long maxMemory, long maxLatency, int maxWriteThreads) {
+ return new MultiTableBatchWriterImpl(context, new BatchWriterConfig().setMaxMemory(maxMemory).setMaxLatency(maxLatency, TimeUnit.MILLISECONDS)
+ .setMaxWriteThreads(maxWriteThreads));
+ }
+
@Override
public MultiTableBatchWriter createMultiTableBatchWriter(BatchWriterConfig config) {
return new MultiTableBatchWriterImpl(context, config);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineScanner.java b/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineScanner.java
index 176096a..427a7cc 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/OfflineScanner.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.io.Text;
public class OfflineScanner extends ScannerOptions implements Scanner {
private int batchSize;
+ private int timeOut;
private Range range;
private Instance instance;
@@ -56,6 +57,18 @@ public class OfflineScanner extends ScannerOptions implements Scanner {
this.timeOut = Integer.MAX_VALUE;
}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ this.timeOut = timeOut;
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ return timeOut;
+ }
+
@Override
public void setRange(Range range) {
this.range = range;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerImpl.java
index b0a0fa3..89406f4 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerImpl.java
@@ -92,7 +92,7 @@ public class ScannerImpl extends ScannerOptions implements Scanner {
@Override
public synchronized Iterator<Entry<Key,Value>> iterator() {
- return new ScannerIterator(context, tableId, authorizations, range, size, getTimeout(TimeUnit.SECONDS), this, isolated, readaheadThreshold);
+ return new ScannerIterator(context, tableId, authorizations, range, size, getTimeOut(), this, isolated, readaheadThreshold);
}
@Override
@@ -110,6 +110,24 @@ public class ScannerImpl extends ScannerOptions implements Scanner {
this.isolated = false;
}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ if (timeOut == Integer.MAX_VALUE)
+ setTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ else
+ setTimeout(timeOut, TimeUnit.SECONDS);
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ long timeout = getTimeout(TimeUnit.SECONDS);
+ if (timeout >= Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ return (int) timeout;
+ }
+
@Override
public synchronized void setReadaheadThreshold(long batches) {
if (0 > batches) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerIterator.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerIterator.java
index 7d01895..ae55cc0 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ScannerIterator.java
@@ -48,7 +48,7 @@ public class ScannerIterator implements Iterator<Entry<Key,Value>> {
private static final Logger log = LoggerFactory.getLogger(ScannerIterator.class);
// scanner options
- private long timeOut;
+ private int timeOut;
// scanner state
private Iterator<KeyValue> iter;
@@ -104,7 +104,7 @@ public class ScannerIterator implements Iterator<Entry<Key,Value>> {
}
- ScannerIterator(ClientContext context, String tableId, Authorizations authorizations, Range range, int size, long timeOut, ScannerOptions options,
+ ScannerIterator(ClientContext context, String tableId, Authorizations authorizations, Range range, int size, int timeOut, ScannerOptions options,
boolean isolated, long readaheadThreshold) {
this.timeOut = timeOut;
this.readaheadThreshold = readaheadThreshold;
@@ -133,6 +133,7 @@ public class ScannerIterator implements Iterator<Entry<Key,Value>> {
}
@Override
+ @SuppressWarnings("unchecked")
public boolean hasNext() {
if (finished)
return false;
@@ -159,7 +160,6 @@ public class ScannerIterator implements Iterator<Entry<Key,Value>> {
throw new RuntimeException((Exception) obj);
}
- @SuppressWarnings("unchecked")
List<KeyValue> currentBatch = (List<KeyValue>) obj;
if (currentBatch.size() == 0) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/SecurityOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/SecurityOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/SecurityOperationsImpl.java
index 6e3d714..781a5d4 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/SecurityOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/SecurityOperationsImpl.java
@@ -93,6 +93,13 @@ public class SecurityOperationsImpl implements SecurityOperations {
this.context = context;
}
+ @Deprecated
+ @Override
+ public void createUser(String user, byte[] password, final Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
+ createLocalUser(user, new PasswordToken(password));
+ changeUserAuthorizations(user, authorizations);
+ }
+
@Override
public void createLocalUser(final String principal, final PasswordToken password) throws AccumuloException, AccumuloSecurityException {
checkArgument(principal != null, "principal is null");
@@ -111,6 +118,12 @@ public class SecurityOperationsImpl implements SecurityOperations {
});
}
+ @Deprecated
+ @Override
+ public void dropUser(final String user) throws AccumuloException, AccumuloSecurityException {
+ dropLocalUser(user);
+ }
+
@Override
public void dropLocalUser(final String principal) throws AccumuloException, AccumuloSecurityException {
checkArgument(principal != null, "principal is null");
@@ -122,6 +135,12 @@ public class SecurityOperationsImpl implements SecurityOperations {
});
}
+ @Deprecated
+ @Override
+ public boolean authenticateUser(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
+ return authenticateUser(user, new PasswordToken(password));
+ }
+
@Override
public boolean authenticateUser(final String principal, final AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
checkArgument(principal != null, "principal is null");
@@ -136,6 +155,12 @@ public class SecurityOperationsImpl implements SecurityOperations {
}
@Override
+ @Deprecated
+ public void changeUserPassword(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
+ changeLocalUserPassword(user, new PasswordToken(password));
+ }
+
+ @Override
public void changeLocalUserPassword(final String principal, final PasswordToken token) throws AccumuloException, AccumuloSecurityException {
checkArgument(principal != null, "principal is null");
checkArgument(token != null, "token is null");
@@ -314,6 +339,12 @@ public class SecurityOperationsImpl implements SecurityOperations {
});
}
+ @Deprecated
+ @Override
+ public Set<String> listUsers() throws AccumuloException, AccumuloSecurityException {
+ return listLocalUsers();
+ }
+
@Override
public Set<String> listLocalUsers() throws AccumuloException, AccumuloSecurityException {
return execute(new ClientExecReturn<Set<String>,ClientService.Client>() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java
index 931c7f7..3d17a85 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/TableOperationsImpl.java
@@ -70,6 +70,7 @@ import org.apache.accumulo.core.client.admin.FindMax;
import org.apache.accumulo.core.client.admin.Locations;
import org.apache.accumulo.core.client.admin.NewTableConfiguration;
import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.client.admin.TimeType;
import org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation;
import org.apache.accumulo.core.client.impl.thrift.ClientService;
import org.apache.accumulo.core.client.impl.thrift.ClientService.Client;
@@ -187,6 +188,26 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
@Override
+ @Deprecated
+ public void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ create(tableName, limitVersion, TimeType.MILLIS);
+ }
+
+ @Override
+ @Deprecated
+ public void create(String tableName, boolean limitVersion, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(timeType != null, "timeType is null");
+
+ NewTableConfiguration ntc = new NewTableConfiguration().setTimeType(timeType);
+
+ if (limitVersion)
+ create(tableName, ntc);
+ else
+ create(tableName, ntc.withoutDefaultIterators());
+ }
+
+ @Override
public void create(String tableName, NewTableConfiguration ntc) throws AccumuloException, AccumuloSecurityException, TableExistsException {
checkArgument(tableName != null, "tableName is null");
checkArgument(ntc != null, "ntc is null");
@@ -573,6 +594,16 @@ public class TableOperationsImpl extends TableOperationsHelper {
return endRows;
}
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
+ try {
+ return listSplits(tableName);
+ } catch (AccumuloSecurityException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Override
public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException, AccumuloSecurityException {
Collection<Text> endRows = listSplits(tableName);
@@ -598,6 +629,16 @@ public class TableOperationsImpl extends TableOperationsHelper {
return subset;
}
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
+ try {
+ return listSplits(tableName, maxSplits);
+ } catch (AccumuloSecurityException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
@Override
public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
checkArgument(tableName != null, "tableName is null");
@@ -657,6 +698,16 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
@Override
+ @Deprecated
+ public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {
+ try {
+ flush(tableName, null, null, false);
+ } catch (TableNotFoundException e) {
+ throw new AccumuloException(e.getMessage(), e);
+ }
+ }
+
+ @Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
checkArgument(tableName != null, "tableName is null");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java b/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
index 7f85afc..e69143c 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
@@ -214,7 +214,7 @@ public class ThriftScanner {
return (long) (Math.min(millis * 2, maxSleep) * (.9 + Math.random() / 5));
}
- public static List<KeyValue> scan(ClientContext context, ScanState scanState, long timeOut) throws ScanTimedOutException, AccumuloException,
+ public static List<KeyValue> scan(ClientContext context, ScanState scanState, int timeOut) throws ScanTimedOutException, AccumuloException,
AccumuloSecurityException, TableNotFoundException {
TabletLocation loc = null;
Instance instance = context.getInstance();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java
index 9ca686c..6165346 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/AbstractInputFormat.java
@@ -16,8 +16,6 @@
*/
package org.apache.accumulo.core.client.mapred;
-import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
-
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -70,6 +68,7 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.data.impl.KeyExtent;
import org.apache.accumulo.core.master.state.tables.TableState;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.InputFormat;
@@ -80,6 +79,8 @@ import org.apache.hadoop.security.token.Token;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
+
/**
* An abstract input format to provide shared methods common to all other input format classes. At the very least, any classes inheriting from this class will
* need to define their own {@link RecordReader}.
@@ -221,6 +222,23 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
*
* @param job
* the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @param zooKeepers
+ * a comma-separated list of zookeeper servers
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #setZooKeeperInstance(JobConf, ClientConfiguration)} instead.
+ */
+ @Deprecated
+ public static void setZooKeeperInstance(JobConf job, String instanceName, String zooKeepers) {
+ setZooKeeperInstance(job, new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
+ }
+
+ /**
+ * Configures a {@link org.apache.accumulo.core.client.ZooKeeperInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
* @param clientConfig
* client configuration containing connection options
* @since 1.6.0
@@ -230,6 +248,21 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
}
/**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @since 1.5.0
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public static void setMockInstance(JobConf job, String instanceName) {
+ InputConfigurator.setMockInstance(CLASS, job, instanceName);
+ }
+
+ /**
* Initializes an Accumulo {@link org.apache.accumulo.core.client.Instance} based on the configuration.
*
* @param job
@@ -295,6 +328,23 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
}
/**
+ * Initializes an Accumulo {@link org.apache.accumulo.core.client.impl.TabletLocator} based on the configuration.
+ *
+ * @param job
+ * the Hadoop context for the configured job
+ * @return an Accumulo tablet locator
+ * @throws org.apache.accumulo.core.client.TableNotFoundException
+ * if the table name set on the configuration doesn't exist
+ * @since 1.6.0
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and is not guaranteed to be stable. The method was deprecated to
+ * discourage its use.
+ */
+ @Deprecated
+ protected static TabletLocator getTabletLocator(JobConf job, String tableId) throws TableNotFoundException {
+ return InputConfigurator.getTabletLocator(CLASS, job, tableId);
+ }
+
+ /**
* Fetch the client configuration from the job.
*
* @param job
@@ -417,6 +467,23 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
}
/**
+ * Configures the iterators on a scanner for the given table name.
+ *
+ * @param job
+ * the Hadoop job configuration
+ * @param scanner
+ * the scanner for which to configure the iterators
+ * @param tableName
+ * the table name for which the scanner is configured
+ * @since 1.6.0
+ * @deprecated since 1.7.0; Use {@link #jobIterators} instead.
+ */
+ @Deprecated
+ protected void setupIterators(JobConf job, Scanner scanner, String tableName, RangeInputSplit split) {
+ setupIterators(job, (ScannerBase) scanner, tableName, split);
+ }
+
+ /**
* Initialize a scanner over the given input split using this task attempt configuration.
*/
public void initialize(InputSplit inSplit, JobConf job) throws IOException {
@@ -494,6 +561,8 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
try {
if (isOffline) {
scanner = new OfflineScanner(instance, new Credentials(principal, token), baseSplit.getTableId(), authorizations);
+ } else if (DeprecationUtil.isMockInstance(instance)) {
+ scanner = instance.getConnector(principal, token).createScanner(baseSplit.getTableName(), authorizations);
} else {
ClientConfiguration clientConf = getClientConfiguration(job);
ClientContext context = new ClientContext(instance, new Credentials(principal, token), clientConf);
@@ -602,10 +671,14 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
Instance instance = getInstance(job);
String tableId;
// resolve table name to id once, and use id from this point forward
- try {
- tableId = Tables.getTableId(instance, tableName);
- } catch (TableNotFoundException e) {
- throw new IOException(e);
+ if (DeprecationUtil.isMockInstance(instance)) {
+ tableId = "";
+ } else {
+ try {
+ tableId = Tables.getTableId(instance, tableName);
+ } catch (TableNotFoundException e) {
+ throw new IOException(e);
+ }
}
Authorizations auths = getScanAuthorizations(job);
@@ -647,10 +720,12 @@ public abstract class AbstractInputFormat<K,V> implements InputFormat<K,V> {
ClientContext context = new ClientContext(getInstance(job), new Credentials(getPrincipal(job), getAuthenticationToken(job)),
getClientConfiguration(job));
while (!tl.binRanges(context, ranges, binnedRanges).isEmpty()) {
- if (!Tables.exists(instance, tableId))
- throw new TableDeletedException(tableId);
- if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
- throw new TableOfflineException(instance, tableId);
+ if (!DeprecationUtil.isMockInstance(instance)) {
+ if (!Tables.exists(instance, tableId))
+ throw new TableDeletedException(tableId);
+ if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
+ throw new TableOfflineException(instance, tableId);
+ }
binnedRanges.clear();
log.warn("Unable to locate bins for specified ranges. Retrying.");
// sleep randomly between 100 and 200 ms
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormat.java
index 640a85d..f2bc4cd 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormat.java
@@ -53,6 +53,21 @@ public class AccumuloFileOutputFormat extends FileOutputFormat<Key,Value> {
protected static final Logger log = Logger.getLogger(CLASS);
/**
+ * This helper method provides an AccumuloConfiguration object constructed from the Accumulo defaults, and overridden with Accumulo properties that have been
+ * stored in the Job's configuration.
+ *
+ * @param job
+ * the Hadoop context for the configured job
+ * @since 1.5.0
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and is not guaranteed to be stable. The method was deprecated to
+ * discourage its use.
+ */
+ @Deprecated
+ protected static AccumuloConfiguration getAccumuloConfiguration(JobConf job) {
+ return FileOutputConfigurator.getAccumuloConfiguration(CLASS, job);
+ }
+
+ /**
* Sets the compression type to use for data blocks. Specifying a compression may require additional libraries to be available to your Job.
*
* @param job
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
index 9ac459e..5feadb8 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/AccumuloOutputFormat.java
@@ -42,6 +42,7 @@ import org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase;
import org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer;
import org.apache.accumulo.core.client.security.tokens.DelegationToken;
import org.apache.accumulo.core.client.security.tokens.KerberosToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -168,6 +169,28 @@ public class AccumuloOutputFormat implements OutputFormat<Text,Mutation> {
}
/**
+ * Gets the serialized token class from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobConf)} instead.
+ */
+ @Deprecated
+ protected static String getTokenClass(JobConf job) {
+ return getAuthenticationToken(job).getClass().getName();
+ }
+
+ /**
+ * Gets the serialized token from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobConf)} instead.
+ */
+ @Deprecated
+ protected static byte[] getToken(JobConf job) {
+ return AuthenticationTokenSerializer.serialize(getAuthenticationToken(job));
+ }
+
+ /**
* Gets the authenticated token from either the specified token file or directly from the configuration, whichever was used when the job was configured.
*
* @param job
@@ -187,6 +210,24 @@ public class AccumuloOutputFormat implements OutputFormat<Text,Mutation> {
*
* @param job
* the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @param zooKeepers
+ * a comma-separated list of zookeeper servers
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #setZooKeeperInstance(JobConf, ClientConfiguration)} instead.
+ */
+
+ @Deprecated
+ public static void setZooKeeperInstance(JobConf job, String instanceName, String zooKeepers) {
+ setZooKeeperInstance(job, new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
+ }
+
+ /**
+ * Configures a {@link ZooKeeperInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
*
* @param clientConfig
* client configuration for specifying connection timeouts, SSL connection options, etc.
@@ -197,6 +238,21 @@ public class AccumuloOutputFormat implements OutputFormat<Text,Mutation> {
}
/**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @since 1.5.0
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public static void setMockInstance(JobConf job, String instanceName) {
+ OutputConfigurator.setMockInstance(CLASS, job, instanceName);
+ }
+
+ /**
* Initializes an Accumulo {@link Instance} based on the configuration.
*
* @param job
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapred/InputFormatBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapred/InputFormatBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapred/InputFormatBase.java
index 2523819..0cf57d2 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapred/InputFormatBase.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapred/InputFormatBase.java
@@ -24,7 +24,10 @@ import java.util.Set;
import org.apache.accumulo.core.client.ClientSideIteratorScanner;
import org.apache.accumulo.core.client.IsolatedScanner;
import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.TabletLocator;
import org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.data.Key;
@@ -352,6 +355,22 @@ public abstract class InputFormatBase<K,V> extends AbstractInputFormat<K,V> {
InputConfigurator.setSamplerConfiguration(CLASS, job, samplerConfig);
}
+ /**
+ * Initializes an Accumulo {@link org.apache.accumulo.core.client.impl.TabletLocator} based on the configuration.
+ *
+ * @param job
+ * the Hadoop job for the configured job
+ * @return an Accumulo tablet locator
+ * @throws org.apache.accumulo.core.client.TableNotFoundException
+ * if the table name set on the job doesn't exist
+ * @since 1.5.0
+ * @deprecated since 1.6.0
+ */
+ @Deprecated
+ protected static TabletLocator getTabletLocator(JobConf job) throws TableNotFoundException {
+ return InputConfigurator.getTabletLocator(CLASS, job, InputConfigurator.getInputTableName(CLASS, job));
+ }
+
protected abstract static class RecordReaderBase<K,V> extends AbstractRecordReader<K,V> {
@Override
@@ -359,6 +378,56 @@ public abstract class InputFormatBase<K,V> extends AbstractInputFormat<K,V> {
return getIterators(job);
}
+ /**
+ * Apply the configured iterators to the scanner.
+ *
+ * @param iterators
+ * the iterators to set
+ * @param scanner
+ * the scanner to configure
+ * @deprecated since 1.7.0; Use {@link #jobIterators} instead.
+ */
+ @Deprecated
+ protected void setupIterators(List<IteratorSetting> iterators, Scanner scanner) {
+ for (IteratorSetting iterator : iterators) {
+ scanner.addScanIterator(iterator);
+ }
+ }
+
+ /**
+ * Apply the configured iterators from the configuration to the scanner.
+ *
+ * @param job
+ * the job configuration
+ * @param scanner
+ * the scanner to configure
+ */
+ @Deprecated
+ protected void setupIterators(JobConf job, Scanner scanner) {
+ setupIterators(getIterators(job), scanner);
+ }
}
+ /**
+ * @deprecated since 1.5.2; Use {@link org.apache.accumulo.core.client.mapred.RangeInputSplit} instead.
+ * @see org.apache.accumulo.core.client.mapred.RangeInputSplit
+ */
+ @Deprecated
+ public static class RangeInputSplit extends org.apache.accumulo.core.client.mapred.RangeInputSplit {
+ public RangeInputSplit() {
+ super();
+ }
+
+ public RangeInputSplit(RangeInputSplit other) throws IOException {
+ super(other);
+ }
+
+ public RangeInputSplit(String table, String tableId, Range range, String[] locations) {
+ super(table, tableId, range, locations);
+ }
+
+ protected RangeInputSplit(String table, Range range, String[] locations) {
+ super(table, "", range, locations);
+ }
+ }
}
[7/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java
index e0da0f8..9ccf78a 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AbstractInputFormat.java
@@ -16,8 +16,6 @@
*/
package org.apache.accumulo.core.client.mapreduce;
-import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
-
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -69,6 +67,7 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.data.impl.KeyExtent;
import org.apache.accumulo.core.master.state.tables.TableState;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
@@ -82,6 +81,8 @@ import org.apache.hadoop.security.token.Token;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
+
/**
* An abstract input format to provide shared methods common to all other input format classes. At the very least, any classes inheriting from this class will
* need to define their own {@link RecordReader}.
@@ -205,6 +206,28 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
}
/**
+ * Gets the serialized token class from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobContext)} instead.
+ */
+ @Deprecated
+ protected static String getTokenClass(JobContext context) {
+ return getAuthenticationToken(context).getClass().getName();
+ }
+
+ /**
+ * Gets the serialized token from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobContext)} instead.
+ */
+ @Deprecated
+ protected static byte[] getToken(JobContext context) {
+ return AuthenticationToken.AuthenticationTokenSerializer.serialize(getAuthenticationToken(context));
+ }
+
+ /**
* Gets the authenticated token from either the specified token file or directly from the configuration, whichever was used when the job was configured.
*
* @param context
@@ -224,6 +247,23 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
*
* @param job
* the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @param zooKeepers
+ * a comma-separated list of zookeeper servers
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #setZooKeeperInstance(Job, ClientConfiguration)} instead.
+ */
+ @Deprecated
+ public static void setZooKeeperInstance(Job job, String instanceName, String zooKeepers) {
+ setZooKeeperInstance(job, new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
+ }
+
+ /**
+ * Configures a {@link org.apache.accumulo.core.client.ZooKeeperInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
*
* @param clientConfig
* client configuration containing connection options
@@ -234,6 +274,21 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
}
/**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @since 1.5.0
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public static void setMockInstance(Job job, String instanceName) {
+ InputConfigurator.setMockInstance(CLASS, job.getConfiguration(), instanceName);
+ }
+
+ /**
* Initializes an Accumulo {@link org.apache.accumulo.core.client.Instance} based on the configuration.
*
* @param context
@@ -326,6 +381,25 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
return InputConfigurator.getInputTableConfig(CLASS, context.getConfiguration(), tableName);
}
+ /**
+ * Initializes an Accumulo {@link org.apache.accumulo.core.client.impl.TabletLocator} based on the configuration.
+ *
+ * @param context
+ * the Hadoop context for the configured job
+ * @param table
+ * the table for which to initialize the locator
+ * @return an Accumulo tablet locator
+ * @throws org.apache.accumulo.core.client.TableNotFoundException
+ * if the table name set on the configuration doesn't exist
+ * @since 1.6.0
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and is not guaranteed to be stable. The method was deprecated to
+ * discourage its use.
+ */
+ @Deprecated
+ protected static TabletLocator getTabletLocator(JobContext context, String table) throws TableNotFoundException {
+ return InputConfigurator.getTabletLocator(CLASS, context.getConfiguration(), table);
+ }
+
// InputFormat doesn't have the equivalent of OutputFormat's checkOutputSpecs(JobContext job)
/**
* Check whether a configuration is fully configured to be used with an Accumulo {@link org.apache.hadoop.mapreduce.InputFormat}.
@@ -424,6 +498,23 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
scanner.addScanIterator(iterator);
}
+ /**
+ * Configures the iterators on a scanner for the given table name.
+ *
+ * @param context
+ * the Hadoop context for the configured job
+ * @param scanner
+ * the scanner for which to configure the iterators
+ * @param tableName
+ * the table name for which the scanner is configured
+ * @since 1.6.0
+ * @deprecated since 1.7.0; Use {@link #contextIterators} instead.
+ */
+ @Deprecated
+ protected void setupIterators(TaskAttemptContext context, Scanner scanner, String tableName, RangeInputSplit split) {
+ setupIterators(context, (ScannerBase) scanner, tableName, split);
+ }
+
@Override
public void initialize(InputSplit inSplit, TaskAttemptContext attempt) throws IOException {
@@ -500,6 +591,8 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
try {
if (isOffline) {
scanner = new OfflineScanner(instance, new Credentials(principal, token), split.getTableId(), authorizations);
+ } else if (DeprecationUtil.isMockInstance(instance)) {
+ scanner = instance.getConnector(principal, token).createScanner(split.getTableName(), authorizations);
} else {
ClientConfiguration clientConf = getClientConfiguration(attempt);
ClientContext context = new ClientContext(instance, new Credentials(principal, token), clientConf);
@@ -625,10 +718,14 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
Instance instance = getInstance(context);
String tableId;
// resolve table name to id once, and use id from this point forward
- try {
- tableId = Tables.getTableId(instance, tableName);
- } catch (TableNotFoundException e) {
- throw new IOException(e);
+ if (DeprecationUtil.isMockInstance(instance)) {
+ tableId = "";
+ } else {
+ try {
+ tableId = Tables.getTableId(instance, tableName);
+ } catch (TableNotFoundException e) {
+ throw new IOException(e);
+ }
}
Authorizations auths = getScanAuthorizations(context);
@@ -671,10 +768,12 @@ public abstract class AbstractInputFormat<K,V> extends InputFormat<K,V> {
ClientContext clientContext = new ClientContext(getInstance(context), new Credentials(getPrincipal(context), getAuthenticationToken(context)),
getClientConfiguration(context));
while (!tl.binRanges(clientContext, ranges, binnedRanges).isEmpty()) {
- if (!Tables.exists(instance, tableId))
- throw new TableDeletedException(tableId);
- if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
- throw new TableOfflineException(instance, tableId);
+ if (!DeprecationUtil.isMockInstance(instance)) {
+ if (!Tables.exists(instance, tableId))
+ throw new TableDeletedException(tableId);
+ if (Tables.getTableState(instance, tableId) == TableState.OFFLINE)
+ throw new TableOfflineException(instance, tableId);
+ }
binnedRanges.clear();
log.warn("Unable to locate bins for specified ranges. Retrying.");
// sleep randomly between 100 and 200 ms
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormat.java
index 656dba7..75afe2b 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormat.java
@@ -30,6 +30,7 @@ import org.apache.accumulo.core.data.Value;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
@@ -51,6 +52,21 @@ public class AccumuloFileOutputFormat extends FileOutputFormat<Key,Value> {
protected static final Logger log = Logger.getLogger(CLASS);
/**
+ * This helper method provides an AccumuloConfiguration object constructed from the Accumulo defaults, and overridden with Accumulo properties that have been
+ * stored in the Job's configuration.
+ *
+ * @param context
+ * the Hadoop context for the configured job
+ * @since 1.5.0
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and is not guaranteed to be stable. The method was deprecated to
+ * discourage its use.
+ */
+ @Deprecated
+ protected static AccumuloConfiguration getAccumuloConfiguration(JobContext context) {
+ return FileOutputConfigurator.getAccumuloConfiguration(CLASS, context.getConfiguration());
+ }
+
+ /**
* Sets the compression type to use for data blocks. Specifying a compression may require additional libraries to be available to your Job.
*
* @param job
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
index 9969b30..1e06ca3 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/AccumuloOutputFormat.java
@@ -42,6 +42,7 @@ import org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase;
import org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer;
import org.apache.accumulo.core.client.security.tokens.DelegationToken;
import org.apache.accumulo.core.client.security.tokens.KerberosToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -169,6 +170,28 @@ public class AccumuloOutputFormat extends OutputFormat<Text,Mutation> {
}
/**
+ * Gets the serialized token class from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobContext)} instead.
+ */
+ @Deprecated
+ protected static String getTokenClass(JobContext context) {
+ return getAuthenticationToken(context).getClass().getName();
+ }
+
+ /**
+ * Gets the serialized token from either the configuration or the token file.
+ *
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #getAuthenticationToken(JobContext)} instead.
+ */
+ @Deprecated
+ protected static byte[] getToken(JobContext context) {
+ return AuthenticationTokenSerializer.serialize(getAuthenticationToken(context));
+ }
+
+ /**
* Gets the authenticated token from either the specified token file or directly from the configuration, whichever was used when the job was configured.
*
* @param context
@@ -188,6 +211,23 @@ public class AccumuloOutputFormat extends OutputFormat<Text,Mutation> {
*
* @param job
* the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @param zooKeepers
+ * a comma-separated list of zookeeper servers
+ * @since 1.5.0
+ * @deprecated since 1.6.0; Use {@link #setZooKeeperInstance(Job, ClientConfiguration)} instead.
+ */
+ @Deprecated
+ public static void setZooKeeperInstance(Job job, String instanceName, String zooKeepers) {
+ setZooKeeperInstance(job, new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
+ }
+
+ /**
+ * Configures a {@link ZooKeeperInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
*
* @param clientConfig
* client configuration for specifying connection timeouts, SSL connection options, etc.
@@ -198,6 +238,20 @@ public class AccumuloOutputFormat extends OutputFormat<Text,Mutation> {
}
/**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param job
+ * the Hadoop job instance to be configured
+ * @param instanceName
+ * the Accumulo instance name
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setMockInstance(Job job, String instanceName) {
+ OutputConfigurator.setMockInstance(CLASS, job.getConfiguration(), instanceName);
+ }
+
+ /**
* Initializes an Accumulo {@link Instance} based on the configuration.
*
* @param context
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
index c6ae5a2..324d5c7 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/InputFormatBase.java
@@ -24,7 +24,10 @@ import java.util.Set;
import org.apache.accumulo.core.client.ClientSideIteratorScanner;
import org.apache.accumulo.core.client.IsolatedScanner;
import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.TabletLocator;
import org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.data.Key;
@@ -351,6 +354,22 @@ public abstract class InputFormatBase<K,V> extends AbstractInputFormat<K,V> {
InputConfigurator.setSamplerConfiguration(CLASS, job.getConfiguration(), samplerConfig);
}
+ /**
+ * Initializes an Accumulo {@link org.apache.accumulo.core.client.impl.TabletLocator} based on the configuration.
+ *
+ * @param context
+ * the Hadoop context for the configured job
+ * @return an Accumulo tablet locator
+ * @throws org.apache.accumulo.core.client.TableNotFoundException
+ * if the table name set on the configuration doesn't exist
+ * @since 1.5.0
+ * @deprecated since 1.6.0
+ */
+ @Deprecated
+ protected static TabletLocator getTabletLocator(JobContext context) throws TableNotFoundException {
+ return InputConfigurator.getTabletLocator(CLASS, context.getConfiguration(), InputConfigurator.getInputTableName(CLASS, context.getConfiguration()));
+ }
+
protected abstract static class RecordReaderBase<K,V> extends AbstractRecordReader<K,V> {
@Override
@@ -358,6 +377,53 @@ public abstract class InputFormatBase<K,V> extends AbstractInputFormat<K,V> {
return getIterators(context);
}
+ /**
+ * Apply the configured iterators from the configuration to the scanner.
+ *
+ * @param context
+ * the Hadoop context for the configured job
+ * @param scanner
+ * the scanner to configure
+ * @deprecated since 1.7.0; Use {@link #contextIterators} instead.
+ */
+ @Deprecated
+ protected void setupIterators(TaskAttemptContext context, Scanner scanner) {
+ // tableName is given as null as it will be ignored in eventual call to #contextIterators
+ setupIterators(context, scanner, null, null);
+ }
+
+ /**
+ * Initialize a scanner over the given input split using this task attempt configuration.
+ *
+ * @deprecated since 1.7.0; Use {@link #contextIterators} instead.
+ */
+ @Deprecated
+ protected void setupIterators(TaskAttemptContext context, Scanner scanner, org.apache.accumulo.core.client.mapreduce.RangeInputSplit split) {
+ setupIterators(context, scanner, null, split);
+ }
}
+ /**
+ * @deprecated since 1.5.2; Use {@link org.apache.accumulo.core.client.mapreduce.RangeInputSplit} instead.
+ * @see org.apache.accumulo.core.client.mapreduce.RangeInputSplit
+ */
+ @Deprecated
+ public static class RangeInputSplit extends org.apache.accumulo.core.client.mapreduce.RangeInputSplit {
+
+ public RangeInputSplit() {
+ super();
+ }
+
+ public RangeInputSplit(RangeInputSplit other) throws IOException {
+ super(other);
+ }
+
+ protected RangeInputSplit(String table, Range range, String[] locations) {
+ super(table, "", range, locations);
+ }
+
+ public RangeInputSplit(String table, String tableId, Range range, String[] locations) {
+ super(table, tableId, range, locations);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java
index 081054d..59af852 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplit.java
@@ -45,6 +45,7 @@ import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
@@ -61,7 +62,7 @@ public class RangeInputSplit extends InputSplit implements Writable {
private TokenSource tokenSource;
private String tokenFile;
private AuthenticationToken token;
- private Boolean offline, isolatedScan, localIterators;
+ private Boolean offline, mockInstance, isolatedScan, localIterators;
private Authorizations auths;
private Set<Pair<Text,Text>> fetchedColumns;
private List<IteratorSetting> iterators;
@@ -154,6 +155,10 @@ public class RangeInputSplit extends InputSplit implements Writable {
}
if (in.readBoolean()) {
+ mockInstance = in.readBoolean();
+ }
+
+ if (in.readBoolean()) {
int numColumns = in.readInt();
List<String> columns = new ArrayList<>(numColumns);
for (int i = 0; i < numColumns; i++) {
@@ -242,6 +247,11 @@ public class RangeInputSplit extends InputSplit implements Writable {
out.writeBoolean(localIterators);
}
+ out.writeBoolean(null != mockInstance);
+ if (null != mockInstance) {
+ out.writeBoolean(mockInstance);
+ }
+
out.writeBoolean(null != fetchedColumns);
if (null != fetchedColumns) {
String[] cols = InputConfigurator.serializeColumns(fetchedColumns);
@@ -304,10 +314,30 @@ public class RangeInputSplit extends InputSplit implements Writable {
}
}
+ /**
+ * Use {@link #getTableName}
+ *
+ * @deprecated since 1.6.1, use getTableName() instead.
+ */
+ @Deprecated
+ public String getTable() {
+ return getTableName();
+ }
+
public String getTableName() {
return tableName;
}
+ /**
+ * Use {@link #setTableName}
+ *
+ * @deprecated since 1.6.1, use setTableName() instead.
+ */
+ @Deprecated
+ public void setTable(String table) {
+ setTableName(table);
+ }
+
public void setTableName(String table) {
this.tableName = table;
}
@@ -320,11 +350,24 @@ public class RangeInputSplit extends InputSplit implements Writable {
return tableId;
}
+ /**
+ * @see #getInstance(ClientConfiguration)
+ * @deprecated since 1.7.0, use getInstance(ClientConfiguration) instead.
+ */
+ @Deprecated
+ public Instance getInstance() {
+ return getInstance(ClientConfiguration.loadDefault());
+ }
+
public Instance getInstance(ClientConfiguration base) {
if (null == instanceName) {
return null;
}
+ if (isMockInstance()) {
+ return DeprecationUtil.makeMockInstance(getInstanceName());
+ }
+
if (null == zooKeepers) {
return null;
}
@@ -382,6 +425,22 @@ public class RangeInputSplit extends InputSplit implements Writable {
this.locations = Arrays.copyOf(locations, locations.length);
}
+ /**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public Boolean isMockInstance() {
+ return mockInstance;
+ }
+
+ /**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public void setMockInstance(Boolean mockInstance) {
+ this.mockInstance = mockInstance;
+ }
+
public Boolean isIsolatedScan() {
return isolatedScan;
}
@@ -456,6 +515,7 @@ public class RangeInputSplit extends InputSplit implements Writable {
sb.append(" authenticationTokenFile: ").append(tokenFile);
sb.append(" Authorizations: ").append(auths);
sb.append(" offlineScan: ").append(offline);
+ sb.append(" mockInstance: ").append(mockInstance);
sb.append(" isolatedScan: ").append(isolatedScan);
sb.append(" localIterators: ").append(localIterators);
sb.append(" fetchColumns: ").append(fetchedColumns);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/impl/SplitUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/impl/SplitUtils.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/impl/SplitUtils.java
index 315e40c..b81b064 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/impl/SplitUtils.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/impl/SplitUtils.java
@@ -27,6 +27,7 @@ import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.hadoop.io.Text;
import org.apache.log4j.Level;
@@ -40,6 +41,7 @@ public class SplitUtils {
Authorizations auths, Level logLevel) {
split.setInstanceName(instance.getInstanceName());
split.setZooKeepers(instance.getZooKeepers());
+ DeprecationUtil.setMockInstance(split, DeprecationUtil.isMockInstance(instance));
split.setPrincipal(principal);
split.setToken(token);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java
index 2911c77..942c746 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBase.java
@@ -37,6 +37,7 @@ import org.apache.accumulo.core.client.impl.DelegationTokenImpl;
import org.apache.accumulo.core.client.mapreduce.impl.DelegationTokenStub;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
@@ -319,6 +320,29 @@ public class ConfiguratorBase {
}
/**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param instanceName
+ * the Accumulo instance name
+ * @since 1.6.0
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework
+ */
+ @Deprecated
+ public static void setMockInstance(Class<?> implementingClass, Configuration conf, String instanceName) {
+ String key = enumToConfKey(implementingClass, InstanceOpts.TYPE);
+ if (!conf.get(key, "").isEmpty())
+ throw new IllegalStateException("Instance info can only be set once per job; it has already been configured with " + conf.get(key));
+ conf.set(key, "MockInstance");
+
+ checkArgument(instanceName != null, "instanceName is null");
+ conf.set(enumToConfKey(implementingClass, InstanceOpts.NAME), instanceName);
+ }
+
+ /**
* Initializes an Accumulo {@link Instance} based on the configuration.
*
* @param implementingClass
@@ -331,7 +355,9 @@ public class ConfiguratorBase {
*/
public static Instance getInstance(Class<?> implementingClass, Configuration conf) {
String instanceType = conf.get(enumToConfKey(implementingClass, InstanceOpts.TYPE), "");
- if ("ZooKeeperInstance".equals(instanceType)) {
+ if ("MockInstance".equals(instanceType))
+ return DeprecationUtil.makeMockInstance(conf.get(enumToConfKey(implementingClass, InstanceOpts.NAME)));
+ else if ("ZooKeeperInstance".equals(instanceType)) {
return new ZooKeeperInstance(getClientConfiguration(implementingClass, conf));
} else if (instanceType.isEmpty())
throw new IllegalStateException("Instance has not been configured for " + implementingClass.getSimpleName());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java
index 57158a6..c8f20e1 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/impl/InputConfigurator.java
@@ -50,10 +50,12 @@ import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.ClientContext;
import org.apache.accumulo.core.client.impl.Credentials;
+import org.apache.accumulo.core.client.impl.DelegationTokenImpl;
import org.apache.accumulo.core.client.impl.Tables;
import org.apache.accumulo.core.client.impl.TabletLocator;
import org.apache.accumulo.core.client.mapreduce.InputTableConfig;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Range;
@@ -66,6 +68,7 @@ import org.apache.accumulo.core.metadata.schema.MetadataSchema;
import org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.TablePermission;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.core.util.TextUtil;
import org.apache.hadoop.conf.Configuration;
@@ -672,6 +675,9 @@ public class InputConfigurator extends ConfiguratorBase {
* @since 1.6.0
*/
public static TabletLocator getTabletLocator(Class<?> implementingClass, Configuration conf, String tableId) throws TableNotFoundException {
+ String instanceType = conf.get(enumToConfKey(implementingClass, InstanceOpts.TYPE));
+ if ("MockInstance".equals(instanceType))
+ return DeprecationUtil.makeMockLocator();
Instance instance = getInstance(implementingClass, conf);
ClientConfiguration clientConf = getClientConfiguration(implementingClass, conf);
ClientContext context = new ClientContext(instance,
@@ -738,6 +744,69 @@ public class InputConfigurator extends ConfiguratorBase {
}
}
+ // InputFormat doesn't have the equivalent of OutputFormat's checkOutputSpecs(JobContext job)
+ /**
+ * Check whether a configuration is fully configured to be used with an Accumulo {@link org.apache.hadoop.mapreduce.InputFormat}.
+ *
+ * <p>
+ * The implementation (JobContext or JobConf which created the Configuration) needs to be used to extract the proper {@link AuthenticationToken} for
+ * {@link DelegationTokenImpl} support.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @throws IOException
+ * if the context is improperly configured
+ * @since 1.6.0
+ *
+ * @see #validateInstance(Class, Configuration)
+ * @see #validatePermissions(Class, Configuration, Connector)
+ */
+ @Deprecated
+ public static void validateOptions(Class<?> implementingClass, Configuration conf) throws IOException {
+
+ Map<String,InputTableConfig> inputTableConfigs = getInputTableConfigs(implementingClass, conf);
+ if (!isConnectorInfoSet(implementingClass, conf))
+ throw new IOException("Input info has not been set.");
+ String instanceKey = conf.get(enumToConfKey(implementingClass, InstanceOpts.TYPE));
+ if (!"MockInstance".equals(instanceKey) && !"ZooKeeperInstance".equals(instanceKey))
+ throw new IOException("Instance info has not been set.");
+ // validate that we can connect as configured
+ try {
+ String principal = getPrincipal(implementingClass, conf);
+ AuthenticationToken token = getAuthenticationToken(implementingClass, conf);
+ Connector c = getInstance(implementingClass, conf).getConnector(principal, token);
+ if (!c.securityOperations().authenticateUser(principal, token))
+ throw new IOException("Unable to authenticate user");
+
+ if (getInputTableConfigs(implementingClass, conf).size() == 0)
+ throw new IOException("No table set.");
+
+ for (Map.Entry<String,InputTableConfig> tableConfig : inputTableConfigs.entrySet()) {
+ if (!c.securityOperations().hasTablePermission(getPrincipal(implementingClass, conf), tableConfig.getKey(), TablePermission.READ))
+ throw new IOException("Unable to access table");
+ }
+ for (Map.Entry<String,InputTableConfig> tableConfigEntry : inputTableConfigs.entrySet()) {
+ InputTableConfig tableConfig = tableConfigEntry.getValue();
+ if (!tableConfig.shouldUseLocalIterators()) {
+ if (tableConfig.getIterators() != null) {
+ for (IteratorSetting iter : tableConfig.getIterators()) {
+ if (!c.tableOperations().testClassLoad(tableConfigEntry.getKey(), iter.getIteratorClass(), SortedKeyValueIterator.class.getName()))
+ throw new AccumuloException("Servers are unable to load " + iter.getIteratorClass() + " as a " + SortedKeyValueIterator.class.getName());
+ }
+ }
+ }
+ }
+ } catch (AccumuloException e) {
+ throw new IOException(e);
+ } catch (AccumuloSecurityException e) {
+ throw new IOException(e);
+ } catch (TableNotFoundException e) {
+ throw new IOException(e);
+ }
+ }
+
/**
* Returns the {@link org.apache.accumulo.core.client.mapreduce.InputTableConfig} for the configuration based on the properties set using the single-table
* input methods.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
new file mode 100644
index 0000000..6914071
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/ConfiguratorBase.java
@@ -0,0 +1,275 @@
+/*
+ * 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.client.mapreduce.lib.util;
+
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.ClientConfiguration;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.log4j.Level;
+
+/**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+@Deprecated
+public class ConfiguratorBase {
+
+ /**
+ * Configuration keys for {@link Instance#getConnector(String, AuthenticationToken)}.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum ConnectorInfo {
+ IS_CONFIGURED, PRINCIPAL, TOKEN, TOKEN_CLASS
+ }
+
+ /**
+ * Configuration keys for {@link Instance}, {@link ZooKeeperInstance}, and {@link org.apache.accumulo.core.client.mock.MockInstance}.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ protected static enum InstanceOpts {
+ TYPE, NAME, ZOO_KEEPERS;
+ }
+
+ /**
+ * Configuration keys for general configuration options.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ protected static enum GeneralOpts {
+ LOG_LEVEL
+ }
+
+ /**
+ * Provides a configuration key for a given feature enum, prefixed by the implementingClass
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param e
+ * the enum used to provide the unique part of the configuration key
+ * @return the configuration key
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ protected static String enumToConfKey(Class<?> implementingClass, Enum<?> e) {
+ return implementingClass.getSimpleName() + "." + e.getDeclaringClass().getSimpleName() + "." + StringUtils.camelize(e.name().toLowerCase());
+ }
+
+ /**
+ * Sets the connector information needed to communicate with Accumulo in this job.
+ *
+ * <p>
+ * <b>WARNING:</b> The serialized token is stored in the configuration and shared with all MapReduce tasks. It is BASE64 encoded to provide a charset safe
+ * conversion to a string, and is not intended to be secure.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param principal
+ * a valid Accumulo user name
+ * @param token
+ * the user's password
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setConnectorInfo(Class<?> implementingClass, Configuration conf, String principal, AuthenticationToken token)
+ throws AccumuloSecurityException {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.setConnectorInfo(implementingClass, conf, principal, token);
+ }
+
+ /**
+ * Determines if the connector info has already been set for this instance.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the connector info has already been set, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken)
+ */
+ @Deprecated
+ public static Boolean isConnectorInfoSet(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.isConnectorInfoSet(implementingClass, conf);
+ }
+
+ /**
+ * Gets the user name from the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the principal
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken)
+ */
+ @Deprecated
+ public static String getPrincipal(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.getPrincipal(implementingClass, conf);
+ }
+
+ /**
+ * DON'T USE THIS. No, really, don't use this. You already have an {@link AuthenticationToken} with
+ * {@link org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase#getAuthenticationToken(Class, Configuration)}. You don't need to construct it
+ * yourself.
+ * <p>
+ * Gets the serialized token class from the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the principal
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken)
+ */
+ @Deprecated
+ public static String getTokenClass(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.getAuthenticationToken(implementingClass, conf).getClass().getName();
+ }
+
+ /**
+ * DON'T USE THIS. No, really, don't use this. You already have an {@link AuthenticationToken} with
+ * {@link org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase#getAuthenticationToken(Class, Configuration)}. You don't need to construct it
+ * yourself.
+ * <p>
+ * Gets the password from the configuration. WARNING: The password is stored in the Configuration and shared with all MapReduce tasks; It is BASE64 encoded to
+ * provide a charset safe conversion to a string, and is not intended to be secure.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the decoded principal's authentication token
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setConnectorInfo(Class, Configuration, String, AuthenticationToken)
+ */
+ @Deprecated
+ public static byte[] getToken(Class<?> implementingClass, Configuration conf) {
+ return AuthenticationTokenSerializer.serialize(org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.getAuthenticationToken(
+ implementingClass, conf));
+ }
+
+ /**
+ * Configures a {@link ZooKeeperInstance} for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param instanceName
+ * the Accumulo instance name
+ * @param zooKeepers
+ * a comma-separated list of zookeeper servers
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setZooKeeperInstance(Class<?> implementingClass, Configuration conf, String instanceName, String zooKeepers) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.setZooKeeperInstance(implementingClass, conf,
+ new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
+ }
+
+ /**
+ * Configures a {@link org.apache.accumulo.core.client.mock.MockInstance} for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param instanceName
+ * the Accumulo instance name
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setMockInstance(Class<?> implementingClass, Configuration conf, String instanceName) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.setMockInstance(implementingClass, conf, instanceName);
+ }
+
+ /**
+ * Initializes an Accumulo {@link Instance} based on the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return an Accumulo instance
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setZooKeeperInstance(Class, Configuration, String, String)
+ */
+ @Deprecated
+ public static Instance getInstance(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.getInstance(implementingClass, conf);
+ }
+
+ /**
+ * Sets the log level for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param level
+ * the logging level
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setLogLevel(Class<?> implementingClass, Configuration conf, Level level) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.setLogLevel(implementingClass, conf, level);
+ }
+
+ /**
+ * Gets the log level from this configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the log level
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setLogLevel(Class, Configuration, Level)
+ */
+ @Deprecated
+ public static Level getLogLevel(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.ConfiguratorBase.getLogLevel(implementingClass, conf);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/FileOutputConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/FileOutputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/FileOutputConfigurator.java
new file mode 100644
index 0000000..b4f6b8a
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/FileOutputConfigurator.java
@@ -0,0 +1,170 @@
+/*
+ * 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.client.mapreduce.lib.util;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+@Deprecated
+public class FileOutputConfigurator extends ConfiguratorBase {
+
+ /**
+ * Configuration keys for {@link AccumuloConfiguration}.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum Opts {
+ ACCUMULO_PROPERTIES;
+ }
+
+ /**
+ * The supported Accumulo properties we set in this OutputFormat, that change the behavior of the RecordWriter.<br>
+ * These properties correspond to the supported public static setter methods available to this class.
+ *
+ * @param property
+ * the Accumulo property to check
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ protected static Boolean isSupportedAccumuloProperty(Property property) {
+ switch (property) {
+ case TABLE_FILE_COMPRESSION_TYPE:
+ case TABLE_FILE_COMPRESSED_BLOCK_SIZE:
+ case TABLE_FILE_BLOCK_SIZE:
+ case TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX:
+ case TABLE_FILE_REPLICATION:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * This helper method provides an AccumuloConfiguration object constructed from the Accumulo defaults, and overridden with Accumulo properties that have been
+ * stored in the Job's configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static AccumuloConfiguration getAccumuloConfiguration(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.getAccumuloConfiguration(implementingClass, conf);
+ }
+
+ /**
+ * Sets the compression type to use for data blocks. Specifying a compression may require additional libraries to be available to your Job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param compressionType
+ * one of "none", "gz", "lzo", or "snappy"
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setCompressionType(Class<?> implementingClass, Configuration conf, String compressionType) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.setCompressionType(implementingClass, conf, compressionType);
+ }
+
+ /**
+ * Sets the size for data blocks within each file.<br>
+ * Data blocks are a span of key/value pairs stored in the file that are compressed and indexed as a group.
+ *
+ * <p>
+ * Making this value smaller may increase seek performance, but at the cost of increasing the size of the indexes (which can also affect seek performance).
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param dataBlockSize
+ * the block size, in bytes
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setDataBlockSize(Class<?> implementingClass, Configuration conf, long dataBlockSize) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.setDataBlockSize(implementingClass, conf, dataBlockSize);
+ }
+
+ /**
+ * Sets the size for file blocks in the file system; file blocks are managed, and replicated, by the underlying file system.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param fileBlockSize
+ * the block size, in bytes
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setFileBlockSize(Class<?> implementingClass, Configuration conf, long fileBlockSize) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.setFileBlockSize(implementingClass, conf, fileBlockSize);
+ }
+
+ /**
+ * Sets the size for index blocks within each file; smaller blocks means a deeper index hierarchy within the file, while larger blocks mean a more shallow
+ * index hierarchy within the file. This can affect the performance of queries.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param indexBlockSize
+ * the block size, in bytes
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setIndexBlockSize(Class<?> implementingClass, Configuration conf, long indexBlockSize) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.setIndexBlockSize(implementingClass, conf, indexBlockSize);
+ }
+
+ /**
+ * Sets the file system replication factor for the resulting file, overriding the file system default.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param replication
+ * the number of replicas for produced files
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setReplication(Class<?> implementingClass, Configuration conf, int replication) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.FileOutputConfigurator.setReplication(implementingClass, conf, replication);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/InputConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/InputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/InputConfigurator.java
new file mode 100644
index 0000000..b85253c
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/InputConfigurator.java
@@ -0,0 +1,461 @@
+/*
+ * 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.client.mapreduce.lib.util;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.ClientSideIteratorScanner;
+import org.apache.accumulo.core.client.IsolatedScanner;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.impl.TabletLocator;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.Pair;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+@Deprecated
+public class InputConfigurator extends ConfiguratorBase {
+
+ /**
+ * Configuration keys for {@link Scanner}.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum ScanOpts {
+ TABLE_NAME, AUTHORIZATIONS, RANGES, COLUMNS, ITERATORS
+ }
+
+ /**
+ * Configuration keys for various features.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum Features {
+ AUTO_ADJUST_RANGES, SCAN_ISOLATION, USE_LOCAL_ITERATORS, SCAN_OFFLINE
+ }
+
+ /**
+ * Sets the name of the input table, over which this job will scan.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param tableName
+ * the table to use when the tablename is null in the write call
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setInputTableName(Class<?> implementingClass, Configuration conf, String tableName) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setInputTableName(implementingClass, conf, tableName);
+ }
+
+ /**
+ * Gets the table name from the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the table name
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setInputTableName(Class, Configuration, String)
+ */
+ @Deprecated
+ public static String getInputTableName(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getInputTableName(implementingClass, conf);
+ }
+
+ /**
+ * Sets the {@link Authorizations} used to scan. Must be a subset of the user's authorization. Defaults to the empty set.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param auths
+ * the user's authorizations
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setScanAuthorizations(Class<?> implementingClass, Configuration conf, Authorizations auths) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setScanAuthorizations(implementingClass, conf, auths);
+ }
+
+ /**
+ * Gets the authorizations to set for the scans from the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the Accumulo scan authorizations
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setScanAuthorizations(Class, Configuration, Authorizations)
+ */
+ @Deprecated
+ public static Authorizations getScanAuthorizations(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getScanAuthorizations(implementingClass, conf);
+ }
+
+ /**
+ * Sets the input ranges to scan for this job. If not set, the entire table will be scanned.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param ranges
+ * the ranges that will be mapped over
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setRanges(Class<?> implementingClass, Configuration conf, Collection<Range> ranges) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setRanges(implementingClass, conf, ranges);
+ }
+
+ /**
+ * Gets the ranges to scan over from a job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the ranges
+ * @throws IOException
+ * if the ranges have been encoded improperly
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setRanges(Class, Configuration, Collection)
+ */
+ @Deprecated
+ public static List<Range> getRanges(Class<?> implementingClass, Configuration conf) throws IOException {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getRanges(implementingClass, conf);
+ }
+
+ /**
+ * Restricts the columns that will be mapped over for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param columnFamilyColumnQualifierPairs
+ * a pair of {@link Text} objects corresponding to column family and column qualifier. If the column qualifier is null, the entire column family is
+ * selected. An empty set is the default and is equivalent to scanning the all columns.
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void fetchColumns(Class<?> implementingClass, Configuration conf, Collection<Pair<Text,Text>> columnFamilyColumnQualifierPairs) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.fetchColumns(implementingClass, conf, columnFamilyColumnQualifierPairs);
+ }
+
+ /**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ */
+ @Deprecated
+ public static String[] serializeColumns(Collection<Pair<Text,Text>> columnFamilyColumnQualifierPairs) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.serializeColumns(columnFamilyColumnQualifierPairs);
+ }
+
+ /**
+ * Gets the columns to be mapped over from this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return a set of columns
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #fetchColumns(Class, Configuration, Collection)
+ */
+ @Deprecated
+ public static Set<Pair<Text,Text>> getFetchedColumns(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getFetchedColumns(implementingClass, conf);
+ }
+
+ /**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ */
+ @Deprecated
+ public static Set<Pair<Text,Text>> deserializeFetchedColumns(Collection<String> serialized) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.deserializeFetchedColumns(serialized);
+ }
+
+ /**
+ * Encode an iterator on the input for this job.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param cfg
+ * the configuration of the iterator
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void addIterator(Class<?> implementingClass, Configuration conf, IteratorSetting cfg) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.addIterator(implementingClass, conf, cfg);
+ }
+
+ /**
+ * Gets a list of the iterator settings (for iterators to apply to a scanner) from this configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return a list of iterators
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #addIterator(Class, Configuration, IteratorSetting)
+ */
+ @Deprecated
+ public static List<IteratorSetting> getIterators(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getIterators(implementingClass, conf);
+ }
+
+ /**
+ * Controls the automatic adjustment of ranges for this job. This feature merges overlapping ranges, then splits them to align with tablet boundaries.
+ * Disabling this feature will cause exactly one Map task to be created for each specified range. The default setting is enabled. *
+ *
+ * <p>
+ * By default, this feature is <b>enabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @see #setRanges(Class, Configuration, Collection)
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setAutoAdjustRanges(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setAutoAdjustRanges(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether a configuration has auto-adjust ranges enabled.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return false if the feature is disabled, true otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setAutoAdjustRanges(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean getAutoAdjustRanges(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getAutoAdjustRanges(implementingClass, conf);
+ }
+
+ /**
+ * Controls the use of the {@link IsolatedScanner} in this job.
+ *
+ * <p>
+ * By default, this feature is <b>disabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setScanIsolation(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setScanIsolation(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether a configuration has isolation enabled.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the feature is enabled, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setScanIsolation(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean isIsolated(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.isIsolated(implementingClass, conf);
+ }
+
+ /**
+ * Controls the use of the {@link ClientSideIteratorScanner} in this job. Enabling this feature will cause the iterator stack to be constructed within the Map
+ * task, rather than within the Accumulo TServer. To use this feature, all classes needed for those iterators must be available on the classpath for the task.
+ *
+ * <p>
+ * By default, this feature is <b>disabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setLocalIterators(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setLocalIterators(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether a configuration uses local iterators.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the feature is enabled, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setLocalIterators(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean usesLocalIterators(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.usesLocalIterators(implementingClass, conf);
+ }
+
+ /**
+ * Enable reading offline tables. By default, this feature is disabled and only online tables are scanned. This will make the map reduce job directly read the
+ * table's files. If the table is not offline, then the job will fail. If the table comes online during the map reduce job, it is likely that the job will
+ * fail.
+ *
+ * <p>
+ * To use this option, the map reduce user will need access to read the Accumulo directory in HDFS.
+ *
+ * <p>
+ * Reading the offline table will create the scan time iterator stack in the map process. So any iterators that are configured for the table will need to be
+ * on the mapper's classpath. The accumulo-site.xml may need to be on the mapper's classpath if HDFS or the Accumulo directory in HDFS are non-standard.
+ *
+ * <p>
+ * One way to use this feature is to clone a table, take the clone offline, and use the clone as the input table for a map reduce job. If you plan to map
+ * reduce over the data many times, it may be better to the compact the table, clone it, take it offline, and use the clone for all map reduce jobs. The
+ * reason to do this is that compaction will reduce each tablet in the table to one file, and it is faster to read from one file.
+ *
+ * <p>
+ * There are two possible advantages to reading a tables file directly out of HDFS. First, you may see better read performance. Second, it will support
+ * speculative execution better. When reading an online table speculative execution can put more load on an already slow tablet server.
+ *
+ * <p>
+ * By default, this feature is <b>disabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setOfflineTableScan(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.setOfflineTableScan(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether a configuration has the offline table scan feature enabled.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the feature is enabled, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setOfflineTableScan(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean isOfflineScan(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.isOfflineScan(implementingClass, conf);
+ }
+
+ /**
+ * Initializes an Accumulo {@link TabletLocator} based on the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return an Accumulo tablet locator
+ * @throws TableNotFoundException
+ * if the table name set on the configuration doesn't exist
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static TabletLocator getTabletLocator(Class<?> implementingClass, Configuration conf) throws TableNotFoundException {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.getTabletLocator(implementingClass, conf,
+ Tables.getTableId(getInstance(implementingClass, conf), getInputTableName(implementingClass, conf)));
+ }
+
+ // InputFormat doesn't have the equivalent of OutputFormat's checkOutputSpecs(JobContext job)
+ /**
+ * Check whether a configuration is fully configured to be used with an Accumulo {@link org.apache.hadoop.mapreduce.InputFormat}.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @throws IOException
+ * if the context is improperly configured
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void validateOptions(Class<?> implementingClass, Configuration conf) throws IOException {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.InputConfigurator.validateOptions(implementingClass, conf);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/OutputConfigurator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/OutputConfigurator.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/OutputConfigurator.java
new file mode 100644
index 0000000..39163a6
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/OutputConfigurator.java
@@ -0,0 +1,196 @@
+/*
+ * 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.client.mapreduce.lib.util;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+@Deprecated
+public class OutputConfigurator extends ConfiguratorBase {
+
+ /**
+ * Configuration keys for {@link BatchWriter}.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum WriteOpts {
+ DEFAULT_TABLE_NAME, BATCH_WRITER_CONFIG
+ }
+
+ /**
+ * Configuration keys for various features.
+ *
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static enum Features {
+ CAN_CREATE_TABLES, SIMULATION_MODE
+ }
+
+ /**
+ * Sets the default table name to use if one emits a null in place of a table name for a given mutation. Table names can only be alpha-numeric and
+ * underscores.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param tableName
+ * the table to use when the tablename is null in the write call
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setDefaultTableName(Class<?> implementingClass, Configuration conf, String tableName) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.setDefaultTableName(implementingClass, conf, tableName);
+ }
+
+ /**
+ * Gets the default table name from the configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the default table name
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setDefaultTableName(Class, Configuration, String)
+ */
+ @Deprecated
+ public static String getDefaultTableName(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.getDefaultTableName(implementingClass, conf);
+ }
+
+ /**
+ * Sets the configuration for for the job's {@link BatchWriter} instances. If not set, a new {@link BatchWriterConfig}, with sensible built-in defaults is
+ * used. Setting the configuration multiple times overwrites any previous configuration.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param bwConfig
+ * the configuration for the {@link BatchWriter}
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setBatchWriterOptions(Class<?> implementingClass, Configuration conf, BatchWriterConfig bwConfig) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.setBatchWriterOptions(implementingClass, conf, bwConfig);
+ }
+
+ /**
+ * Gets the {@link BatchWriterConfig} settings.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return the configuration object
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setBatchWriterOptions(Class, Configuration, BatchWriterConfig)
+ */
+ @Deprecated
+ public static BatchWriterConfig getBatchWriterOptions(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.getBatchWriterOptions(implementingClass, conf);
+ }
+
+ /**
+ * Sets the directive to create new tables, as necessary. Table names can only be alpha-numeric and underscores.
+ *
+ * <p>
+ * By default, this feature is <b>disabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setCreateTables(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.setCreateTables(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether tables are permitted to be created as needed.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the feature is disabled, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setCreateTables(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean canCreateTables(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.canCreateTables(implementingClass, conf);
+ }
+
+ /**
+ * Sets the directive to use simulation mode for this job. In simulation mode, no output is produced. This is useful for testing.
+ *
+ * <p>
+ * By default, this feature is <b>disabled</b>.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @param enableFeature
+ * the feature is enabled if true, disabled otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ */
+ @Deprecated
+ public static void setSimulationMode(Class<?> implementingClass, Configuration conf, boolean enableFeature) {
+ org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.setSimulationMode(implementingClass, conf, enableFeature);
+ }
+
+ /**
+ * Determines whether this feature is enabled.
+ *
+ * @param implementingClass
+ * the class whose name will be used as a prefix for the property configuration key
+ * @param conf
+ * the Hadoop configuration object to configure
+ * @return true if the feature is enabled, false otherwise
+ * @deprecated since 1.6.0; Configure your job with the appropriate InputFormat or OutputFormat.
+ * @since 1.5.0
+ * @see #setSimulationMode(Class, Configuration, boolean)
+ */
+ @Deprecated
+ public static Boolean getSimulationMode(Class<?> implementingClass, Configuration conf) {
+ return org.apache.accumulo.core.client.mapreduce.lib.impl.OutputConfigurator.getSimulationMode(implementingClass, conf);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/package-info.java b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/package-info.java
new file mode 100644
index 0000000..269ffea
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mapreduce/lib/util/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ * @deprecated since 1.6.0; This package was moved out of the public API.
+ * @since 1.5.0
+ */
+package org.apache.accumulo.core.client.mapreduce.lib.util;
+
[3/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
new file mode 100644
index 0000000..58f3777
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
@@ -0,0 +1,345 @@
+/*
+ * 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.client.mock;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+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.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.file.FileOperations;
+import org.apache.accumulo.core.file.FileSKVWriter;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.user.VersioningIterator;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.ColumnVisibility;
+import org.apache.accumulo.core.util.Pair;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import com.google.common.collect.Iterators;
+
+@Deprecated
+public class MockTableOperationsTest {
+
+ @Rule
+ public TestName test = new TestName();
+
+ private Connector conn;
+
+ @Before
+ public void setupInstance() throws Exception {
+ Instance inst = new MockInstance(test.getMethodName());
+ conn = inst.getConnector("user", new PasswordToken("pass"));
+ }
+
+ @Test
+ public void testCreateUseVersions() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
+ String t = "tableName1";
+
+ {
+ conn.tableOperations().create(t, new NewTableConfiguration().withoutDefaultIterators().setTimeType(TimeType.LOGICAL));
+
+ writeVersionable(conn, t, 3);
+ assertVersionable(conn, t, 3);
+
+ IteratorSetting settings = new IteratorSetting(20, VersioningIterator.class);
+ conn.tableOperations().attachIterator(t, settings);
+
+ assertVersionable(conn, t, 1);
+
+ conn.tableOperations().delete(t);
+ }
+
+ {
+ conn.tableOperations().create(t, new NewTableConfiguration().setTimeType(TimeType.MILLIS));
+
+ try {
+ IteratorSetting settings = new IteratorSetting(20, VersioningIterator.class);
+ conn.tableOperations().attachIterator(t, settings);
+ Assert.fail();
+ } catch (AccumuloException ex) {}
+
+ writeVersionable(conn, t, 3);
+ assertVersionable(conn, t, 1);
+
+ conn.tableOperations().delete(t);
+ }
+ }
+
+ protected void writeVersionable(Connector c, String tableName, int size) throws TableNotFoundException, MutationsRejectedException {
+ for (int i = 0; i < size; i++) {
+ BatchWriter w = c.createBatchWriter(tableName, new BatchWriterConfig());
+ Mutation m = new Mutation("row1");
+ m.put("cf", "cq", String.valueOf(i));
+ w.addMutation(m);
+ w.close();
+ }
+ }
+
+ protected void assertVersionable(Connector c, String tableName, int size) throws TableNotFoundException {
+ BatchScanner s = c.createBatchScanner(tableName, Authorizations.EMPTY, 1);
+ s.setRanges(Collections.singleton(Range.exact("row1", "cf", "cq")));
+ int count = 0;
+ for (Map.Entry<Key,Value> e : s) {
+ Assert.assertEquals("row1", e.getKey().getRow().toString());
+ Assert.assertEquals("cf", e.getKey().getColumnFamily().toString());
+ Assert.assertEquals("cq", e.getKey().getColumnQualifier().toString());
+ count++;
+
+ }
+ Assert.assertEquals(size, count);
+ s.close();
+ }
+
+ @Test
+ public void testTableNotFound() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
+ IteratorSetting setting = new IteratorSetting(100, "myvers", VersioningIterator.class);
+ String t = "tableName";
+ try {
+ conn.tableOperations().attachIterator(t, setting);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().checkIteratorConflicts(t, setting, EnumSet.allOf(IteratorScope.class));
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().delete(t);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().getIteratorSetting(t, "myvers", IteratorScope.scan);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().getProperties(t);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().listSplits(t);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().listIterators(t);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().removeIterator(t, null, EnumSet.noneOf(IteratorScope.class));
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ try {
+ conn.tableOperations().rename(t, t);
+ Assert.fail();
+ } catch (TableNotFoundException e) {}
+ conn.tableOperations().create(t);
+ try {
+ conn.tableOperations().create(t);
+ Assert.fail();
+ } catch (TableExistsException e) {}
+ try {
+ conn.tableOperations().rename(t, t);
+ Assert.fail();
+ } catch (TableExistsException e) {}
+ }
+
+ private static class ImportTestFilesAndData {
+ Path importPath;
+ Path failurePath;
+ List<Pair<Key,Value>> keyVals;
+ }
+
+ @Test
+ public void testImport() throws Throwable {
+ ImportTestFilesAndData dataAndFiles = prepareTestFiles();
+ TableOperations tableOperations = conn.tableOperations();
+ tableOperations.create("a_table");
+ tableOperations.importDirectory("a_table", dataAndFiles.importPath.toString(), dataAndFiles.failurePath.toString(), false);
+ Scanner scanner = conn.createScanner("a_table", new Authorizations());
+ Iterator<Entry<Key,Value>> iterator = scanner.iterator();
+ for (int i = 0; i < 5; i++) {
+ Assert.assertTrue(iterator.hasNext());
+ Entry<Key,Value> kv = iterator.next();
+ Pair<Key,Value> expected = dataAndFiles.keyVals.get(i);
+ Assert.assertEquals(expected.getFirst(), kv.getKey());
+ Assert.assertEquals(expected.getSecond(), kv.getValue());
+ }
+ Assert.assertFalse(iterator.hasNext());
+ }
+
+ private ImportTestFilesAndData prepareTestFiles() throws Throwable {
+ Configuration defaultConf = new Configuration();
+ Path tempFile = new Path("target/accumulo-test/import/sample.rf");
+ Path failures = new Path("target/accumulo-test/failures/");
+ FileSystem fs = FileSystem.get(new URI("file:///"), defaultConf);
+ fs.deleteOnExit(tempFile);
+ fs.deleteOnExit(failures);
+ fs.delete(failures, true);
+ fs.delete(tempFile, true);
+ fs.mkdirs(failures);
+ fs.mkdirs(tempFile.getParent());
+ FileSKVWriter writer = FileOperations.getInstance().newWriterBuilder().forFile(tempFile.toString(), fs, defaultConf)
+ .withTableConfiguration(AccumuloConfiguration.getDefaultConfiguration()).build();
+ writer.startDefaultLocalityGroup();
+ List<Pair<Key,Value>> keyVals = new ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ keyVals.add(new Pair<>(new Key("a" + i, "b" + i, "c" + i, new ColumnVisibility(""), 1000l + i), new Value(Integer.toString(i).getBytes())));
+ }
+ for (Pair<Key,Value> keyVal : keyVals) {
+ writer.append(keyVal.getFirst(), keyVal.getSecond());
+ }
+ writer.close();
+ ImportTestFilesAndData files = new ImportTestFilesAndData();
+ files.failurePath = failures;
+ files.importPath = tempFile.getParent();
+ files.keyVals = keyVals;
+ return files;
+ }
+
+ @Test(expected = TableNotFoundException.class)
+ public void testFailsWithNoTable() throws Throwable {
+ TableOperations tableOperations = conn.tableOperations();
+ ImportTestFilesAndData testFiles = prepareTestFiles();
+ tableOperations.importDirectory("doesnt_exist_table", testFiles.importPath.toString(), testFiles.failurePath.toString(), false);
+ }
+
+ @Test(expected = IOException.class)
+ public void testFailsWithNonEmptyFailureDirectory() throws Throwable {
+ TableOperations tableOperations = conn.tableOperations();
+ ImportTestFilesAndData testFiles = prepareTestFiles();
+ FileSystem fs = testFiles.failurePath.getFileSystem(new Configuration());
+ fs.open(testFiles.failurePath.suffix("/something")).close();
+ tableOperations.importDirectory("doesnt_exist_table", testFiles.importPath.toString(), testFiles.failurePath.toString(), false);
+ }
+
+ @Test
+ public void testDeleteRows() throws Exception {
+ TableOperations to = conn.tableOperations();
+ to.create("test");
+ BatchWriter bw = conn.createBatchWriter("test", new BatchWriterConfig());
+ for (int r = 0; r < 20; r++) {
+ Mutation m = new Mutation("" + r);
+ for (int c = 0; c < 5; c++) {
+ m.put(new Text("cf"), new Text("" + c), new Value(("" + c).getBytes()));
+ }
+ bw.addMutation(m);
+ }
+ bw.flush();
+ to.deleteRows("test", new Text("1"), new Text("2"));
+ Scanner s = conn.createScanner("test", Authorizations.EMPTY);
+ int oneCnt = 0;
+ for (Entry<Key,Value> entry : s) {
+ char rowStart = entry.getKey().getRow().toString().charAt(0);
+ Assert.assertTrue(rowStart != '2');
+ oneCnt += rowStart == '1' ? 1 : 0;
+ }
+ Assert.assertEquals(5, oneCnt);
+ }
+
+ @Test
+ public void testDeleteRowsWithNullKeys() throws Exception {
+ TableOperations to = conn.tableOperations();
+ to.create("test2");
+ BatchWriter bw = conn.createBatchWriter("test2", new BatchWriterConfig());
+ for (int r = 0; r < 30; r++) {
+ Mutation m = new Mutation(Integer.toString(r));
+ for (int c = 0; c < 5; c++) {
+ m.put(new Text("cf"), new Text(Integer.toString(c)), new Value(Integer.toString(c).getBytes()));
+ }
+ bw.addMutation(m);
+ }
+ bw.flush();
+
+ // test null end
+ // will remove rows 4 through 9 (6 * 5 = 30 entries)
+ to.deleteRows("test2", new Text("30"), null);
+ Scanner s = conn.createScanner("test2", Authorizations.EMPTY);
+ int rowCnt = 0;
+ for (Entry<Key,Value> entry : s) {
+ String rowId = entry.getKey().getRow().toString();
+ Assert.assertFalse(rowId.startsWith("30"));
+ rowCnt++;
+ }
+ s.close();
+ Assert.assertEquals(120, rowCnt);
+
+ // test null start
+ // will remove 0-1, 10-19, 2
+ to.deleteRows("test2", null, new Text("2"));
+ s = conn.createScanner("test2", Authorizations.EMPTY);
+ rowCnt = 0;
+ for (Entry<Key,Value> entry : s) {
+ char rowStart = entry.getKey().getRow().toString().charAt(0);
+ Assert.assertTrue(rowStart >= '2');
+ rowCnt++;
+ }
+ s.close();
+ Assert.assertEquals(55, rowCnt);
+
+ // test null start and end
+ // deletes everything still left
+ to.deleteRows("test2", null, null);
+ s = conn.createScanner("test2", Authorizations.EMPTY);
+ rowCnt = Iterators.size(s.iterator());
+ s.close();
+ to.delete("test2");
+ Assert.assertEquals(0, rowCnt);
+
+ }
+
+ @Test
+ public void testTableIdMap() throws Exception {
+ TableOperations tops = conn.tableOperations();
+ tops.create("foo");
+
+ // Should get a table ID, not the table name
+ Assert.assertNotEquals("foo", tops.tableIdMap().get("foo"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mock/TestBatchScanner821.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/TestBatchScanner821.java b/core/src/test/java/org/apache/accumulo/core/client/mock/TestBatchScanner821.java
new file mode 100644
index 0000000..4f041c9
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/TestBatchScanner821.java
@@ -0,0 +1,77 @@
+/*
+ * 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.client.mock;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.WrappingIterator;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+
+@Deprecated
+public class TestBatchScanner821 {
+
+ public static class TransformIterator extends WrappingIterator {
+
+ @Override
+ public Key getTopKey() {
+ Key k = getSource().getTopKey();
+ return new Key(new Text(k.getRow().toString().toLowerCase()), k.getColumnFamily(), k.getColumnQualifier(), k.getColumnVisibility(), k.getTimestamp());
+ }
+ }
+
+ @Test
+ public void test() throws Exception {
+ MockInstance inst = new MockInstance();
+ Connector conn = inst.getConnector("root", new PasswordToken(""));
+ conn.tableOperations().create("test");
+ BatchWriter bw = conn.createBatchWriter("test", new BatchWriterConfig());
+ for (String row : "A,B,C,D".split(",")) {
+ Mutation m = new Mutation(row);
+ m.put("cf", "cq", "");
+ bw.addMutation(m);
+ }
+ bw.flush();
+ BatchScanner bs = conn.createBatchScanner("test", Authorizations.EMPTY, 1);
+ IteratorSetting cfg = new IteratorSetting(100, TransformIterator.class);
+ bs.addScanIterator(cfg);
+ bs.setRanges(Collections.singletonList(new Range("A", "Z")));
+ StringBuilder sb = new StringBuilder();
+ String comma = "";
+ for (Entry<Key,Value> entry : bs) {
+ sb.append(comma);
+ sb.append(entry.getKey().getRow());
+ comma = ",";
+ }
+ assertEquals("a,b,c,d", sb.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java b/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java
index 0bff486..79968be 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/KeyExtentTest.java
@@ -16,9 +16,13 @@
*/
package org.apache.accumulo.core.data;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
@@ -26,6 +30,9 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -285,6 +292,57 @@ public class KeyExtentTest {
return out;
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testKeyExtentsForSimpleRange() {
+ Collection<KeyExtent> results;
+
+ results = KeyExtent.getKeyExtentsForRange(null, null, null);
+ assertTrue("Non-empty set returned from no extents", results.isEmpty());
+
+ results = KeyExtent.getKeyExtentsForRange(null, null, Collections.<KeyExtent> emptySet());
+ assertTrue("Non-empty set returned from no extents", results.isEmpty());
+
+ KeyExtent t = nke("t", null, null);
+ results = KeyExtent.getKeyExtentsForRange(null, null, Collections.<KeyExtent> singleton(t));
+ assertEquals("Single tablet should always be returned", 1, results.size());
+ assertEquals(t, results.iterator().next());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testKeyExtentsForRange() {
+ KeyExtent b = nke("t", "b", null);
+ KeyExtent e = nke("t", "e", "b");
+ KeyExtent h = nke("t", "h", "e");
+ KeyExtent m = nke("t", "m", "h");
+ KeyExtent z = nke("t", null, "m");
+
+ set0.addAll(Arrays.asList(b, e, h, m, z));
+
+ Collection<KeyExtent> results;
+
+ results = KeyExtent.getKeyExtentsForRange(null, null, set0);
+ assertThat("infinite range should return full set", results.size(), is(5));
+ assertThat("infinite range should return full set", results, hasItems(b, e, h, m, z));
+
+ results = KeyExtent.getKeyExtentsForRange(new Text("a"), new Text("z"), set0);
+ assertThat("full overlap should return full set", results.size(), is(5));
+ assertThat("full overlap should return full set", results, hasItems(b, e, h, m, z));
+
+ results = KeyExtent.getKeyExtentsForRange(null, new Text("f"), set0);
+ assertThat("end row should return head set", results.size(), is(3));
+ assertThat("end row should return head set", results, hasItems(b, e, h));
+
+ results = KeyExtent.getKeyExtentsForRange(new Text("f"), null, set0);
+ assertThat("start row should return tail set", results.size(), is(3));
+ assertThat("start row should return tail set", results, hasItems(h, m, z));
+
+ results = KeyExtent.getKeyExtentsForRange(new Text("f"), new Text("g"), set0);
+ assertThat("slice should return correct subset", results.size(), is(1));
+ assertThat("slice should return correct subset", results, hasItem(h));
+ }
+
@Test
public void testDecodeEncode() {
assertNull(KeyExtent.decodePrevEndRow(KeyExtent.encodePrevEndRow(null)));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java b/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java
index 0c0042b..93fab1f 100644
--- a/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/ValueTest.java
@@ -33,6 +33,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
+import java.util.List;
import org.apache.hadoop.io.Text;
import org.junit.Before;
@@ -102,6 +103,13 @@ public class ValueTest {
}
@Test
+ public void testByteBufferCopy() {
+ @SuppressWarnings("deprecation")
+ Value v = new Value(DATABUFF, true);
+ assertArrayEquals(DATA, v.get());
+ }
+
+ @Test
public void testValueCopy() {
Value ov = createMock(Value.class);
expect(ov.get()).andReturn(DATA);
@@ -192,6 +200,24 @@ public class ValueTest {
}
@Test
+ @Deprecated
+ public void testToArray() {
+ List<byte[]> l = new java.util.ArrayList<>();
+ byte[] one = toBytes("one");
+ byte[] two = toBytes("two");
+ byte[] three = toBytes("three");
+ l.add(one);
+ l.add(two);
+ l.add(three);
+
+ byte[][] a = Value.toArray(l);
+ assertEquals(3, a.length);
+ assertArrayEquals(one, a[0]);
+ assertArrayEquals(two, a[1]);
+ assertArrayEquals(three, a[2]);
+ }
+
+ @Test
public void testString() {
Value v1 = new Value("abc");
Value v2 = new Value("abc".getBytes(UTF_8));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java
new file mode 100644
index 0000000..09064a5
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java
@@ -0,0 +1,471 @@
+/*
+ * 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.iterators;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.system.MultiIterator;
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+
+public class AggregatingIteratorTest {
+
+ private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<>();
+
+ /**
+ * @deprecated since 1.4; visible only for testing
+ */
+ @Deprecated
+ public static class SummationAggregator implements org.apache.accumulo.core.iterators.aggregation.Aggregator {
+
+ int sum;
+
+ @Override
+ public Value aggregate() {
+ return new Value((sum + "").getBytes());
+ }
+
+ @Override
+ public void collect(Value value) {
+ int val = Integer.parseInt(value.toString());
+
+ sum += val;
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+
+ }
+
+ }
+
+ static Key nk(int row, int colf, int colq, long ts, boolean deleted) {
+ Key k = nk(row, colf, colq, ts);
+ k.setDeleted(true);
+ return k;
+ }
+
+ static Key nk(int row, int colf, int colq, long ts) {
+ return new Key(nr(row), new Text(String.format("cf%03d", colf)), new Text(String.format("cq%03d", colq)), ts);
+ }
+
+ static Range nr(int row, int colf, int colq, long ts, boolean inclusive) {
+ return new Range(nk(row, colf, colq, ts), inclusive, null, true);
+ }
+
+ static Range nr(int row, int colf, int colq, long ts) {
+ return nr(row, colf, colq, ts, true);
+ }
+
+ static void nkv(TreeMap<Key,Value> tm, int row, int colf, int colq, long ts, boolean deleted, String val) {
+ Key k = nk(row, colf, colq, ts);
+ k.setDeleted(deleted);
+ tm.put(k, new Value(val.getBytes()));
+ }
+
+ static Text nr(int row) {
+ return new Text(String.format("r%03d", row));
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test1() throws IOException {
+
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ // keys that do not aggregate
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+ nkv(tm1, 1, 1, 1, 2, false, "3");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> emptyMap = Collections.emptyMap();
+ ai.init(new SortedMapIterator(tm1), emptyMap, null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("4", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 1), ai.getTopKey());
+ assertEquals("2", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // try seeking
+
+ ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 1), ai.getTopKey());
+ assertEquals("2", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // seek after everything
+ ai.seek(nr(1, 1, 1, 0), EMPTY_COL_FAMS, false);
+
+ assertFalse(ai.hasTop());
+
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test2() throws IOException {
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ // keys that aggregate
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+ nkv(tm1, 1, 1, 1, 2, false, "3");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> opts = new HashMap<>();
+
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ ai.init(new SortedMapIterator(tm1), opts, null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // try seeking to the beginning of a key that aggregates
+
+ ai.seek(nr(1, 1, 1, 3), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // try seeking the middle of a key the aggregates
+ ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false);
+
+ assertFalse(ai.hasTop());
+
+ // try seeking to the end of a key the aggregates
+ ai.seek(nr(1, 1, 1, 1), EMPTY_COL_FAMS, false);
+
+ assertFalse(ai.hasTop());
+
+ // try seeking before a key the aggregates
+ ai.seek(nr(1, 1, 1, 4), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test3() throws IOException {
+
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ // keys that aggregate
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+ nkv(tm1, 1, 1, 1, 2, false, "3");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+
+ // keys that do not aggregate
+ nkv(tm1, 2, 2, 1, 1, false, "2");
+ nkv(tm1, 2, 2, 1, 2, false, "3");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> opts = new HashMap<>();
+
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ ai.init(new SortedMapIterator(tm1), opts, null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 1), ai.getTopKey());
+ assertEquals("2", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // seek after key that aggregates
+ ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ // seek before key that aggregates
+ ai.seek(nr(1, 1, 1, 4), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test4() throws IOException {
+
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ // keys that do not aggregate
+ nkv(tm1, 0, 0, 1, 1, false, "7");
+
+ // keys that aggregate
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+ nkv(tm1, 1, 1, 1, 2, false, "3");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+
+ // keys that do not aggregate
+ nkv(tm1, 2, 2, 1, 1, false, "2");
+ nkv(tm1, 2, 2, 1, 2, false, "3");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> opts = new HashMap<>();
+
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ ai.init(new SortedMapIterator(tm1), opts, null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(0, 0, 1, 1), ai.getTopKey());
+ assertEquals("7", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 1), ai.getTopKey());
+ assertEquals("2", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertFalse(ai.hasTop());
+
+ // seek test
+ ai.seek(nr(0, 0, 1, 0), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+
+ ai.next();
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ // seek after key that aggregates
+ ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(2, 2, 1, 2), ai.getTopKey());
+ assertEquals("3", ai.getTopValue().toString());
+
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test5() throws IOException {
+ // try aggregating across multiple data sets that contain
+ // the exact same keys w/ different values
+
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+
+ TreeMap<Key,Value> tm2 = new TreeMap<>();
+ nkv(tm2, 1, 1, 1, 1, false, "3");
+
+ TreeMap<Key,Value> tm3 = new TreeMap<>();
+ nkv(tm3, 1, 1, 1, 1, false, "4");
+
+ AggregatingIterator ai = new AggregatingIterator();
+ Map<String,String> opts = new HashMap<>();
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ List<SortedKeyValueIterator<Key,Value>> sources = new ArrayList<>(3);
+ sources.add(new SortedMapIterator(tm1));
+ sources.add(new SortedMapIterator(tm2));
+ sources.add(new SortedMapIterator(tm3));
+
+ MultiIterator mi = new MultiIterator(sources, true);
+ ai.init(mi, opts, null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 1), ai.getTopKey());
+ assertEquals("9", ai.getTopValue().toString());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test6() throws IOException {
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ // keys that aggregate
+ nkv(tm1, 1, 1, 1, 1, false, "2");
+ nkv(tm1, 1, 1, 1, 2, false, "3");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> opts = new HashMap<>();
+
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment());
+
+ // try seeking to the beginning of a key that aggregates
+
+ ai.seek(nr(1, 1, 1, 3, false), EMPTY_COL_FAMS, false);
+
+ assertFalse(ai.hasTop());
+
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test7() throws IOException {
+ // test that delete is not aggregated
+
+ TreeMap<Key,Value> tm1 = new TreeMap<>();
+
+ nkv(tm1, 1, 1, 1, 2, true, "");
+ nkv(tm1, 1, 1, 1, 3, false, "4");
+ nkv(tm1, 1, 1, 1, 4, false, "3");
+
+ AggregatingIterator ai = new AggregatingIterator();
+
+ Map<String,String> opts = new HashMap<>();
+
+ opts.put("cf001", SummationAggregator.class.getName());
+
+ ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment());
+
+ ai.seek(nr(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 4), ai.getTopKey());
+ assertEquals("7", ai.getTopValue().toString());
+
+ ai.next();
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 2, true), ai.getTopKey());
+ assertEquals("", ai.getTopValue().toString());
+
+ ai.next();
+ assertFalse(ai.hasTop());
+
+ tm1 = new TreeMap<>();
+ nkv(tm1, 1, 1, 1, 2, true, "");
+ ai = new AggregatingIterator();
+ ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment());
+
+ ai.seek(nr(1, 1, 1, 4, true), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(nk(1, 1, 1, 2, true), ai.getTopKey());
+ assertEquals("", ai.getTopValue().toString());
+
+ ai.next();
+ assertFalse(ai.hasTop());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java
new file mode 100644
index 0000000..5a56ead
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.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.iterators.aggregation;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.data.Value;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @deprecated since 1.4
+ */
+@Deprecated
+public class NumSummationTest {
+
+ private static final Logger log = LoggerFactory.getLogger(NumSummationTest.class);
+
+ public byte[] init(int n) {
+ byte[] b = new byte[n];
+ for (int i = 0; i < b.length; i++)
+ b[i] = 0;
+ return b;
+ }
+
+ @Test
+ public void test1() {
+ try {
+ long[] la = {1l, 2l, 3l};
+ byte[] b = NumArraySummation.longArrayToBytes(la);
+ long[] la2 = NumArraySummation.bytesToLongArray(b);
+
+ assertTrue(la.length == la2.length);
+ for (int i = 0; i < la.length; i++) {
+ assertTrue(i + ": " + la[i] + " does not equal " + la2[i], la[i] == la2[i]);
+ }
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void test2() {
+ try {
+ NumArraySummation nas = new NumArraySummation();
+ long[] la = {1l, 2l, 3l};
+ nas.collect(new Value(NumArraySummation.longArrayToBytes(la)));
+ long[] la2 = {3l, 2l, 1l, 0l};
+ nas.collect(new Value(NumArraySummation.longArrayToBytes(la2)));
+ la = NumArraySummation.bytesToLongArray(nas.aggregate().get());
+ assertTrue(la.length == 4);
+ for (int i = 0; i < la.length - 1; i++) {
+ assertTrue(la[i] == 4);
+ }
+ assertTrue(la[la.length - 1] == 0);
+ nas.reset();
+ la = NumArraySummation.bytesToLongArray(nas.aggregate().get());
+ assertTrue(la.length == 0);
+ } catch (Exception e) {
+ log.error("{}", e.getMessage(), e);
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void test3() {
+ try {
+ NumArraySummation nas = new NumArraySummation();
+ long[] la = {Long.MAX_VALUE, Long.MIN_VALUE, 3l, -5l, 5l, 5l};
+ nas.collect(new Value(NumArraySummation.longArrayToBytes(la)));
+ long[] la2 = {1l, -3l, 2l, 10l};
+ nas.collect(new Value(NumArraySummation.longArrayToBytes(la2)));
+ la = NumArraySummation.bytesToLongArray(nas.aggregate().get());
+ assertTrue(la.length == 6);
+ for (int i = 2; i < la.length; i++) {
+ assertTrue(la[i] == 5);
+ }
+ assertTrue("max long plus one was " + la[0], la[0] == Long.MAX_VALUE);
+ assertTrue("min long minus 3 was " + la[1], la[1] == Long.MIN_VALUE);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void test4() {
+ try {
+ long l = 5l;
+ byte[] b = NumSummation.longToBytes(l);
+ long l2 = NumSummation.bytesToLong(b);
+
+ assertTrue(l == l2);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void test5() {
+ try {
+ NumSummation ns = new NumSummation();
+ for (long l = -5l; l < 8l; l++) {
+ ns.collect(new Value(NumSummation.longToBytes(l)));
+ }
+ long l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == 13);
+
+ ns.collect(new Value(NumSummation.longToBytes(Long.MAX_VALUE)));
+ l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == Long.MAX_VALUE);
+
+ ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE)));
+ l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == -1);
+
+ ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE)));
+ l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == Long.MIN_VALUE);
+
+ ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE)));
+ l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == Long.MIN_VALUE);
+
+ ns.reset();
+ l = NumSummation.bytesToLong(ns.aggregate().get());
+ assertTrue("l was " + l, l == 0);
+ } catch (IOException | RuntimeException e) {
+ fail();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java
new file mode 100644
index 0000000..61693ab
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.iterators.aggregation.conf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.hadoop.io.Text;
+import org.junit.Test;
+
+public class AggregatorConfigurationTest {
+
+ @Test
+ public void testBinary() {
+ Text colf = new Text();
+ Text colq = new Text();
+
+ for (int i = 0; i < 256; i++) {
+ colf.append(new byte[] {(byte) i}, 0, 1);
+ colq.append(new byte[] {(byte) (255 - i)}, 0, 1);
+ }
+
+ runTest(colf, colq);
+ runTest(colf);
+ }
+
+ @Test
+ public void testBasic() {
+ runTest(new Text("colf1"), new Text("cq2"));
+ runTest(new Text("colf1"));
+ }
+
+ @SuppressWarnings("deprecation")
+ private void runTest(Text colf) {
+ String encodedCols;
+ org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig ac3 = new org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig(colf,
+ "com.foo.SuperAgg");
+ encodedCols = ac3.encodeColumns();
+ org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig ac4 = org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig.decodeColumns(
+ encodedCols, "com.foo.SuperAgg");
+
+ assertEquals(colf, ac4.getColumnFamily());
+ assertNull(ac4.getColumnQualifier());
+ }
+
+ @SuppressWarnings("deprecation")
+ private void runTest(Text colf, Text colq) {
+ org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig ac = new org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig(colf, colq,
+ "com.foo.SuperAgg");
+ String encodedCols = ac.encodeColumns();
+ org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig ac2 = org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig.decodeColumns(
+ encodedCols, "com.foo.SuperAgg");
+
+ assertEquals(colf, ac2.getColumnFamily());
+ assertEquals(colq, ac2.getColumnQualifier());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
index 6546352..b26c218 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java
@@ -258,7 +258,7 @@ public class FilterTest {
Text colf = new Text("a");
Text colq = new Text("b");
Value dv = new Value();
- TreeMap<Key,Value> tm = new TreeMap<Key,Value>();
+ TreeMap<Key,Value> tm = new TreeMap<>();
IteratorSetting is = new IteratorSetting(1, ColumnAgeOffFilter.class);
ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("a"), 901l);
ColumnAgeOffFilter.setNegate(is, true);
@@ -299,7 +299,7 @@ public class FilterTest {
Text colf = new Text("negate");
Text colq = new Text("b");
Value dv = new Value();
- TreeMap<Key,Value> tm = new TreeMap<Key,Value>();
+ TreeMap<Key,Value> tm = new TreeMap<>();
IteratorSetting is = new IteratorSetting(1, ColumnAgeOffFilter.class);
ColumnAgeOffFilter.addTTL(is, new IteratorSetting.Column("negate"), 901l);
long ts = System.currentTimeMillis();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java b/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java
index 8422c6f..bd4b1ba 100644
--- a/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/security/CredentialsTest.java
@@ -25,7 +25,9 @@ import static org.junit.Assert.fail;
import javax.security.auth.DestroyFailedException;
+import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
@@ -33,6 +35,7 @@ import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Authe
import org.apache.accumulo.core.client.security.tokens.NullToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.security.thrift.TCredentials;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Rule;
@@ -83,6 +86,24 @@ public class CredentialsTest {
}
@Test
+ public void testMockConnector() throws AccumuloException, DestroyFailedException, AccumuloSecurityException {
+ Instance inst = DeprecationUtil.makeMockInstance(test.getMethodName());
+ Connector rootConnector = inst.getConnector("root", new PasswordToken());
+ PasswordToken testToken = new PasswordToken("testPass");
+ rootConnector.securityOperations().createLocalUser("testUser", testToken);
+
+ assertFalse(testToken.isDestroyed());
+ testToken.destroy();
+ assertTrue(testToken.isDestroyed());
+ try {
+ inst.getConnector("testUser", testToken);
+ fail();
+ } catch (AccumuloSecurityException e) {
+ assertTrue(e.getSecurityErrorCode().equals(SecurityErrorCode.TOKEN_EXPIRED));
+ }
+ }
+
+ @Test
public void testEqualsAndHashCode() {
Credentials nullNullCreds = new Credentials(null, null);
Credentials abcNullCreds = new Credentials("abc", new NullToken());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/util/format/DateStringFormatterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/format/DateStringFormatterTest.java b/core/src/test/java/org/apache/accumulo/core/util/format/DateStringFormatterTest.java
new file mode 100644
index 0000000..22af5b0
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/format/DateStringFormatterTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.format;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.TreeMap;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("deprecation")
+public class DateStringFormatterTest {
+ DateStringFormatter formatter;
+
+ Map<Key,Value> data;
+
+ @Before
+ public void setUp() {
+ formatter = new DateStringFormatter();
+ data = new TreeMap<>();
+ data.put(new Key("", "", "", 0), new Value());
+ }
+
+ private void testFormatterIgnoresConfig(FormatterConfig config, DateStringFormatter formatter) {
+ // ignores config's DateFormatSupplier and substitutes its own
+ formatter.initialize(data.entrySet(), config);
+
+ assertTrue(formatter.hasNext());
+ final String next = formatter.next();
+ assertTrue(next, next.endsWith("1970/01/01 00:00:00.000"));
+ }
+
+ @Test
+ public void testTimestamps() {
+ final TimeZone utc = TimeZone.getTimeZone("UTC");
+ final TimeZone est = TimeZone.getTimeZone("EST");
+ final FormatterConfig config = new FormatterConfig().setPrintTimestamps(true);
+ DateStringFormatter formatter;
+
+ formatter = new DateStringFormatter(utc);
+ testFormatterIgnoresConfig(config, formatter);
+
+ // even though config says to use EST and only print year, the Formatter will override these
+ formatter = new DateStringFormatter(utc);
+ DateFormatSupplier dfSupplier = DateFormatSupplier.createSimpleFormatSupplier("YYYY", est);
+ config.setDateFormatSupplier(dfSupplier);
+ testFormatterIgnoresConfig(config, formatter);
+ }
+
+ @Test
+ public void testNoTimestamps() {
+ data.put(new Key("", "", "", 1), new Value());
+
+ assertEquals(2, data.size());
+
+ formatter.initialize(data.entrySet(), new FormatterConfig());
+
+ assertEquals(formatter.next(), formatter.next());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
index 47ba1c9..1baa3a1 100644
--- a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
@@ -38,11 +38,15 @@ import org.apache.accumulo.minicluster.ServerType;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* AccumuloCluster implementation to connect to an existing deployment of Accumulo
*/
public class StandaloneAccumuloCluster implements AccumuloCluster {
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(StandaloneAccumuloCluster.class);
static final List<ServerType> ALL_SERVER_TYPES = Collections.unmodifiableList(Arrays.asList(ServerType.MASTER, ServerType.TABLET_SERVER, ServerType.TRACER,
ServerType.GARBAGE_COLLECTOR, ServerType.MONITOR));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
index 1e5a4f9..62b977d 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
@@ -380,11 +380,9 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
* @param config
* initial configuration
*/
+ @SuppressWarnings("deprecation")
public MiniAccumuloClusterImpl(MiniAccumuloConfigImpl config) throws IOException {
- @SuppressWarnings("deprecation")
- Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
+
this.config = config.initialize();
mkdirs(config.getConfDir());
@@ -429,8 +427,8 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
writeConfig(hdfsFile, conf);
Map<String,String> siteConfig = config.getSiteConfig();
- siteConfig.put(INSTANCE_DFS_URI.getKey(), dfsUri);
- siteConfig.put(INSTANCE_DFS_DIR.getKey(), "/accumulo");
+ siteConfig.put(Property.INSTANCE_DFS_URI.getKey(), dfsUri);
+ siteConfig.put(Property.INSTANCE_DFS_DIR.getKey(), "/accumulo");
config.setSiteConfig(siteConfig);
} else if (config.useExistingInstance()) {
dfsUri = CachedConfiguration.getInstance().get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 25dfd46..c2bd679 100644
--- a/pom.xml
+++ b/pom.xml
@@ -619,36 +619,6 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-invoker-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.0.0</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>3.0.0</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.10</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>1.6</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-scm-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>1.9.4</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.12</version>
<configuration>
@@ -664,8 +634,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>3.0.0</version>
<configuration>
<filesets>
<fileset>
@@ -681,8 +649,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>3.5.1</version>
<configuration>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
@@ -698,8 +664,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.6</version>
<configuration>
<archive>
<manifestEntries>
@@ -712,8 +676,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.10.3</version>
<configuration>
<quiet>true</quiet>
<javadocVersion>${maven.compiler.target}</javadocVersion>
@@ -724,8 +686,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.5.3</version>
<configuration>
<arguments>-P !autoformat,thrift,sunny -Dtimeout.factor=2 ${extraReleaseArgs}</arguments>
<autoVersionSubmodules>true</autoVersionSubmodules>
@@ -741,8 +701,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>3.5.1</version>
<configuration>
<skipDeploy>true</skipDeploy>
</configuration>
@@ -750,8 +708,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
@@ -762,8 +718,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
@@ -805,8 +759,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
- <!-- overridden version from ASF-17 parent pom -->
- <version>1.4.1</version>
<configuration>
<rules>
<requireJavaVersion>
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
----------------------------------------------------------------------
diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
index c4b422c..56866c2 100644
--- a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
+++ b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java
@@ -85,6 +85,7 @@ import org.apache.accumulo.core.security.NamespacePermission;
import org.apache.accumulo.core.security.SystemPermission;
import org.apache.accumulo.core.security.TablePermission;
import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.TextUtil;
import org.apache.accumulo.proxy.thrift.AccumuloProxy;
import org.apache.accumulo.proxy.thrift.BatchScanOptions;
@@ -189,18 +190,23 @@ public class ProxyServer implements AccumuloProxy.Iface {
public ProxyServer(Properties props) {
- ClientConfiguration clientConf;
- if (props.containsKey("clientConfigurationFile")) {
- String clientConfFile = props.getProperty("clientConfigurationFile");
- try {
- clientConf = new ClientConfiguration(clientConfFile);
- } catch (ConfigurationException e) {
- throw new RuntimeException(e);
+ String useMock = props.getProperty("useMockInstance");
+ if (useMock != null && Boolean.parseBoolean(useMock))
+ instance = DeprecationUtil.makeMockInstance(this.getClass().getName());
+ else {
+ ClientConfiguration clientConf;
+ if (props.containsKey("clientConfigurationFile")) {
+ String clientConfFile = props.getProperty("clientConfigurationFile");
+ try {
+ clientConf = new ClientConfiguration(clientConfFile);
+ } catch (ConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ clientConf = ClientConfiguration.loadDefault();
}
- } else {
- clientConf = ClientConfiguration.loadDefault();
+ instance = new ZooKeeperInstance(clientConf.withInstance(props.getProperty("instance")).withZkHosts(props.getProperty("zookeepers")));
}
- instance = new ZooKeeperInstance(clientConf.withInstance(props.getProperty("instance")).withZkHosts(props.getProperty("zookeepers")));
try {
String tokenProp = props.getProperty("tokenClass", PasswordToken.class.getName());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/AccumuloServerContext.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/AccumuloServerContext.java b/server/base/src/main/java/org/apache/accumulo/server/AccumuloServerContext.java
index 1a61707..ce7bfad 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/AccumuloServerContext.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/AccumuloServerContext.java
@@ -28,9 +28,11 @@ import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.client.impl.ClientContext;
import org.apache.accumulo.core.client.impl.ConnectorImpl;
import org.apache.accumulo.core.client.impl.Credentials;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.rpc.SslConnectionParams;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.server.client.HdfsZooInstance;
import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.accumulo.server.rpc.SaslServerConnectionParams;
@@ -92,6 +94,9 @@ public class AccumuloServerContext extends ClientContext {
* Get the credentials to use for this instance so it can be passed to the superclass during construction.
*/
private static Credentials getCredentials(Instance instance) {
+ if (DeprecationUtil.isMockInstance(instance)) {
+ return new Credentials("mockSystemUser", new PasswordToken("mockSystemPassword"));
+ }
return SystemCredentials.get(instance);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java
index 7af978b..a058660 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.server.cli;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.server.client.HdfsZooInstance;
public class ClientOnDefaultTable extends org.apache.accumulo.core.cli.ClientOnDefaultTable {
@@ -30,6 +31,8 @@ public class ClientOnDefaultTable extends org.apache.accumulo.core.cli.ClientOnD
if (cachedInstance != null)
return cachedInstance;
+ if (mock)
+ return cachedInstance = DeprecationUtil.makeMockInstance(instance);
if (instance == null) {
return cachedInstance = HdfsZooInstance.getInstance();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java
index c966723..e02dd93 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.server.cli;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.server.client.HdfsZooInstance;
public class ClientOnRequiredTable extends org.apache.accumulo.core.cli.ClientOnRequiredTable {
@@ -30,6 +31,8 @@ public class ClientOnRequiredTable extends org.apache.accumulo.core.cli.ClientOn
if (cachedInstance != null)
return cachedInstance;
+ if (mock)
+ return cachedInstance = DeprecationUtil.makeMockInstance(instance);
if (instance == null) {
return cachedInstance = HdfsZooInstance.getInstance();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java
index 81a42f8..c91471e 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.server.cli;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.server.client.HdfsZooInstance;
public class ClientOpts extends org.apache.accumulo.core.cli.ClientOpts {
@@ -28,6 +29,8 @@ public class ClientOpts extends org.apache.accumulo.core.cli.ClientOpts {
@Override
public Instance getInstance() {
+ if (mock)
+ return DeprecationUtil.makeMockInstance(instance);
if (instance == null) {
return HdfsZooInstance.getInstance();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java b/server/base/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
index bca8ddf..e4e73d2 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.server.client;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -34,24 +35,28 @@ import org.apache.accumulo.core.client.impl.ConnectorImpl;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.impl.InstanceOperationsImpl;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.conf.SiteConfiguration;
import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.accumulo.core.util.OpTimer;
+import org.apache.accumulo.core.util.TextUtil;
import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.ZooCache;
import org.apache.accumulo.fate.zookeeper.ZooCacheFactory;
import org.apache.accumulo.server.Accumulo;
+import org.apache.accumulo.server.conf.ServerConfigurationFactory;
import org.apache.accumulo.server.fs.VolumeManager;
import org.apache.accumulo.server.fs.VolumeManagerImpl;
import org.apache.accumulo.server.zookeeper.ZooLock;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
+import com.google.common.base.Joiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Joiner;
-
/**
* An implementation of Instance that looks in HDFS and ZooKeeper to find the master and root tablet location.
*
@@ -172,6 +177,38 @@ public class HdfsZooInstance implements Instance {
return new ConnectorImpl(new ClientContext(this, new Credentials(principal, token), SiteConfiguration.getInstance()));
}
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, new PasswordToken(pass));
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, ByteBufferUtil.toBytes(pass));
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, TextUtil.getBytes(new Text(pass.toString())));
+ }
+
+ private AccumuloConfiguration conf = null;
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ return conf = conf == null ? new ServerConfigurationFactory(this).getConfiguration() : conf;
+ }
+
+ @Override
+ @Deprecated
+ public void setConfiguration(AccumuloConfiguration conf) {
+ this.conf = conf;
+ }
+
public static void main(String[] args) {
Instance instance = HdfsZooInstance.getInstance();
System.out.println("Instance Name: " + instance.getInstanceName());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/main/java/org/apache/accumulo/server/security/UserImpersonation.java
----------------------------------------------------------------------
diff --git a/server/base/src/main/java/org/apache/accumulo/server/security/UserImpersonation.java b/server/base/src/main/java/org/apache/accumulo/server/security/UserImpersonation.java
index 9e8f576..97bc858 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/security/UserImpersonation.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/security/UserImpersonation.java
@@ -22,11 +22,14 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* When SASL is enabled, this parses properties from the site configuration to build up a set of all users capable of impersonating another user, the users
@@ -41,8 +44,9 @@ import org.apache.commons.lang.StringUtils;
*/
public class UserImpersonation {
+ private static final Logger log = LoggerFactory.getLogger(UserImpersonation.class);
private static final Set<String> ALWAYS_TRUE = new AlwaysTrueSet<>();
- private static final String ALL = "*";
+ private static final String ALL = "*", USERS = "users", HOSTS = "hosts";
public static class AlwaysTrueSet<T> implements Set<T> {
@@ -169,6 +173,7 @@ public class UserImpersonation {
private final Map<String,UsersWithHosts> proxyUsers;
+ @SuppressWarnings("deprecation")
public UserImpersonation(AccumuloConfiguration conf) {
proxyUsers = new HashMap<>();
@@ -177,6 +182,9 @@ public class UserImpersonation {
if (!Property.INSTANCE_RPC_SASL_ALLOWED_USER_IMPERSONATION.getDefaultValue().equals(userConfig)) {
String hostConfig = conf.get(Property.INSTANCE_RPC_SASL_ALLOWED_HOST_IMPERSONATION);
parseOnelineConfiguration(userConfig, hostConfig);
+ } else {
+ // Otherwise, assume the old-style
+ parseMultiPropertyConfiguration(conf.getAllPropertiesWithPrefix(Property.INSTANCE_RPC_SASL_PROXYUSERS));
}
}
@@ -244,6 +252,64 @@ public class UserImpersonation {
}
}
+ /**
+ * Parses all properties that start with {@link Property#INSTANCE_RPC_SASL_PROXYUSERS}. This approach was the original configuration method, but does not work
+ * with Ambari.
+ *
+ * @param configProperties
+ * The relevant configuration properties for impersonation.
+ */
+ @SuppressWarnings("javadoc")
+ private void parseMultiPropertyConfiguration(Map<String,String> configProperties) {
+ @SuppressWarnings("deprecation")
+ final String configKey = Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey();
+ for (Entry<String,String> entry : configProperties.entrySet()) {
+ String aclKey = entry.getKey().substring(configKey.length());
+ int index = aclKey.lastIndexOf('.');
+
+ if (-1 == index) {
+ throw new RuntimeException("Expected 2 elements in key suffix: " + aclKey);
+ }
+
+ final String remoteUser = aclKey.substring(0, index).trim(), usersOrHosts = aclKey.substring(index + 1).trim();
+ UsersWithHosts usersWithHosts = proxyUsers.get(remoteUser);
+ if (null == usersWithHosts) {
+ usersWithHosts = new UsersWithHosts();
+ proxyUsers.put(remoteUser, usersWithHosts);
+ }
+
+ if (USERS.equals(usersOrHosts)) {
+ String userString = entry.getValue().trim();
+ if (ALL.equals(userString)) {
+ usersWithHosts.setAcceptAllUsers(true);
+ } else if (!usersWithHosts.acceptsAllUsers()) {
+ Set<String> users = usersWithHosts.getUsers();
+ if (null == users) {
+ users = new HashSet<>();
+ usersWithHosts.setUsers(users);
+ }
+ String[] userValues = StringUtils.split(userString, ',');
+ users.addAll(Arrays.<String> asList(userValues));
+ }
+ } else if (HOSTS.equals(usersOrHosts)) {
+ String hostsString = entry.getValue().trim();
+ if (ALL.equals(hostsString)) {
+ usersWithHosts.setAcceptAllHosts(true);
+ } else if (!usersWithHosts.acceptsAllHosts()) {
+ Set<String> hosts = usersWithHosts.getHosts();
+ if (null == hosts) {
+ hosts = new HashSet<>();
+ usersWithHosts.setHosts(hosts);
+ }
+ String[] hostValues = StringUtils.split(hostsString, ',');
+ hosts.addAll(Arrays.<String> asList(hostValues));
+ }
+ } else {
+ log.debug("Ignoring key " + aclKey);
+ }
+ }
+ }
+
public UsersWithHosts get(String remoteUser) {
return proxyUsers.get(remoteUser);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/test/java/org/apache/accumulo/server/init/InitializeTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/init/InitializeTest.java b/server/base/src/test/java/org/apache/accumulo/server/init/InitializeTest.java
index 1f915c0..cb34fb9 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/init/InitializeTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/init/InitializeTest.java
@@ -41,11 +41,6 @@ import org.junit.Test;
* This test is not thread-safe.
*/
public class InitializeTest {
- @SuppressWarnings("deprecation")
- private static Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
-
private Configuration conf;
private VolumeManager fs;
private SiteConfiguration sconf;
@@ -82,9 +77,10 @@ public class InitializeTest {
assertTrue(Initialize.isInitialized(fs));
}
+ @SuppressWarnings("deprecation")
@Test
public void testCheckInit_NoZK() throws Exception {
- expect(sconf.get(INSTANCE_DFS_URI)).andReturn("hdfs://foo");
+ expect(sconf.get(Property.INSTANCE_DFS_URI)).andReturn("hdfs://foo");
expectLastCall().anyTimes();
expect(sconf.get(Property.INSTANCE_ZK_HOST)).andReturn("zk1");
replay(sconf);
@@ -94,11 +90,12 @@ public class InitializeTest {
assertFalse(Initialize.checkInit(conf, fs, sconf));
}
+ @SuppressWarnings("deprecation")
@Test
public void testCheckInit_AlreadyInit() throws Exception {
- expect(sconf.get(INSTANCE_DFS_URI)).andReturn("hdfs://foo");
+ expect(sconf.get(Property.INSTANCE_DFS_URI)).andReturn("hdfs://foo");
expectLastCall().anyTimes();
- expect(sconf.get(INSTANCE_DFS_DIR)).andReturn("/bar");
+ expect(sconf.get(Property.INSTANCE_DFS_DIR)).andReturn("/bar");
expect(sconf.get(Property.INSTANCE_VOLUMES)).andReturn("");
expect(sconf.get(Property.INSTANCE_ZK_HOST)).andReturn("zk1");
expect(sconf.get(Property.INSTANCE_SECRET)).andReturn(Property.INSTANCE_SECRET.getDefaultValue());
@@ -112,12 +109,13 @@ public class InitializeTest {
}
// Cannot test, need to mock static FileSystem.getDefaultUri()
+ @SuppressWarnings("deprecation")
@Ignore
@Test
public void testCheckInit_AlreadyInit_DefaultUri() throws Exception {
- expect(sconf.get(INSTANCE_DFS_URI)).andReturn("");
+ expect(sconf.get(Property.INSTANCE_DFS_URI)).andReturn("");
expectLastCall().anyTimes();
- expect(sconf.get(INSTANCE_DFS_DIR)).andReturn("/bar");
+ expect(sconf.get(Property.INSTANCE_DFS_DIR)).andReturn("/bar");
expect(sconf.get(Property.INSTANCE_ZK_HOST)).andReturn("zk1");
expect(sconf.get(Property.INSTANCE_SECRET)).andReturn(Property.INSTANCE_SECRET.getDefaultValue());
replay(sconf);
@@ -130,9 +128,10 @@ public class InitializeTest {
assertFalse(Initialize.checkInit(conf, fs, sconf));
}
+ @SuppressWarnings("deprecation")
@Test(expected = IOException.class)
public void testCheckInit_FSException() throws Exception {
- expect(sconf.get(INSTANCE_DFS_URI)).andReturn("hdfs://foo");
+ expect(sconf.get(Property.INSTANCE_DFS_URI)).andReturn("hdfs://foo");
expectLastCall().anyTimes();
expect(sconf.get(Property.INSTANCE_ZK_HOST)).andReturn("zk1");
expect(sconf.get(Property.INSTANCE_SECRET)).andReturn(Property.INSTANCE_SECRET.getDefaultValue());
@@ -145,9 +144,10 @@ public class InitializeTest {
Initialize.checkInit(conf, fs, sconf);
}
+ @SuppressWarnings("deprecation")
@Test
public void testCheckInit_OK() throws Exception {
- expect(sconf.get(INSTANCE_DFS_URI)).andReturn("hdfs://foo");
+ expect(sconf.get(Property.INSTANCE_DFS_URI)).andReturn("hdfs://foo");
expectLastCall().anyTimes();
expect(sconf.get(Property.INSTANCE_ZK_HOST)).andReturn("zk1");
expect(sconf.get(Property.INSTANCE_SECRET)).andReturn(Property.INSTANCE_SECRET.getDefaultValue());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/test/java/org/apache/accumulo/server/master/balancer/BaseHostRegexTableLoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/master/balancer/BaseHostRegexTableLoadBalancerTest.java b/server/base/src/test/java/org/apache/accumulo/server/master/balancer/BaseHostRegexTableLoadBalancerTest.java
index b887f29..3ed6a1b 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/master/balancer/BaseHostRegexTableLoadBalancerTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/master/balancer/BaseHostRegexTableLoadBalancerTest.java
@@ -17,6 +17,7 @@
package org.apache.accumulo.server.master.balancer;
import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -79,6 +80,34 @@ public abstract class BaseHostRegexTableLoadBalancerTest extends HostRegexTableL
return 30;
}
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public void setConfiguration(AccumuloConfiguration conf) {}
+
@Override
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
throw new UnsupportedOperationException();
[4/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumSummation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumSummation.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumSummation.java
new file mode 100644
index 0000000..4d79894
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumSummation.java
@@ -0,0 +1,91 @@
+/*
+ * 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.iterators.aggregation;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.accumulo.core.data.Value;
+import org.apache.hadoop.io.WritableUtils;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.SummingCombiner} with
+ * {@link org.apache.accumulo.core.iterators.LongCombiner.Type#VARLEN}
+ */
+@Deprecated
+public class NumSummation implements Aggregator {
+ long sum = 0l;
+
+ @Override
+ public Value aggregate() {
+ try {
+ return new Value(NumSummation.longToBytes(sum));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void collect(Value value) {
+ long l;
+ try {
+ l = NumSummation.bytesToLong(value.get());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ sum = NumSummation.safeAdd(sum, l);
+ }
+
+ public static byte[] longToBytes(long l) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+
+ WritableUtils.writeVLong(dos, l);
+
+ return baos.toByteArray();
+ }
+
+ public static long bytesToLong(byte[] b) throws IOException {
+ DataInputStream dis = new DataInputStream(new ByteArrayInputStream(b));
+ return WritableUtils.readVLong(dis);
+ }
+
+ public static long safeAdd(long a, long b) {
+ long aSign = Long.signum(a);
+ long bSign = Long.signum(b);
+ if ((aSign != 0) && (bSign != 0) && (aSign == bSign)) {
+ if (aSign > 0) {
+ if (Long.MAX_VALUE - a < b)
+ return Long.MAX_VALUE;
+ } else {
+ if (Long.MIN_VALUE - a > b)
+ return Long.MIN_VALUE;
+ }
+ }
+ return a + b;
+ }
+
+ @Override
+ public void reset() {
+ sum = 0l;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMax.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMax.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMax.java
new file mode 100644
index 0000000..3d4516d
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMax.java
@@ -0,0 +1,48 @@
+/*
+ * 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.iterators.aggregation;
+
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.MaxCombiner} with
+ * {@link org.apache.accumulo.core.iterators.LongCombiner.Type#STRING}
+ */
+@Deprecated
+public class StringMax implements Aggregator {
+
+ long max = Long.MIN_VALUE;
+
+ @Override
+ public Value aggregate() {
+ return new Value(Long.toString(max).getBytes());
+ }
+
+ @Override
+ public void collect(Value value) {
+ long l = Long.parseLong(new String(value.get()));
+ if (l > max) {
+ max = l;
+ }
+ }
+
+ @Override
+ public void reset() {
+ max = Long.MIN_VALUE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMin.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMin.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMin.java
new file mode 100644
index 0000000..7a49f81
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringMin.java
@@ -0,0 +1,48 @@
+/*
+ * 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.iterators.aggregation;
+
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.MinCombiner} with
+ * {@link org.apache.accumulo.core.iterators.LongCombiner.Type#STRING}
+ */
+@Deprecated
+public class StringMin implements Aggregator {
+
+ long min = Long.MAX_VALUE;
+
+ @Override
+ public Value aggregate() {
+ return new Value(Long.toString(min).getBytes());
+ }
+
+ @Override
+ public void collect(Value value) {
+ long l = Long.parseLong(new String(value.get()));
+ if (l < min) {
+ min = l;
+ }
+ }
+
+ @Override
+ public void reset() {
+ min = Long.MAX_VALUE;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringSummation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringSummation.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringSummation.java
new file mode 100644
index 0000000..a8b5967
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/StringSummation.java
@@ -0,0 +1,45 @@
+/*
+ * 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.iterators.aggregation;
+
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.SummingCombiner} with
+ * {@link org.apache.accumulo.core.iterators.LongCombiner.Type#STRING}
+ */
+@Deprecated
+public class StringSummation implements Aggregator {
+
+ long sum = 0;
+
+ @Override
+ public Value aggregate() {
+ return new Value(Long.toString(sum).getBytes());
+ }
+
+ @Override
+ public void collect(Value value) {
+ sum += Long.parseLong(new String(value.get()));
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfiguration.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfiguration.java
new file mode 100644
index 0000000..3432cf5
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfiguration.java
@@ -0,0 +1,34 @@
+/*
+ * 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.iterators.aggregation.conf;
+
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.4
+ */
+@Deprecated
+public class AggregatorConfiguration extends org.apache.accumulo.core.iterators.conf.PerColumnIteratorConfig {
+
+ public AggregatorConfiguration(Text columnFamily, String aggClassName) {
+ super(columnFamily, aggClassName);
+ }
+
+ public AggregatorConfiguration(Text columnFamily, Text columnQualifier, String aggClassName) {
+ super(columnFamily, columnQualifier, aggClassName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorSet.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorSet.java
new file mode 100644
index 0000000..d6545ac
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorSet.java
@@ -0,0 +1,41 @@
+/*
+ * 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.iterators.aggregation.conf;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.iterators.conf.ColumnToClassMapping;
+
+/**
+ * @deprecated since 1.4
+ */
+@Deprecated
+public class AggregatorSet extends ColumnToClassMapping<org.apache.accumulo.core.iterators.aggregation.Aggregator> {
+ public AggregatorSet(Map<String,String> opts) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
+ super(opts, org.apache.accumulo.core.iterators.aggregation.Aggregator.class);
+ }
+
+ public AggregatorSet() {
+ super();
+ }
+
+ public org.apache.accumulo.core.iterators.aggregation.Aggregator getAggregator(Key k) {
+ return getObject(k);
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/conf/PerColumnIteratorConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/conf/PerColumnIteratorConfig.java b/core/src/main/java/org/apache/accumulo/core/iterators/conf/PerColumnIteratorConfig.java
new file mode 100644
index 0000000..310776aa
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/conf/PerColumnIteratorConfig.java
@@ -0,0 +1,81 @@
+/*
+ * 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.iterators.conf;
+
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.4
+ *
+ * @see org.apache.accumulo.core.client.IteratorSetting.Column
+ * @see org.apache.accumulo.core.iterators.Combiner#setColumns(org.apache.accumulo.core.client.IteratorSetting, java.util.List)
+ */
+@Deprecated
+public class PerColumnIteratorConfig {
+
+ private String parameter;
+ private Text colq;
+ private Text colf;
+
+ public PerColumnIteratorConfig(Text columnFamily, String parameter) {
+ this.colf = columnFamily;
+ this.colq = null;
+ this.parameter = parameter;
+ }
+
+ public PerColumnIteratorConfig(Text columnFamily, Text columnQualifier, String parameter) {
+ this.colf = columnFamily;
+ this.colq = columnQualifier;
+ this.parameter = parameter;
+ }
+
+ public Text getColumnFamily() {
+ return colf;
+ }
+
+ public Text getColumnQualifier() {
+ return colq;
+ }
+
+ public String encodeColumns() {
+ return encodeColumns(this);
+ }
+
+ public String getClassName() {
+ return parameter;
+ }
+
+ private static String encodeColumns(PerColumnIteratorConfig pcic) {
+ return ColumnSet.encodeColumns(pcic.colf, pcic.colq);
+ }
+
+ public static String encodeColumns(Text columnFamily, Text columnQualifier) {
+ return ColumnSet.encodeColumns(columnFamily, columnQualifier);
+ }
+
+ public static PerColumnIteratorConfig decodeColumns(String columns, String className) {
+ String[] cols = columns.split(":");
+
+ if (cols.length == 1) {
+ return new PerColumnIteratorConfig(ColumnSet.decode(cols[0]), className);
+ } else if (cols.length == 2) {
+ return new PerColumnIteratorConfig(ColumnSet.decode(cols[0]), ColumnSet.decode(cols[1]), className);
+ } else {
+ throw new IllegalArgumentException(columns);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java
index f848b10..94995cb 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/IntersectingIterator.java
@@ -503,6 +503,30 @@ public class IntersectingIterator implements SortedKeyValueIterator<Key,Value> {
}
/**
+ * @deprecated since 1.6.0
+ */
+ @Deprecated
+ public void addSource(SortedKeyValueIterator<Key,Value> source, IteratorEnvironment env, Text term, boolean notFlag) {
+ // Check if we have space for the added Source
+ if (sources == null) {
+ sources = new TermSource[1];
+ } else {
+ // allocate space for node, and copy current tree.
+ // TODO: Should we change this to an ArrayList so that we can just add() ? - ACCUMULO-1309
+ TermSource[] localSources = new TermSource[sources.length + 1];
+ int currSource = 0;
+ for (TermSource myTerm : sources) {
+ // TODO: Do I need to call new here? or can I just re-use the term? - ACCUMULO-1309
+ localSources[currSource] = new TermSource(myTerm);
+ currSource++;
+ }
+ sources = localSources;
+ }
+ sources[sourcesCount] = new TermSource(source.deepCopy(env), term, notFlag);
+ sourcesCount++;
+ }
+
+ /**
* Encode the columns to be used when iterating.
*/
public static void setColumnFamilies(IteratorSetting cfg, Text[] columns) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java
index 2479051..7076757 100644
--- a/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java
+++ b/core/src/main/java/org/apache/accumulo/core/replication/ReplicationTable.java
@@ -35,6 +35,7 @@ import org.apache.accumulo.core.master.state.tables.TableState;
import org.apache.accumulo.core.replication.ReplicationSchema.StatusSection;
import org.apache.accumulo.core.replication.ReplicationSchema.WorkSection;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.hadoop.io.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,7 +87,7 @@ public class ReplicationTable {
}
public static boolean isOnline(Connector conn) {
- return TableState.ONLINE == Tables.getTableState(conn.getInstance(), ID);
+ return DeprecationUtil.isMockInstance(conn.getInstance()) || TableState.ONLINE == Tables.getTableState(conn.getInstance(), ID);
}
public static void setOnline(Connector conn) throws AccumuloSecurityException, AccumuloException {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java b/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
new file mode 100644
index 0000000..611c8d4
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/security/VisibilityConstraint.java
@@ -0,0 +1,29 @@
+/*
+ * 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.security;
+
+/**
+ *
+ * @deprecated since 1.7.0 This is server side code not intended to exist in a public API package. This class references types that are not in the public API
+ * and therefore is not guaranteed to be stable. It was deprecated to clearly communicate this. Use
+ * {@link org.apache.accumulo.core.constraints.VisibilityConstraint} instead.
+ */
+@Deprecated
+public class VisibilityConstraint extends org.apache.accumulo.core.constraints.VisibilityConstraint {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java b/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
index 9be89db..7b79d99 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/crypto/CachingHDFSSecretKeyEncryptionStrategy.java
@@ -41,8 +41,6 @@ import org.slf4j.LoggerFactory;
*/
public class CachingHDFSSecretKeyEncryptionStrategy implements SecretKeyEncryptionStrategy {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
private static final Logger log = LoggerFactory.getLogger(CachingHDFSSecretKeyEncryptionStrategy.class);
private SecretKeyCache secretKeyCache = new SecretKeyCache();
@@ -175,16 +173,17 @@ public class CachingHDFSSecretKeyEncryptionStrategy implements SecretKeyEncrypti
}
+ @SuppressWarnings("deprecation")
private String getFullPathToKey(CryptoModuleParameters params) {
String pathToKeyName = params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_KEY_LOCATION.getKey());
- String instanceDirectory = params.getAllOptions().get(INSTANCE_DFS_DIR.getKey());
+ String instanceDirectory = params.getAllOptions().get(Property.INSTANCE_DFS_DIR.getKey());
if (pathToKeyName == null) {
pathToKeyName = Property.CRYPTO_DEFAULT_KEY_STRATEGY_KEY_LOCATION.getDefaultValue();
}
if (instanceDirectory == null) {
- instanceDirectory = INSTANCE_DFS_DIR.getDefaultValue();
+ instanceDirectory = Property.INSTANCE_DFS_DIR.getDefaultValue();
}
if (!pathToKeyName.startsWith("/")) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java b/core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
index f0eaa26..1dd8d60 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
@@ -39,10 +39,6 @@ import org.slf4j.LoggerFactory;
//TODO ACCUMULO-2530 Update properties to use a URI instead of a relative path to secret key
public class NonCachingSecretKeyEncryptionStrategy implements SecretKeyEncryptionStrategy {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
private static final Logger log = LoggerFactory.getLogger(NonCachingSecretKeyEncryptionStrategy.class);
private void doKeyEncryptionOperation(int encryptionMode, CryptoModuleParameters params, String pathToKeyName, Path pathToKey, FileSystem fs)
@@ -125,16 +121,17 @@ public class NonCachingSecretKeyEncryptionStrategy implements SecretKeyEncryptio
}
}
+ @SuppressWarnings("deprecation")
private String getFullPathToKey(CryptoModuleParameters params) {
String pathToKeyName = params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_KEY_LOCATION.getKey());
- String instanceDirectory = params.getAllOptions().get(INSTANCE_DFS_DIR.getKey());
+ String instanceDirectory = params.getAllOptions().get(Property.INSTANCE_DFS_DIR.getKey());
if (pathToKeyName == null) {
pathToKeyName = Property.CRYPTO_DEFAULT_KEY_STRATEGY_KEY_LOCATION.getDefaultValue();
}
if (instanceDirectory == null) {
- instanceDirectory = INSTANCE_DFS_DIR.getDefaultValue();
+ instanceDirectory = Property.INSTANCE_DFS_DIR.getDefaultValue();
}
if (!pathToKeyName.startsWith("/")) {
@@ -145,11 +142,12 @@ public class NonCachingSecretKeyEncryptionStrategy implements SecretKeyEncryptio
return fullPath;
}
+ @SuppressWarnings("deprecation")
@Override
public CryptoModuleParameters encryptSecretKey(CryptoModuleParameters params) {
- String hdfsURI = params.getAllOptions().get(INSTANCE_DFS_URI.getKey());
+ String hdfsURI = params.getAllOptions().get(Property.INSTANCE_DFS_URI.getKey());
if (hdfsURI == null) {
- hdfsURI = INSTANCE_DFS_URI.getDefaultValue();
+ hdfsURI = Property.INSTANCE_DFS_URI.getDefaultValue();
}
String fullPath = getFullPathToKey(params);
@@ -168,11 +166,12 @@ public class NonCachingSecretKeyEncryptionStrategy implements SecretKeyEncryptio
return params;
}
+ @SuppressWarnings("deprecation")
@Override
public CryptoModuleParameters decryptSecretKey(CryptoModuleParameters params) {
- String hdfsURI = params.getAllOptions().get(INSTANCE_DFS_URI.getKey());
+ String hdfsURI = params.getAllOptions().get(Property.INSTANCE_DFS_URI.getKey());
if (hdfsURI == null) {
- hdfsURI = INSTANCE_DFS_URI.getDefaultValue();
+ hdfsURI = Property.INSTANCE_DFS_URI.getDefaultValue();
}
String pathToKeyName = getFullPathToKey(params);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/trace/DistributedTrace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/DistributedTrace.java b/core/src/main/java/org/apache/accumulo/core/trace/DistributedTrace.java
index bb8a683..f833b11 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/DistributedTrace.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/DistributedTrace.java
@@ -23,13 +23,16 @@ import java.util.Map.Entry;
import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
+import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.fate.zookeeper.ZooReader;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ShutdownHookManager;
import org.apache.htrace.HTraceConfiguration;
import org.apache.htrace.SpanReceiver;
import org.apache.htrace.SpanReceiverBuilder;
+import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +55,14 @@ public class DistributedTrace {
private static final HashSet<SpanReceiver> receivers = new HashSet<>();
/**
+ * @deprecated since 1.7, use {@link DistributedTrace#enable(String, String, org.apache.accumulo.core.client.ClientConfiguration)} instead
+ */
+ @Deprecated
+ public static void enable(Instance instance, ZooReader zoo, String application, String address) throws IOException, KeeperException, InterruptedException {
+ enable(address, application);
+ }
+
+ /**
* Enable tracing by setting up SpanReceivers for the current process.
*/
public static void enable() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/trace/Trace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/trace/Trace.java b/core/src/main/java/org/apache/accumulo/core/trace/Trace.java
index 35227c5..3ebd031 100644
--- a/core/src/main/java/org/apache/accumulo/core/trace/Trace.java
+++ b/core/src/main/java/org/apache/accumulo/core/trace/Trace.java
@@ -56,6 +56,14 @@ public class Trace {
}
/**
+ * @deprecated since 1.7, use {@link #off()} instead
+ */
+ @Deprecated
+ public static void offNoFlush() {
+ off();
+ }
+
+ /**
* Returns whether tracing is currently on.
*/
public static boolean isTracing() {
@@ -63,6 +71,16 @@ public class Trace {
}
/**
+ * Return the current span.
+ *
+ * @deprecated since 1.7 -- it is better to save the span you create in a local variable and call its methods, rather than retrieving the current span
+ */
+ @Deprecated
+ public static Span currentTrace() {
+ return new Span(org.apache.htrace.Trace.currentSpan());
+ }
+
+ /**
* Get the trace id of the current span.
*/
public static long currentTraceId() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/util/DeprecationUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/DeprecationUtil.java b/core/src/main/java/org/apache/accumulo/core/util/DeprecationUtil.java
new file mode 100644
index 0000000..cd798bb
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/util/DeprecationUtil.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.impl.TabletLocator;
+import org.apache.accumulo.core.client.mapreduce.RangeInputSplit;
+
+/**
+ * A utility class for managing deprecated items. This avoids scattering private helper methods all over the code with warnings suppression.
+ *
+ * <p>
+ * This class will never be public API and methods will be removed as soon as they are no longer needed. No methods in this class will, themselves, be
+ * deprecated, because that would propagate the deprecation warning we are trying to avoid.
+ *
+ * <p>
+ * This class should not be used as a substitute for deprecated classes. It should <b>only</b> be used for implementation code which must remain to support the
+ * deprecated features, and <b>only</b> until that feature is removed.
+ */
+public class DeprecationUtil {
+
+ @SuppressWarnings("deprecation")
+ public static boolean isMockInstance(Instance instance) {
+ return instance instanceof org.apache.accumulo.core.client.mock.MockInstance;
+ }
+
+ @SuppressWarnings("deprecation")
+ public static Instance makeMockInstance(String instance) {
+ return new org.apache.accumulo.core.client.mock.MockInstance(instance);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static void setMockInstance(RangeInputSplit split, boolean isMockInstance) {
+ split.setMockInstance(isMockInstance);
+ }
+
+ @SuppressWarnings("deprecation")
+ public static boolean isMockInstanceSet(RangeInputSplit split) {
+ return split.isMockInstance();
+ }
+
+ @SuppressWarnings("deprecation")
+ public static TabletLocator makeMockLocator() {
+ return new org.apache.accumulo.core.client.mock.impl.MockTabletLocator();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/util/format/BinaryFormatter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/format/BinaryFormatter.java b/core/src/main/java/org/apache/accumulo/core/util/format/BinaryFormatter.java
new file mode 100644
index 0000000..f5cbe39
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/util/format/BinaryFormatter.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.format;
+
+import java.util.Map.Entry;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.ColumnVisibility;
+
+/**
+ * @deprecated Use {@link DefaultFormatter} providing showLength and printTimestamps via {@link FormatterConfig}.
+ */
+@Deprecated
+public class BinaryFormatter extends DefaultFormatter {
+ // this class can probably be replaced by DefaultFormatter since DefaultFormatter has the max length stuff
+ @Override
+ public String next() {
+ checkState(true);
+ return formatEntry(getScannerIterator().next(), config.willPrintTimestamps(), config.getShownLength());
+ }
+
+ public static String formatEntry(Entry<Key,Value> entry, boolean printTimestamps, int shownLength) {
+ StringBuilder sb = new StringBuilder();
+
+ Key key = entry.getKey();
+
+ // append row
+ appendText(sb, key.getRow(), shownLength).append(" ");
+
+ // append column family
+ appendText(sb, key.getColumnFamily(), shownLength).append(":");
+
+ // append column qualifier
+ appendText(sb, key.getColumnQualifier(), shownLength).append(" ");
+
+ // append visibility expression
+ sb.append(new ColumnVisibility(key.getColumnVisibility()));
+
+ // append timestamp
+ if (printTimestamps)
+ sb.append(" ").append(entry.getKey().getTimestamp());
+
+ // append value
+ Value value = entry.getValue();
+ if (value != null && value.getSize() > 0) {
+ sb.append("\t");
+ appendValue(sb, value, shownLength);
+ }
+ return sb.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/util/format/DateStringFormatter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/format/DateStringFormatter.java b/core/src/main/java/org/apache/accumulo/core/util/format/DateStringFormatter.java
new file mode 100644
index 0000000..63bd536
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/util/format/DateStringFormatter.java
@@ -0,0 +1,75 @@
+/*
+ * 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.format;
+
+import java.util.Map.Entry;
+import java.util.TimeZone;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * This class is <strong>not</strong> recommended because {@link #initialize(Iterable, FormatterConfig)} replaces parameters in {@link FormatterConfig}, which
+ * could surprise users.
+ *
+ * This class can be replaced by {@link DefaultFormatter} where FormatterConfig is initialized with a DateFormat set to {@link #DATE_FORMAT}. See
+ * {@link DateFormatSupplier#createSimpleFormatSupplier(String, java.util.TimeZone)}.
+ *
+ * <pre>
+ * final DateFormatSupplier dfSupplier = DateFormatSupplier.createSimpleFormatSupplier(DateFormatSupplier.HUMAN_READABLE_FORMAT, TimeZone.getTimeZone("UTC"));
+ * final FormatterConfig config = new FormatterConfig().setPrintTimestamps(true).setDateFormatSupplier(dfSupplier);
+ * </pre>
+ */
+@Deprecated
+public class DateStringFormatter implements Formatter {
+
+ private DefaultFormatter defaultFormatter;
+ private TimeZone timeZone;
+
+ public static final String DATE_FORMAT = DateFormatSupplier.HUMAN_READABLE_FORMAT;
+
+ public DateStringFormatter() {
+ this(TimeZone.getDefault());
+ }
+
+ public DateStringFormatter(TimeZone timeZone) {
+ this.defaultFormatter = new DefaultFormatter();
+ this.timeZone = timeZone;
+ }
+
+ @Override
+ public void initialize(Iterable<Entry<Key,Value>> scanner, FormatterConfig config) {
+ FormatterConfig newConfig = new FormatterConfig(config);
+ newConfig.setDateFormatSupplier(DateFormatSupplier.createSimpleFormatSupplier(DATE_FORMAT, timeZone));
+ defaultFormatter.initialize(scanner, newConfig);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return defaultFormatter.hasNext();
+ }
+
+ @Override
+ public String next() {
+ return defaultFormatter.next();
+ }
+
+ @Override
+ public void remove() {
+ defaultFormatter.remove();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/volume/VolumeConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/volume/VolumeConfiguration.java b/core/src/main/java/org/apache/accumulo/core/volume/VolumeConfiguration.java
index 31cf53c..573978d 100644
--- a/core/src/main/java/org/apache/accumulo/core/volume/VolumeConfiguration.java
+++ b/core/src/main/java/org/apache/accumulo/core/volume/VolumeConfiguration.java
@@ -31,11 +31,6 @@ import org.apache.hadoop.fs.Path;
public class VolumeConfiguration {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
-
public static Volume getVolume(String path, Configuration conf, AccumuloConfiguration acuconf) throws IOException {
requireNonNull(path);
@@ -49,7 +44,8 @@ public class VolumeConfiguration {
}
public static Volume getDefaultVolume(Configuration conf, AccumuloConfiguration acuconf) throws IOException {
- String uri = acuconf.get(INSTANCE_DFS_URI);
+ @SuppressWarnings("deprecation")
+ String uri = acuconf.get(Property.INSTANCE_DFS_URI);
// By default pull from INSTANCE_DFS_URI, falling back to the Hadoop defined
// default filesystem (fs.defaultFS or the deprecated fs.default.name)
@@ -64,14 +60,12 @@ public class VolumeConfiguration {
}
/**
- * This method gets the old configured base directory, using the URI and DIR. It will not longer be needed when we no longer support upgrading from non-volume
- * based Accumulo config
- *
- * @see #getVolumeUris(AccumuloConfiguration,Configuration)
+ * @see org.apache.accumulo.core.volume.VolumeConfiguration#getVolumeUris(AccumuloConfiguration,Configuration)
*/
- private static String getConfiguredBaseDir(AccumuloConfiguration conf, Configuration hadoopConfig) {
- String singleNamespace = conf.get(INSTANCE_DFS_DIR);
- String dfsUri = conf.get(INSTANCE_DFS_URI);
+ @Deprecated
+ public static String getConfiguredBaseDir(AccumuloConfiguration conf, Configuration hadoopConfig) {
+ String singleNamespace = conf.get(Property.INSTANCE_DFS_DIR);
+ String dfsUri = conf.get(Property.INSTANCE_DFS_URI);
String baseDir;
if (dfsUri == null || dfsUri.isEmpty()) {
@@ -82,7 +76,7 @@ public class VolumeConfiguration {
}
} else {
if (!dfsUri.contains(":"))
- throw new IllegalArgumentException("Expected fully qualified URI for " + INSTANCE_DFS_URI.getKey() + " got " + dfsUri);
+ throw new IllegalArgumentException("Expected fully qualified URI for " + Property.INSTANCE_DFS_URI.getKey() + " got " + dfsUri);
baseDir = dfsUri + singleNamespace;
}
return baseDir;
@@ -146,9 +140,10 @@ public class VolumeConfiguration {
* A FileSystem to write to
* @return A Volume instance writing to the given FileSystem in the default path
*/
+ @SuppressWarnings("deprecation")
public static <T extends FileSystem> Volume create(T fs, AccumuloConfiguration acuconf) {
- String dfsDir = acuconf.get(INSTANCE_DFS_DIR);
- return new VolumeImpl(fs, null == dfsDir ? INSTANCE_DFS_DIR.getDefaultValue() : dfsDir);
+ String dfsDir = acuconf.get(Property.INSTANCE_DFS_DIR);
+ return new VolumeImpl(fs, null == dfsDir ? Property.INSTANCE_DFS_DIR.getDefaultValue() : dfsDir);
}
public static <T extends FileSystem> Volume create(T fs, String basePath) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
index 638f152..65df5c9 100644
--- a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
+++ b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
@@ -50,10 +50,6 @@ import org.junit.rules.TestName;
import com.beust.jcommander.JCommander;
public class TestClientOpts {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
@Rule
public TemporaryFolder tmpDir = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
@@ -137,6 +133,7 @@ public class TestClientOpts {
args.getInstance();
}
+ @SuppressWarnings("deprecation")
@Test
public void testInstanceDir() throws IOException {
File instanceId = tmpDir.newFolder("instance_id");
@@ -149,8 +146,9 @@ public class TestClientOpts {
FileWriter fileWriter = new FileWriter(siteXml);
fileWriter.append("<configuration>\n");
- fileWriter.append("<property><name>" + INSTANCE_DFS_DIR.getKey() + "</name><value>" + tmpDir.getRoot().getAbsolutePath() + "</value></property>\n");
- fileWriter.append("<property><name>" + INSTANCE_DFS_URI.getKey() + "</name><value>file://</value></property>\n");
+ fileWriter
+ .append("<property><name>" + Property.INSTANCE_DFS_DIR.getKey() + "</name><value>" + tmpDir.getRoot().getAbsolutePath() + "</value></property>\n");
+ fileWriter.append("<property><name>" + Property.INSTANCE_DFS_URI.getKey() + "</name><value>file://</value></property>\n");
fileWriter.append("<property><name>" + ClientProperty.INSTANCE_NAME + "</name><value>foo</value></property>\n");
fileWriter.append("</configuration>\n");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java
index fff03fb..1d699c2 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TableOperationsHelperTest.java
@@ -37,6 +37,7 @@ import org.apache.accumulo.core.client.admin.CompactionConfig;
import org.apache.accumulo.core.client.admin.DiskUsage;
import org.apache.accumulo.core.client.admin.Locations;
import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.client.admin.TimeType;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
@@ -64,11 +65,33 @@ public class TableOperationsHelperTest {
public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {}
@Override
+ @Deprecated
+ public void create(String tableName, boolean limitVersion) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ create(tableName, limitVersion, TimeType.MILLIS);
+ }
+
+ @Override
+ @Deprecated
+ public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {}
+
+ @Override
public void create(String tableName, NewTableConfiguration ntc) throws AccumuloException, AccumuloSecurityException, TableExistsException {}
@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {}
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
+ return null;
+ }
+
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
+ return null;
+ }
+
@Override
public Collection<Text> listSplits(String tableName) throws TableNotFoundException {
return null;
@@ -115,6 +138,10 @@ public class TableOperationsHelperTest {
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
TableExistsException {}
+ @Deprecated
+ @Override
+ public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
+
@Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
index d7988ff..bab52f6 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/impl/TabletLocatorImplTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -44,6 +45,7 @@ import org.apache.accumulo.core.client.impl.TabletLocator.TabletServerMutations;
import org.apache.accumulo.core.client.impl.TabletLocatorImpl.TabletLocationObtainer;
import org.apache.accumulo.core.client.impl.TabletLocatorImpl.TabletServerLockChecker;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.PartialKey;
@@ -83,6 +85,7 @@ public class TabletLocatorImplTest {
return objs;
}
+ @SuppressWarnings("unchecked")
static Map<String,Map<KeyExtent,List<Range>>> createExpectedBinnings(Object... data) {
Map<String,Map<KeyExtent,List<Range>>> expBinnedRanges = new HashMap<>();
@@ -97,7 +100,6 @@ public class TabletLocatorImplTest {
for (int j = 0; j < binData.length; j += 2) {
KeyExtent ke = (KeyExtent) binData[j];
- @SuppressWarnings("unchecked")
List<Range> ranges = (List<Range>) binData[j + 1];
binnedKE.put(ke, ranges);
@@ -438,6 +440,36 @@ public class TabletLocatorImplTest {
}
@Override
+ @Deprecated
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public void setConfiguration(AccumuloConfiguration conf) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
throw new UnsupportedOperationException();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mapred/RangeInputSplitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapred/RangeInputSplitTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapred/RangeInputSplitTest.java
index 47a0e53..c399fb0 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapred/RangeInputSplitTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapred/RangeInputSplitTest.java
@@ -33,6 +33,7 @@ import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.iterators.user.SummingCombiner;
import org.apache.accumulo.core.iterators.user.WholeRowIterator;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.io.Text;
import org.apache.log4j.Level;
@@ -86,6 +87,7 @@ public class RangeInputSplitTest {
split.setToken(new PasswordToken("password"));
split.setPrincipal("root");
split.setInstanceName("instance");
+ DeprecationUtil.setMockInstance(split, true);
split.setZooKeepers("localhost");
split.setIterators(iterators);
split.setLogLevel(Level.WARN);
@@ -111,6 +113,7 @@ public class RangeInputSplitTest {
Assert.assertEquals(split.getToken(), newSplit.getToken());
Assert.assertEquals(split.getPrincipal(), newSplit.getPrincipal());
Assert.assertEquals(split.getInstanceName(), newSplit.getInstanceName());
+ Assert.assertEquals(DeprecationUtil.isMockInstanceSet(split), DeprecationUtil.isMockInstanceSet(newSplit));
Assert.assertEquals(split.getZooKeepers(), newSplit.getZooKeepers());
Assert.assertEquals(split.getIterators(), newSplit.getIterators());
Assert.assertEquals(split.getLogLevel(), newSplit.getLogLevel());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplitTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplitTest.java
index b1b378e..0eb8010 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplitTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/RangeInputSplitTest.java
@@ -33,6 +33,7 @@ import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.iterators.user.SummingCombiner;
import org.apache.accumulo.core.iterators.user.WholeRowIterator;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.io.Text;
import org.apache.log4j.Level;
@@ -89,6 +90,7 @@ public class RangeInputSplitTest {
split.setToken(new PasswordToken("password"));
split.setPrincipal("root");
split.setInstanceName("instance");
+ DeprecationUtil.setMockInstance(split, true);
split.setZooKeepers("localhost");
split.setIterators(iterators);
split.setLogLevel(Level.WARN);
@@ -115,6 +117,7 @@ public class RangeInputSplitTest {
Assert.assertEquals(split.getToken(), newSplit.getToken());
Assert.assertEquals(split.getPrincipal(), newSplit.getPrincipal());
Assert.assertEquals(split.getInstanceName(), newSplit.getInstanceName());
+ Assert.assertEquals(DeprecationUtil.isMockInstanceSet(split), DeprecationUtil.isMockInstanceSet(newSplit));
Assert.assertEquals(split.getZooKeepers(), newSplit.getZooKeepers());
Assert.assertEquals(split.getIterators(), newSplit.getIterators());
Assert.assertEquals(split.getLogLevel(), newSplit.getLogLevel());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java
index 50b149a..17c781d 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/impl/BatchInputSplitTest.java
@@ -33,6 +33,7 @@ import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.iterators.user.SummingCombiner;
import org.apache.accumulo.core.iterators.user.WholeRowIterator;
import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.Pair;
import org.apache.hadoop.io.Text;
import org.apache.log4j.Level;
@@ -87,6 +88,7 @@ public class BatchInputSplitTest {
split.setFetchedColumns(fetchedColumns);
split.setToken(new PasswordToken("password"));
split.setPrincipal("root");
+ DeprecationUtil.setMockInstance(split, true);
split.setInstanceName("instance");
split.setZooKeepers("localhost");
split.setIterators(iterators);
@@ -111,6 +113,7 @@ public class BatchInputSplitTest {
Assert.assertEquals(split.getToken(), newSplit.getToken());
Assert.assertEquals(split.getPrincipal(), newSplit.getPrincipal());
Assert.assertEquals(split.getInstanceName(), newSplit.getInstanceName());
+ Assert.assertEquals(DeprecationUtil.isMockInstanceSet(split), DeprecationUtil.isMockInstanceSet(newSplit));
Assert.assertEquals(split.getZooKeepers(), newSplit.getZooKeepers());
Assert.assertEquals(split.getIterators(), newSplit.getIterators());
Assert.assertEquals(split.getLogLevel(), newSplit.getLogLevel());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java
index 1eb29e3..7b5ac26 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/lib/impl/ConfiguratorBaseTest.java
@@ -26,6 +26,7 @@ import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
+import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken.AuthenticationTokenSerializer;
@@ -100,6 +101,19 @@ public class ConfiguratorBaseTest {
// assertEquals(1234000, ((ZooKeeperInstance) instance).getZooKeepersSessionTimeOut());
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testSetMockInstance() {
+ Class<?> mockClass = org.apache.accumulo.core.client.mock.MockInstance.class;
+ Configuration conf = new Configuration();
+ ConfiguratorBase.setMockInstance(this.getClass(), conf, "testInstanceName");
+ assertEquals("testInstanceName", conf.get(ConfiguratorBase.enumToConfKey(this.getClass(), ConfiguratorBase.InstanceOpts.NAME)));
+ assertEquals(null, conf.get(ConfiguratorBase.enumToConfKey(this.getClass(), ConfiguratorBase.InstanceOpts.ZOO_KEEPERS)));
+ assertEquals(mockClass.getSimpleName(), conf.get(ConfiguratorBase.enumToConfKey(this.getClass(), ConfiguratorBase.InstanceOpts.TYPE)));
+ Instance instance = ConfiguratorBase.getInstance(this.getClass(), conf);
+ assertEquals(mockClass.getName(), instance.getClass().getName());
+ }
+
@Test
public void testSetLogLevel() {
Configuration conf = new Configuration();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
new file mode 100644
index 0000000..b70cb00
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
@@ -0,0 +1,375 @@
+/*
+ * 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.client.mock;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchDeleter;
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MultiTableBatchWriter;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Combiner;
+import org.apache.accumulo.core.iterators.user.SummingCombiner;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.hadoop.io.Text;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.Iterators;
+
+@Deprecated
+public class MockConnectorTest {
+ Random random = new Random();
+
+ static Text asText(int i) {
+ return new Text(Integer.toHexString(i));
+ }
+
+ @Test
+ public void testSunnyDay() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("test");
+ BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
+ for (int i = 0; i < 100; i++) {
+ int r = random.nextInt();
+ Mutation m = new Mutation(asText(r));
+ m.put(asText(random.nextInt()), asText(random.nextInt()), new Value(Integer.toHexString(r).getBytes()));
+ bw.addMutation(m);
+ }
+ bw.close();
+ BatchScanner s = c.createBatchScanner("test", Authorizations.EMPTY, 2);
+ s.setRanges(Collections.singletonList(new Range()));
+ Key key = null;
+ int count = 0;
+ for (Entry<Key,Value> entry : s) {
+ if (key != null)
+ assertTrue(key.compareTo(entry.getKey()) < 0);
+ assertEquals(entry.getKey().getRow(), new Text(entry.getValue().get()));
+ key = entry.getKey();
+ count++;
+ }
+ assertEquals(100, count);
+ }
+
+ @Test
+ public void testChangeAuths() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.securityOperations().createLocalUser("greg", new PasswordToken(new byte[0]));
+ assertTrue(c.securityOperations().getUserAuthorizations("greg").isEmpty());
+ c.securityOperations().changeUserAuthorizations("greg", new Authorizations("A".getBytes()));
+ assertTrue(c.securityOperations().getUserAuthorizations("greg").contains("A".getBytes()));
+ c.securityOperations().changeUserAuthorizations("greg", new Authorizations("X", "Y", "Z"));
+ assertTrue(c.securityOperations().getUserAuthorizations("greg").contains("X".getBytes()));
+ assertFalse(c.securityOperations().getUserAuthorizations("greg").contains("A".getBytes()));
+ }
+
+ @Test
+ public void testBadMutations() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("test");
+ BatchWriter bw = c
+ .createBatchWriter("test", new BatchWriterConfig().setMaxMemory(10000L).setMaxLatency(1000L, TimeUnit.MILLISECONDS).setMaxWriteThreads(4));
+
+ try {
+ bw.addMutation(null);
+ Assert.fail("addMutation should throw IAE for null mutation");
+ } catch (IllegalArgumentException iae) {}
+ try {
+ bw.addMutations(null);
+ Assert.fail("addMutations should throw IAE for null iterable");
+ } catch (IllegalArgumentException iae) {}
+
+ bw.addMutations(Collections.<Mutation> emptyList());
+
+ Mutation bad = new Mutation("bad");
+ try {
+ bw.addMutation(bad);
+ Assert.fail("addMutation should throw IAE for empty mutation");
+ } catch (IllegalArgumentException iae) {}
+
+ Mutation good = new Mutation("good");
+ good.put(asText(random.nextInt()), asText(random.nextInt()), new Value("good".getBytes()));
+ List<Mutation> mutations = new ArrayList<>();
+ mutations.add(good);
+ mutations.add(bad);
+ try {
+ bw.addMutations(mutations);
+ Assert.fail("addMutations should throw IAE if it contains empty mutation");
+ } catch (IllegalArgumentException iae) {}
+
+ bw.close();
+ }
+
+ @Test
+ public void testAggregation() throws Exception {
+ MockInstance mockInstance = new MockInstance();
+ Connector c = mockInstance.getConnector("root", new PasswordToken(""));
+ String table = "perDayCounts";
+ c.tableOperations().create(table);
+ IteratorSetting is = new IteratorSetting(10, "String Summation", SummingCombiner.class);
+ Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("day")));
+ SummingCombiner.setEncodingType(is, SummingCombiner.Type.STRING);
+ c.tableOperations().attachIterator(table, is);
+ String keys[][] = { {"foo", "day", "20080101"}, {"foo", "day", "20080101"}, {"foo", "day", "20080103"}, {"bar", "day", "20080101"},
+ {"bar", "day", "20080101"},};
+ BatchWriter bw = c.createBatchWriter("perDayCounts", new BatchWriterConfig());
+ for (String elt[] : keys) {
+ Mutation m = new Mutation(new Text(elt[0]));
+ m.put(new Text(elt[1]), new Text(elt[2]), new Value("1".getBytes()));
+ bw.addMutation(m);
+ }
+ bw.close();
+
+ Scanner s = c.createScanner("perDayCounts", Authorizations.EMPTY);
+ Iterator<Entry<Key,Value>> iterator = s.iterator();
+ assertTrue(iterator.hasNext());
+ checkEntry(iterator.next(), "bar", "day", "20080101", "2");
+ assertTrue(iterator.hasNext());
+ checkEntry(iterator.next(), "foo", "day", "20080101", "2");
+ assertTrue(iterator.hasNext());
+ checkEntry(iterator.next(), "foo", "day", "20080103", "1");
+ assertFalse(iterator.hasNext());
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("test");
+ BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
+
+ Mutation m1 = new Mutation("r1");
+
+ m1.put("cf1", "cq1", 1, "v1");
+
+ bw.addMutation(m1);
+ bw.flush();
+
+ Mutation m2 = new Mutation("r1");
+
+ m2.putDelete("cf1", "cq1", 2);
+
+ bw.addMutation(m2);
+ bw.flush();
+
+ Scanner scanner = c.createScanner("test", Authorizations.EMPTY);
+
+ int count = Iterators.size(scanner.iterator());
+
+ assertEquals(0, count);
+
+ try {
+ c.tableOperations().create("test_this_$tableName");
+ assertTrue(false);
+
+ } catch (IllegalArgumentException iae) {
+
+ }
+ }
+
+ @Test
+ public void testDeletewithBatchDeleter() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+
+ // make sure we are using a clean table
+ if (c.tableOperations().exists("test"))
+ c.tableOperations().delete("test");
+ c.tableOperations().create("test");
+
+ BatchDeleter deleter = c.createBatchDeleter("test", Authorizations.EMPTY, 2, new BatchWriterConfig());
+ // first make sure it deletes fine when its empty
+ deleter.setRanges(Collections.singletonList(new Range(("r1"))));
+ deleter.delete();
+ this.checkRemaining(c, "test", 0);
+
+ // test deleting just one row
+ BatchWriter writer = c.createBatchWriter("test", new BatchWriterConfig());
+ Mutation m = new Mutation("r1");
+ m.put("fam", "qual", "value");
+ writer.addMutation(m);
+
+ // make sure the write goes through
+ writer.flush();
+ writer.close();
+
+ deleter.setRanges(Collections.singletonList(new Range(("r1"))));
+ deleter.delete();
+ this.checkRemaining(c, "test", 0);
+
+ // test multi row deletes
+ writer = c.createBatchWriter("test", new BatchWriterConfig());
+ m = new Mutation("r1");
+ m.put("fam", "qual", "value");
+ writer.addMutation(m);
+ Mutation m2 = new Mutation("r2");
+ m2.put("fam", "qual", "value");
+ writer.addMutation(m2);
+
+ // make sure the write goes through
+ writer.flush();
+ writer.close();
+
+ deleter.setRanges(Collections.singletonList(new Range(("r1"))));
+ deleter.delete();
+ checkRemaining(c, "test", 1);
+ }
+
+ /**
+ * Test to make sure that a certain number of rows remain
+ *
+ * @param c
+ * connector to the {@link MockInstance}
+ * @param tableName
+ * Table to check
+ * @param count
+ * number of entries to expect in the table
+ */
+ private void checkRemaining(Connector c, String tableName, int count) throws Exception {
+ Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY);
+
+ int total = Iterators.size(scanner.iterator());
+ assertEquals(count, total);
+ }
+
+ @Test
+ public void testCMod() throws Exception {
+ // test writing to a table that the is being scanned
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("test");
+ BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
+
+ for (int i = 0; i < 10; i++) {
+ Mutation m1 = new Mutation("r" + i);
+ m1.put("cf1", "cq1", 1, "v" + i);
+ bw.addMutation(m1);
+ }
+
+ bw.flush();
+
+ int count = 10;
+
+ Scanner scanner = c.createScanner("test", Authorizations.EMPTY);
+ for (Entry<Key,Value> entry : scanner) {
+ Key key = entry.getKey();
+ Mutation m = new Mutation(key.getRow());
+ m.put(key.getColumnFamily().toString(), key.getColumnQualifier().toString(), key.getTimestamp() + 1, "v" + (count));
+ count++;
+ bw.addMutation(m);
+ }
+
+ bw.flush();
+
+ count = 10;
+
+ for (Entry<Key,Value> entry : scanner) {
+ assertEquals(entry.getValue().toString(), "v" + (count++));
+ }
+
+ assertEquals(count, 20);
+
+ try {
+ c.tableOperations().create("test_this_$tableName");
+ assertTrue(false);
+
+ } catch (IllegalArgumentException iae) {
+
+ }
+ }
+
+ private void checkEntry(Entry<Key,Value> next, String row, String cf, String cq, String value) {
+ assertEquals(row, next.getKey().getRow().toString());
+ assertEquals(cf, next.getKey().getColumnFamily().toString());
+ assertEquals(cq, next.getKey().getColumnQualifier().toString());
+ assertEquals(value, next.getValue().toString());
+ }
+
+ @Test
+ public void testMockMultiTableBatchWriter() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("a");
+ c.tableOperations().create("b");
+ MultiTableBatchWriter bw = c.createMultiTableBatchWriter(new BatchWriterConfig());
+ Mutation m1 = new Mutation("r1");
+ m1.put("cf1", "cq1", 1, "v1");
+ BatchWriter b = bw.getBatchWriter("a");
+ b.addMutation(m1);
+ b.flush();
+ b = bw.getBatchWriter("b");
+ b.addMutation(m1);
+ b.flush();
+
+ Scanner scanner = c.createScanner("a", Authorizations.EMPTY);
+ int count = Iterators.size(scanner.iterator());
+ assertEquals(1, count);
+ scanner = c.createScanner("b", Authorizations.EMPTY);
+ count = Iterators.size(scanner.iterator());
+ assertEquals(1, count);
+
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ Connector c = new MockConnector("root", new MockInstance());
+ c.tableOperations().create("test");
+ BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
+
+ for (int i = 0; i < 10; i++) {
+ Mutation m = new Mutation("r1");
+ m.put("cf1", "cq1", "" + i);
+ bw.addMutation(m);
+ }
+
+ bw.close();
+
+ Scanner scanner = c.createScanner("test", Authorizations.EMPTY);
+
+ Entry<Key,Value> entry = scanner.iterator().next();
+
+ assertEquals("9", entry.getValue().toString());
+
+ }
+
+ @Test
+ public void testMockConnectorReturnsCorrectInstance() throws AccumuloException, AccumuloSecurityException {
+ String name = "an-interesting-instance-name";
+ Instance mockInstance = new MockInstance(name);
+ assertEquals(mockInstance, mockInstance.getConnector("foo", new PasswordToken("bar")).getInstance());
+ assertEquals(name, mockInstance.getConnector("foo", new PasswordToken("bar")).getInstance().getInstanceName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
new file mode 100644
index 0000000..ca12838
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
@@ -0,0 +1,297 @@
+/*
+ * 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.client.mock;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Map.Entry;
+
+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.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.NamespaceNotEmptyException;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.admin.NamespaceOperations;
+import org.apache.accumulo.core.client.impl.Namespaces;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Filter;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.security.Authorizations;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+@Deprecated
+public class MockNamespacesTest {
+
+ @Rule
+ public TestName test = new TestName();
+
+ private Connector conn;
+
+ @Before
+ public void setupInstance() throws Exception {
+ Instance inst = new MockInstance(test.getMethodName());
+ conn = inst.getConnector("user", new PasswordToken("pass"));
+ }
+
+ /**
+ * This test creates a table without specifying a namespace. In this case, it puts the table into the default namespace.
+ */
+ @Test
+ public void testDefaultNamespace() throws Exception {
+ String tableName = "test";
+
+ assertTrue(conn.namespaceOperations().exists(Namespaces.DEFAULT_NAMESPACE));
+ conn.tableOperations().create(tableName);
+ assertTrue(conn.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
+ * tables and delete the namespace.
+ */
+ @Test
+ public void testCreateAndDeleteNamespace() throws Exception {
+ String namespace = "testing";
+ String tableName1 = namespace + ".table1";
+ String tableName2 = namespace + ".table2";
+
+ conn.namespaceOperations().create(namespace);
+ assertTrue(conn.namespaceOperations().exists(namespace));
+
+ conn.tableOperations().create(tableName1);
+ assertTrue(conn.tableOperations().exists(tableName1));
+
+ conn.tableOperations().create(tableName2);
+ assertTrue(conn.tableOperations().exists(tableName2));
+
+ // deleting
+ try {
+ // can't delete a namespace with tables in it
+ conn.namespaceOperations().delete(namespace);
+ fail();
+ } catch (NamespaceNotEmptyException e) {
+ // ignore, supposed to happen
+ }
+ assertTrue(conn.namespaceOperations().exists(namespace));
+ assertTrue(conn.tableOperations().exists(tableName1));
+ assertTrue(conn.tableOperations().exists(tableName2));
+
+ conn.tableOperations().delete(tableName2);
+ assertTrue(!conn.tableOperations().exists(tableName2));
+ assertTrue(conn.namespaceOperations().exists(namespace));
+
+ conn.tableOperations().delete(tableName1);
+ assertTrue(!conn.tableOperations().exists(tableName1));
+ conn.namespaceOperations().delete(namespace);
+ assertTrue(!conn.namespaceOperations().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 {@link NamespaceOperations}.
+ *
+ * Checks to make sure namespace-level properties are overridden by table-level properties.
+ *
+ * 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";
+
+ conn.namespaceOperations().create(namespace);
+ conn.tableOperations().create(tableName1);
+ conn.namespaceOperations().setProperty(namespace, propKey, propVal);
+
+ // check the namespace has the property
+ assertTrue(checkNamespaceHasProp(conn, namespace, propKey, propVal));
+
+ // check that the table gets it from the namespace
+ assertTrue(checkTableHasProp(conn, 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)
+ conn.tableOperations().create(tableName2);
+ assertTrue(checkTableHasProp(conn, tableName2, propKey, propVal));
+
+ // test that table properties override namespace properties
+ String propKey2 = Property.TABLE_FILE_MAX.getKey();
+ String propVal2 = "42";
+ String tablePropVal = "13";
+
+ conn.tableOperations().setProperty(tableName2, propKey2, tablePropVal);
+ conn.namespaceOperations().setProperty("propchange", propKey2, propVal2);
+
+ assertTrue(checkTableHasProp(conn, tableName2, propKey2, tablePropVal));
+
+ // now check that you can change the default namespace's properties
+ propVal = "13K";
+ String tableName = "some_table";
+ conn.tableOperations().create(tableName);
+ conn.namespaceOperations().setProperty(Namespaces.DEFAULT_NAMESPACE, propKey, propVal);
+
+ assertTrue(checkTableHasProp(conn, tableName, propKey, propVal));
+
+ // test the properties server-side by configuring an iterator.
+ // should not show anything with column-family = 'a'
+ String tableName3 = namespace + ".table3";
+ conn.tableOperations().create(tableName3);
+
+ IteratorSetting setting = new IteratorSetting(250, "thing", SimpleFilter.class.getName());
+ conn.namespaceOperations().attachIterator(namespace, setting);
+
+ BatchWriter bw = conn.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);
+ // do scanners work correctly in mock?
+ // assertTrue(!s.iterator().hasNext());
+ }
+
+ /**
+ * This test renames and clones two separate table into different namespaces. different namespace.
+ */
+ @Test
+ public void testRenameAndCloneTableToNewNamespace() throws Exception {
+ String namespace1 = "renamed";
+ String namespace2 = "cloned";
+ String tableName = "table";
+ String tableName1 = "renamed.table1";
+ // String tableName2 = "cloned.table2";
+
+ conn.tableOperations().create(tableName);
+ conn.namespaceOperations().create(namespace1);
+ conn.namespaceOperations().create(namespace2);
+
+ conn.tableOperations().rename(tableName, tableName1);
+
+ assertTrue(conn.tableOperations().exists(tableName1));
+ assertTrue(!conn.tableOperations().exists(tableName));
+
+ // TODO implement clone in mock
+ // c.tableOperations().clone(tableName1, tableName2, false, null, null);
+ // assertTrue(c.tableOperations().exists(tableName1)); assertTrue(c.tableOperations().exists(tableName2));
+ }
+
+ /**
+ * This test renames a namespace and ensures that its tables are still correct
+ */
+ @Test
+ public void testNamespaceRename() throws Exception {
+ String namespace1 = "n1";
+ String namespace2 = "n2";
+ String table = "t";
+
+ conn.namespaceOperations().create(namespace1);
+ conn.tableOperations().create(namespace1 + "." + table);
+
+ conn.namespaceOperations().rename(namespace1, namespace2);
+
+ assertTrue(!conn.namespaceOperations().exists(namespace1));
+ assertTrue(conn.namespaceOperations().exists(namespace2));
+ assertTrue(!conn.tableOperations().exists(namespace1 + "." + table));
+ assertTrue(conn.tableOperations().exists(namespace2 + "." + table));
+ }
+
+ /**
+ * This tests adding iterators to a namespace, listing them, and removing them
+ */
+ @Test
+ public void testNamespaceIterators() throws Exception {
+ String namespace = "iterator";
+ String tableName = namespace + ".table";
+ String iter = "thing";
+
+ conn.namespaceOperations().create(namespace);
+ conn.tableOperations().create(tableName);
+
+ IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
+ HashSet<IteratorScope> scope = new HashSet<>();
+ scope.add(IteratorScope.scan);
+ conn.namespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
+
+ BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
+ Mutation m = new Mutation("r");
+ m.put("a", "b", new Value("abcde".getBytes(UTF_8)));
+ bw.addMutation(m);
+ bw.flush();
+
+ Scanner s = conn.createScanner(tableName, Authorizations.EMPTY);
+ System.out.println(s.iterator().next());
+ // do scanners work correctly in mock?
+ // assertTrue(!s.iterator().hasNext());
+
+ assertTrue(conn.namespaceOperations().listIterators(namespace).containsKey(iter));
+ conn.namespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
+ }
+
+ 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)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean checkNamespaceHasProp(Connector c, String n, String propKey, String propVal) throws AccumuloException, NamespaceNotFoundException,
+ AccumuloSecurityException {
+ for (Entry<String,String> e : c.namespaceOperations().getProperties(n)) {
+ if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static class SimpleFilter extends Filter {
+ @Override
+ public boolean accept(Key k, Value v) {
+ if (k.getColumnFamily().toString().equals("a"))
+ return false;
+ return true;
+ }
+ }
+}
[5/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
new file mode 100644
index 0000000..de89137
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
@@ -0,0 +1,505 @@
+/*
+ * 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.client.mock;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+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;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.admin.CompactionConfig;
+import org.apache.accumulo.core.client.admin.DiskUsage;
+import org.apache.accumulo.core.client.admin.FindMax;
+import org.apache.accumulo.core.client.admin.Locations;
+import org.apache.accumulo.core.client.admin.NewTableConfiguration;
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.client.impl.TableOperationsHelper;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.sample.SamplerConfiguration;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.file.FileOperations;
+import org.apache.accumulo.core.file.FileSKVIterator;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.ColumnVisibility;
+import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+class MockTableOperations extends TableOperationsHelper {
+ private static final Logger log = LoggerFactory.getLogger(MockTableOperations.class);
+ private static final byte[] ZERO = {0};
+ private final MockAccumulo acu;
+ private final String username;
+
+ MockTableOperations(MockAccumulo acu, String username) {
+ this.acu = acu;
+ this.username = username;
+ }
+
+ @Override
+ public SortedSet<String> list() {
+ return new TreeSet<>(acu.tables.keySet());
+ }
+
+ @Override
+ public boolean exists(String tableName) {
+ return acu.tables.containsKey(tableName);
+ }
+
+ private boolean namespaceExists(String namespace) {
+ return acu.namespaces.containsKey(namespace);
+ }
+
+ @Override
+ public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ create(tableName, new NewTableConfiguration());
+ }
+
+ @Override
+ @Deprecated
+ public void create(String tableName, boolean versioningIter) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ create(tableName, versioningIter, TimeType.MILLIS);
+ }
+
+ @Override
+ @Deprecated
+ public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ NewTableConfiguration ntc = new NewTableConfiguration().setTimeType(timeType);
+
+ if (versioningIter)
+ create(tableName, ntc);
+ else
+ create(tableName, ntc.withoutDefaultIterators());
+ }
+
+ @Override
+ public void create(String tableName, NewTableConfiguration ntc) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ String namespace = Tables.qualify(tableName).getFirst();
+
+ checkArgument(tableName.matches(Tables.VALID_NAME_REGEX));
+ if (exists(tableName))
+ throw new TableExistsException(tableName, tableName, "");
+ checkArgument(namespaceExists(namespace), "Namespace (" + namespace + ") does not exist, create it first");
+ acu.createTable(username, tableName, ntc.getTimeType(), ntc.getProperties());
+ }
+
+ @Override
+ public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ acu.addSplits(tableName, partitionKeys);
+ }
+
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName) throws TableNotFoundException {
+ return listSplits(tableName);
+ }
+
+ @Deprecated
+ @Override
+ public Collection<Text> getSplits(String tableName, int maxSplits) throws TableNotFoundException {
+ return listSplits(tableName);
+ }
+
+ @Override
+ public Collection<Text> listSplits(String tableName) throws TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ return acu.getSplits(tableName);
+ }
+
+ @Override
+ public Collection<Text> listSplits(String tableName, int maxSplits) throws TableNotFoundException {
+ return listSplits(tableName);
+ }
+
+ @Override
+ public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ acu.tables.remove(tableName);
+ }
+
+ @Override
+ public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
+ TableExistsException {
+ if (!exists(oldTableName))
+ throw new TableNotFoundException(oldTableName, oldTableName, "");
+ if (exists(newTableName))
+ throw new TableExistsException(newTableName, newTableName, "");
+ MockTable t = acu.tables.remove(oldTableName);
+ String namespace = Tables.qualify(newTableName).getFirst();
+ MockNamespace n = acu.namespaces.get(namespace);
+ if (n == null) {
+ n = new MockNamespace();
+ }
+ t.setNamespaceName(namespace);
+ t.setNamespace(n);
+ acu.namespaces.put(namespace, n);
+ acu.tables.put(newTableName, t);
+ }
+
+ @Deprecated
+ @Override
+ public void flush(String tableName) throws AccumuloException, AccumuloSecurityException {}
+
+ @Override
+ public void setProperty(String tableName, String property, String value) throws AccumuloException, AccumuloSecurityException {
+ acu.tables.get(tableName).settings.put(property, value);
+ }
+
+ @Override
+ public void removeProperty(String tableName, String property) throws AccumuloException, AccumuloSecurityException {
+ acu.tables.get(tableName).settings.remove(property);
+ }
+
+ @Override
+ public Iterable<Entry<String,String>> getProperties(String tableName) throws TableNotFoundException {
+ String namespace = Tables.qualify(tableName).getFirst();
+ if (!exists(tableName)) {
+ if (!namespaceExists(namespace))
+ throw new TableNotFoundException(tableName, new NamespaceNotFoundException(null, namespace, null));
+ throw new TableNotFoundException(null, tableName, null);
+ }
+
+ Set<Entry<String,String>> props = new HashSet<>(acu.namespaces.get(namespace).settings.entrySet());
+
+ Set<Entry<String,String>> tableProps = acu.tables.get(tableName).settings.entrySet();
+ for (Entry<String,String> e : tableProps) {
+ if (props.contains(e)) {
+ props.remove(e);
+ }
+ props.add(e);
+ }
+ return props;
+ }
+
+ @Override
+ public void setLocalityGroups(String tableName, Map<String,Set<Text>> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ acu.tables.get(tableName).setLocalityGroups(groups);
+ }
+
+ @Override
+ public Map<String,Set<Text>> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ return acu.tables.get(tableName).getLocalityGroups();
+ }
+
+ @Override
+ public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ return Collections.singleton(range);
+ }
+
+ @Override
+ public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloException,
+ AccumuloSecurityException, TableNotFoundException {
+ long time = System.currentTimeMillis();
+ MockTable table = acu.tables.get(tableName);
+ if (table == null) {
+ throw new TableNotFoundException(null, tableName, "The table was not found");
+ }
+ Path importPath = new Path(dir);
+ Path failurePath = new Path(failureDir);
+
+ FileSystem fs = acu.getFileSystem();
+ /*
+ * check preconditions
+ */
+ // directories are directories
+ if (fs.isFile(importPath)) {
+ throw new IOException("Import path must be a directory.");
+ }
+ if (fs.isFile(failurePath)) {
+ throw new IOException("Failure path must be a directory.");
+ }
+ // failures are writable
+ Path createPath = failurePath.suffix("/.createFile");
+ FSDataOutputStream createStream = null;
+ try {
+ createStream = fs.create(createPath);
+ } catch (IOException e) {
+ throw new IOException("Error path is not writable.");
+ } finally {
+ if (createStream != null) {
+ createStream.close();
+ }
+ }
+ fs.delete(createPath, false);
+ // failures are empty
+ FileStatus[] failureChildStats = fs.listStatus(failurePath);
+ if (failureChildStats.length > 0) {
+ throw new IOException("Error path must be empty.");
+ }
+ /*
+ * Begin the import - iterate the files in the path
+ */
+ for (FileStatus importStatus : fs.listStatus(importPath)) {
+ try {
+ FileSKVIterator importIterator = FileOperations.getInstance().newReaderBuilder().forFile(importStatus.getPath().toString(), fs, fs.getConf())
+ .withTableConfiguration(AccumuloConfiguration.getDefaultConfiguration()).seekToBeginning().build();
+ while (importIterator.hasTop()) {
+ Key key = importIterator.getTopKey();
+ Value value = importIterator.getTopValue();
+ if (setTime) {
+ key.setTimestamp(time);
+ }
+ Mutation mutation = new Mutation(key.getRow());
+ if (!key.isDeleted()) {
+ mutation.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()), key.getTimestamp(),
+ value);
+ } else {
+ mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibilityData().toArray()),
+ key.getTimestamp());
+ }
+ table.addMutation(mutation);
+ importIterator.next();
+ }
+ } catch (Exception e) {
+ FSDataOutputStream failureWriter = null;
+ DataInputStream failureReader = null;
+ try {
+ failureWriter = fs.create(failurePath.suffix("/" + importStatus.getPath().getName()));
+ failureReader = fs.open(importStatus.getPath());
+ int read = 0;
+ byte[] buffer = new byte[1024];
+ while (-1 != (read = failureReader.read(buffer))) {
+ failureWriter.write(buffer, 0, read);
+ }
+ } finally {
+ if (failureReader != null)
+ failureReader.close();
+ if (failureWriter != null)
+ failureWriter.close();
+ }
+ }
+ fs.delete(importStatus.getPath(), true);
+ }
+ }
+
+ @Override
+ public void offline(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
+ offline(tableName, false);
+ }
+
+ @Override
+ public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public void online(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
+ online(tableName, false);
+ }
+
+ @Override
+ public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public void clearLocatorCache(String tableName) throws TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public Map<String,String> tableIdMap() {
+ Map<String,String> result = new HashMap<>();
+ for (Entry<String,MockTable> entry : acu.tables.entrySet()) {
+ String table = entry.getKey();
+ if (RootTable.NAME.equals(table))
+ result.put(table, RootTable.ID);
+ else if (MetadataTable.NAME.equals(table))
+ result.put(table, MetadataTable.ID);
+ else
+ result.put(table, entry.getValue().getTableId());
+ }
+ return result;
+ }
+
+ @Override
+ public List<DiskUsage> getDiskUsage(Set<String> tables) throws AccumuloException, AccumuloSecurityException {
+
+ List<DiskUsage> diskUsages = new ArrayList<>();
+ diskUsages.add(new DiskUsage(new TreeSet<>(tables), 0l));
+
+ return diskUsages;
+ }
+
+ @Override
+ public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ acu.merge(tableName, start, end);
+ }
+
+ @Override
+ public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ MockTable t = acu.tables.get(tableName);
+ Text startText = start != null ? new Text(start) : new Text();
+ if (startText.getLength() == 0 && end == null) {
+ t.table.clear();
+ return;
+ }
+ Text endText = end != null ? new Text(end) : new Text(t.table.lastKey().getRow().getBytes());
+ startText.append(ZERO, 0, 1);
+ endText.append(ZERO, 0, 1);
+ Set<Key> keep = new TreeSet<>(t.table.subMap(new Key(startText), new Key(endText)).keySet());
+ t.table.keySet().removeAll(keep);
+ }
+
+ @Override
+ public void compact(String tableName, Text start, Text end, boolean flush, boolean wait) throws AccumuloSecurityException, TableNotFoundException,
+ AccumuloException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
+ TableNotFoundException, AccumuloException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+
+ if (iterators != null && iterators.size() > 0)
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+
+ if (config.getIterators().size() > 0 || config.getCompactionStrategy() != null)
+ throw new UnsupportedOperationException("Mock does not support iterators or compaction strategies for compactions");
+ }
+
+ @Override
+ public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
+ throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!exists(tableName))
+ throw new TableNotFoundException(tableName, tableName, "");
+ }
+
+ @Override
+ public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
+ throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+ MockTable table = acu.tables.get(tableName);
+ if (table == null)
+ throw new TableNotFoundException(tableName, tableName, "no such table");
+
+ return FindMax.findMax(new MockScanner(table, auths), startRow, startInclusive, endRow, endInclusive);
+ }
+
+ @Override
+ public void importTable(String tableName, String exportDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public boolean testClassLoad(String tableName, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+
+ try {
+ AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
+ } catch (ClassNotFoundException e) {
+ log.warn("Could not load class '" + className + "' with type name '" + asTypeName + "' in testClassLoad().", e);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void setSamplerConfiguration(String tableName, SamplerConfiguration samplerConfiguration) throws TableNotFoundException, AccumuloException,
+ AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clearSamplerConfiguration(String tableName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SamplerConfiguration getSamplerConfiguration(String tableName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Locations locate(String tableName, Collection<Range> ranges) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
new file mode 100644
index 0000000..e32edad
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockUser.java
@@ -0,0 +1,41 @@
+/*
+ * 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.client.mock;
+
+import java.util.EnumSet;
+
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.SystemPermission;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockUser {
+ final EnumSet<SystemPermission> permissions;
+ final String name;
+ AuthenticationToken token;
+ Authorizations authorizations;
+
+ MockUser(String principal, AuthenticationToken token, Authorizations auths) {
+ this.name = principal;
+ this.token = token.clone();
+ this.authorizations = auths;
+ this.permissions = EnumSet.noneOf(SystemPermission.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java
new file mode 100644
index 0000000..a52af79
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/impl/MockTabletLocator.java
@@ -0,0 +1,75 @@
+/*
+ * 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.client.mock.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+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.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.ClientContext;
+import org.apache.accumulo.core.client.impl.TabletLocator;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.impl.KeyExtent;
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockTabletLocator extends TabletLocator {
+ public MockTabletLocator() {}
+
+ @Override
+ public TabletLocation locateTablet(ClientContext context, Text row, boolean skipRow, boolean retry) throws AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <T extends Mutation> void binMutations(ClientContext context, List<T> mutations, Map<String,TabletServerMutations<T>> binnedMutations, List<T> failures)
+ throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ TabletServerMutations<T> tsm = new TabletServerMutations<>("5");
+ for (T m : mutations)
+ tsm.addMutation(new KeyExtent(), m);
+ binnedMutations.put("", tsm);
+ }
+
+ @Override
+ public List<Range> binRanges(ClientContext context, List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges) throws AccumuloException,
+ AccumuloSecurityException, TableNotFoundException {
+ binnedRanges.put("", Collections.singletonMap(new KeyExtent("", null, null), ranges));
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void invalidateCache(KeyExtent failedExtent) {}
+
+ @Override
+ public void invalidateCache(Collection<KeyExtent> keySet) {}
+
+ @Override
+ public void invalidateCache() {}
+
+ @Override
+ public void invalidateCache(Instance instance, String server) {}
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/package-info.java b/core/src/main/java/org/apache/accumulo/core/client/mock/package-info.java
new file mode 100644
index 0000000..cdd5593
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/package-info.java
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+/**
+ * Mock framework for Accumulo
+ *
+ * <p>
+ * Deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+package org.apache.accumulo.core.client.mock;
+
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
index 7b747d1..4dfba68 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileScanner.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
+import java.util.concurrent.TimeUnit;
import org.apache.accumulo.core.client.IteratorSetting;
import org.apache.accumulo.core.client.Scanner;
@@ -155,6 +156,24 @@ class RFileScanner extends ScannerOptions implements Scanner {
throw new UnsupportedOperationException();
}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ if (timeOut == Integer.MAX_VALUE)
+ setTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ else
+ setTimeout(timeOut, TimeUnit.SECONDS);
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ long timeout = getTimeout(TimeUnit.SECONDS);
+ if (timeout >= Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ return (int) timeout;
+ }
+
@Override
public void setRange(Range range) {
this.range = range;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/security/tokens/KerberosToken.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/security/tokens/KerberosToken.java b/core/src/main/java/org/apache/accumulo/core/client/security/tokens/KerberosToken.java
index 26f2d02..1a4869d 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/security/tokens/KerberosToken.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/security/tokens/KerberosToken.java
@@ -69,10 +69,33 @@ public class KerberosToken implements AuthenticationToken {
* A keytab file containing the principal's credentials.
*/
public KerberosToken(String principal, File keytab) throws IOException {
+ this(principal, keytab, false);
+ }
+
+ /**
+ * Creates a token and logs in via {@link UserGroupInformation} using the provided principal and keytab. A key for the principal must exist in the keytab,
+ * otherwise login will fail.
+ *
+ * @param principal
+ * The Kerberos principal
+ * @param keytab
+ * A keytab file
+ * @param replaceCurrentUser
+ * Should the current Hadoop user be replaced with this user
+ * @deprecated since 1.8.0, @see #KerberosToken(String, File)
+ */
+ @Deprecated
+ public KerberosToken(String principal, File keytab, boolean replaceCurrentUser) throws IOException {
requireNonNull(principal, "Principal was null");
requireNonNull(keytab, "Keytab was null");
checkArgument(keytab.exists() && keytab.isFile(), "Keytab was not a normal file");
- UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab.getAbsolutePath());
+ UserGroupInformation ugi;
+ if (replaceCurrentUser) {
+ UserGroupInformation.loginUserFromKeytab(principal, keytab.getAbsolutePath());
+ ugi = UserGroupInformation.getCurrentUser();
+ } else {
+ ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab.getAbsolutePath());
+ }
this.principal = ugi.getUserName();
this.keytab = keytab;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/conf/Property.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
index 143b823..5f4f715 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
@@ -159,6 +159,9 @@ public enum Property {
*/
INSTANCE_RPC_SASL_ENABLED("instance.rpc.sasl.enabled", "false", PropertyType.BOOLEAN,
"Configures Thrift RPCs to require SASL with GSSAPI which supports Kerberos authentication. Mutually exclusive with SSL RPC configuration."),
+ @Deprecated
+ INSTANCE_RPC_SASL_PROXYUSERS("instance.rpc.sasl.impersonation.", null, PropertyType.PREFIX,
+ "Prefix that allows configuration of users that are allowed to impersonate other users"),
INSTANCE_RPC_SASL_ALLOWED_USER_IMPERSONATION("instance.rpc.sasl.allowed.user.impersonation", "", PropertyType.STRING,
"One-line configuration property controlling what users are allowed to impersonate other users"),
INSTANCE_RPC_SASL_ALLOWED_HOST_IMPERSONATION("instance.rpc.sasl.allowed.host.impersonation", "", PropertyType.STRING,
@@ -242,6 +245,12 @@ public enum Property {
TSERV_INDEXCACHE_SIZE("tserver.cache.index.size", "512M", PropertyType.MEMORY, "Specifies the size of the cache for file indices."),
TSERV_PORTSEARCH("tserver.port.search", "false", PropertyType.BOOLEAN, "if the ports above are in use, search higher ports until one is available"),
TSERV_CLIENTPORT("tserver.port.client", "9997", PropertyType.PORT, "The port used for handling client connections on the tablet servers"),
+ @Deprecated
+ TSERV_MUTATION_QUEUE_MAX("tserver.mutation.queue.max", "1M", PropertyType.MEMORY, "This setting is deprecated. See tserver.total.mutation.queue.max. "
+ + "The amount of memory to use to store write-ahead-log mutations-per-session before flushing them. Since the buffer is per write session, consider the"
+ + " max number of concurrent writer when configuring. When using Hadoop 2, Accumulo will call hsync() on the WAL . For a small number of "
+ + "concurrent writers, increasing this buffer size decreases the frequncy of hsync calls. For a large number of concurrent writers a small buffers "
+ + "size is ok because of group commit."),
TSERV_TOTAL_MUTATION_QUEUE_MAX("tserver.total.mutation.queue.max", "50M", PropertyType.MEMORY,
"The amount of memory used to store write-ahead-log mutations before flushing them."),
TSERV_TABLET_SPLIT_FINDMIDPOINT_MAXOPEN("tserver.tablet.split.midpoint.files.max", "300", PropertyType.COUNT,
@@ -335,6 +344,8 @@ public enum Property {
"The number of threads for the distributed work queue. These threads are used for copying failed bulk files."),
TSERV_WAL_SYNC("tserver.wal.sync", "true", PropertyType.BOOLEAN,
"Use the SYNC_BLOCK create flag to sync WAL writes to disk. Prevents problems recovering from sudden system resets."),
+ @Deprecated
+ TSERV_WAL_SYNC_METHOD("tserver.wal.sync.method", "hsync", PropertyType.STRING, "This property is deprecated. Use table.durability instead."),
TSERV_ASSIGNMENT_DURATION_WARNING("tserver.assignment.duration.warning", "10m", PropertyType.TIMEDURATION, "The amount of time an assignment can run "
+ " before the server will print a warning along with the current stack trace. Meant to help debug stuck assignments"),
TSERV_REPLICATION_REPLAYERS("tserver.replication.replayer.", null, PropertyType.PREFIX,
@@ -454,6 +465,8 @@ public enum Property {
"Determines the max # of files each tablet in a table can have. When adjusting this property you may want to consider adjusting"
+ " table.compaction.major.ratio also. Setting this property to 0 will make it default to tserver.scan.files.open.max-1, this will prevent a"
+ " tablet from having more files than can be opened. Setting this property low may throttle ingest and increase query performance."),
+ @Deprecated
+ TABLE_WALOG_ENABLED("table.walog.enabled", "true", PropertyType.BOOLEAN, "This setting is deprecated. Use table.durability=none instead."),
TABLE_BLOOM_ENABLED("table.bloom.enabled", "false", PropertyType.BOOLEAN, "Use bloom filters on this table."),
TABLE_BLOOM_LOAD_THRESHOLD("table.bloom.load.threshold", "1", PropertyType.COUNT,
"This number of seeks that would actually use a bloom filter must occur before a file's bloom filter is loaded."
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java b/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java
index b70afc6..a936ef5 100644
--- a/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java
+++ b/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.impl.KeyExtent;
import org.apache.accumulo.core.security.AuthorizationContainer;
+import org.apache.accumulo.core.security.Authorizations;
/**
* Constraint objects are used to determine if mutations will be applied to a table.
@@ -61,6 +62,15 @@ public interface Constraint {
* Gets the authorizations in the environment.
*
* @return authorizations
+ * @deprecated Use {@link #getAuthorizationsContainer()} instead.
+ */
+ @Deprecated
+ Authorizations getAuthorizations();
+
+ /**
+ * Gets the authorizations in the environment.
+ *
+ * @return authorizations
*/
AuthorizationContainer getAuthorizationsContainer();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/ComparableBytes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/ComparableBytes.java b/core/src/main/java/org/apache/accumulo/core/data/ComparableBytes.java
new file mode 100644
index 0000000..78c0e56
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/data/ComparableBytes.java
@@ -0,0 +1,58 @@
+/*
+ * 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.data;
+
+import org.apache.hadoop.io.BinaryComparable;
+
+/**
+ * An array of bytes wrapped so as to extend Hadoop's <code>BinaryComparable</code> class.
+ *
+ * @deprecated since 1.7.0 In an attempt to clean up types in the data package that were not intended to be in public API this type was deprecated. Technically
+ * this method was not considered part of the public API in 1.6.0 and earlier, therefore it could have been deleted. However a decision was made to
+ * deprecate in order to be cautious and avoid confusion between 1.6.0 and 1.7.0.
+ */
+@Deprecated
+public class ComparableBytes extends BinaryComparable {
+
+ public byte[] data;
+
+ /**
+ * Creates a new byte wrapper. The given byte array is used directly as a backing array, so later changes made to the array reflect into the new object.
+ *
+ * @param b
+ * bytes to wrap
+ */
+ public ComparableBytes(byte[] b) {
+ this.data = b;
+ }
+
+ /**
+ * Gets the wrapped bytes in this object.
+ *
+ * @return bytes
+ */
+ @Override
+ public byte[] getBytes() {
+ return data;
+ }
+
+ @Override
+ public int getLength() {
+ return data.length;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/KeyExtent.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/KeyExtent.java b/core/src/main/java/org/apache/accumulo/core/data/KeyExtent.java
new file mode 100644
index 0000000..4e3d058
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/data/KeyExtent.java
@@ -0,0 +1,259 @@
+/*
+ * 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.data;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+
+import org.apache.accumulo.core.data.thrift.TKeyExtent;
+import org.apache.accumulo.core.metadata.schema.MetadataSchema;
+import org.apache.hadoop.io.BinaryComparable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.io.WritableComparable;
+
+/**
+ * keeps track of information needed to identify a tablet
+ *
+ * @deprecated since 1.7.0 use {@link TabletId}
+ */
+@Deprecated
+public class KeyExtent implements WritableComparable<KeyExtent> {
+
+ // Wrapping impl.KeyExtent to resuse code. Did not want to extend impl.KeyExtent because any changes to impl.KeyExtent would be reflected in this class.
+ // Wrapping impl.KeyExtent allows the API of this deprecated class to be frozen.
+ private org.apache.accumulo.core.data.impl.KeyExtent wrapped;
+
+ public KeyExtent() {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent();
+ }
+
+ public KeyExtent(Text table, Text endRow, Text prevEndRow) {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent(table.toString(), endRow, prevEndRow);
+ }
+
+ public KeyExtent(KeyExtent extent) {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent(extent.getTableId().toString(), extent.getEndRow(), extent.getPrevEndRow());
+ }
+
+ public KeyExtent(TKeyExtent tke) {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent(tke);
+ }
+
+ // constructor for loading extents from metadata rows
+ public KeyExtent(Text flattenedExtent, Value prevEndRow) {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent(flattenedExtent, prevEndRow);
+ }
+
+ // recreates an encoded extent from a string representation
+ // this encoding is what is stored as the row id of the metadata table
+ public KeyExtent(Text flattenedExtent, Text prevEndRow) {
+ this.wrapped = new org.apache.accumulo.core.data.impl.KeyExtent(flattenedExtent, prevEndRow);
+ }
+
+ public Text getMetadataEntry() {
+ return wrapped.getMetadataEntry();
+ }
+
+ public void setTableId(Text tId) {
+ wrapped.setTableId(tId.toString());
+ }
+
+ public Text getTableId() {
+ return new Text(wrapped.getTableId());
+ }
+
+ public void setEndRow(Text endRow) {
+ wrapped.setEndRow(endRow);
+ }
+
+ public Text getEndRow() {
+ return wrapped.getEndRow();
+ }
+
+ public Text getPrevEndRow() {
+ return wrapped.getPrevEndRow();
+ }
+
+ public void setPrevEndRow(Text prevEndRow) {
+ wrapped.setPrevEndRow(prevEndRow);
+ }
+
+ @Override
+ public void readFields(DataInput in) throws IOException {
+ wrapped.readFields(in);
+ }
+
+ @Override
+ public void write(DataOutput out) throws IOException {
+ wrapped.write(out);
+ }
+
+ public Mutation getPrevRowUpdateMutation() {
+ return wrapped.getPrevRowUpdateMutation();
+ }
+
+ @Override
+ public int compareTo(KeyExtent other) {
+ return wrapped.compareTo(other.wrapped);
+ }
+
+ @Override
+ public int hashCode() {
+ return wrapped.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof KeyExtent) {
+ return wrapped.equals(((KeyExtent) o).wrapped);
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return wrapped.toString();
+ }
+
+ public UUID getUUID() {
+ return wrapped.getUUID();
+ }
+
+ public boolean contains(ByteSequence bsrow) {
+ return wrapped.contains(bsrow);
+ }
+
+ public boolean contains(BinaryComparable row) {
+ return wrapped.contains(row);
+ }
+
+ public Range toDataRange() {
+ return wrapped.toDataRange();
+ }
+
+ public Range toMetadataRange() {
+ return wrapped.toMetadataRange();
+ }
+
+ public boolean overlaps(KeyExtent other) {
+ return wrapped.overlaps(other.wrapped);
+ }
+
+ public TKeyExtent toThrift() {
+ return wrapped.toThrift();
+ }
+
+ public boolean isPreviousExtent(KeyExtent prevExtent) {
+ return wrapped.isPreviousExtent(prevExtent.wrapped);
+ }
+
+ public boolean isMeta() {
+ return wrapped.isMeta();
+ }
+
+ public boolean isRootTablet() {
+ return wrapped.isRootTablet();
+ }
+
+ private static SortedSet<org.apache.accumulo.core.data.impl.KeyExtent> unwrap(Set<KeyExtent> tablets) {
+ SortedSet<org.apache.accumulo.core.data.impl.KeyExtent> trans = new TreeSet<>();
+ for (KeyExtent wrapper : tablets) {
+ trans.add(wrapper.wrapped);
+ }
+
+ return trans;
+ }
+
+ private static KeyExtent wrap(org.apache.accumulo.core.data.impl.KeyExtent ke) {
+ return new KeyExtent(new Text(ke.getTableId()), ke.getEndRow(), ke.getPrevEndRow());
+ }
+
+ private static SortedSet<KeyExtent> wrap(Collection<org.apache.accumulo.core.data.impl.KeyExtent> unwrapped) {
+ SortedSet<KeyExtent> wrapped = new TreeSet<>();
+ for (org.apache.accumulo.core.data.impl.KeyExtent wrappee : unwrapped) {
+ wrapped.add(wrap(wrappee));
+ }
+
+ return wrapped;
+ }
+
+ public static Text getMetadataEntry(Text tableId, Text endRow) {
+ return MetadataSchema.TabletsSection.getRow(tableId.toString(), endRow);
+ }
+
+ /**
+ * Empty start or end rows tell the method there are no start or end rows, and to use all the keyextents that are before the end row if no start row etc.
+ *
+ * @deprecated this method not intended for public use and is likely to be removed in a future version.
+ * @return all the key extents that the rows cover
+ */
+ @Deprecated
+ public static Collection<KeyExtent> getKeyExtentsForRange(Text startRow, Text endRow, Set<KeyExtent> kes) {
+ return wrap(org.apache.accumulo.core.data.impl.KeyExtent.getKeyExtentsForRange(startRow, endRow, unwrap(kes)));
+ }
+
+ public static Text decodePrevEndRow(Value ibw) {
+ return org.apache.accumulo.core.data.impl.KeyExtent.decodePrevEndRow(ibw);
+ }
+
+ public static Value encodePrevEndRow(Text per) {
+ return org.apache.accumulo.core.data.impl.KeyExtent.encodePrevEndRow(per);
+ }
+
+ public static Mutation getPrevRowUpdateMutation(KeyExtent ke) {
+ return org.apache.accumulo.core.data.impl.KeyExtent.getPrevRowUpdateMutation(ke.wrapped);
+ }
+
+ public static byte[] tableOfMetadataRow(Text row) {
+ return org.apache.accumulo.core.data.impl.KeyExtent.tableOfMetadataRow(row);
+ }
+
+ public static SortedSet<KeyExtent> findChildren(KeyExtent ke, SortedSet<KeyExtent> tablets) {
+ return wrap(org.apache.accumulo.core.data.impl.KeyExtent.findChildren(ke.wrapped, unwrap(tablets)));
+ }
+
+ public static KeyExtent findContainingExtent(KeyExtent extent, SortedSet<KeyExtent> extents) {
+ return wrap(org.apache.accumulo.core.data.impl.KeyExtent.findContainingExtent(extent.wrapped, unwrap(extents)));
+ }
+
+ public static Set<KeyExtent> findOverlapping(KeyExtent nke, SortedSet<KeyExtent> extents) {
+ return wrap(org.apache.accumulo.core.data.impl.KeyExtent.findOverlapping(nke.wrapped, unwrap(extents)));
+ }
+
+ public static Set<KeyExtent> findOverlapping(KeyExtent nke, SortedMap<KeyExtent,?> extents) {
+ SortedMap<org.apache.accumulo.core.data.impl.KeyExtent,Object> trans = new TreeMap<>();
+ for (Entry<KeyExtent,?> entry : extents.entrySet()) {
+ trans.put(entry.getKey().wrapped, entry.getValue());
+ }
+
+ return wrap(org.apache.accumulo.core.data.impl.KeyExtent.findOverlapping(nke.wrapped, trans));
+ }
+
+ public static Text getMetadataEntry(KeyExtent extent) {
+ return org.apache.accumulo.core.data.impl.KeyExtent.getMetadataEntry(extent.wrapped);
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/PartialKey.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/PartialKey.java b/core/src/main/java/org/apache/accumulo/core/data/PartialKey.java
index 8ff0017..bf0df1e 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/PartialKey.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/PartialKey.java
@@ -31,6 +31,24 @@ public enum PartialKey {
}
/**
+ * Get a partial key specification by depth of the specification.
+ *
+ * @param depth
+ * depth of scope (i.e., number of fields included)
+ * @return partial key
+ * @throws IllegalArgumentException
+ * if no partial key has the given depth
+ * @deprecated since 1.7.0
+ */
+ @Deprecated
+ public static PartialKey getByDepth(int depth) {
+ for (PartialKey d : PartialKey.values())
+ if (depth == d.depth)
+ return d;
+ throw new IllegalArgumentException("Invalid legacy depth " + depth);
+ }
+
+ /**
* Gets the depth of this partial key.
*
* @return depth
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/Value.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Value.java b/core/src/main/java/org/apache/accumulo/core/data/Value.java
index 9c63a6a..95c3c70 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Value.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Value.java
@@ -25,6 +25,8 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
@@ -56,7 +58,7 @@ public class Value implements WritableComparable<Object> {
* @since 1.8.0
*/
public Value(CharSequence cs) {
- this(cs.toString().getBytes(UTF_8));
+ this(cs.toString().getBytes(StandardCharsets.UTF_8));
}
/**
@@ -94,6 +96,20 @@ public class Value implements WritableComparable<Object> {
}
/**
+ * @deprecated A copy of the bytes in the buffer is always made. Use {@link #Value(ByteBuffer)} instead.
+ *
+ * @param bytes
+ * bytes of value (may not be null)
+ * @param copy
+ * false to use the backing array of the buffer directly as the backing array, true to force a copy
+ */
+ @Deprecated
+ public Value(ByteBuffer bytes, boolean copy) {
+ /* TODO ACCUMULO-2509 right now this uses the entire backing array, which must be accessible. */
+ this(toBytes(bytes), false);
+ }
+
+ /**
* Creates a Value using a byte array as the initial value.
*
* @param bytes
@@ -262,4 +278,22 @@ public class Value implements WritableComparable<Object> {
WritableComparator.define(Value.class, new Comparator());
}
+ /**
+ * Converts a list of byte arrays to a two-dimensional array.
+ *
+ * @param array
+ * list of byte arrays
+ * @return two-dimensional byte array containing one given byte array per row
+ * @deprecated since 1.7.0; this utility method is not appropriate for the {@link Value} object
+ */
+ @Deprecated
+ public static byte[][] toArray(final List<byte[]> array) {
+ // List#toArray doesn't work on lists of byte [].
+ byte[][] results = new byte[array.size()][];
+ for (int i = 0; i < array.size(); i++) {
+ results[i] = array.get(i);
+ }
+ return results;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java b/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java
index 304abb8..dcb8eb7 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/impl/KeyExtent.java
@@ -25,6 +25,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.Set;
@@ -293,6 +295,77 @@ public class KeyExtent implements WritableComparable<KeyExtent> {
return getPrevRowUpdateMutation(this);
}
+ /**
+ * Empty start or end rows tell the method there are no start or end rows, and to use all the keyextents that are before the end row if no start row etc.
+ *
+ * @deprecated this method not intended for public use and is likely to be removed in a future version.
+ * @return all the key extents that the rows cover
+ */
+ @Deprecated
+ public static Collection<KeyExtent> getKeyExtentsForRange(Text startRow, Text endRow, Set<KeyExtent> kes) {
+ if (kes == null)
+ return Collections.emptyList();
+ if (startRow == null)
+ startRow = new Text();
+ if (endRow == null)
+ endRow = new Text();
+ Collection<KeyExtent> keys = new ArrayList<>();
+ for (KeyExtent ckes : kes) {
+ if (ckes.getPrevEndRow() == null) {
+ if (ckes.getEndRow() == null) {
+ // only tablet
+ keys.add(ckes);
+ } else {
+ // first tablet
+ // if start row = '' then we want everything up to the endRow which will always include the first tablet
+ if (startRow.getLength() == 0) {
+ keys.add(ckes);
+ } else if (ckes.getEndRow().compareTo(startRow) >= 0) {
+ keys.add(ckes);
+ }
+ }
+ } else {
+ if (ckes.getEndRow() == null) {
+ // last tablet
+ // if endRow = '' and we're at the last tablet, add it
+ if (endRow.getLength() == 0) {
+ keys.add(ckes);
+ }
+ if (ckes.getPrevEndRow().compareTo(endRow) < 0) {
+ keys.add(ckes);
+ }
+ } else {
+ // tablet in the middle
+ if (startRow.getLength() == 0) {
+ // no start row
+
+ if (endRow.getLength() == 0) {
+ // no start & end row
+ keys.add(ckes);
+ } else {
+ // just no start row
+ if (ckes.getPrevEndRow().compareTo(endRow) < 0) {
+ keys.add(ckes);
+ }
+ }
+ } else if (endRow.getLength() == 0) {
+ // no end row
+ if (ckes.getEndRow().compareTo(startRow) >= 0) {
+ keys.add(ckes);
+ }
+ } else {
+ // no null prevend or endrows and no empty string start or end rows
+ if (ckes.getPrevEndRow().compareTo(endRow) < 0 && ckes.getEndRow().compareTo(startRow) >= 0) {
+ keys.add(ckes);
+ }
+ }
+
+ }
+ }
+ }
+ return keys;
+ }
+
public static Text decodePrevEndRow(Value ibw) {
Text per = null;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java b/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java
index d34e379..d28a1ee 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/impl/TabletIdImpl.java
@@ -17,6 +17,8 @@
package org.apache.accumulo.core.data.impl;
+import java.util.function.Function;
+
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.TabletId;
import org.apache.hadoop.io.Text;
@@ -25,6 +27,35 @@ public class TabletIdImpl implements TabletId {
private KeyExtent ke;
+ @SuppressWarnings("deprecation")
+ public static final Function<org.apache.accumulo.core.data.KeyExtent,TabletId> KE_2_TID_OLD = new Function<org.apache.accumulo.core.data.KeyExtent,TabletId>() {
+ @Override
+ public TabletId apply(org.apache.accumulo.core.data.KeyExtent input) {
+ // the following if null check is to appease findbugs... grumble grumble spent a good part of my morning looking into this
+ // http://sourceforge.net/p/findbugs/bugs/1139/
+ // https://code.google.com/p/guava-libraries/issues/detail?id=920
+ if (input == null)
+ return null;
+ return new TabletIdImpl(input);
+ }
+ };
+
+ @SuppressWarnings("deprecation")
+ public static final Function<TabletId,org.apache.accumulo.core.data.KeyExtent> TID_2_KE_OLD = new Function<TabletId,org.apache.accumulo.core.data.KeyExtent>() {
+ @Override
+ public org.apache.accumulo.core.data.KeyExtent apply(TabletId input) {
+ if (input == null)
+ return null;
+ return new org.apache.accumulo.core.data.KeyExtent(input.getTableId(), input.getEndRow(), input.getPrevEndRow());
+ }
+
+ };
+
+ @Deprecated
+ public TabletIdImpl(org.apache.accumulo.core.data.KeyExtent ke) {
+ this.ke = new KeyExtent(ke.getTableId().toString(), ke.getEndRow(), ke.getPrevEndRow());
+ }
+
public TabletIdImpl(KeyExtent ke) {
this.ke = ke;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/AggregatingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/AggregatingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/AggregatingIterator.java
new file mode 100644
index 0000000..979eaeb
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/AggregatingIterator.java
@@ -0,0 +1,215 @@
+/*
+ * 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.iterators;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.PartialKey;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.conf.ColumnToClassMapping;
+import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This iterator wraps another iterator. It automatically aggregates.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.Combiner}
+ */
+
+@Deprecated
+public class AggregatingIterator implements SortedKeyValueIterator<Key,Value>, OptionDescriber {
+
+ private SortedKeyValueIterator<Key,Value> iterator;
+ private ColumnToClassMapping<org.apache.accumulo.core.iterators.aggregation.Aggregator> aggregators;
+
+ private Key workKey = new Key();
+
+ private Key aggrKey;
+ private Value aggrValue;
+ // private boolean propogateDeletes;
+ private static final Logger log = LoggerFactory.getLogger(AggregatingIterator.class);
+
+ @Override
+ public AggregatingIterator deepCopy(IteratorEnvironment env) {
+ return new AggregatingIterator(this, env);
+ }
+
+ private AggregatingIterator(AggregatingIterator other, IteratorEnvironment env) {
+ iterator = other.iterator.deepCopy(env);
+ aggregators = other.aggregators;
+ }
+
+ public AggregatingIterator() {}
+
+ private void aggregateRowColumn(org.apache.accumulo.core.iterators.aggregation.Aggregator aggr) throws IOException {
+ // this function assumes that first value is not delete
+
+ if (iterator.getTopKey().isDeleted())
+ return;
+
+ workKey.set(iterator.getTopKey());
+
+ Key keyToAggregate = workKey;
+
+ aggr.reset();
+
+ aggr.collect(iterator.getTopValue());
+ iterator.next();
+
+ while (iterator.hasTop() && !iterator.getTopKey().isDeleted() && iterator.getTopKey().equals(keyToAggregate, PartialKey.ROW_COLFAM_COLQUAL_COLVIS)) {
+ aggr.collect(iterator.getTopValue());
+ iterator.next();
+ }
+
+ aggrKey = workKey;
+ aggrValue = aggr.aggregate();
+
+ }
+
+ private void findTop() throws IOException {
+ // check if aggregation is needed
+ if (iterator.hasTop()) {
+ org.apache.accumulo.core.iterators.aggregation.Aggregator aggr = aggregators.getObject(iterator.getTopKey());
+ if (aggr != null) {
+ aggregateRowColumn(aggr);
+ }
+ }
+ }
+
+ public AggregatingIterator(SortedKeyValueIterator<Key,Value> iterator,
+ ColumnToClassMapping<org.apache.accumulo.core.iterators.aggregation.Aggregator> aggregators) throws IOException {
+ this.iterator = iterator;
+ this.aggregators = aggregators;
+ }
+
+ @Override
+ public Key getTopKey() {
+ if (aggrKey != null) {
+ return aggrKey;
+ }
+ return iterator.getTopKey();
+ }
+
+ @Override
+ public Value getTopValue() {
+ if (aggrKey != null) {
+ return aggrValue;
+ }
+ return iterator.getTopValue();
+ }
+
+ @Override
+ public boolean hasTop() {
+ return aggrKey != null || iterator.hasTop();
+ }
+
+ @Override
+ public void next() throws IOException {
+ if (aggrKey != null) {
+ aggrKey = null;
+ aggrValue = null;
+ } else {
+ iterator.next();
+ }
+
+ findTop();
+ }
+
+ @Override
+ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
+ // do not want to seek to the middle of a value that should be
+ // aggregated...
+
+ Range seekRange = IteratorUtil.maximizeStartKeyTimeStamp(range);
+
+ iterator.seek(seekRange, columnFamilies, inclusive);
+ findTop();
+
+ if (range.getStartKey() != null) {
+ while (hasTop() && getTopKey().equals(range.getStartKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS)
+ && getTopKey().getTimestamp() > range.getStartKey().getTimestamp()) {
+ // the value has a more recent time stamp, so
+ // pass it up
+ // log.debug("skipping "+getTopKey());
+ next();
+ }
+
+ while (hasTop() && range.beforeStartKey(getTopKey())) {
+ next();
+ }
+ }
+
+ }
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {
+
+ this.iterator = source;
+
+ try {
+ String context = null;
+ if (null != env)
+ context = env.getConfig().get(Property.TABLE_CLASSPATH);
+ this.aggregators = new ColumnToClassMapping<>(options, org.apache.accumulo.core.iterators.aggregation.Aggregator.class, context);
+ } catch (ClassNotFoundException e) {
+ log.error(e.toString());
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ log.error(e.toString());
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ log.error(e.toString());
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ @Override
+ public IteratorOptions describeOptions() {
+ return new IteratorOptions("agg", "Aggregators apply aggregating functions to values with identical keys", null,
+ Collections.singletonList("<columnName> <aggregatorClass>"));
+ }
+
+ @Override
+ public boolean validateOptions(Map<String,String> options) {
+ for (Entry<String,String> entry : options.entrySet()) {
+ String classname = entry.getValue();
+ if (classname == null)
+ throw new IllegalArgumentException("classname null");
+ Class<? extends org.apache.accumulo.core.iterators.aggregation.Aggregator> clazz;
+ try {
+ clazz = AccumuloVFSClassLoader.loadClass(classname, org.apache.accumulo.core.iterators.aggregation.Aggregator.class);
+ clazz.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("class not found: " + classname);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException("instantiation exception: " + classname);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException("illegal access exception: " + classname);
+ }
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/FamilyIntersectingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/FamilyIntersectingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/FamilyIntersectingIterator.java
new file mode 100644
index 0000000..04102b8
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/FamilyIntersectingIterator.java
@@ -0,0 +1,29 @@
+/*
+ * 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.iterators;
+
+import org.apache.accumulo.core.iterators.user.IndexedDocIterator;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.IndexedDocIterator}
+ */
+@Deprecated
+public class FamilyIntersectingIterator extends IndexedDocIterator {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/GrepIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/GrepIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/GrepIterator.java
new file mode 100644
index 0000000..5c44c31
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/GrepIterator.java
@@ -0,0 +1,27 @@
+/*
+ * 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.iterators;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.GrepIterator}
+ */
+@Deprecated
+public class GrepIterator extends org.apache.accumulo.core.iterators.user.GrepIterator {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/IntersectingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/IntersectingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/IntersectingIterator.java
new file mode 100644
index 0000000..5765982
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/IntersectingIterator.java
@@ -0,0 +1,27 @@
+/*
+ * 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.iterators;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.IntersectingIterator}
+ */
+@Deprecated
+public class IntersectingIterator extends org.apache.accumulo.core.iterators.user.IntersectingIterator {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
index 1d5728b..3f23fd2 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java
@@ -70,6 +70,17 @@ public class IteratorUtil {
*/
public static enum IteratorScope {
majc, minc, scan;
+
+ /**
+ * Fetch the correct configuration key prefix for the given scope. Throws an IllegalArgumentException if no property exists for the given scope.
+ *
+ * @deprecated since 1.7.0 This method returns a type that is not part of the public API and is not guaranteed to be stable. The method was deprecated to
+ * discourage its use.
+ */
+ @Deprecated
+ public static Property getProperty(IteratorScope scope) {
+ return IteratorUtil.getProperty(scope);
+ }
}
public static class IterInfoComparator implements Comparator<IterInfo>, Serializable {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/LargeRowFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/LargeRowFilter.java b/core/src/main/java/org/apache/accumulo/core/iterators/LargeRowFilter.java
new file mode 100644
index 0000000..75155f9
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/LargeRowFilter.java
@@ -0,0 +1,27 @@
+/*
+ * 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.iterators;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.LargeRowFilter}
+ */
+@Deprecated
+public class LargeRowFilter extends org.apache.accumulo.core.iterators.user.LargeRowFilter {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/RowDeletingIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/RowDeletingIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/RowDeletingIterator.java
new file mode 100644
index 0000000..ee6989f
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/RowDeletingIterator.java
@@ -0,0 +1,27 @@
+/*
+ * 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.iterators;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.RowDeletingIterator}
+ */
+@Deprecated
+public class RowDeletingIterator extends org.apache.accumulo.core.iterators.user.RowDeletingIterator {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java
new file mode 100644
index 0000000..d849275
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java
@@ -0,0 +1,36 @@
+/*
+ * 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.iterators;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.VersioningIterator}
+ */
+@Deprecated
+public class VersioningIterator extends org.apache.accumulo.core.iterators.user.VersioningIterator {
+ public VersioningIterator() {}
+
+ public VersioningIterator(SortedKeyValueIterator<Key,Value> iterator, int maxVersions) {
+ super();
+ this.setSource(iterator);
+ this.maxVersions = maxVersions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/WholeRowIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/WholeRowIterator.java b/core/src/main/java/org/apache/accumulo/core/iterators/WholeRowIterator.java
new file mode 100644
index 0000000..7432a88
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/WholeRowIterator.java
@@ -0,0 +1,27 @@
+/*
+ * 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.iterators;
+
+/**
+ * This class remains here for backwards compatibility.
+ *
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.WholeRowIterator}
+ */
+@Deprecated
+public class WholeRowIterator extends org.apache.accumulo.core.iterators.user.WholeRowIterator {
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/Aggregator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/Aggregator.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/Aggregator.java
new file mode 100644
index 0000000..f9183dc
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/Aggregator.java
@@ -0,0 +1,31 @@
+/*
+ * 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.iterators.aggregation;
+
+import org.apache.accumulo.core.data.Value;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.Combiner}
+ */
+@Deprecated
+public interface Aggregator {
+ void reset();
+
+ void collect(Value value);
+
+ Value aggregate();
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/LongSummation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/LongSummation.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/LongSummation.java
new file mode 100644
index 0000000..7692ecb
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/LongSummation.java
@@ -0,0 +1,76 @@
+/*
+ * 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.iterators.aggregation;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.data.Value;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.SummingCombiner} with
+ * {@link org.apache.accumulo.core.iterators.LongCombiner.Type#FIXEDLEN}
+ */
+@Deprecated
+public class LongSummation implements Aggregator {
+ private static final Logger log = LoggerFactory.getLogger(LongSummation.class);
+ long sum = 0;
+
+ @Override
+ public Value aggregate() {
+ return new Value(longToBytes(sum));
+ }
+
+ @Override
+ public void collect(Value value) {
+ try {
+ sum += bytesToLong(value.get());
+ } catch (IOException e) {
+ log.error(LongSummation.class.getSimpleName() + " trying to convert bytes to long, but byte array isn't length 8");
+ }
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+ }
+
+ public static long bytesToLong(byte[] b) throws IOException {
+ return bytesToLong(b, 0);
+ }
+
+ public static long bytesToLong(byte[] b, int offset) throws IOException {
+ if (b.length < offset + 8)
+ throw new IOException("trying to convert to long, but byte array isn't long enough, wanted " + (offset + 8) + " found " + b.length);
+ return (((long) b[offset + 0] << 56) + ((long) (b[offset + 1] & 255) << 48) + ((long) (b[offset + 2] & 255) << 40) + ((long) (b[offset + 3] & 255) << 32)
+ + ((long) (b[offset + 4] & 255) << 24) + ((b[offset + 5] & 255) << 16) + ((b[offset + 6] & 255) << 8) + ((b[offset + 7] & 255) << 0));
+ }
+
+ public static byte[] longToBytes(long l) {
+ byte[] b = new byte[8];
+ b[0] = (byte) (l >>> 56);
+ b[1] = (byte) (l >>> 48);
+ b[2] = (byte) (l >>> 40);
+ b[3] = (byte) (l >>> 32);
+ b[4] = (byte) (l >>> 24);
+ b[5] = (byte) (l >>> 16);
+ b[6] = (byte) (l >>> 8);
+ b[7] = (byte) (l >>> 0);
+ return b;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumArraySummation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumArraySummation.java b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumArraySummation.java
new file mode 100644
index 0000000..66cd2d5
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/aggregation/NumArraySummation.java
@@ -0,0 +1,96 @@
+/*
+ * 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.iterators.aggregation;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.accumulo.core.data.Value;
+import org.apache.hadoop.io.WritableUtils;
+
+/**
+ * @deprecated since 1.4, replaced by {@link org.apache.accumulo.core.iterators.user.SummingArrayCombiner} with
+ * {@link org.apache.accumulo.core.iterators.user.SummingArrayCombiner.Type#VARLEN}
+ */
+@Deprecated
+public class NumArraySummation implements Aggregator {
+ long[] sum = new long[0];
+
+ @Override
+ public Value aggregate() {
+ try {
+ return new Value(NumArraySummation.longArrayToBytes(sum));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void collect(Value value) {
+ long[] la;
+ try {
+ la = NumArraySummation.bytesToLongArray(value.get());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ if (la.length > sum.length) {
+ for (int i = 0; i < sum.length; i++) {
+ la[i] = NumSummation.safeAdd(la[i], sum[i]);
+ }
+ sum = la;
+ } else {
+ for (int i = 0; i < la.length; i++) {
+ sum[i] = NumSummation.safeAdd(sum[i], la[i]);
+ }
+ }
+ }
+
+ public static byte[] longArrayToBytes(long[] la) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+
+ WritableUtils.writeVInt(dos, la.length);
+ for (int i = 0; i < la.length; i++) {
+ WritableUtils.writeVLong(dos, la[i]);
+ }
+
+ return baos.toByteArray();
+ }
+
+ public static long[] bytesToLongArray(byte[] b) throws IOException {
+ DataInputStream dis = new DataInputStream(new ByteArrayInputStream(b));
+ int len = WritableUtils.readVInt(dis);
+
+ long[] la = new long[len];
+
+ for (int i = 0; i < len; i++) {
+ la[i] = WritableUtils.readVLong(dis);
+ }
+
+ return la;
+ }
+
+ @Override
+ public void reset() {
+ sum = new long[0];
+ }
+
+}
[2/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/test/java/org/apache/accumulo/server/rpc/TCredentialsUpdatingInvocationHandlerTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/rpc/TCredentialsUpdatingInvocationHandlerTest.java b/server/base/src/test/java/org/apache/accumulo/server/rpc/TCredentialsUpdatingInvocationHandlerTest.java
index 1b87a9e..4f7cbba 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/rpc/TCredentialsUpdatingInvocationHandlerTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/rpc/TCredentialsUpdatingInvocationHandlerTest.java
@@ -116,6 +116,18 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testAllowedAnyImpersonationForAnyUser() throws Exception {
+ final String proxyServer = "proxy";
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".users", "*");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".hosts", "*");
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test
public void testAllowedAnyImpersonationForAnyUserNewConfig() throws Exception {
final String proxyServer = "proxy";
@@ -127,6 +139,20 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testAllowedImpersonationForSpecificUsers() throws Exception {
+ final String proxyServer = "proxy";
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".users", "client1,client2");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".hosts", "*");
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client1", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ tcreds = new TCredentials("client2", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test
public void testAllowedImpersonationForSpecificUsersNewConfig() throws Exception {
final String proxyServer = "proxy";
@@ -140,6 +166,19 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test(expected = ThriftSecurityException.class)
+ public void testDisallowedImpersonationForUser() throws Exception {
+ final String proxyServer = "proxy";
+ // let "otherproxy" impersonate, but not "proxy"
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy" + ".users", "*");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy" + ".hosts", "*");
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test(expected = ThriftSecurityException.class)
public void testDisallowedImpersonationForUserNewConfig() throws Exception {
final String proxyServer = "proxy";
@@ -152,6 +191,21 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test(expected = ThriftSecurityException.class)
+ public void testDisallowedImpersonationForMultipleUsers() throws Exception {
+ final String proxyServer = "proxy";
+ // let "otherproxy" impersonate, but not "proxy"
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy1" + ".users", "*");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy1" + ".hosts", "*");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy2" + ".users", "client1,client2");
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + "otherproxy2" + ".hosts", "*");
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client1", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test(expected = ThriftSecurityException.class)
public void testDisallowedImpersonationForMultipleUsersNewConfig() throws Exception {
final String proxyServer = "proxy";
@@ -164,6 +218,19 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testAllowedImpersonationFromSpecificHost() throws Exception {
+ final String proxyServer = "proxy", client = "client", host = "host.domain.com";
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".users", client);
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".hosts", host);
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ TServerUtils.clientAddress.set(host);
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test
public void testAllowedImpersonationFromSpecificHostNewConfig() throws Exception {
final String proxyServer = "proxy", client = "client", host = "host.domain.com";
@@ -176,6 +243,20 @@ public class TCredentialsUpdatingInvocationHandlerTest {
proxy.updateArgs(new Object[] {new Object(), tcreds});
}
+ @SuppressWarnings("deprecation")
+ @Test(expected = ThriftSecurityException.class)
+ public void testDisallowedImpersonationFromSpecificHost() throws Exception {
+ final String proxyServer = "proxy", client = "client", host = "host.domain.com";
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".users", client);
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + proxyServer + ".hosts", host);
+ proxy = new TCredentialsUpdatingInvocationHandler<>(new Object(), conf);
+ TCredentials tcreds = new TCredentials("client", KerberosToken.class.getName(), ByteBuffer.allocate(0), UUID.randomUUID().toString());
+ UGIAssumingProcessor.rpcPrincipal.set(proxyServer);
+ // The RPC came from a different host than is allowed
+ TServerUtils.clientAddress.set("otherhost.domain.com");
+ proxy.updateArgs(new Object[] {new Object(), tcreds});
+ }
+
@Test(expected = ThriftSecurityException.class)
public void testDisallowedImpersonationFromSpecificHostNewConfig() throws Exception {
final String proxyServer = "proxy", client = "client", host = "host.domain.com";
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/test/java/org/apache/accumulo/server/security/UserImpersonationTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/security/UserImpersonationTest.java b/server/base/src/test/java/org/apache/accumulo/server/security/UserImpersonationTest.java
index 714a1c1..5b4e1b0 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/security/UserImpersonationTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/security/UserImpersonationTest.java
@@ -67,6 +67,19 @@ public class UserImpersonationTest {
};
}
+ void setValidHosts(String user, String hosts) {
+ setUsersOrHosts(user, ".hosts", hosts);
+ }
+
+ void setValidUsers(String user, String users) {
+ setUsersOrHosts(user, ".users", users);
+ }
+
+ @SuppressWarnings("deprecation")
+ void setUsersOrHosts(String user, String suffix, String value) {
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + user + suffix, value);
+ }
+
void setValidHostsNewConfig(String user, String... hosts) {
cc.set(Property.INSTANCE_RPC_SASL_ALLOWED_HOST_IMPERSONATION.getKey(), Joiner.on(';').join(hosts));
}
@@ -83,6 +96,23 @@ public class UserImpersonationTest {
}
@Test
+ public void testAnyUserAndHosts() {
+ String server = "server";
+ setValidHosts(server, "*");
+ setValidUsers(server, "*");
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertTrue(uwh.acceptsAllHosts());
+ assertTrue(uwh.acceptsAllUsers());
+
+ assertEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+ }
+
+ @Test
public void testAnyUserAndHostsNewConfig() {
String server = "server";
setValidHostsNewConfig(server, "*");
@@ -100,6 +130,22 @@ public class UserImpersonationTest {
}
@Test
+ public void testNoHostByDefault() {
+ String server = "server";
+ setValidUsers(server, "*");
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertTrue(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+ }
+
+ @Test
public void testNoHostByDefaultNewConfig() {
String server = "server";
setValidUsersNewConfig(ImmutableMap.of(server, "*"));
@@ -116,6 +162,22 @@ public class UserImpersonationTest {
}
@Test
+ public void testNoUsersByDefault() {
+ String server = "server";
+ setValidHosts(server, "*");
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertTrue(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+ }
+
+ @Test
public void testNoUsersByDefaultNewConfig() {
String server = "server";
setValidHostsNewConfig(server, "*");
@@ -126,6 +188,29 @@ public class UserImpersonationTest {
}
@Test
+ public void testSingleUserAndHost() {
+ String server = "server", host = "single_host.domain.com", client = "single_client";
+ setValidHosts(server, host);
+ setValidUsers(server, client);
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertTrue(uwh.getUsers().contains(client));
+ assertTrue(uwh.getHosts().contains(host));
+
+ assertFalse(uwh.getUsers().contains("some_other_user"));
+ assertFalse(uwh.getHosts().contains("other_host.domain.com"));
+ }
+
+ @Test
public void testSingleUserAndHostNewConfig() {
String server = "server", host = "single_host.domain.com", client = "single_client";
setValidHostsNewConfig(server, host);
@@ -149,6 +234,28 @@ public class UserImpersonationTest {
}
@Test
+ public void testMultipleExplicitUsers() {
+ String server = "server", client1 = "client1", client2 = "client2", client3 = "client3";
+ setValidHosts(server, "*");
+ setValidUsers(server, Joiner.on(',').join(client1, client2, client3));
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertTrue(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertTrue(uwh.getUsers().contains(client1));
+ assertTrue(uwh.getUsers().contains(client2));
+ assertTrue(uwh.getUsers().contains(client3));
+ assertFalse(uwh.getUsers().contains("other_client"));
+ }
+
+ @Test
public void testMultipleExplicitUsersNewConfig() {
String server = "server", client1 = "client1", client2 = "client2", client3 = "client3";
setValidHostsNewConfig(server, "*");
@@ -171,6 +278,28 @@ public class UserImpersonationTest {
}
@Test
+ public void testMultipleExplicitHosts() {
+ String server = "server", host1 = "host1", host2 = "host2", host3 = "host3";
+ setValidHosts(server, Joiner.on(',').join(host1, host2, host3));
+ setValidUsers(server, "*");
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertTrue(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertTrue(uwh.getHosts().contains(host1));
+ assertTrue(uwh.getHosts().contains(host2));
+ assertTrue(uwh.getHosts().contains(host3));
+ assertFalse(uwh.getHosts().contains("other_host"));
+ }
+
+ @Test
public void testMultipleExplicitHostsNewConfig() {
String server = "server", host1 = "host1", host2 = "host2", host3 = "host3";
setValidHostsNewConfig(server, Joiner.on(',').join(host1, host2, host3));
@@ -193,6 +322,33 @@ public class UserImpersonationTest {
}
@Test
+ public void testMultipleExplicitUsersHosts() {
+ String server = "server", host1 = "host1", host2 = "host2", host3 = "host3", client1 = "client1", client2 = "client2", client3 = "client3";
+ setValidHosts(server, Joiner.on(',').join(host1, host2, host3));
+ setValidUsers(server, Joiner.on(',').join(client1, client2, client3));
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertTrue(uwh.getUsers().contains(client1));
+ assertTrue(uwh.getUsers().contains(client2));
+ assertTrue(uwh.getUsers().contains(client3));
+ assertFalse(uwh.getUsers().contains("other_client"));
+
+ assertTrue(uwh.getHosts().contains(host1));
+ assertTrue(uwh.getHosts().contains(host2));
+ assertTrue(uwh.getHosts().contains(host3));
+ assertFalse(uwh.getHosts().contains("other_host"));
+ }
+
+ @Test
public void testMultipleExplicitUsersHostsNewConfig() {
String server = "server", host1 = "host1", host2 = "host2", host3 = "host3", client1 = "client1", client2 = "client2", client3 = "client3";
setValidHostsNewConfig(server, Joiner.on(',').join(host1, host2, host3));
@@ -220,6 +376,59 @@ public class UserImpersonationTest {
}
@Test
+ public void testMultipleAllowedImpersonators() {
+ String server1 = "server1", server2 = "server2", host1 = "host1", host2 = "host2", host3 = "host3", client1 = "client1", client2 = "client2", client3 = "client3";
+ // server1 can impersonate client1 and client2 from host1 or host2
+ setValidHosts(server1, Joiner.on(',').join(host1, host2));
+ setValidUsers(server1, Joiner.on(',').join(client1, client2));
+ // server2 can impersonate only client3 from host3
+ setValidHosts(server2, host3);
+ setValidUsers(server2, client3);
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server1);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertTrue(uwh.getUsers().contains(client1));
+ assertTrue(uwh.getUsers().contains(client2));
+ assertFalse(uwh.getUsers().contains(client3));
+ assertFalse(uwh.getUsers().contains("other_client"));
+
+ assertTrue(uwh.getHosts().contains(host1));
+ assertTrue(uwh.getHosts().contains(host2));
+ assertFalse(uwh.getHosts().contains(host3));
+ assertFalse(uwh.getHosts().contains("other_host"));
+
+ uwh = impersonation.get(server2);
+ assertNotNull(uwh);
+
+ assertFalse(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertNotEquals(AlwaysTrueSet.class, uwh.getHosts().getClass());
+ assertNotEquals(AlwaysTrueSet.class, uwh.getUsers().getClass());
+
+ assertFalse(uwh.getUsers().contains(client1));
+ assertFalse(uwh.getUsers().contains(client2));
+ assertTrue(uwh.getUsers().contains(client3));
+ assertFalse(uwh.getUsers().contains("other_client"));
+
+ assertFalse(uwh.getHosts().contains(host1));
+ assertFalse(uwh.getHosts().contains(host2));
+ assertTrue(uwh.getHosts().contains(host3));
+ assertFalse(uwh.getHosts().contains("other_host"));
+
+ // client3 is not allowed to impersonate anyone
+ assertNull(impersonation.get(client3));
+ }
+
+ @Test
public void testMultipleAllowedImpersonatorsNewConfig() {
String server1 = "server1", server2 = "server2", host1 = "host1", host2 = "host2", host3 = "host3", client1 = "client1", client2 = "client2", client3 = "client3";
// server1 can impersonate client1 and client2 from host1 or host2
@@ -270,6 +479,24 @@ public class UserImpersonationTest {
assertNull(impersonation.get(client3));
}
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testSingleUser() throws Exception {
+ final String server = "server/hostname@EXAMPLE.COM", client = "client@EXAMPLE.COM";
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + server + ".users", client);
+ cc.set(Property.INSTANCE_RPC_SASL_PROXYUSERS.getKey() + server + ".hosts", "*");
+ UserImpersonation impersonation = new UserImpersonation(conf);
+
+ UsersWithHosts uwh = impersonation.get(server);
+
+ assertNotNull(uwh);
+
+ assertTrue(uwh.acceptsAllHosts());
+ assertFalse(uwh.acceptsAllUsers());
+
+ assertTrue(uwh.getUsers().contains(client));
+ }
+
@Test
public void testSingleUserNewConfig() throws Exception {
final String server = "server/hostname@EXAMPLE.COM", client = "client@EXAMPLE.COM";
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/base/src/test/java/org/apache/accumulo/server/util/TServerUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/base/src/test/java/org/apache/accumulo/server/util/TServerUtilsTest.java b/server/base/src/test/java/org/apache/accumulo/server/util/TServerUtilsTest.java
index fde9e6d..37d127a 100644
--- a/server/base/src/test/java/org/apache/accumulo/server/util/TServerUtilsTest.java
+++ b/server/base/src/test/java/org/apache/accumulo/server/util/TServerUtilsTest.java
@@ -29,6 +29,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -87,6 +88,34 @@ public class TServerUtilsTest {
return 30;
}
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ @Override
+ public void setConfiguration(AccumuloConfiguration conf) {}
+
@Override
public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
throw new UnsupportedOperationException();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/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 8233673..dbf0f87 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
@@ -343,7 +343,8 @@ public class Master extends AccumuloServerContext implements LiveTServerSet.List
zoo.putPersistentData(zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_COMPACT_CANCEL_ID, zero, NodeExistsPolicy.SKIP);
}
- String zpath = zooRoot + Constants.ZCONFIG + "/tserver.wal.sync.method";
+ @SuppressWarnings("deprecation")
+ String zpath = zooRoot + Constants.ZCONFIG + "/" + Property.TSERV_WAL_SYNC_METHOD.getKey();
// is the entire instance set to use flushing vs sync?
boolean flushDefault = false;
try {
@@ -357,7 +358,8 @@ public class Master extends AccumuloServerContext implements LiveTServerSet.List
for (String id : zoo.getChildren(zooRoot + Constants.ZTABLES)) {
log.debug("Converting table " + id + " WALog setting to Durability");
try {
- String path = zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_CONF + "/table.walog.enabled";
+ @SuppressWarnings("deprecation")
+ String path = zooRoot + Constants.ZTABLES + "/" + id + Constants.ZTABLE_CONF + "/" + Property.TABLE_WALOG_ENABLED.getKey();
byte[] data = zoo.getData(path, null);
boolean useWAL = Boolean.parseBoolean(new String(data, UTF_8));
zoo.recursiveDelete(path, NodeMissingPolicy.FAIL);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/master/src/main/java/org/apache/accumulo/master/util/FateAdmin.java
----------------------------------------------------------------------
diff --git a/server/master/src/main/java/org/apache/accumulo/master/util/FateAdmin.java b/server/master/src/main/java/org/apache/accumulo/master/util/FateAdmin.java
new file mode 100644
index 0000000..a1dd303
--- /dev/null
+++ b/server/master/src/main/java/org/apache/accumulo/master/util/FateAdmin.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.master.util;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.zookeeper.ZooUtil;
+import org.apache.accumulo.fate.AdminUtil;
+import org.apache.accumulo.fate.ReadOnlyStore;
+import org.apache.accumulo.fate.ZooStore;
+import org.apache.accumulo.fate.zookeeper.IZooReaderWriter;
+import org.apache.accumulo.master.Master;
+import org.apache.accumulo.server.client.HdfsZooInstance;
+import org.apache.accumulo.server.zookeeper.ZooReaderWriter;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+
+/**
+ * A utility to administer FATE operations
+ */
+public class FateAdmin {
+
+ static class TxOpts {
+ @Parameter(description = "<txid>...", required = true)
+ List<String> txids = new ArrayList<>();
+ }
+
+ @Parameters(commandDescription = "Stop an existing FATE by transaction id")
+ static class FailOpts extends TxOpts {}
+
+ @Parameters(commandDescription = "Delete an existing FATE by transaction id")
+ static class DeleteOpts extends TxOpts {}
+
+ @Parameters(commandDescription = "List the existing FATE transactions")
+ static class PrintOpts {}
+
+ public static void main(String[] args) throws Exception {
+ Help opts = new Help();
+ JCommander jc = new JCommander(opts);
+ jc.setProgramName(FateAdmin.class.getName());
+ LinkedHashMap<String,TxOpts> txOpts = new LinkedHashMap<>(2);
+ txOpts.put("fail", new FailOpts());
+ txOpts.put("delete", new DeleteOpts());
+ for (Entry<String,TxOpts> entry : txOpts.entrySet()) {
+ jc.addCommand(entry.getKey(), entry.getValue());
+ }
+ jc.addCommand("print", new PrintOpts());
+ jc.parse(args);
+ if (opts.help || jc.getParsedCommand() == null) {
+ jc.usage();
+ System.exit(1);
+ }
+
+ System.err
+ .printf("This tool has been deprecated%nFATE administration now available within 'accumulo shell'%n$ fate fail <txid>... | delete <txid>... | print [<txid>...]%n%n");
+
+ AdminUtil<Master> admin = new AdminUtil<>();
+
+ Instance instance = HdfsZooInstance.getInstance();
+ String path = ZooUtil.getRoot(instance) + Constants.ZFATE;
+ String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK;
+ IZooReaderWriter zk = ZooReaderWriter.getInstance();
+ ZooStore<Master> zs = new ZooStore<>(path, zk);
+
+ if (jc.getParsedCommand().equals("fail")) {
+ for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
+ if (!admin.prepFail(zs, zk, masterPath, txid)) {
+ System.exit(1);
+ }
+ }
+ } else if (jc.getParsedCommand().equals("delete")) {
+ for (String txid : txOpts.get(jc.getParsedCommand()).txids) {
+ if (!admin.prepDelete(zs, zk, masterPath, txid)) {
+ System.exit(1);
+ }
+ admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, txid);
+ }
+ } else if (jc.getParsedCommand().equals("print")) {
+ admin.print(new ReadOnlyStore<>(zs), zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
index 0aa9d72..31bea15 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/ShellServlet.java
@@ -81,6 +81,7 @@ public class ShellServlet extends BasicServlet {
// user attribute is null, check to see if username and password are passed as parameters
user = req.getParameter("user");
String pass = req.getParameter("pass");
+ String mock = req.getParameter("mock");
if (user == null || pass == null) {
// username or password are null, re-authenticate
sb.append(authenticationForm(req.getRequestURI(), CSRF_TOKEN));
@@ -88,7 +89,7 @@ public class ShellServlet extends BasicServlet {
}
try {
// get a new shell for this user
- ShellExecutionThread shellThread = new ShellExecutionThread(user, pass);
+ ShellExecutionThread shellThread = new ShellExecutionThread(user, pass, mock);
service().submit(shellThread);
userShells().put(session.getId(), shellThread);
} catch (IOException e) {
@@ -223,7 +224,8 @@ public class ShellServlet extends BasicServlet {
private String authenticationForm(String requestURI, String csrfToken) {
return "<div id='login'><form method=POST action='" + requestURI + "'>"
- + "<table><tr><td>Username: </td><td><input type='text' name='user'></td></tr>"
+ + "<table><tr><td>Mock: </td><td><input type='checkbox' name='mock' value='mock'></td></tr>"
+ + "<tr><td>Username: </td><td><input type='text' name='user'></td></tr>"
+ "<tr><td>Password: </td><td><input type='password' name='pass'></td><td>" + "<input type='hidden' name='" + CSRF_KEY + "' value='" + csrfToken
+ "'/><input type='submit' value='Enter'></td></tr></table></form></div>";
}
@@ -253,7 +255,7 @@ public class ShellServlet extends BasicServlet {
private boolean done;
private boolean readWait;
- private ShellExecutionThread(String username, String password) throws IOException {
+ private ShellExecutionThread(String username, String password, String mock) throws IOException {
this.done = false;
this.cmd = null;
this.cmdIndex = 0;
@@ -262,7 +264,10 @@ public class ShellServlet extends BasicServlet {
ConsoleReader reader = new ConsoleReader(this, output);
this.shell = new Shell(reader);
shell.setLogErrorsToConsole();
- if (shell.config("-u", username, "-p", password)) {
+ if (mock != null) {
+ if (shell.config("--fake", "-u", username, "-p", password))
+ throw new IOException("mock shell config error");
+ } else if (shell.config("-u", username, "-p", password)) {
throw new IOException("shell config error");
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/trace/NullScanner.java
----------------------------------------------------------------------
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/trace/NullScanner.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/trace/NullScanner.java
index d96d23f..b91d454 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/trace/NullScanner.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/servlets/trace/NullScanner.java
@@ -53,6 +53,16 @@ public class NullScanner implements Scanner {
@Override
public void clearScanIterators() {}
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {}
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ return 0;
+ }
+
@Override
public void setRange(Range range) {}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/tracer/src/test/java/org/apache/accumulo/tracer/TracerTest.java
----------------------------------------------------------------------
diff --git a/server/tracer/src/test/java/org/apache/accumulo/tracer/TracerTest.java b/server/tracer/src/test/java/org/apache/accumulo/tracer/TracerTest.java
index 19891a4..6dcf7a4 100644
--- a/server/tracer/src/test/java/org/apache/accumulo/tracer/TracerTest.java
+++ b/server/tracer/src/test/java/org/apache/accumulo/tracer/TracerTest.java
@@ -99,6 +99,7 @@ public class TracerTest {
public void close() throws IOException {}
}
+ @SuppressWarnings("deprecation")
@Test
public void testTrace() throws Exception {
TestReceiver tracer = new TestReceiver();
@@ -114,7 +115,7 @@ public class TracerTest {
assertFalse(Trace.isTracing());
Span start = Trace.on("testing");
- assertEquals(org.apache.htrace.Trace.currentSpan(), start.getScope().getSpan());
+ assertEquals(Trace.currentTrace().getSpan(), start.getScope().getSpan());
assertTrue(Trace.isTracing());
Span span = Trace.start("shortest trace ever");
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
index 5a50e8f..fc371c9 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TservConstraintEnv.java
@@ -24,6 +24,7 @@ import org.apache.accumulo.core.constraints.Constraint.Environment;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.impl.KeyExtent;
import org.apache.accumulo.core.security.AuthorizationContainer;
+import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.thrift.TCredentials;
import org.apache.accumulo.server.security.SecurityOperation;
@@ -31,6 +32,7 @@ public class TservConstraintEnv implements Environment {
private final TCredentials credentials;
private final SecurityOperation security;
+ private Authorizations auths;
private KeyExtent ke;
TservConstraintEnv(SecurityOperation secOp, TCredentials credentials) {
@@ -53,6 +55,18 @@ public class TservConstraintEnv implements Environment {
}
@Override
+ @Deprecated
+ public Authorizations getAuthorizations() {
+ if (auths == null)
+ try {
+ this.auths = security.getUserAuthorizations(credentials);
+ } catch (ThriftSecurityException e) {
+ throw new RuntimeException(e);
+ }
+ return auths;
+ }
+
+ @Override
public AuthorizationContainer getAuthorizationsContainer() {
return new AuthorizationContainer() {
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/tserver/src/main/java/org/apache/accumulo/tserver/log/LocalWALRecovery.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/LocalWALRecovery.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/LocalWALRecovery.java
index a3d8782..2667b53 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/LocalWALRecovery.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/LocalWALRecovery.java
@@ -48,6 +48,7 @@ import com.google.common.annotations.VisibleForTesting;
/**
* This class will attempt to rewrite any local WALs to HDFS.
*/
+@SuppressWarnings("deprecation")
public class LocalWALRecovery implements Runnable {
private static final Logger log = LoggerFactory.getLogger(LocalWALRecovery.class);
@@ -153,8 +154,8 @@ public class LocalWALRecovery implements Runnable {
Path localWal = new Path(file.toURI());
FileSystem localFs = FileSystem.getLocal(fs.getConf());
- Reader reader = new SequenceFile.Reader(localFs.getConf(), SequenceFile.Reader.file(localWal.makeQualified(localWal.toUri(),
- localFs.getWorkingDirectory())));
+ Reader reader = new SequenceFile.Reader(localFs, localWal, localFs.getConf());
+ // Reader reader = new SequenceFile.Reader(localFs.getConf(), SequenceFile.Reader.file(localWal));
Path tmp = new Path(options.destination + "/" + name + ".copy");
FSDataOutputStream writer = fs.create(tmp);
while (reader.next(key, value)) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java
index d9a4e0e..b65d5ce 100644
--- a/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/log/SortedLogRecoveryTest.java
@@ -138,7 +138,8 @@ public class SortedLogRecoveryTest {
for (Entry<String,KeyValue[]> entry : logs.entrySet()) {
String path = workdir + "/" + entry.getKey();
FileSystem ns = fs.getVolumeByPath(new Path(path)).getFileSystem();
- Writer map = new MapFile.Writer(ns.getConf(), new Path(path + "/log1"), Writer.keyClass(LogFileKey.class), Writer.valueClass(LogFileValue.class));
+ @SuppressWarnings("deprecation")
+ Writer map = new MapFile.Writer(ns.getConf(), ns, path + "/log1", LogFileKey.class, LogFileValue.class);
for (KeyValue lfe : entry.getValue()) {
map.append(lfe.key, lfe.value);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/RootFilesTest.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/RootFilesTest.java b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/RootFilesTest.java
index 7a1a785..d9c6862 100644
--- a/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/RootFilesTest.java
+++ b/server/tserver/src/test/java/org/apache/accumulo/tserver/tablet/RootFilesTest.java
@@ -41,10 +41,6 @@ import org.junit.rules.TemporaryFolder;
*
*/
public class RootFilesTest {
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static final Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
@@ -120,12 +116,13 @@ public class RootFilesTest {
}
}
+ @SuppressWarnings("deprecation")
@Test
public void testFileReplacement() throws IOException {
ConfigurationCopy conf = new ConfigurationCopy();
- conf.set(INSTANCE_DFS_URI, "file:///");
- conf.set(INSTANCE_DFS_DIR, "/");
+ conf.set(Property.INSTANCE_DFS_URI, "file:///");
+ conf.set(Property.INSTANCE_DFS_DIR, "/");
VolumeManager vm = VolumeManagerImpl.get(conf);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/Shell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/Shell.java b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
index 1819f43..7678ead 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/Shell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/Shell.java
@@ -66,6 +66,7 @@ import org.apache.accumulo.core.data.thrift.TConstraintViolationSummary;
import org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException;
import org.apache.accumulo.core.trace.DistributedTrace;
import org.apache.accumulo.core.util.BadArgumentException;
+import org.apache.accumulo.core.util.DeprecationUtil;
import org.apache.accumulo.core.util.format.DefaultFormatter;
import org.apache.accumulo.core.util.format.Formatter;
import org.apache.accumulo.core.util.format.FormatterConfig;
@@ -95,6 +96,7 @@ import org.apache.accumulo.shell.commands.DeleteIterCommand;
import org.apache.accumulo.shell.commands.DeleteManyCommand;
import org.apache.accumulo.shell.commands.DeleteNamespaceCommand;
import org.apache.accumulo.shell.commands.DeleteRowsCommand;
+import org.apache.accumulo.shell.commands.DeleteScanIterCommand;
import org.apache.accumulo.shell.commands.DeleteShellIterCommand;
import org.apache.accumulo.shell.commands.DeleteTableCommand;
import org.apache.accumulo.shell.commands.DeleteUserCommand;
@@ -147,6 +149,7 @@ import org.apache.accumulo.shell.commands.ScriptCommand;
import org.apache.accumulo.shell.commands.SetAuthsCommand;
import org.apache.accumulo.shell.commands.SetGroupsCommand;
import org.apache.accumulo.shell.commands.SetIterCommand;
+import org.apache.accumulo.shell.commands.SetScanIterCommand;
import org.apache.accumulo.shell.commands.SetShellIterCommand;
import org.apache.accumulo.shell.commands.SleepCommand;
import org.apache.accumulo.shell.commands.SystemPermissionsCommand;
@@ -368,7 +371,9 @@ public class Shell extends ShellOptions implements KeywordExecutable {
}
}
- DistributedTrace.enable(InetAddress.getLocalHost().getHostName(), "shell", clientConf);
+ if (!options.isFake()) {
+ DistributedTrace.enable(InetAddress.getLocalHost().getHostName(), "shell", clientConf);
+ }
this.setTableName("");
connector = instance.getConnector(user, token);
@@ -401,8 +406,8 @@ public class Shell extends ShellOptions implements KeywordExecutable {
Command[] execCommands = {new ExecfileCommand(), new HistoryCommand(), new ExtensionCommand(), new ScriptCommand()};
Command[] exitCommands = {new ByeCommand(), new ExitCommand(), new QuitCommand()};
Command[] helpCommands = {new AboutCommand(), new HelpCommand(), new InfoCommand(), new QuestionCommand()};
- Command[] iteratorCommands = {new DeleteIterCommand(), new ListIterCommand(), new SetIterCommand(), new SetShellIterCommand(), new ListShellIterCommand(),
- new DeleteShellIterCommand()};
+ Command[] iteratorCommands = {new DeleteIterCommand(), new DeleteScanIterCommand(), new ListIterCommand(), new SetIterCommand(), new SetScanIterCommand(),
+ new SetShellIterCommand(), new ListShellIterCommand(), new DeleteShellIterCommand()};
Command[] otherCommands = {new HiddenCommand()};
Command[] permissionsCommands = {new GrantCommand(), new RevokeCommand(), new SystemPermissionsCommand(), new TablePermissionsCommand(),
new UserPermissionsCommand(), new NamespacePermissionsCommand()};
@@ -446,24 +451,28 @@ public class Shell extends ShellOptions implements KeywordExecutable {
protected void setInstance(ShellOptionsJC options) {
// should only be one set of instance options set
instance = null;
- String instanceName, hosts;
- if (options.isHdfsZooInstance()) {
- instanceName = hosts = null;
- } else if (options.getZooKeeperInstance().size() > 0) {
- List<String> zkOpts = options.getZooKeeperInstance();
- instanceName = zkOpts.get(0);
- hosts = zkOpts.get(1);
+ if (options.isFake()) {
+ instance = DeprecationUtil.makeMockInstance("fake");
} else {
- instanceName = options.getZooKeeperInstanceName();
- hosts = options.getZooKeeperHosts();
- }
- final ClientConfiguration clientConf;
- try {
- clientConf = options.getClientConfiguration();
- } catch (ConfigurationException | FileNotFoundException e) {
- throw new IllegalArgumentException("Unable to load client config from " + options.getClientConfigFile(), e);
+ String instanceName, hosts;
+ if (options.isHdfsZooInstance()) {
+ instanceName = hosts = null;
+ } else if (options.getZooKeeperInstance().size() > 0) {
+ List<String> zkOpts = options.getZooKeeperInstance();
+ instanceName = zkOpts.get(0);
+ hosts = zkOpts.get(1);
+ } else {
+ instanceName = options.getZooKeeperInstanceName();
+ hosts = options.getZooKeeperHosts();
+ }
+ final ClientConfiguration clientConf;
+ try {
+ clientConf = options.getClientConfiguration();
+ } catch (ConfigurationException | FileNotFoundException e) {
+ throw new IllegalArgumentException("Unable to load client config from " + options.getClientConfigFile(), e);
+ }
+ instance = getZooInstance(instanceName, hosts, clientConf);
}
- instance = getZooInstance(instanceName, hosts, clientConf);
}
/**
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
index 7f476c1..1e5156f 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/ShellOptionsJC.java
@@ -241,6 +241,10 @@ public class ShellOptionsJC {
return debugEnabled;
}
+ public boolean isFake() {
+ return fake;
+ }
+
public boolean isHelpEnabled() {
return helpEnabled;
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteScanIterCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteScanIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteScanIterCommand.java
new file mode 100644
index 0000000..7c8cf22
--- /dev/null
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/DeleteScanIterCommand.java
@@ -0,0 +1,103 @@
+/*
+ * 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.shell.commands;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.shell.Shell;
+import org.apache.accumulo.shell.Shell.Command;
+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 DeleteScanIterCommand extends Command {
+ private Option nameOpt, allOpt;
+
+ @Override
+ public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
+ Shell.log.warn("Deprecated, use " + new DeleteShellIterCommand().getName());
+ final String tableName = OptUtil.getTableOpt(cl, shellState);
+
+ if (cl.hasOption(allOpt.getOpt())) {
+ final List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.remove(tableName);
+ if (tableScanIterators == null) {
+ Shell.log.info("No scan iterators set on table " + tableName);
+ } else {
+ Shell.log.info("Removed the following scan iterators from table " + tableName + ":" + tableScanIterators);
+ }
+ } else if (cl.hasOption(nameOpt.getOpt())) {
+ final String name = cl.getOptionValue(nameOpt.getOpt());
+ final List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(tableName);
+ if (tableScanIterators != null) {
+ boolean found = false;
+ for (Iterator<IteratorSetting> iter = tableScanIterators.iterator(); iter.hasNext();) {
+ if (iter.next().getName().equals(name)) {
+ iter.remove();
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ Shell.log.info("No iterator named " + name + " found for table " + tableName);
+ } else {
+ Shell.log.info("Removed scan iterator " + name + " from table " + tableName + " (" + shellState.scanIteratorOptions.get(tableName).size() + " left)");
+ if (shellState.scanIteratorOptions.get(tableName).size() == 0) {
+ shellState.scanIteratorOptions.remove(tableName);
+ }
+ }
+ } else {
+ Shell.log.info("No iterator named " + name + " found for table " + tableName);
+ }
+ }
+
+ return 0;
+ }
+
+ @Override
+ public String description() {
+ return "deletes a table-specific scan iterator so it is no longer used during this shell session";
+ }
+
+ @Override
+ public Options getOptions() {
+ final Options o = new Options();
+
+ OptionGroup nameGroup = new OptionGroup();
+
+ nameOpt = new Option("n", "name", true, "iterator to delete");
+ nameOpt.setArgName("itername");
+
+ allOpt = new Option("a", "all", false, "delete all scan iterators");
+ allOpt.setArgName("all");
+
+ nameGroup.addOption(nameOpt);
+ nameGroup.addOption(allOpt);
+ nameGroup.setRequired(true);
+ o.addOptionGroup(nameGroup);
+ o.addOption(OptUtil.tableOpt("table to delete scan iterators from"));
+
+ return o;
+ }
+
+ @Override
+ public int numArgs() {
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java
index 6e89298..fffdf21 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/SetIterCommand.java
@@ -53,7 +53,7 @@ import jline.console.ConsoleReader;
public class SetIterCommand extends Command {
private Option allScopeOpt, mincScopeOpt, majcScopeOpt, scanScopeOpt, nameOpt, priorityOpt;
- private Option ageoffTypeOpt, regexTypeOpt, versionTypeOpt, reqvisTypeOpt, classnameTypeOpt;
+ private Option aggTypeOpt, ageoffTypeOpt, regexTypeOpt, versionTypeOpt, reqvisTypeOpt, classnameTypeOpt;
@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException,
@@ -66,7 +66,12 @@ public class SetIterCommand extends Command {
final Map<String,String> options = new HashMap<>();
String classname = cl.getOptionValue(classnameTypeOpt.getOpt());
- if (cl.hasOption(regexTypeOpt.getOpt())) {
+ if (cl.hasOption(aggTypeOpt.getOpt())) {
+ Shell.log.warn("aggregators are deprecated");
+ @SuppressWarnings("deprecation")
+ String deprecatedClassName = org.apache.accumulo.core.iterators.AggregatingIterator.class.getName();
+ classname = deprecatedClassName;
+ } else if (cl.hasOption(regexTypeOpt.getOpt())) {
classname = RegExFilter.class.getName();
} else if (cl.hasOption(ageoffTypeOpt.getOpt())) {
classname = AgeOffFilter.class.getName();
@@ -114,6 +119,14 @@ public class SetIterCommand extends Command {
ScanCommand.ensureTserversCanLoadIterator(shellState, tableName, classname);
+ final String aggregatorClass = options.get("aggregatorClass");
+ @SuppressWarnings("deprecation")
+ String deprecatedAggregatorClassName = org.apache.accumulo.core.iterators.aggregation.Aggregator.class.getName();
+ if (aggregatorClass != null && !shellState.getConnector().tableOperations().testClassLoad(tableName, aggregatorClass, deprecatedAggregatorClassName)) {
+ throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + aggregatorClass + " as type "
+ + deprecatedAggregatorClassName);
+ }
+
for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) {
final Entry<String,String> entry = i.next();
if (entry.getValue() == null || entry.getValue().isEmpty()) {
@@ -148,6 +161,14 @@ public class SetIterCommand extends Command {
+ SortedKeyValueIterator.class.getName());
}
+ final String aggregatorClass = options.get("aggregatorClass");
+ @SuppressWarnings("deprecation")
+ String deprecatedAggregatorClassName = org.apache.accumulo.core.iterators.aggregation.Aggregator.class.getName();
+ if (aggregatorClass != null && !shellState.getConnector().namespaceOperations().testClassLoad(namespace, aggregatorClass, deprecatedAggregatorClassName)) {
+ throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + aggregatorClass + " as type "
+ + deprecatedAggregatorClassName);
+ }
+
for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) {
final Entry<String,String> entry = i.next();
if (entry.getValue() == null || entry.getValue().isEmpty()) {
@@ -336,12 +357,14 @@ public class SetIterCommand extends Command {
final OptionGroup typeGroup = new OptionGroup();
classnameTypeOpt = new Option("class", "class-name", true, "a java class that implements SortedKeyValueIterator");
classnameTypeOpt.setArgName("name");
+ aggTypeOpt = new Option("agg", "aggregator", false, "an aggregating type");
regexTypeOpt = new Option("regex", "regular-expression", false, "a regex matching iterator");
versionTypeOpt = new Option("vers", "version", false, "a versioning iterator");
reqvisTypeOpt = new Option("reqvis", "require-visibility", false, "an iterator that omits entries with empty visibilities");
ageoffTypeOpt = new Option("ageoff", "ageoff", false, "an aging off iterator");
typeGroup.addOption(classnameTypeOpt);
+ typeGroup.addOption(aggTypeOpt);
typeGroup.addOption(regexTypeOpt);
typeGroup.addOption(versionTypeOpt);
typeGroup.addOption(reqvisTypeOpt);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
new file mode 100644
index 0000000..2399d0e
--- /dev/null
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/SetScanIterCommand.java
@@ -0,0 +1,113 @@
+/*
+ * 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.shell.commands;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.shell.Shell;
+import org.apache.accumulo.shell.ShellCommandException;
+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 SetScanIterCommand extends SetIterCommand {
+ @Override
+ public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException,
+ TableNotFoundException, IOException, ShellCommandException {
+ Shell.log.warn("Deprecated, use " + new SetShellIterCommand().getName());
+ return super.execute(fullCommand, cl, shellState);
+ }
+
+ @Override
+ protected void setTableProperties(final CommandLine cl, final Shell shellState, final int priority, final Map<String,String> options, final String classname,
+ final String name) throws AccumuloException, AccumuloSecurityException, ShellCommandException, TableNotFoundException {
+
+ final String tableName = OptUtil.getTableOpt(cl, shellState);
+
+ ScanCommand.ensureTserversCanLoadIterator(shellState, tableName, classname);
+
+ for (Iterator<Entry<String,String>> i = options.entrySet().iterator(); i.hasNext();) {
+ final Entry<String,String> entry = i.next();
+ if (entry.getValue() == null || entry.getValue().isEmpty()) {
+ i.remove();
+ }
+ }
+
+ List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.get(tableName);
+ if (tableScanIterators == null) {
+ tableScanIterators = new ArrayList<>();
+ shellState.scanIteratorOptions.put(tableName, tableScanIterators);
+ }
+ final IteratorSetting setting = new IteratorSetting(priority, name, classname);
+ setting.addOptions(options);
+
+ // initialize a scanner to ensure the new setting does not conflict with existing settings
+ final String user = shellState.getConnector().whoami();
+ final Authorizations auths = shellState.getConnector().securityOperations().getUserAuthorizations(user);
+ final Scanner scanner = shellState.getConnector().createScanner(tableName, auths);
+ for (IteratorSetting s : tableScanIterators) {
+ scanner.addScanIterator(s);
+ }
+ scanner.addScanIterator(setting);
+
+ // if no exception has been thrown, it's safe to add it to the list
+ tableScanIterators.add(setting);
+ Shell.log.debug("Scan iterators :" + shellState.scanIteratorOptions.get(tableName));
+ }
+
+ @Override
+ public String description() {
+ return "sets a table-specific scan iterator for this shell session";
+ }
+
+ @Override
+ public Options getOptions() {
+ // Remove the options that specify which type of iterator this is, since
+ // they are all scan iterators with this command.
+ final HashSet<OptionGroup> groups = new HashSet<>();
+ final Options parentOptions = super.getOptions();
+ final Options modifiedOptions = new Options();
+ for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) {
+ Option o = (Option) it.next();
+ if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt()) && !IteratorScope.scan.name().equals(o.getOpt())) {
+ modifiedOptions.addOption(o);
+ OptionGroup group = parentOptions.getOptionGroup(o);
+ if (group != null)
+ groups.add(group);
+ }
+ }
+ for (OptionGroup group : groups) {
+ modifiedOptions.addOptionGroup(group);
+ }
+ return modifiedOptions;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java b/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
new file mode 100644
index 0000000..ebc92f7
--- /dev/null
+++ b/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
@@ -0,0 +1,159 @@
+/*
+ * 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.shell.mock;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import jline.console.ConsoleReader;
+
+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.shell.Shell;
+import org.apache.accumulo.shell.ShellOptionsJC;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.vfs2.FileSystemException;
+
+/**
+ * An Accumulo Shell implementation that allows a developer to attach an InputStream and Writer to the Shell for testing purposes.
+ *
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockShell extends Shell {
+ private static final String NEWLINE = "\n";
+
+ protected InputStream in;
+ protected OutputStream out;
+
+ public MockShell(InputStream in, OutputStream out) throws IOException {
+ super();
+ this.in = in;
+ this.out = out;
+ }
+
+ @Override
+ public boolean config(String... args) throws IOException {
+ // If configuring the shell failed, fail quickly
+ if (!super.config(args)) {
+ return false;
+ }
+
+ // Update the ConsoleReader with the input and output "redirected"
+ try {
+ this.reader = new ConsoleReader(in, out);
+ } catch (Exception e) {
+ printException(e);
+ return false;
+ }
+
+ // Don't need this for testing purposes
+ this.reader.setHistoryEnabled(false);
+ this.reader.setPaginationEnabled(false);
+
+ // Make the parsing from the client easier;
+ this.verbose = false;
+ return true;
+ }
+
+ @Override
+ protected void setInstance(ShellOptionsJC options) {
+ // We always want a MockInstance for this test
+ instance = new org.apache.accumulo.core.client.mock.MockInstance();
+ }
+
+ @Override
+ public int start() throws IOException {
+ String input;
+ if (isVerbose())
+ printInfo();
+
+ if (execFile != null) {
+ java.util.Scanner scanner = new java.util.Scanner(execFile, UTF_8.name());
+ try {
+ while (scanner.hasNextLine() && !hasExited()) {
+ execCommand(scanner.nextLine(), true, isVerbose());
+ }
+ } finally {
+ scanner.close();
+ }
+ } else if (execCommand != null) {
+ for (String command : execCommand.split("\n")) {
+ execCommand(command, true, isVerbose());
+ }
+ return exitCode;
+ }
+
+ while (true) {
+ if (hasExited())
+ return exitCode;
+
+ reader.setPrompt(getDefaultPrompt());
+ input = reader.readLine();
+ if (input == null) {
+ reader.println();
+ return exitCode;
+ } // user canceled
+
+ execCommand(input, false, false);
+ }
+ }
+
+ /**
+ * @param in
+ * the in to set
+ */
+ public void setConsoleInputStream(InputStream in) {
+ this.in = in;
+ }
+
+ /**
+ * @param out
+ * the output stream to set
+ */
+ public void setConsoleWriter(OutputStream out) {
+ this.out = out;
+ }
+
+ @Override
+ public ClassLoader getClassLoader(final CommandLine cl, final Shell shellState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException,
+ IOException, FileSystemException {
+ return MockShell.class.getClassLoader();
+ }
+
+ /**
+ * Convenience method to create the byte-array to hand to the console
+ *
+ * @param commands
+ * An array of commands to run
+ * @return A byte[] input stream which can be handed to the console.
+ */
+ public static ByteArrayInputStream makeCommands(String... commands) {
+ StringBuilder sb = new StringBuilder(commands.length * 8);
+
+ for (String command : commands) {
+ sb.append(command).append(NEWLINE);
+ }
+
+ return new ByteArrayInputStream(sb.toString().getBytes(UTF_8));
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
index 5e8736c..8bef14d 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellConfigTest.java
@@ -24,48 +24,29 @@ import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
+import jline.console.ConsoleReader;
+
import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.ConfigurationCopy;
import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.shell.ShellTest.TestOutputStream;
import org.apache.log4j.Level;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.beust.jcommander.ParameterException;
-import jline.console.ConsoleReader;
-
public class ShellConfigTest {
-
- public static class TestOutputStream extends OutputStream {
- StringBuilder sb = new StringBuilder();
-
- @Override
- public void write(int b) throws IOException {
- sb.append((char) (0xff & b));
- }
-
- public String get() {
- return sb.toString();
- }
-
- public void clear() {
- sb.setLength(0);
- }
- }
-
TestOutputStream output;
Shell shell;
PrintStream out;
@@ -121,20 +102,17 @@ public class ShellConfigTest {
assertTrue("Did not print usage", output.get().startsWith("Usage"));
}
- @Ignore
@Test
public void testTokenWithoutOptions() throws IOException {
assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getName())));
assertFalse(output.get().contains(ParameterException.class.getName()));
}
- @Ignore
@Test
public void testTokenAndOption() throws IOException {
assertTrue(shell.config(args("--fake", "-tc", PasswordToken.class.getName(), "-u", "foo", "-l", "password=foo")));
}
- @Ignore
@Test
public void testTokenAndOptionAndPassword() throws IOException {
assertFalse(shell.config(args("--fake", "-tc", PasswordToken.class.getName(), "-l", "password=foo", "-p", "bar")));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
index 6dae0b4..428481a 100644
--- a/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellSetInstanceTest.java
@@ -34,6 +34,8 @@ import java.util.Collections;
import java.util.List;
import java.util.UUID;
+import jline.console.ConsoleReader;
+
import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
import org.apache.accumulo.core.client.ZooKeeperInstance;
@@ -47,6 +49,7 @@ import org.apache.log4j.Level;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -56,17 +59,10 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import jline.console.ConsoleReader;
-
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.security.*")
@PrepareForTest({Shell.class, ZooUtil.class, ConfigSanityCheck.class})
public class ShellSetInstanceTest {
- @SuppressWarnings("deprecation")
- private static Property INSTANCE_DFS_DIR = Property.INSTANCE_DFS_DIR;
- @SuppressWarnings("deprecation")
- private static Property INSTANCE_DFS_URI = Property.INSTANCE_DFS_URI;
-
public static class TestOutputStream extends OutputStream {
StringBuilder sb = new StringBuilder();
@@ -125,6 +121,17 @@ public class ShellSetInstanceTest {
SiteConfiguration.clearInstance();
}
+ @Deprecated
+ @Test
+ public void testSetInstance_Fake() throws Exception {
+ ShellOptionsJC opts = createMock(ShellOptionsJC.class);
+ expect(opts.isFake()).andReturn(true);
+ replay(opts);
+
+ shell.setInstance(opts);
+ Assert.assertTrue(shell.getInstance() instanceof org.apache.accumulo.core.client.mock.MockInstance);
+ }
+
@Test
public void testSetInstance_HdfsZooInstance_Explicit() throws Exception {
testSetInstance_HdfsZooInstance(true, false, false);
@@ -148,6 +155,7 @@ public class ShellSetInstanceTest {
private void testSetInstance_HdfsZooInstance(boolean explicitHdfs, boolean onlyInstance, boolean onlyHosts) throws Exception {
ClientConfiguration clientConf = createMock(ClientConfiguration.class);
ShellOptionsJC opts = createMock(ShellOptionsJC.class);
+ expect(opts.isFake()).andReturn(false);
expect(opts.getClientConfiguration()).andReturn(clientConf);
expect(opts.isHdfsZooInstance()).andReturn(explicitHdfs);
if (!explicitHdfs) {
@@ -183,10 +191,14 @@ public class ShellSetInstanceTest {
}
if (!onlyInstance) {
expect(clientConf.containsKey(Property.INSTANCE_VOLUMES.getKey())).andReturn(false).atLeastOnce();
- expect(clientConf.containsKey(INSTANCE_DFS_DIR.getKey())).andReturn(true).atLeastOnce();
- expect(clientConf.containsKey(INSTANCE_DFS_URI.getKey())).andReturn(true).atLeastOnce();
- expect(clientConf.getString(INSTANCE_DFS_URI.getKey())).andReturn("hdfs://nn1").atLeastOnce();
- expect(clientConf.getString(INSTANCE_DFS_DIR.getKey())).andReturn("/dfs").atLeastOnce();
+ @SuppressWarnings("deprecation")
+ String INSTANCE_DFS_DIR_KEY = Property.INSTANCE_DFS_DIR.getKey();
+ @SuppressWarnings("deprecation")
+ String INSTANCE_DFS_URI_KEY = Property.INSTANCE_DFS_URI.getKey();
+ expect(clientConf.containsKey(INSTANCE_DFS_DIR_KEY)).andReturn(true).atLeastOnce();
+ expect(clientConf.containsKey(INSTANCE_DFS_URI_KEY)).andReturn(true).atLeastOnce();
+ expect(clientConf.getString(INSTANCE_DFS_URI_KEY)).andReturn("hdfs://nn1").atLeastOnce();
+ expect(clientConf.getString(INSTANCE_DFS_DIR_KEY)).andReturn("/dfs").atLeastOnce();
}
UUID randomUUID = null;
@@ -221,6 +233,7 @@ public class ShellSetInstanceTest {
private void testSetInstance_ZKInstance(boolean dashZ) throws Exception {
ClientConfiguration clientConf = createMock(ClientConfiguration.class);
ShellOptionsJC opts = createMock(ShellOptionsJC.class);
+ expect(opts.isFake()).andReturn(false);
expect(opts.getClientConfiguration()).andReturn(clientConf);
expect(opts.isHdfsZooInstance()).andReturn(false);
expect(clientConf.getKeys()).andReturn(Arrays.asList(ClientProperty.INSTANCE_NAME.getKey(), ClientProperty.INSTANCE_ZK_HOST.getKey()).iterator());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
----------------------------------------------------------------------
diff --git a/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
new file mode 100644
index 0000000..dc902ce
--- /dev/null
+++ b/shell/src/test/java/org/apache/accumulo/shell/ShellTest.java
@@ -0,0 +1,394 @@
+/*
+ * 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.shell;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.apache.log4j.Level;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jline.console.ConsoleReader;
+
+public class ShellTest {
+ private static final Logger log = LoggerFactory.getLogger(ShellTest.class);
+
+ public static class TestOutputStream extends OutputStream {
+ StringBuilder sb = new StringBuilder();
+
+ @Override
+ public void write(int b) throws IOException {
+ sb.append((char) (0xff & b));
+ }
+
+ public String get() {
+ return sb.toString();
+ }
+
+ public void clear() {
+ sb.setLength(0);
+ }
+ }
+
+ public static class StringInputStream extends InputStream {
+ private String source = "";
+ private int offset = 0;
+
+ @Override
+ public int read() throws IOException {
+ if (offset == source.length())
+ return '\n';
+ else
+ return source.charAt(offset++);
+ }
+
+ public void set(String other) {
+ source = other;
+ offset = 0;
+ }
+ }
+
+ private StringInputStream input;
+ private TestOutputStream output;
+ private Shell shell;
+ private File config;
+
+ void execExpectList(String cmd, boolean expecteGoodExit, List<String> expectedStrings) throws IOException {
+ exec(cmd);
+ if (expecteGoodExit) {
+ assertGoodExit("", true);
+ } else {
+ assertBadExit("", true);
+ }
+
+ for (String expectedString : expectedStrings) {
+ assertTrue(expectedString + " was not present in " + output.get(), output.get().contains(expectedString));
+ }
+ }
+
+ void exec(String cmd) throws IOException {
+ output.clear();
+ shell.execCommand(cmd, true, true);
+ }
+
+ void exec(String cmd, boolean expectGoodExit) throws IOException {
+ exec(cmd);
+ if (expectGoodExit)
+ assertGoodExit("", true);
+ else
+ assertBadExit("", true);
+ }
+
+ void exec(String cmd, boolean expectGoodExit, String expectString) throws IOException {
+ exec(cmd, expectGoodExit, expectString, true);
+ }
+
+ void exec(String cmd, boolean expectGoodExit, String expectString, boolean stringPresent) throws IOException {
+ exec(cmd);
+ if (expectGoodExit)
+ assertGoodExit(expectString, stringPresent);
+ else
+ assertBadExit(expectString, stringPresent);
+ }
+
+ @Before
+ public void setup() throws IOException {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ Shell.log.setLevel(Level.OFF);
+ output = new TestOutputStream();
+ input = new StringInputStream();
+ config = Files.createTempFile(null, null).toFile();
+ shell = new Shell(new ConsoleReader(input, output));
+ shell.setLogErrorsToConsole();
+ shell.config("--config-file", config.toString(), "--fake", "-u", "test", "-p", "secret");
+ }
+
+ @After
+ public void teardown() {
+ if (config.exists()) {
+ if (!config.delete()) {
+ log.error("Unable to delete {}", config);
+ }
+ }
+ shell.shutdown();
+ }
+
+ void assertGoodExit(String s, boolean stringPresent) {
+ Shell.log.debug(output.get());
+ assertEquals(shell.getExitCode(), 0);
+ if (s.length() > 0)
+ assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
+ }
+
+ void assertBadExit(String s, boolean stringPresent) {
+ Shell.log.debug(output.get());
+ assertTrue(shell.getExitCode() > 0);
+ if (s.length() > 0)
+ assertEquals(s + " present in " + output.get() + " was not " + stringPresent, stringPresent, output.get().contains(s));
+ shell.resetExitCode();
+ }
+
+ @Test
+ public void aboutTest() throws IOException {
+ Shell.log.debug("Starting about test -----------------------------------");
+ exec("about", true, "Shell - Apache Accumulo Interactive Shell");
+ exec("about -v", true, "Current user:");
+ exec("about arg", false, "java.lang.IllegalArgumentException: Expected 0 arguments");
+ }
+
+ @Test
+ public void addGetSplitsTest() throws IOException {
+ Shell.log.debug("Starting addGetSplits test ----------------------------");
+ exec("addsplits arg", false, "java.lang.IllegalStateException: Not in a table context");
+ exec("createtable test", true);
+ exec("addsplits 1 \\x80", true);
+ exec("getsplits", true, "1\n\\x80");
+ exec("getsplits -m 1", true, "1");
+ exec("getsplits -b64", true, "MQ==\ngA==");
+ exec("deletetable test -f", true, "Table: [test] has been deleted");
+ }
+
+ @Test
+ public void insertDeleteScanTest() throws IOException {
+ Shell.log.debug("Starting insertDeleteScan test ------------------------");
+ exec("insert r f q v", false, "java.lang.IllegalStateException: Not in a table context");
+ exec("delete r f q", false, "java.lang.IllegalStateException: Not in a table context");
+ exec("createtable test", true);
+ exec("insert r f q v", true);
+ exec("scan", true, "r f:q [] v");
+ exec("delete r f q", true);
+ exec("scan", true, "r f:q [] v", false);
+ exec("insert \\x90 \\xa0 \\xb0 \\xc0\\xd0\\xe0\\xf0", true);
+ exec("scan", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0");
+ exec("scan -f 2", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0");
+ exec("scan -f 2", true, "\\x90 \\xA0:\\xB0 [] \\xC0\\xD0\\xE0", false);
+ exec("scan -b \\x90 -e \\x90 -c \\xA0", true, "\\x90 \\xA0:\\xB0 [] \\xC0");
+ exec("scan -b \\x90 -e \\x90 -c \\xA0:\\xB0", true, "\\x90 \\xA0:\\xB0 [] \\xC0");
+ exec("scan -b \\x90 -be", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
+ exec("scan -e \\x90 -ee", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
+ exec("scan -b \\x90\\x00", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
+ exec("scan -e \\x8f", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
+ exec("delete \\x90 \\xa0 \\xb0", true);
+ exec("scan", true, "\\x90 \\xA0:\\xB0 [] \\xC0", false);
+ exec("deletetable test -f", true, "Table: [test] has been deleted");
+ }
+
+ @Test
+ public void deleteManyTest() throws IOException {
+ exec("deletemany", false, "java.lang.IllegalStateException: Not in a table context");
+ exec("createtable test", true);
+ exec("deletemany", true, "\n");
+
+ exec("insert 0 0 0 0 -ts 0");
+ exec("insert 0 0 0 0 -l 0 -ts 0");
+ exec("insert 1 1 1 1 -ts 1");
+ exec("insert 2 2 2 2 -ts 2");
+
+ // prompts for delete, and rejects by default
+ exec("deletemany", true, "[SKIPPED] 0 0:0 []");
+ exec("deletemany -r 0", true, "[SKIPPED] 0 0:0 []");
+ exec("deletemany -r 0 -f", true, "[DELETED] 0 0:0 []");
+
+ // with auths, can delete the other record
+ exec("setauths -s 0");
+ exec("deletemany -r 0 -f", true, "[DELETED] 0 0:0 [0]");
+
+ // delete will show the timestamp
+ exec("deletemany -r 1 -f -st", true, "[DELETED] 1 1:1 [] 1");
+
+ // DeleteManyCommand has its own Formatter (DeleterFormatter), so it does not honor the -fm flag
+ exec("deletemany -r 2 -f -st -fm org.apache.accumulo.core.util.format.DateStringFormatter", true, "[DELETED] 2 2:2 [] 2");
+
+ exec("setauths -c ", true);
+ exec("deletetable test -f", true, "Table: [test] has been deleted");
+ }
+
+ @Test
+ public void authsTest() throws Exception {
+ Shell.log.debug("Starting auths test --------------------------");
+ exec("setauths x,y,z", false, "Missing required option");
+ exec("setauths -s x,y,z -u notauser", false, "user does not exist");
+ exec("setauths -s y,z,x", true);
+ exec("getauths -u notauser", false, "user does not exist");
+ execExpectList("getauths", true, Arrays.asList("x", "y", "z"));
+ exec("addauths -u notauser", false, "Missing required option");
+ exec("addauths -u notauser -s foo", false, "user does not exist");
+ exec("addauths -s a", true);
+ execExpectList("getauths", true, Arrays.asList("x", "y", "z", "a"));
+ exec("setauths -c", true);
+ }
+
+ @Test
+ public void userTest() throws Exception {
+ Shell.log.debug("Starting user test --------------------------");
+ // Test cannot be done via junit because createuser only prompts for password
+ // exec("createuser root", false, "user exists");
+ }
+
+ @Test
+ public void duContextTest() throws Exception {
+ Shell.log.debug("Starting du context test --------------------------");
+ exec("createtable t", true);
+ exec("du", true, "0 [t]");
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ }
+
+ @Test
+ public void duTest() throws IOException {
+ Shell.log.debug("Starting DU test --------------------------");
+ exec("createtable t", true);
+ exec("du t", true, "0 [t]");
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ }
+
+ @Test
+ public void duPatternTest() throws IOException {
+ Shell.log.debug("Starting DU with pattern test --------------------------");
+ exec("createtable t", true);
+ exec("createtable tt", true);
+ exec("du -p t.*", true, "0 [t, tt]");
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ exec("deletetable tt -f", true, "Table: [tt] has been deleted");
+ }
+
+ @Test
+ public void scanTimestampTest() throws IOException {
+ Shell.log.debug("Starting scanTimestamp test ------------------------");
+ exec("createtable test", true);
+ exec("insert r f q v -ts 0", true);
+ exec("scan -st", true, "r f:q [] 0 v");
+ exec("scan -st -f 0", true, " : [] 0 ");
+ exec("deletemany -f", true);
+ exec("deletetable test -f", true, "Table: [test] has been deleted");
+ }
+
+ @Test
+ public void scanFewTest() throws IOException {
+ Shell.log.debug("Starting scanFew test ------------------------");
+ exec("createtable test", true);
+ // historically, showing few did not pertain to ColVis or Timestamp
+ exec("insert 1 123 123456 -l '12345678' -ts 123456789 1234567890", true);
+ exec("setauths -s 12345678", true);
+ String expected = "1 123:123456 [12345678] 123456789 1234567890";
+ String expectedFew = "1 123:12345 [12345678] 123456789 12345";
+ exec("scan -st", true, expected);
+ exec("scan -st -f 5", true, expectedFew);
+ // also prove that BinaryFormatter behaves same as the default
+ exec("scan -st -fm org.apache.accumulo.core.util.format.BinaryFormatter", true, expected);
+ exec("scan -st -f 5 -fm org.apache.accumulo.core.util.format.BinaryFormatter", true, expectedFew);
+ exec("setauths -c", true);
+ exec("deletetable test -f", true, "Table: [test] has been deleted");
+ }
+
+ @Test
+ public void scanDateStringFormatterTest() throws IOException {
+ Shell.log.debug("Starting scan dateStringFormatter test --------------------------");
+ exec("createtable t", true);
+ exec("insert r f q v -ts 0", true);
+ @SuppressWarnings("deprecation")
+ DateFormat dateFormat = new SimpleDateFormat(org.apache.accumulo.core.util.format.DateStringFormatter.DATE_FORMAT);
+ String expected = String.format("r f:q [] %s v", dateFormat.format(new Date(0)));
+ // historically, showing few did not pertain to ColVis or Timestamp
+ String expectedFew = expected;
+ String expectedNoTimestamp = String.format("r f:q [] v");
+ exec("scan -fm org.apache.accumulo.core.util.format.DateStringFormatter -st", true, expected);
+ exec("scan -fm org.apache.accumulo.core.util.format.DateStringFormatter -st -f 1000", true, expected);
+ exec("scan -fm org.apache.accumulo.core.util.format.DateStringFormatter -st -f 5", true, expectedFew);
+ exec("scan -fm org.apache.accumulo.core.util.format.DateStringFormatter", true, expectedNoTimestamp);
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ }
+
+ @Test
+ public void grepTest() throws IOException {
+ Shell.log.debug("Starting grep test --------------------------");
+ exec("grep", false, "java.lang.IllegalStateException: Not in a table context");
+ exec("createtable t", true);
+ exec("setauths -s vis", true);
+ exec("insert r f q v -ts 0 -l vis", true);
+
+ String expected = "r f:q [vis] v";
+ String expectedTimestamp = "r f:q [vis] 0 v";
+ exec("grep", false, "No terms specified");
+ exec("grep non_matching_string", true, "");
+ // historically, showing few did not pertain to ColVis or Timestamp
+ exec("grep r", true, expected);
+ exec("grep r -f 1", true, expected);
+ exec("grep r -st", true, expectedTimestamp);
+ exec("grep r -st -f 1", true, expectedTimestamp);
+ exec("setauths -c", true);
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ }
+
+ @Test
+ public void commentTest() throws IOException {
+ Shell.log.debug("Starting comment test --------------------------");
+ exec("#", true, "Unknown command", false);
+ exec("# foo", true, "Unknown command", false);
+ exec("- foo", true, "Unknown command", true);
+ }
+
+ @Test
+ public void execFileTest() throws IOException {
+ Shell.log.debug("Starting exec file test --------------------------");
+ shell.config("--config-file", config.toString(), "--fake", "-u", "test", "-p", "secret", "-f", "src/test/resources/shelltest.txt");
+ assertEquals(0, shell.start());
+ assertGoodExit("Unknown command", false);
+ }
+
+ @Test
+ public void setIterTest() throws IOException {
+ Shell.log.debug("Starting setiter test --------------------------");
+ exec("createtable t", true);
+
+ String cmdJustClass = "setiter -class VersioningIterator -p 1";
+ exec(cmdJustClass, false, "java.lang.IllegalArgumentException", false);
+ exec(cmdJustClass, false, "fully qualified package name", true);
+
+ String cmdFullPackage = "setiter -class o.a.a.foo -p 1";
+ exec(cmdFullPackage, false, "java.lang.IllegalArgumentException", false);
+ exec(cmdFullPackage, false, "class not found", true);
+
+ String cmdNoOption = "setiter -class java.lang.String -p 1";
+ exec(cmdNoOption, false, "loaded successfully but does not implement SortedKeyValueIterator", true);
+
+ input.set("\n\n");
+ exec("setiter -scan -class org.apache.accumulo.core.iterators.ColumnFamilyCounter -p 30 -name foo", true);
+
+ input.set("bar\nname value\n");
+ exec("setiter -scan -class org.apache.accumulo.core.iterators.ColumnFamilyCounter -p 31", true);
+
+ // TODO can't verify this as config -t fails, functionality verified in ShellServerIT
+
+ exec("deletetable t -f", true, "Table: [t] has been deleted");
+ }
+}
[6/8] accumulo git commit: Revert "ACCUMULO-2589 Drop deprecated code
from 1.x"
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/IteratorAdapter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/IteratorAdapter.java b/core/src/main/java/org/apache/accumulo/core/client/mock/IteratorAdapter.java
new file mode 100644
index 0000000..d88dac9
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/IteratorAdapter.java
@@ -0,0 +1,33 @@
+/*
+ * 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.client.mock;
+
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+
+/**
+ * @deprecated since 1.8.0; use {@link org.apache.accumulo.core.iterators.IteratorAdapter} instead.
+ */
+@Deprecated
+public class IteratorAdapter extends org.apache.accumulo.core.iterators.IteratorAdapter {
+
+ public IteratorAdapter(SortedKeyValueIterator<Key,Value> inner) {
+ super(inner);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java
new file mode 100644
index 0000000..f362add
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java
@@ -0,0 +1,148 @@
+/*
+ * 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.client.mock;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.client.impl.Namespaces;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.metadata.MetadataTable;
+import org.apache.accumulo.core.metadata.RootTable;
+import org.apache.accumulo.core.replication.ReplicationTable;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.NamespacePermission;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockAccumulo {
+ final Map<String,MockTable> tables = new HashMap<>();
+ final Map<String,MockNamespace> namespaces = new HashMap<>();
+ final Map<String,String> systemProperties = new HashMap<>();
+ Map<String,MockUser> users = new HashMap<>();
+ final FileSystem fs;
+ final AtomicInteger tableIdCounter = new AtomicInteger(0);
+
+ @Deprecated
+ MockAccumulo(FileSystem fs) {
+ MockUser root = new MockUser("root", new PasswordToken(new byte[0]), Authorizations.EMPTY);
+ root.permissions.add(SystemPermission.SYSTEM);
+ users.put(root.name, root);
+ namespaces.put(Namespaces.DEFAULT_NAMESPACE, new MockNamespace());
+ namespaces.put(Namespaces.ACCUMULO_NAMESPACE, new MockNamespace());
+ createTable("root", RootTable.NAME, true, TimeType.LOGICAL);
+ createTable("root", MetadataTable.NAME, true, TimeType.LOGICAL);
+ createTable("root", ReplicationTable.NAME, true, TimeType.LOGICAL);
+ this.fs = fs;
+ }
+
+ public FileSystem getFileSystem() {
+ return fs;
+ }
+
+ void setProperty(String key, String value) {
+ systemProperties.put(key, value);
+ }
+
+ String removeProperty(String key) {
+ return systemProperties.remove(key);
+ }
+
+ public void addMutation(String table, Mutation m) {
+ MockTable t = tables.get(table);
+ t.addMutation(m);
+ }
+
+ public BatchScanner createBatchScanner(String tableName, Authorizations authorizations) {
+ return new MockBatchScanner(tables.get(tableName), authorizations);
+ }
+
+ public void createTable(String username, String tableName, boolean useVersions, TimeType timeType) {
+ Map<String,String> opts = Collections.emptyMap();
+ createTable(username, tableName, useVersions, timeType, opts);
+ }
+
+ public void createTable(String username, String tableName, boolean useVersions, TimeType timeType, Map<String,String> properties) {
+ String namespace = Tables.qualify(tableName).getFirst();
+
+ if (!namespaceExists(namespace)) {
+ return;
+ }
+
+ MockNamespace n = namespaces.get(namespace);
+ MockTable t = new MockTable(n, useVersions, timeType, Integer.toString(tableIdCounter.incrementAndGet()), properties);
+ t.userPermissions.put(username, EnumSet.allOf(TablePermission.class));
+ t.setNamespaceName(namespace);
+ t.setNamespace(n);
+ tables.put(tableName, t);
+ }
+
+ public void createTable(String username, String tableName, TimeType timeType, Map<String,String> properties) {
+ String namespace = Tables.qualify(tableName).getFirst();
+ HashMap<String,String> props = new HashMap<>(properties);
+
+ if (!namespaceExists(namespace)) {
+ return;
+ }
+
+ MockNamespace n = namespaces.get(namespace);
+ MockTable t = new MockTable(n, timeType, Integer.toString(tableIdCounter.incrementAndGet()), props);
+ t.userPermissions.put(username, EnumSet.allOf(TablePermission.class));
+ t.setNamespaceName(namespace);
+ t.setNamespace(n);
+ tables.put(tableName, t);
+ }
+
+ public void createNamespace(String username, String namespace) {
+ if (!namespaceExists(namespace)) {
+ MockNamespace n = new MockNamespace();
+ n.userPermissions.put(username, EnumSet.allOf(NamespacePermission.class));
+ namespaces.put(namespace, n);
+ }
+ }
+
+ public void addSplits(String tableName, SortedSet<Text> partitionKeys) {
+ tables.get(tableName).addSplits(partitionKeys);
+ }
+
+ public Collection<Text> getSplits(String tableName) {
+ return tables.get(tableName).getSplits();
+ }
+
+ public void merge(String tableName, Text start, Text end) {
+ tables.get(tableName).merge(start, end);
+ }
+
+ private boolean namespaceExists(String namespace) {
+ return namespaces.containsKey(namespace);
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchDeleter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchDeleter.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchDeleter.java
new file mode 100644
index 0000000..bacd844
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchDeleter.java
@@ -0,0 +1,76 @@
+/*
+ * 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.client.mock;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.BatchDeleter;
+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.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.ColumnVisibility;
+
+/**
+ * {@link BatchDeleter} for a {@link MockAccumulo} instance. Behaves similarly to a regular {@link BatchDeleter}, with a few exceptions:
+ * <ol>
+ * <li>There is no waiting for memory to fill before flushing</li>
+ * <li>Only one thread is used for writing</li>
+ * </ol>
+ *
+ * Otherwise, it behaves as expected.
+ *
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockBatchDeleter extends MockBatchScanner implements BatchDeleter {
+
+ private final MockAccumulo acc;
+ private final String tableName;
+
+ /**
+ * Create a {@link BatchDeleter} for the specified instance on the specified table where the writer uses the specified {@link Authorizations}.
+ */
+ public MockBatchDeleter(MockAccumulo acc, String tableName, Authorizations auths) {
+ super(acc.tables.get(tableName), auths);
+ this.acc = acc;
+ this.tableName = tableName;
+ }
+
+ @Override
+ public void delete() throws MutationsRejectedException, TableNotFoundException {
+
+ BatchWriter writer = new MockBatchWriter(acc, tableName);
+ try {
+ Iterator<Entry<Key,Value>> iter = super.iterator();
+ while (iter.hasNext()) {
+ Entry<Key,Value> next = iter.next();
+ Key k = next.getKey();
+ Mutation m = new Mutation(k.getRow());
+ m.putDelete(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp());
+ writer.addMutation(m);
+ }
+ } finally {
+ writer.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchScanner.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchScanner.java
new file mode 100644
index 0000000..1ea27b5
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchScanner.java
@@ -0,0 +1,79 @@
+/*
+ * 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.client.mock;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.SortedMapIterator;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.commons.collections.iterators.IteratorChain;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockBatchScanner extends MockScannerBase implements BatchScanner {
+
+ List<Range> ranges = null;
+
+ public MockBatchScanner(MockTable mockTable, Authorizations authorizations) {
+ super(mockTable, authorizations);
+ }
+
+ @Override
+ public void setRanges(Collection<Range> ranges) {
+ if (ranges == null || ranges.size() == 0) {
+ throw new IllegalArgumentException("ranges must be non null and contain at least 1 range");
+ }
+
+ this.ranges = new ArrayList<>(ranges);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Entry<Key,Value>> iterator() {
+ if (ranges == null) {
+ throw new IllegalStateException("ranges not set");
+ }
+
+ IteratorChain chain = new IteratorChain();
+ for (Range range : ranges) {
+ SortedKeyValueIterator<Key,Value> i = new SortedMapIterator(table.table);
+ try {
+ i = createFilter(i);
+ i.seek(range, createColumnBSS(fetchedColumns), !fetchedColumns.isEmpty());
+ chain.addIterator(new IteratorAdapter(i));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return chain;
+ }
+
+ @Override
+ public void close() {}
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchWriter.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchWriter.java
new file mode 100644
index 0000000..53a0ddc
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockBatchWriter.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.client.mock;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.data.Mutation;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockBatchWriter implements BatchWriter {
+
+ final String tablename;
+ final MockAccumulo acu;
+
+ MockBatchWriter(MockAccumulo acu, String tablename) {
+ this.acu = acu;
+ this.tablename = tablename;
+ }
+
+ @Override
+ public void addMutation(Mutation m) throws MutationsRejectedException {
+ checkArgument(m != null, "m is null");
+ acu.addMutation(tablename, m);
+ }
+
+ @Override
+ public void addMutations(Iterable<Mutation> iterable) throws MutationsRejectedException {
+ checkArgument(iterable != null, "iterable is null");
+ for (Mutation m : iterable) {
+ acu.addMutation(tablename, m);
+ }
+ }
+
+ @Override
+ public void flush() throws MutationsRejectedException {}
+
+ @Override
+ public void close() throws MutationsRejectedException {}
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java
new file mode 100644
index 0000000..38ed1df
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConfiguration.java
@@ -0,0 +1,54 @@
+/*
+ * 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.client.mock;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Predicate;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+class MockConfiguration extends AccumuloConfiguration {
+ Map<String,String> map;
+
+ MockConfiguration(Map<String,String> settings) {
+ map = settings;
+ }
+
+ public void put(String k, String v) {
+ map.put(k, v);
+ }
+
+ @Override
+ public String get(Property property) {
+ return map.get(property.getKey());
+ }
+
+ @Override
+ public void getProperties(Map<String,String> props, Predicate<String> filter) {
+ for (Entry<String,String> entry : map.entrySet()) {
+ if (filter.test(entry.getKey())) {
+ props.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
new file mode 100644
index 0000000..9b5601b
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
@@ -0,0 +1,162 @@
+/*
+ * 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.client.mock;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchDeleter;
+import org.apache.accumulo.core.client.BatchScanner;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.ConditionalWriter;
+import org.apache.accumulo.core.client.ConditionalWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.MultiTableBatchWriter;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.admin.InstanceOperations;
+import org.apache.accumulo.core.client.admin.NamespaceOperations;
+import org.apache.accumulo.core.client.admin.ReplicationOperations;
+import org.apache.accumulo.core.client.admin.SecurityOperations;
+import org.apache.accumulo.core.client.admin.TableOperations;
+import org.apache.accumulo.core.client.impl.Credentials;
+import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
+import org.apache.accumulo.core.client.security.tokens.NullToken;
+import org.apache.accumulo.core.security.Authorizations;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockConnector extends Connector {
+
+ String username;
+ private final MockAccumulo acu;
+ private final Instance instance;
+
+ MockConnector(String username, MockInstance instance) throws AccumuloSecurityException {
+ this(new Credentials(username, new NullToken()), new MockAccumulo(MockInstance.getDefaultFileSystem()), instance);
+ }
+
+ MockConnector(Credentials credentials, MockAccumulo acu, MockInstance instance) throws AccumuloSecurityException {
+ if (credentials.getToken().isDestroyed())
+ throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.TOKEN_EXPIRED);
+ this.username = credentials.getPrincipal();
+ this.acu = acu;
+ this.instance = instance;
+ }
+
+ @Override
+ public BatchScanner createBatchScanner(String tableName, Authorizations authorizations, int numQueryThreads) throws TableNotFoundException {
+ if (acu.tables.get(tableName) == null)
+ throw new TableNotFoundException(tableName, tableName, "no such table");
+ return acu.createBatchScanner(tableName, authorizations);
+ }
+
+ @Deprecated
+ @Override
+ public BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, long maxMemory, long maxLatency,
+ int maxWriteThreads) throws TableNotFoundException {
+ if (acu.tables.get(tableName) == null)
+ throw new TableNotFoundException(tableName, tableName, "no such table");
+ return new MockBatchDeleter(acu, tableName, authorizations);
+ }
+
+ @Override
+ public BatchDeleter createBatchDeleter(String tableName, Authorizations authorizations, int numQueryThreads, BatchWriterConfig config)
+ throws TableNotFoundException {
+ return createBatchDeleter(tableName, authorizations, numQueryThreads, config.getMaxMemory(), config.getMaxLatency(TimeUnit.MILLISECONDS),
+ config.getMaxWriteThreads());
+ }
+
+ @Deprecated
+ @Override
+ public BatchWriter createBatchWriter(String tableName, long maxMemory, long maxLatency, int maxWriteThreads) throws TableNotFoundException {
+ if (acu.tables.get(tableName) == null)
+ throw new TableNotFoundException(tableName, tableName, "no such table");
+ return new MockBatchWriter(acu, tableName);
+ }
+
+ @Override
+ public BatchWriter createBatchWriter(String tableName, BatchWriterConfig config) throws TableNotFoundException {
+ return createBatchWriter(tableName, config.getMaxMemory(), config.getMaxLatency(TimeUnit.MILLISECONDS), config.getMaxWriteThreads());
+ }
+
+ @Deprecated
+ @Override
+ public MultiTableBatchWriter createMultiTableBatchWriter(long maxMemory, long maxLatency, int maxWriteThreads) {
+ return new MockMultiTableBatchWriter(acu);
+ }
+
+ @Override
+ public MultiTableBatchWriter createMultiTableBatchWriter(BatchWriterConfig config) {
+ return createMultiTableBatchWriter(config.getMaxMemory(), config.getMaxLatency(TimeUnit.MILLISECONDS), config.getMaxWriteThreads());
+ }
+
+ @Override
+ public Scanner createScanner(String tableName, Authorizations authorizations) throws TableNotFoundException {
+ MockTable table = acu.tables.get(tableName);
+ if (table == null)
+ throw new TableNotFoundException(tableName, tableName, "no such table");
+ return new MockScanner(table, authorizations);
+ }
+
+ @Override
+ public Instance getInstance() {
+ return instance;
+ }
+
+ @Override
+ public String whoami() {
+ return username;
+ }
+
+ @Override
+ public TableOperations tableOperations() {
+ return new MockTableOperations(acu, username);
+ }
+
+ @Override
+ public SecurityOperations securityOperations() {
+ return new MockSecurityOperations(acu);
+ }
+
+ @Override
+ public InstanceOperations instanceOperations() {
+ return new MockInstanceOperations(acu);
+ }
+
+ @Override
+ public NamespaceOperations namespaceOperations() {
+ return new MockNamespaceOperations(acu, username);
+ }
+
+ @Override
+ public ConditionalWriter createConditionalWriter(String tableName, ConditionalWriterConfig config) throws TableNotFoundException {
+ // TODO add implementation
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ReplicationOperations replicationOperations() {
+ // TODO add implementation
+ throw new UnsupportedOperationException();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
new file mode 100644
index 0000000..50d212f
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
@@ -0,0 +1,163 @@
+/*
+ * 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.client.mock;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.impl.Credentials;
+import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.DefaultConfiguration;
+import org.apache.accumulo.core.util.ByteBufferUtil;
+import org.apache.accumulo.core.util.CachedConfiguration;
+import org.apache.accumulo.core.util.TextUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.io.Text;
+
+/**
+ * Mock Accumulo provides an in memory implementation of the Accumulo client API. It is possible that the behavior of this implementation may differ subtly from
+ * the behavior of Accumulo. This could result in unit tests that pass on Mock Accumulo and fail on Accumulo or visa-versa. Documenting the differences would be
+ * difficult and is not done.
+ *
+ * <p>
+ * An alternative to Mock Accumulo called MiniAccumuloCluster was introduced in Accumulo 1.5. MiniAccumuloCluster spins up actual Accumulo server processes, can
+ * be used for unit testing, and its behavior should match Accumulo. The drawback of MiniAccumuloCluster is that it starts more slowly than Mock Accumulo.
+ *
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockInstance implements Instance {
+
+ static final String genericAddress = "localhost:1234";
+ static final Map<String,MockAccumulo> instances = new HashMap<>();
+ MockAccumulo acu;
+ String instanceName;
+
+ public MockInstance() {
+ acu = new MockAccumulo(getDefaultFileSystem());
+ instanceName = "mock-instance";
+ }
+
+ static FileSystem getDefaultFileSystem() {
+ try {
+ Configuration conf = CachedConfiguration.getInstance();
+ conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem");
+ conf.set("fs.default.name", "file:///");
+ return FileSystem.get(CachedConfiguration.getInstance());
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public MockInstance(String instanceName) {
+ this(instanceName, getDefaultFileSystem());
+ }
+
+ public MockInstance(String instanceName, FileSystem fs) {
+ synchronized (instances) {
+ if (instances.containsKey(instanceName))
+ acu = instances.get(instanceName);
+ else
+ instances.put(instanceName, acu = new MockAccumulo(fs));
+ }
+ this.instanceName = instanceName;
+ }
+
+ @Override
+ public String getRootTabletLocation() {
+ return genericAddress;
+ }
+
+ @Override
+ public List<String> getMasterLocations() {
+ return Collections.singletonList(genericAddress);
+ }
+
+ @Override
+ public String getInstanceID() {
+ return "mock-instance-id";
+ }
+
+ @Override
+ public String getInstanceName() {
+ return instanceName;
+ }
+
+ @Override
+ public String getZooKeepers() {
+ return "localhost";
+ }
+
+ @Override
+ public int getZooKeepersSessionTimeOut() {
+ return 30 * 1000;
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, new PasswordToken(pass));
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, ByteBuffer pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, ByteBufferUtil.toBytes(pass));
+ }
+
+ @Override
+ @Deprecated
+ public Connector getConnector(String user, CharSequence pass) throws AccumuloException, AccumuloSecurityException {
+ return getConnector(user, TextUtil.getBytes(new Text(pass.toString())));
+ }
+
+ AccumuloConfiguration conf = null;
+
+ @Deprecated
+ @Override
+ public AccumuloConfiguration getConfiguration() {
+ return conf == null ? DefaultConfiguration.getInstance() : conf;
+ }
+
+ @Override
+ @Deprecated
+ public void setConfiguration(AccumuloConfiguration conf) {
+ this.conf = conf;
+ }
+
+ @Override
+ public Connector getConnector(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
+ Connector conn = new MockConnector(new Credentials(principal, token), acu, this);
+ if (!acu.users.containsKey(principal))
+ conn.securityOperations().createLocalUser(principal, (PasswordToken) token);
+ else if (!acu.users.get(principal).token.equals(token))
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.BAD_CREDENTIALS);
+ return conn;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
new file mode 100644
index 0000000..e264104
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java
@@ -0,0 +1,97 @@
+/*
+ * 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.client.mock;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.admin.ActiveCompaction;
+import org.apache.accumulo.core.client.admin.ActiveScan;
+import org.apache.accumulo.core.client.admin.InstanceOperations;
+import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+class MockInstanceOperations implements InstanceOperations {
+ private static final Logger log = LoggerFactory.getLogger(MockInstanceOperations.class);
+ MockAccumulo acu;
+
+ public MockInstanceOperations(MockAccumulo acu) {
+ this.acu = acu;
+ }
+
+ @Override
+ public void setProperty(String property, String value) throws AccumuloException, AccumuloSecurityException {
+ acu.setProperty(property, value);
+ }
+
+ @Override
+ public void removeProperty(String property) throws AccumuloException, AccumuloSecurityException {
+ acu.removeProperty(property);
+ }
+
+ @Override
+ public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException {
+ return acu.systemProperties;
+ }
+
+ @Override
+ public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException {
+ return acu.systemProperties;
+ }
+
+ @Override
+ public List<String> getTabletServers() {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException {
+ try {
+ AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
+ } catch (ClassNotFoundException e) {
+ log.warn("Could not find class named '" + className + "' in testClassLoad.", e);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException {
+ return new ArrayList<>();
+ }
+
+ @Override
+ public void ping(String tserver) throws AccumuloException {
+
+ }
+
+ @Override
+ public void waitForBalance() throws AccumuloException {}
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.java
new file mode 100644
index 0000000..5b9bc2b
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockMultiTableBatchWriter.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.client.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+
+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.MultiTableBatchWriter;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockMultiTableBatchWriter implements MultiTableBatchWriter {
+ MockAccumulo acu = null;
+ Map<String,MockBatchWriter> bws = null;
+
+ public MockMultiTableBatchWriter(MockAccumulo acu) {
+ this.acu = acu;
+ bws = new HashMap<>();
+ }
+
+ @Override
+ public BatchWriter getBatchWriter(String table) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
+ if (!bws.containsKey(table)) {
+ bws.put(table, new MockBatchWriter(acu, table));
+ }
+ return bws.get(table);
+ }
+
+ @Override
+ public void flush() throws MutationsRejectedException {}
+
+ @Override
+ public void close() throws MutationsRejectedException {}
+
+ @Override
+ public boolean isClosed() {
+ throw new UnsupportedOperationException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespace.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespace.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespace.java
new file mode 100644
index 0000000..456580b
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespace.java
@@ -0,0 +1,58 @@
+/*
+ * 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.client.mock;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.security.NamespacePermission;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockNamespace {
+
+ final HashMap<String,String> settings;
+ Map<String,EnumSet<NamespacePermission>> userPermissions = new HashMap<>();
+
+ public MockNamespace() {
+ settings = new HashMap<>();
+ for (Entry<String,String> entry : AccumuloConfiguration.getDefaultConfiguration()) {
+ String key = entry.getKey();
+ if (key.startsWith(Property.TABLE_PREFIX.getKey())) {
+ settings.put(key, entry.getValue());
+ }
+ }
+ }
+
+ public List<String> getTables(MockAccumulo acu) {
+ List<String> l = new LinkedList<>();
+ for (String t : acu.tables.keySet()) {
+ if (acu.tables.get(t).getNamespace().equals(this)) {
+ l.add(t);
+ }
+ }
+ return l;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespaceOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespaceOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespaceOperations.java
new file mode 100644
index 0000000..b1cb980
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockNamespaceOperations.java
@@ -0,0 +1,138 @@
+/*
+ * 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.client.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.NamespaceExistsException;
+import org.apache.accumulo.core.client.NamespaceNotEmptyException;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
+import org.apache.accumulo.core.client.impl.NamespaceOperationsHelper;
+import org.apache.accumulo.core.client.impl.Namespaces;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+class MockNamespaceOperations extends NamespaceOperationsHelper {
+
+ private static final Logger log = LoggerFactory.getLogger(MockNamespaceOperations.class);
+
+ final private MockAccumulo acu;
+ final private String username;
+
+ MockNamespaceOperations(MockAccumulo acu, String username) {
+ this.acu = acu;
+ this.username = username;
+ }
+
+ @Override
+ public SortedSet<String> list() {
+ return new TreeSet<>(acu.namespaces.keySet());
+ }
+
+ @Override
+ public boolean exists(String namespace) {
+ return acu.namespaces.containsKey(namespace);
+ }
+
+ @Override
+ public void create(String namespace) throws AccumuloException, AccumuloSecurityException, NamespaceExistsException {
+ if (!namespace.matches(Namespaces.VALID_NAME_REGEX))
+ throw new IllegalArgumentException();
+
+ if (exists(namespace))
+ throw new NamespaceExistsException(namespace, namespace, "");
+ else
+ acu.createNamespace(username, namespace);
+ }
+
+ @Override
+ public void delete(String namespace) throws AccumuloException, AccumuloSecurityException, NamespaceNotFoundException, NamespaceNotEmptyException {
+ if (acu.namespaces.get(namespace).getTables(acu).size() > 0) {
+ throw new NamespaceNotEmptyException(null, namespace, null);
+ }
+ acu.namespaces.remove(namespace);
+ }
+
+ @Override
+ public void rename(String oldNamespaceName, String newNamespaceName) throws AccumuloSecurityException, NamespaceNotFoundException, AccumuloException,
+ NamespaceExistsException {
+ if (!exists(oldNamespaceName))
+ throw new NamespaceNotFoundException(oldNamespaceName, oldNamespaceName, "");
+ if (exists(newNamespaceName))
+ throw new NamespaceExistsException(newNamespaceName, newNamespaceName, "");
+
+ MockNamespace n = acu.namespaces.get(oldNamespaceName);
+ for (String t : n.getTables(acu)) {
+ String tt = newNamespaceName + "." + Tables.qualify(t).getSecond();
+ acu.tables.put(tt, acu.tables.remove(t));
+ }
+ acu.namespaces.put(newNamespaceName, acu.namespaces.remove(oldNamespaceName));
+ }
+
+ @Override
+ public void setProperty(String namespace, String property, String value) throws AccumuloException, AccumuloSecurityException {
+ acu.namespaces.get(namespace).settings.put(property, value);
+ }
+
+ @Override
+ public void removeProperty(String namespace, String property) throws AccumuloException, AccumuloSecurityException {
+ acu.namespaces.get(namespace).settings.remove(property);
+ }
+
+ @Override
+ public Iterable<Entry<String,String>> getProperties(String namespace) throws NamespaceNotFoundException {
+ if (!exists(namespace)) {
+ throw new NamespaceNotFoundException(namespace, namespace, "");
+ }
+
+ return acu.namespaces.get(namespace).settings.entrySet();
+ }
+
+ @Override
+ public Map<String,String> namespaceIdMap() {
+ Map<String,String> result = new HashMap<>();
+ for (String table : acu.tables.keySet()) {
+ result.put(table, table);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean testClassLoad(String namespace, String className, String asTypeName) throws AccumuloException, AccumuloSecurityException,
+ NamespaceNotFoundException {
+
+ try {
+ AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
+ } catch (ClassNotFoundException e) {
+ log.warn("Could not load class '" + className + "' with type name '" + asTypeName + "' in testClassLoad()", e);
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
new file mode 100644
index 0000000..1e36964
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScanner.java
@@ -0,0 +1,127 @@
+/*
+ * 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.client.mock;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Range;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Filter;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.SortedMapIterator;
+import org.apache.accumulo.core.security.Authorizations;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockScanner extends MockScannerBase implements Scanner {
+
+ int batchSize = 0;
+ Range range = new Range();
+
+ MockScanner(MockTable table, Authorizations auths) {
+ super(table, auths);
+ }
+
+ @Deprecated
+ @Override
+ public void setTimeOut(int timeOut) {
+ if (timeOut == Integer.MAX_VALUE)
+ setTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
+ else
+ setTimeout(timeOut, TimeUnit.SECONDS);
+ }
+
+ @Deprecated
+ @Override
+ public int getTimeOut() {
+ long timeout = getTimeout(TimeUnit.SECONDS);
+ if (timeout >= Integer.MAX_VALUE)
+ return Integer.MAX_VALUE;
+ return (int) timeout;
+ }
+
+ @Override
+ public void setRange(Range range) {
+ this.range = range;
+ }
+
+ @Override
+ public Range getRange() {
+ return this.range;
+ }
+
+ @Override
+ public void setBatchSize(int size) {
+ this.batchSize = size;
+ }
+
+ @Override
+ public int getBatchSize() {
+ return this.batchSize;
+ }
+
+ @Override
+ public void enableIsolation() {}
+
+ @Override
+ public void disableIsolation() {}
+
+ static class RangeFilter extends Filter {
+ Range range;
+
+ RangeFilter(SortedKeyValueIterator<Key,Value> i, Range range) {
+ setSource(i);
+ this.range = range;
+ }
+
+ @Override
+ public boolean accept(Key k, Value v) {
+ return range.contains(k);
+ }
+ }
+
+ @Override
+ public Iterator<Entry<Key,Value>> iterator() {
+ SortedKeyValueIterator<Key,Value> i = new SortedMapIterator(table.table);
+ try {
+ i = new RangeFilter(createFilter(i), range);
+ i.seek(range, createColumnBSS(fetchedColumns), !fetchedColumns.isEmpty());
+ return new IteratorAdapter(i);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ public long getReadaheadThreshold() {
+ return 0;
+ }
+
+ @Override
+ public void setReadaheadThreshold(long batches) {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
new file mode 100644
index 0000000..8684697
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java
@@ -0,0 +1,159 @@
+/*
+ * 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.client.mock;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.ScannerBase;
+import org.apache.accumulo.core.client.impl.ScannerOptions;
+import org.apache.accumulo.core.client.sample.SamplerConfiguration;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.data.ArrayByteSequence;
+import org.apache.accumulo.core.data.ByteSequence;
+import org.apache.accumulo.core.data.Column;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.IteratorEnvironment;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
+import org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator;
+import org.apache.accumulo.core.iterators.system.ColumnQualifierFilter;
+import org.apache.accumulo.core.iterators.system.DeletingIterator;
+import org.apache.accumulo.core.iterators.system.MultiIterator;
+import org.apache.accumulo.core.iterators.system.VisibilityFilter;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.commons.lang.NotImplementedException;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockScannerBase extends ScannerOptions implements ScannerBase {
+
+ protected final MockTable table;
+ protected final Authorizations auths;
+
+ MockScannerBase(MockTable mockTable, Authorizations authorizations) {
+ this.table = mockTable;
+ this.auths = authorizations;
+ }
+
+ static HashSet<ByteSequence> createColumnBSS(Collection<Column> columns) {
+ HashSet<ByteSequence> columnSet = new HashSet<>();
+ for (Column c : columns) {
+ columnSet.add(new ArrayByteSequence(c.getColumnFamily()));
+ }
+ return columnSet;
+ }
+
+ static class MockIteratorEnvironment implements IteratorEnvironment {
+
+ private final Authorizations auths;
+
+ MockIteratorEnvironment(Authorizations auths) {
+ this.auths = auths;
+ }
+
+ @Override
+ public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName) throws IOException {
+ throw new NotImplementedException();
+ }
+
+ @Override
+ public AccumuloConfiguration getConfig() {
+ return AccumuloConfiguration.getDefaultConfiguration();
+ }
+
+ @Override
+ public IteratorScope getIteratorScope() {
+ return IteratorScope.scan;
+ }
+
+ @Override
+ public boolean isFullMajorCompaction() {
+ return false;
+ }
+
+ private ArrayList<SortedKeyValueIterator<Key,Value>> topLevelIterators = new ArrayList<>();
+
+ @Override
+ public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) {
+ topLevelIterators.add(iter);
+ }
+
+ @Override
+ public Authorizations getAuthorizations() {
+ return auths;
+ }
+
+ SortedKeyValueIterator<Key,Value> getTopLevelIterator(SortedKeyValueIterator<Key,Value> iter) {
+ if (topLevelIterators.isEmpty())
+ return iter;
+ ArrayList<SortedKeyValueIterator<Key,Value>> allIters = new ArrayList<>(topLevelIterators);
+ allIters.add(iter);
+ return new MultiIterator(allIters, false);
+ }
+
+ @Override
+ public boolean isSamplingEnabled() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SamplerConfiguration getSamplerConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IteratorEnvironment cloneWithSamplingEnabled() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public SortedKeyValueIterator<Key,Value> createFilter(SortedKeyValueIterator<Key,Value> inner) throws IOException {
+ byte[] defaultLabels = {};
+ inner = new ColumnFamilySkippingIterator(new DeletingIterator(inner, false));
+ ColumnQualifierFilter cqf = new ColumnQualifierFilter(inner, new HashSet<>(fetchedColumns));
+ VisibilityFilter vf = new VisibilityFilter(cqf, auths, defaultLabels);
+ AccumuloConfiguration conf = new MockConfiguration(table.settings);
+ MockIteratorEnvironment iterEnv = new MockIteratorEnvironment(auths);
+ SortedKeyValueIterator<Key,Value> result = iterEnv.getTopLevelIterator(IteratorUtil.loadIterators(IteratorScope.scan, vf, null, conf,
+ serverSideIteratorList, serverSideIteratorOptions, iterEnv, false));
+ return result;
+ }
+
+ @Override
+ public Iterator<Entry<Key,Value>> iterator() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Authorizations getAuthorizations() {
+ return auths;
+ }
+
+ @Override
+ public void setClassLoaderContext(String context) {
+ throw new UnsupportedOperationException();
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
new file mode 100644
index 0000000..bf4b46e
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperations.java
@@ -0,0 +1,236 @@
+/*
+ * 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.client.mock;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.admin.DelegationTokenConfig;
+import org.apache.accumulo.core.client.admin.SecurityOperations;
+import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
+import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
+import org.apache.accumulo.core.client.security.tokens.DelegationToken;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.NamespacePermission;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.security.TablePermission;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+class MockSecurityOperations implements SecurityOperations {
+
+ final private MockAccumulo acu;
+
+ MockSecurityOperations(MockAccumulo acu) {
+ this.acu = acu;
+ }
+
+ @Deprecated
+ @Override
+ public void createUser(String user, byte[] password, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
+ createLocalUser(user, new PasswordToken(password));
+ changeUserAuthorizations(user, authorizations);
+ }
+
+ @Override
+ public void createLocalUser(String principal, PasswordToken password) throws AccumuloException, AccumuloSecurityException {
+ this.acu.users.put(principal, new MockUser(principal, password, new Authorizations()));
+ }
+
+ @Deprecated
+ @Override
+ public void dropUser(String user) throws AccumuloException, AccumuloSecurityException {
+ dropLocalUser(user);
+ }
+
+ @Override
+ public void dropLocalUser(String principal) throws AccumuloException, AccumuloSecurityException {
+ this.acu.users.remove(principal);
+ }
+
+ @Deprecated
+ @Override
+ public boolean authenticateUser(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
+ return authenticateUser(user, new PasswordToken(password));
+ }
+
+ @Override
+ public boolean authenticateUser(String principal, AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user == null)
+ return false;
+ return user.token.equals(token);
+ }
+
+ @Deprecated
+ @Override
+ public void changeUserPassword(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
+ changeLocalUserPassword(user, new PasswordToken(password));
+ }
+
+ @Override
+ public void changeLocalUserPassword(String principal, PasswordToken token) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ user.token = token.clone();
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public void changeUserAuthorizations(String principal, Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ user.authorizations = authorizations;
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public Authorizations getUserAuthorizations(String principal) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ return user.authorizations;
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public boolean hasSystemPermission(String principal, SystemPermission perm) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ return user.permissions.contains(perm);
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public boolean hasTablePermission(String principal, String tableName, TablePermission perm) throws AccumuloException, AccumuloSecurityException {
+ MockTable table = acu.tables.get(tableName);
+ if (table == null)
+ throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
+ EnumSet<TablePermission> perms = table.userPermissions.get(principal);
+ if (perms == null)
+ return false;
+ return perms.contains(perm);
+ }
+
+ @Override
+ public boolean hasNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
+ MockNamespace mockNamespace = acu.namespaces.get(namespace);
+ if (mockNamespace == null)
+ throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
+ EnumSet<NamespacePermission> perms = mockNamespace.userPermissions.get(principal);
+ if (perms == null)
+ return false;
+ return perms.contains(permission);
+ }
+
+ @Override
+ public void grantSystemPermission(String principal, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ user.permissions.add(permission);
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public void grantTablePermission(String principal, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
+ if (acu.users.get(principal) == null)
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ MockTable table = acu.tables.get(tableName);
+ if (table == null)
+ throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
+ EnumSet<TablePermission> perms = table.userPermissions.get(principal);
+ if (perms == null)
+ table.userPermissions.put(principal, EnumSet.of(permission));
+ else
+ perms.add(permission);
+ }
+
+ @Override
+ public void grantNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
+ if (acu.users.get(principal) == null)
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ MockNamespace mockNamespace = acu.namespaces.get(namespace);
+ if (mockNamespace == null)
+ throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
+ EnumSet<NamespacePermission> perms = mockNamespace.userPermissions.get(principal);
+ if (perms == null)
+ mockNamespace.userPermissions.put(principal, EnumSet.of(permission));
+ else
+ perms.add(permission);
+ }
+
+ @Override
+ public void revokeSystemPermission(String principal, SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
+ MockUser user = acu.users.get(principal);
+ if (user != null)
+ user.permissions.remove(permission);
+ else
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ }
+
+ @Override
+ public void revokeTablePermission(String principal, String tableName, TablePermission permission) throws AccumuloException, AccumuloSecurityException {
+ if (acu.users.get(principal) == null)
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ MockTable table = acu.tables.get(tableName);
+ if (table == null)
+ throw new AccumuloSecurityException(tableName, SecurityErrorCode.TABLE_DOESNT_EXIST);
+ EnumSet<TablePermission> perms = table.userPermissions.get(principal);
+ if (perms != null)
+ perms.remove(permission);
+
+ }
+
+ @Override
+ public void revokeNamespacePermission(String principal, String namespace, NamespacePermission permission) throws AccumuloException, AccumuloSecurityException {
+ if (acu.users.get(principal) == null)
+ throw new AccumuloSecurityException(principal, SecurityErrorCode.USER_DOESNT_EXIST);
+ MockNamespace mockNamespace = acu.namespaces.get(namespace);
+ if (mockNamespace == null)
+ throw new AccumuloSecurityException(namespace, SecurityErrorCode.NAMESPACE_DOESNT_EXIST);
+ EnumSet<NamespacePermission> perms = mockNamespace.userPermissions.get(principal);
+ if (perms != null)
+ perms.remove(permission);
+
+ }
+
+ @Deprecated
+ @Override
+ public Set<String> listUsers() throws AccumuloException, AccumuloSecurityException {
+ return listLocalUsers();
+ }
+
+ @Override
+ public Set<String> listLocalUsers() throws AccumuloException, AccumuloSecurityException {
+ return acu.users.keySet();
+ }
+
+ @Override
+ public DelegationToken getDelegationToken(DelegationTokenConfig cfg) throws AccumuloException, AccumuloSecurityException {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/4f2e6472/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
new file mode 100644
index 0000000..6a8bd2f
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
@@ -0,0 +1,212 @@
+/*
+ * 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.client.mock;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.ColumnUpdate;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.IteratorUtil;
+import org.apache.accumulo.core.security.TablePermission;
+import org.apache.hadoop.io.Text;
+
+/**
+ * @deprecated since 1.8.0; use MiniAccumuloCluster or a standard mock framework instead.
+ */
+@Deprecated
+public class MockTable {
+
+ static class MockMemKey extends Key {
+ private int count;
+
+ MockMemKey(Key key, int count) {
+ super(key);
+ this.count = count;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() + count;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ return (other instanceof MockMemKey) && super.equals(other) && count == ((MockMemKey) other).count;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + " count=" + count;
+ }
+
+ @Override
+ public int compareTo(Key o) {
+ int compare = super.compareTo(o);
+ if (compare != 0)
+ return compare;
+ if (o instanceof MockMemKey) {
+ MockMemKey other = (MockMemKey) o;
+ if (count < other.count)
+ return 1;
+ if (count > other.count)
+ return -1;
+ } else {
+ return 1;
+ }
+ return 0;
+ }
+ };
+
+ final SortedMap<Key,Value> table = new ConcurrentSkipListMap<>();
+ int mutationCount = 0;
+ final Map<String,String> settings;
+ Map<String,EnumSet<TablePermission>> userPermissions = new HashMap<>();
+ private TimeType timeType;
+ SortedSet<Text> splits = new ConcurrentSkipListSet<>();
+ Map<String,Set<Text>> localityGroups = new TreeMap<>();
+ private MockNamespace namespace;
+ private String namespaceName;
+ private String tableId;
+
+ MockTable(boolean limitVersion, TimeType timeType, String tableId) {
+ this.timeType = timeType;
+ this.tableId = tableId;
+ settings = IteratorUtil.generateInitialTableProperties(limitVersion);
+ for (Entry<String,String> entry : AccumuloConfiguration.getDefaultConfiguration()) {
+ String key = entry.getKey();
+ if (key.startsWith(Property.TABLE_PREFIX.getKey()))
+ settings.put(key, entry.getValue());
+ }
+ }
+
+ MockTable(MockNamespace namespace, boolean limitVersion, TimeType timeType, String tableId, Map<String,String> properties) {
+ this(limitVersion, timeType, tableId);
+ Set<Entry<String,String>> set = namespace.settings.entrySet();
+ Iterator<Entry<String,String>> entries = set.iterator();
+ while (entries.hasNext()) {
+ Entry<String,String> entry = entries.next();
+ String key = entry.getKey();
+ if (key.startsWith(Property.TABLE_PREFIX.getKey()))
+ settings.put(key, entry.getValue());
+ }
+
+ for (Entry<String,String> initialProp : properties.entrySet()) {
+ settings.put(initialProp.getKey(), initialProp.getValue());
+ }
+ }
+
+ public MockTable(MockNamespace namespace, TimeType timeType, String tableId, Map<String,String> properties) {
+ this.timeType = timeType;
+ this.tableId = tableId;
+ settings = properties;
+ for (Entry<String,String> entry : AccumuloConfiguration.getDefaultConfiguration()) {
+ String key = entry.getKey();
+ if (key.startsWith(Property.TABLE_PREFIX.getKey()))
+ settings.put(key, entry.getValue());
+ }
+
+ Set<Entry<String,String>> set = namespace.settings.entrySet();
+ Iterator<Entry<String,String>> entries = set.iterator();
+ while (entries.hasNext()) {
+ Entry<String,String> entry = entries.next();
+ String key = entry.getKey();
+ if (key.startsWith(Property.TABLE_PREFIX.getKey()))
+ settings.put(key, entry.getValue());
+ }
+ }
+
+ synchronized void addMutation(Mutation m) {
+ if (m.size() == 0)
+ throw new IllegalArgumentException("Can not add empty mutations");
+ long now = System.currentTimeMillis();
+ mutationCount++;
+ for (ColumnUpdate u : m.getUpdates()) {
+ Key key = new Key(m.getRow(), 0, m.getRow().length, u.getColumnFamily(), 0, u.getColumnFamily().length, u.getColumnQualifier(), 0,
+ u.getColumnQualifier().length, u.getColumnVisibility(), 0, u.getColumnVisibility().length, u.getTimestamp());
+ if (u.isDeleted())
+ key.setDeleted(true);
+ if (!u.hasTimestamp())
+ if (timeType.equals(TimeType.LOGICAL))
+ key.setTimestamp(mutationCount);
+ else
+ key.setTimestamp(now);
+
+ table.put(new MockMemKey(key, mutationCount), new Value(u.getValue()));
+ }
+ }
+
+ public void addSplits(SortedSet<Text> partitionKeys) {
+ splits.addAll(partitionKeys);
+ }
+
+ public Collection<Text> getSplits() {
+ return splits;
+ }
+
+ public void setLocalityGroups(Map<String,Set<Text>> groups) {
+ localityGroups = groups;
+ }
+
+ public Map<String,Set<Text>> getLocalityGroups() {
+ return localityGroups;
+ }
+
+ public void merge(Text start, Text end) {
+ boolean reAdd = false;
+ if (splits.contains(start))
+ reAdd = true;
+ splits.removeAll(splits.subSet(start, end));
+ if (reAdd)
+ splits.add(start);
+ }
+
+ public void setNamespaceName(String n) {
+ this.namespaceName = n;
+ }
+
+ public void setNamespace(MockNamespace n) {
+ this.namespace = n;
+ }
+
+ public String getNamespaceName() {
+ return this.namespaceName;
+ }
+
+ public MockNamespace getNamespace() {
+ return this.namespace;
+ }
+
+ public String getTableId() {
+ return this.tableId;
+ }
+}