@Override
public Collection getSplits(String tableName, int maxSplits) throws TableNotFoundException {
public class MockTableOperations extends MockTableOperationsImpl {
MockTableOperations(MockAccumulo acu, String username) {
<<<<<<< HEAD
super(acu,username);
=======
this.acu = acu;
this.username = username;
}
@Override
public SortedSet list() {
return new TreeSet(acu.tables.keySet());
}
@Override
public boolean exists(String tableName) {
return acu.tables.containsKey(tableName);
}
@Override
public void create(String tableName) throws AccumuloException, AccumuloSecurityException, TableExistsException {
if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
throw new IllegalArgumentException();
}
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 {
if (!tableName.matches(Constants.VALID_TABLE_NAME_REGEX)) {
throw new IllegalArgumentException();
}
if (exists(tableName))
throw new TableExistsException(tableName, tableName, "");
acu.createTable(username, tableName, versioningIter, timeType);
}
@Override
AccumuloSecurityException, TableNotFoundException {
public void addSplits(String tableName, SortedSet partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.addSplits(tableName, partitionKeys);
}
@Deprecated
@Override
public Collection getSplits(String tableName) throws TableNotFoundException {
return listSplits(tableName);
}
@Deprecated
long time = System.currentTimeMillis();
return listSplits(tableName);
}
@Override
public Collection listSplits(String tableName) throws TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
return acu.getSplits(tableName);
}
@Override
public Collection 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);
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> getProperties(String tableName) throws TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
return acu.tables.get(tableName).settings.entrySet();
}
@Override
public void setLocalityGroups(String tableName, Map> groups) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
acu.tables.get(tableName).setLocalityGroups(groups);
}
@Override
public Map> getLocalityGroups(String tableName) throws AccumuloException, TableNotFoundException {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
return acu.tables.get(tableName).getLocalityGroups();
}
@Override
public Set 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,
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)) {
@Override
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 {
if (!exists(tableName))
throw new TableNotFoundException(tableName, tableName, "");
}
@Override
public void online(String tableName) 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 tableIdMap() {
Map result = new HashMap();
for (Entry entry : acu.tables.entrySet()) {
result.put(entry.getKey(), entry.getValue().getTableId());
}
return result;
}
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();
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 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 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 propertiesToSet, Set 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;
>>>>>>> 9fcca2ede18a7b96bee4edb5ab105316ac383604
}
} |