You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by bu...@apache.org on 2014/04/26 01:12:43 UTC
[14/17] ACCUMULO-2726 cleanup for master's branch.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/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 cd49986..166abc8 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
@@ -16,10 +16,13 @@
*/
package org.apache.accumulo.core.client.impl;
+import static com.google.common.base.Preconditions.checkArgument;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -61,8 +64,8 @@ import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.TableOfflineException;
import org.apache.accumulo.core.client.admin.DiskUsage;
import org.apache.accumulo.core.client.admin.FindMax;
-import org.apache.accumulo.core.client.admin.TableOperations;
import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.client.admin.TableOperations;
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;
@@ -92,7 +95,6 @@ import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException;
import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
-import org.apache.accumulo.core.util.ArgumentChecker;
import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.accumulo.core.util.CachedConfiguration;
import org.apache.accumulo.core.util.LocalityGroupUtil;
@@ -100,7 +102,6 @@ import org.apache.accumulo.core.util.MapCounter;
import org.apache.accumulo.core.util.NamingThreadFactory;
import org.apache.accumulo.core.util.OpTimer;
import org.apache.accumulo.core.util.Pair;
-import org.apache.accumulo.core.util.StringUtil;
import org.apache.accumulo.core.util.TextUtil;
import org.apache.accumulo.core.util.ThriftUtil;
import org.apache.accumulo.core.util.UtilWaitThread;
@@ -116,6 +117,8 @@ import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
+import com.google.common.base.Joiner;
+
public class TableOperationsImpl extends TableOperationsHelper {
private Instance instance;
private Credentials credentials;
@@ -131,7 +134,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
* the username/password for this connection
*/
public TableOperationsImpl(Instance instance, Credentials credentials) {
- ArgumentChecker.notNull(instance, credentials);
+ checkArgument(instance != null, "instance is null");
+ checkArgument(credentials != null, "credentials is null");
this.instance = instance;
this.credentials = credentials;
}
@@ -158,7 +162,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public boolean exists(String tableName) {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
if (tableName.equals(MetadataTable.NAME) || tableName.equals(RootTable.NAME))
return true;
@@ -206,9 +210,10 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void create(String tableName, boolean limitVersion, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
- ArgumentChecker.notNull(tableName, timeType);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(timeType != null, "timeType is null");
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), ByteBuffer.wrap(timeType.name().getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(timeType.name().getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts;
if (limitVersion)
@@ -522,9 +527,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void merge(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
ByteBuffer EMPTY = ByteBuffer.allocate(0);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
end == null ? EMPTY : TextUtil.getByteBuffer(end));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -538,9 +543,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
ByteBuffer EMPTY = ByteBuffer.allocate(0);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
end == null ? EMPTY : TextUtil.getByteBuffer(end));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -559,7 +564,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public Collection<Text> listSplits(String tableName) throws TableNotFoundException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
String tableId = Tables.getTableId(instance, tableName);
@@ -662,9 +667,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void delete(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -680,7 +685,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
public void clone(String srcTableName, String newTableName, boolean flush, Map<String,String> propertiesToSet, Set<String> propertiesToExclude)
throws AccumuloSecurityException, TableNotFoundException, AccumuloException, TableExistsException {
- ArgumentChecker.notNull(srcTableName, newTableName);
+ checkArgument(srcTableName != null, "srcTableName is null");
+ checkArgument(newTableName != null, "newTableName is null");
String srcTableId = Tables.getTableId(instance, srcTableName);
@@ -693,7 +699,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
if (propertiesToSet == null)
propertiesToSet = Collections.emptyMap();
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(srcTableId.getBytes(Constants.UTF8)), ByteBuffer.wrap(newTableName.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(srcTableId.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(newTableName.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
for (Entry<String,String> entry : propertiesToSet.entrySet()) {
if (entry.getKey().startsWith(CLONE_EXCLUDE_PREFIX))
@@ -728,7 +734,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
public void rename(String oldTableName, String newTableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException,
TableExistsException {
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(oldTableName.getBytes(Constants.UTF8)), ByteBuffer.wrap(newTableName.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(oldTableName.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(newTableName.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
doTableFateOperation(oldTableName, TableNotFoundException.class, FateOperation.TABLE_RENAME, args, opts);
}
@@ -758,7 +764,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void flush(String tableName, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
String tableId = Tables.getTableId(instance, tableName);
_flush(tableId, start, end, wait);
@@ -773,7 +779,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void compact(String tableName, Text start, Text end, List<IteratorSetting> iterators, boolean flush, boolean wait) throws AccumuloSecurityException,
TableNotFoundException, AccumuloException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
ByteBuffer EMPTY = ByteBuffer.allocate(0);
String tableId = Tables.getTableId(instance, tableName);
@@ -781,7 +787,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
if (flush)
_flush(tableId, start, end, true);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(Constants.UTF8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(StandardCharsets.UTF_8)), start == null ? EMPTY : TextUtil.getByteBuffer(start),
end == null ? EMPTY : TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(iterators)));
Map<String,String> opts = new HashMap<String,String>();
@@ -802,7 +808,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
public void cancelCompaction(String tableName) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
String tableId = Tables.getTableId(instance, tableName);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -886,7 +892,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void setProperty(final String tableName, final String property, final String value) throws AccumuloException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, property, value);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(property != null, "property is null");
+ checkArgument(value != null, "value is null");
try {
MasterClient.executeTable(instance, new ClientExec<MasterClientService.Client>() {
@Override
@@ -913,7 +921,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void removeProperty(final String tableName, final String property) throws AccumuloException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, property);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(property != null, "property is null");
try {
MasterClient.executeTable(instance, new ClientExec<MasterClientService.Client>() {
@Override
@@ -937,7 +946,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public Iterable<Entry<String,String>> getProperties(final String tableName) throws AccumuloException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
try {
return ServerClient.executeRaw(instance, new ClientExecReturn<Map<String,String>,ClientService.Client>() {
@Override
@@ -996,7 +1005,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
}
try {
- setProperty(tableName, Property.TABLE_LOCALITY_GROUPS.getKey(), StringUtil.join(groups.keySet(), ","));
+ setProperty(tableName, Property.TABLE_LOCALITY_GROUPS.getKey(), Joiner.on(",").join(groups.keySet()));
} catch (AccumuloException e) {
if (e.getCause() instanceof TableNotFoundException)
throw (TableNotFoundException) e.getCause();
@@ -1070,7 +1079,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public Set<Range> splitRangeByTablets(String tableName, Range range, int maxSplits) throws AccumuloException, AccumuloSecurityException,
TableNotFoundException {
- ArgumentChecker.notNull(tableName, range);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(range != null, "range is null");
if (maxSplits < 1)
throw new IllegalArgumentException("maximum splits must be >= 1");
if (maxSplits == 1)
@@ -1161,15 +1171,17 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloSecurityException,
TableNotFoundException, AccumuloException {
- ArgumentChecker.notNull(tableName, dir, failureDir);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(dir != null, "dir is null");
+ checkArgument(failureDir != null, "failureDir is null");
// check for table existance
Tables.getTableId(instance, tableName);
Path dirPath = checkPath(dir, "Bulk", "");
Path failPath = checkPath(failureDir, "Bulk", "failure");
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), ByteBuffer.wrap(dirPath.toString().getBytes(Constants.UTF8)),
- ByteBuffer.wrap(failPath.toString().getBytes(Constants.UTF8)), ByteBuffer.wrap((setTime + "").getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(dirPath.toString().getBytes(StandardCharsets.UTF_8)),
+ ByteBuffer.wrap(failPath.toString().getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap((setTime + "").getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -1314,9 +1326,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void offline(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
String tableId = Tables.getTableId(instance, tableName);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -1346,9 +1358,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void online(String tableName, boolean wait) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
String tableId = Tables.getTableId(instance, tableName);
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = new HashMap<String,String>();
try {
@@ -1372,7 +1384,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
*/
@Override
public void clearLocatorCache(String tableName) throws TableNotFoundException {
- ArgumentChecker.notNull(tableName);
+ checkArgument(tableName != null, "tableName is null");
TabletLocator tabLocator = TabletLocator.getLocator(instance, new Text(Tables.getTableId(instance, tableName)));
tabLocator.invalidateCache();
}
@@ -1390,7 +1402,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public Text getMaxRow(String tableName, Authorizations auths, Text startRow, boolean startInclusive, Text endRow, boolean endInclusive)
throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, auths);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(auths != null, "auths is null");
Scanner scanner = instance.getConnector(credentials.getPrincipal(), credentials.getToken()).createScanner(tableName, auths);
return FindMax.findMax(scanner, startRow, startInclusive, endRow, endInclusive);
}
@@ -1447,7 +1460,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
ZipEntry zipEntry;
while ((zipEntry = zis.getNextEntry()) != null) {
if (zipEntry.getName().equals(Constants.EXPORT_TABLE_CONFIG_FILE)) {
- BufferedReader in = new BufferedReader(new InputStreamReader(zis, Constants.UTF8));
+ BufferedReader in = new BufferedReader(new InputStreamReader(zis, StandardCharsets.UTF_8));
try {
String line;
while ((line = in.readLine()) != null) {
@@ -1469,7 +1482,8 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void importTable(String tableName, String importDir) throws TableExistsException, AccumuloException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, importDir);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(importDir != null, "importDir is null");
try {
importDir = checkPath(importDir, "Table", "").toString();
@@ -1492,7 +1506,7 @@ public class TableOperationsImpl extends TableOperationsHelper {
Logger.getLogger(this.getClass()).warn("Failed to check if imported table references external java classes : " + ioe.getMessage());
}
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), ByteBuffer.wrap(importDir.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(importDir.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = Collections.emptyMap();
@@ -1507,9 +1521,10 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public void exportTable(String tableName, String exportDir) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, exportDir);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(exportDir != null, "exportDir is null");
- List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(Constants.UTF8)), ByteBuffer.wrap(exportDir.getBytes(Constants.UTF8)));
+ List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(exportDir.getBytes(StandardCharsets.UTF_8)));
Map<String,String> opts = Collections.emptyMap();
@@ -1524,7 +1539,9 @@ public class TableOperationsImpl extends TableOperationsHelper {
@Override
public boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException,
AccumuloSecurityException {
- ArgumentChecker.notNull(tableName, className, asTypeName);
+ checkArgument(tableName != null, "tableName is null");
+ checkArgument(className != null, "className is null");
+ checkArgument(asTypeName != null, "asTypeName is null");
try {
return ServerClient.executeRaw(instance, new ClientExecReturn<Boolean,ClientService.Client>() {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/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
index 6cd6f2c..996198c 100644
--- 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
@@ -124,17 +124,17 @@ public class MockConnector extends Connector {
@Override
public TableOperations tableOperations() {
- return new MockTableOperationsImpl(acu, username);
+ return new MockTableOperations(acu, username);
}
@Override
public SecurityOperations securityOperations() {
- return new MockSecurityOperationsImpl(acu);
+ return new MockSecurityOperations(acu);
}
@Override
public InstanceOperations instanceOperations() {
- return new MockInstanceOperationsImpl(acu);
+ return new MockInstanceOperations(acu);
}
@Override
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/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
index 58eff24..89bf39c 100644
--- 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
@@ -16,13 +16,72 @@
*/
package org.apache.accumulo.core.client.mock;
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class MockInstanceOperations extends MockInstanceOperationsImpl {
-
+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;
+
+class MockInstanceOperations implements InstanceOperations {
+ MockAccumulo acu;
+
public MockInstanceOperations(MockAccumulo acu) {
- super(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<String>();
+ }
+
+ @Override
+ public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException {
+ return new ArrayList<ActiveScan>();
+ }
+
+ @Override
+ public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException {
+ try {
+ AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException {
+ return new ArrayList<ActiveCompaction>();
+ }
+
+ @Override
+ public void ping(String tserver) throws AccumuloException {
+
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperationsImpl.java
deleted file mode 100644
index 1bec226..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperationsImpl.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.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;
-
-class MockInstanceOperationsImpl implements InstanceOperations {
- MockAccumulo acu;
-
- public MockInstanceOperationsImpl(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<String>();
- }
-
- @Override
- public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException {
- return new ArrayList<ActiveScan>();
- }
-
- @Override
- public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException {
- try {
- AccumuloVFSClassLoader.loadClass(className, Class.forName(asTypeName));
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
-
- @Override
- public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException {
- return new ArrayList<ActiveCompaction>();
- }
-
- @Override
- public void ping(String tserver) throws AccumuloException {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/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
index 6271059..db88cfb 100644
--- 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
@@ -16,13 +16,210 @@
*/
package org.apache.accumulo.core.client.mock;
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class MockSecurityOperations extends MockSecurityOperationsImpl {
+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.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.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;
+
+class MockSecurityOperations implements SecurityOperations {
+
+ final private MockAccumulo acu;
MockSecurityOperations(MockAccumulo acu) {
- super(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();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java
deleted file mode 100644
index f97069a..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockSecurityOperationsImpl.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.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.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.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;
-
-class MockSecurityOperationsImpl implements SecurityOperations {
-
- final private MockAccumulo acu;
-
- MockSecurityOperationsImpl(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();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/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
index ee8880c..f1e1914 100644
--- 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
@@ -16,13 +16,432 @@
*/
package org.apache.accumulo.core.client.mock;
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class MockTableOperations extends MockTableOperationsImpl {
+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.DiskUsage;
+import org.apache.accumulo.core.client.admin.FindMax;
+import org.apache.accumulo.core.client.impl.TableOperationsHelper;
+import org.apache.accumulo.core.client.admin.TimeType;
+import org.apache.accumulo.core.client.impl.Tables;
+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;
+
+class MockTableOperations extends TableOperationsHelper {
+ private static final byte[] ZERO = {0};
+ private final MockAccumulo acu;
+ private final String username;
MockTableOperations(MockAccumulo acu, String username) {
- super(acu,username);
+ this.acu = acu;
+ this.username = username;
+ }
+
+ @Override
+ public SortedSet<String> list() {
+ return new TreeSet<String>(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, true, TimeType.MILLIS);
+ }
+
+ @Override
+ public void create(String tableName, boolean versioningIter) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ create(tableName, versioningIter, TimeType.MILLIS);
+ }
+
+ @Override
+ public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
+ String namespace = Tables.qualify(tableName).getFirst();
+ if (!tableName.matches(Tables.VALID_NAME_REGEX)) {
+ throw new IllegalArgumentException();
+ }
+ if (exists(tableName))
+ throw new TableExistsException(tableName, tableName, "");
+
+ if (!namespaceExists(namespace)) {
+ throw new IllegalArgumentException("Namespace (" + namespace + ") does not exist, create it first");
+ }
+ acu.createTable(username, tableName, versioningIter, timeType);
+ }
+
+ @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<Entry<String,String>>(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().openReader(importStatus.getPath().toString(), true, fs, fs.getConf(),
+ AccumuloConfiguration.getDefaultConfiguration());
+ 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<String,String>();
+ for (String table : acu.tables.keySet()) {
+ 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, table);
+ }
+ return result;
+ }
+
+ @Override
+ public List<DiskUsage> getDiskUsage(Set<String> tables) throws AccumuloException, AccumuloSecurityException {
+
+ List<DiskUsage> diskUsages = new ArrayList<DiskUsage>();
+ diskUsages.add(new DiskUsage(new TreeSet<String>(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 = new Text(start);
+ Text endText = new Text(end);
+ startText.append(ZERO, 0, 1);
+ endText.append(ZERO, 0, 1);
+ Set<Key> keep = new TreeSet<Key>(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, "");
+ }
+
+ @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) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java
deleted file mode 100644
index fea9568..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperationsImpl.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.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.DiskUsage;
-import org.apache.accumulo.core.client.admin.FindMax;
-import org.apache.accumulo.core.client.impl.TableOperationsHelper;
-import org.apache.accumulo.core.client.admin.TimeType;
-import org.apache.accumulo.core.client.impl.Tables;
-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;
-
-class MockTableOperationsImpl extends TableOperationsHelper {
- private static final byte[] ZERO = {0};
- private final MockAccumulo acu;
- private final String username;
-
- MockTableOperationsImpl(MockAccumulo acu, String username) {
- this.acu = acu;
- this.username = username;
- }
-
- @Override
- public SortedSet<String> list() {
- return new TreeSet<String>(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, true, TimeType.MILLIS);
- }
-
- @Override
- public void create(String tableName, boolean versioningIter) throws AccumuloException, AccumuloSecurityException, TableExistsException {
- create(tableName, versioningIter, TimeType.MILLIS);
- }
-
- @Override
- public void create(String tableName, boolean versioningIter, TimeType timeType) throws AccumuloException, AccumuloSecurityException, TableExistsException {
- String namespace = Tables.qualify(tableName).getFirst();
- if (!tableName.matches(Tables.VALID_NAME_REGEX)) {
- throw new IllegalArgumentException();
- }
- if (exists(tableName))
- throw new TableExistsException(tableName, tableName, "");
-
- if (!namespaceExists(namespace)) {
- throw new IllegalArgumentException("Namespace (" + namespace + ") does not exist, create it first");
- }
- acu.createTable(username, tableName, versioningIter, timeType);
- }
-
- @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<Entry<String,String>>(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().openReader(importStatus.getPath().toString(), true, fs, fs.getConf(),
- AccumuloConfiguration.getDefaultConfiguration());
- 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<String,String>();
- for (String table : acu.tables.keySet()) {
- 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, table);
- }
- return result;
- }
-
- @Override
- public List<DiskUsage> getDiskUsage(Set<String> tables) throws AccumuloException, AccumuloSecurityException {
-
- List<DiskUsage> diskUsages = new ArrayList<DiskUsage>();
- diskUsages.add(new DiskUsage(new TreeSet<String>(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 = new Text(start);
- Text endText = new Text(end);
- startText.append(ZERO, 0, 1);
- endText.append(ZERO, 0, 1);
- Set<Key> keep = new TreeSet<Key>(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, "");
- }
-
- @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) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
deleted file mode 100644
index ac6a6e9..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTabletLocator.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.client.mock;
-
-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.TableNotFoundException;
-import org.apache.accumulo.core.data.KeyExtent;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.Range;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.core.security.thrift.TCredentials;
-import org.apache.hadoop.io.Text;
-
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class MockTabletLocator extends org.apache.accumulo.core.client.mock.impl.MockTabletLocator {
- public MockTabletLocator() {}
-
- public TabletLocation locateTablet(Text row, boolean skipRow, boolean retry, TCredentials credentials) throws AccumuloException, AccumuloSecurityException,
- TableNotFoundException {
- return locateTablet(Credentials.fromThrift(credentials), row, skipRow, retry);
- }
-
- public <T extends Mutation> void binMutations(List<T> mutations, Map<String,TabletServerMutations<T>> binnedMutations, List<T> failures, TCredentials credentials)
- throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- binMutations(Credentials.fromThrift(credentials), mutations, binnedMutations, failures);
- }
-
- public List<Range> binRanges(List<Range> ranges, Map<String,Map<KeyExtent,List<Range>>> binnedRanges, TCredentials credentials) throws AccumuloException,
- AccumuloSecurityException, TableNotFoundException {
- return binRanges(Credentials.fromThrift(credentials), ranges, binnedRanges);
- }
-}