use of org.apache.accumulo.core.client.NamespaceExistsException in project accumulo by apache.
the class MockNamespaceOperations method rename.
@Override
public void rename(String oldNamespaceName, String newNamespaceName) throws AccumuloSecurityException, NamespaceNotFoundException, AccumuloException, NamespaceExistsException {
if (!exists(oldNamespaceName))
throw new NamespaceNotFoundException(oldNamespaceName, oldNamespaceName, "");
if (exists(newNamespaceName))
throw new NamespaceExistsException(newNamespaceName, newNamespaceName, "");
MockNamespace n = acu.namespaces.get(oldNamespaceName);
for (String t : n.getTables(acu)) {
String tt = newNamespaceName + "." + Tables.qualify(t).getSecond();
acu.tables.put(tt, acu.tables.remove(t));
}
acu.namespaces.put(newNamespaceName, acu.namespaces.remove(oldNamespaceName));
}
use of org.apache.accumulo.core.client.NamespaceExistsException in project accumulo by apache.
the class TableOperationsImpl method compact.
@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
checkArgument(tableName != null, "tableName is null");
ByteBuffer EMPTY = ByteBuffer.allocate(0);
// Ensure compaction iterators exist on a tabletserver
final String skviName = SortedKeyValueIterator.class.getName();
for (IteratorSetting setting : config.getIterators()) {
String iteratorClass = setting.getIteratorClass();
if (!testClassLoad(tableName, iteratorClass, skviName)) {
throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
}
}
// Make sure the specified compaction strategy exists on a tabletserver
final String compactionStrategyName = config.getCompactionStrategy().getClassName();
if (!CompactionStrategyConfigUtil.DEFAULT_STRATEGY.getClassName().equals(compactionStrategyName)) {
if (!testClassLoad(tableName, compactionStrategyName, "org.apache.accumulo.tserver.compaction.CompactionStrategy")) {
throw new AccumuloException("TabletServer could not load CompactionStrategy class " + compactionStrategyName);
}
}
Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
Text start = config.getStartRow();
Text end = config.getEndRow();
if (config.getFlush())
_flush(tableId, start, end, true);
List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.getUtf8()), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end), ByteBuffer.wrap(IteratorUtil.encodeIteratorSettings(config.getIterators())), ByteBuffer.wrap(CompactionStrategyConfigUtil.encode(config.getCompactionStrategy())));
Map<String, String> opts = new HashMap<>();
try {
doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
} catch (TableExistsException | NamespaceExistsException e) {
// should not happen
throw new AssertionError(e);
} catch (NamespaceNotFoundException e) {
throw new TableNotFoundException(null, tableName, "Namespace not found", e);
}
}
use of org.apache.accumulo.core.client.NamespaceExistsException in project accumulo by apache.
the class TableOperationsImpl method doFateOperation.
String doFateOperation(FateOperation op, List<ByteBuffer> args, Map<String, String> opts, String tableOrNamespaceName, boolean wait) throws AccumuloSecurityException, TableExistsException, TableNotFoundException, AccumuloException, NamespaceExistsException, NamespaceNotFoundException {
Long opid = null;
try {
opid = beginFateOperation();
executeFateOperation(opid, op, args, opts, !wait);
if (!wait) {
opid = null;
return null;
}
String ret = waitForFateOperation(opid);
return ret;
} catch (ThriftSecurityException e) {
switch(e.getCode()) {
case TABLE_DOESNT_EXIST:
throw new TableNotFoundException(null, tableOrNamespaceName, "Target table does not exist");
case NAMESPACE_DOESNT_EXIST:
throw new NamespaceNotFoundException(null, tableOrNamespaceName, "Target namespace does not exist");
default:
String tableInfo = Tables.getPrintableTableInfoFromName(context.getInstance(), tableOrNamespaceName);
throw new AccumuloSecurityException(e.user, e.code, tableInfo, e);
}
} catch (ThriftTableOperationException e) {
switch(e.getType()) {
case EXISTS:
throw new TableExistsException(e);
case NOTFOUND:
throw new TableNotFoundException(e);
case NAMESPACE_EXISTS:
throw new NamespaceExistsException(e);
case NAMESPACE_NOTFOUND:
throw new NamespaceNotFoundException(e);
case OFFLINE:
throw new TableOfflineException(context.getInstance(), Tables.getTableId(context.getInstance(), tableOrNamespaceName).canonicalID());
default:
throw new AccumuloException(e.description, e);
}
} catch (Exception e) {
throw new AccumuloException(e.getMessage(), e);
} finally {
Tables.clearCache(context.getInstance());
// always finish table op, even when exception
if (opid != null)
try {
finishFateOperation(opid);
} catch (Exception e) {
log.warn("Exception thrown while finishing fate table operation", e);
}
}
}
use of org.apache.accumulo.core.client.NamespaceExistsException in project accumulo by apache.
the class NamespacesIT method verifyNamespaceOperationsExceptions.
@Test
public void verifyNamespaceOperationsExceptions() throws Exception {
IteratorSetting setting = new IteratorSetting(200, VersioningIterator.class);
NamespaceOperations ops = c.namespaceOperations();
// this one doesn't throw an exception, so don't fail; just check that it works
assertFalse(ops.exists(namespace));
// namespace operations that should throw a NamespaceNotFoundException
int numRun = 0;
NAMESPACENOTFOUND: for (int i = 0; ; ++i) try {
switch(i) {
case 0:
ops.addConstraint(namespace, NumericValueConstraint.class.getName());
fail();
break;
case 1:
ops.attachIterator(namespace, setting);
fail();
break;
case 2:
ops.checkIteratorConflicts(namespace, setting, EnumSet.of(IteratorScope.scan));
fail();
break;
case 3:
ops.delete(namespace);
fail();
break;
case 4:
ops.getIteratorSetting(namespace, "thing", IteratorScope.scan);
fail();
break;
case 5:
ops.getProperties(namespace);
fail();
break;
case 6:
ops.listConstraints(namespace);
fail();
break;
case 7:
ops.listIterators(namespace);
fail();
break;
case 8:
ops.removeConstraint(namespace, 1);
fail();
break;
case 9:
ops.removeIterator(namespace, "thing", EnumSet.allOf(IteratorScope.class));
fail();
break;
case 10:
ops.removeProperty(namespace, "a");
fail();
break;
case 11:
ops.rename(namespace, namespace + "2");
fail();
break;
case 12:
ops.setProperty(namespace, "k", "v");
fail();
break;
case 13:
ops.testClassLoad(namespace, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
fail();
break;
default:
// break out of infinite loop
// check test integrity
assertEquals(14, i);
// check test integrity
assertEquals(14, numRun);
break NAMESPACENOTFOUND;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
// namespace operations that should throw a NamespaceExistsException
numRun = 0;
NAMESPACEEXISTS: for (int i = 0; ; ++i) try {
switch(i) {
case 0:
ops.create(namespace + "0");
// should fail here
ops.create(namespace + "0");
fail();
break;
case 1:
ops.create(namespace + i + "_1");
ops.create(namespace + i + "_2");
// should fail here
ops.rename(namespace + i + "_1", namespace + i + "_2");
fail();
break;
case 2:
ops.create(Namespace.DEFAULT);
fail();
break;
case 3:
ops.create(Namespace.ACCUMULO);
fail();
break;
case 4:
ops.create(namespace + i + "_1");
// should fail here
ops.rename(namespace + i + "_1", Namespace.DEFAULT);
fail();
break;
case 5:
ops.create(namespace + i + "_1");
// should fail here
ops.rename(namespace + i + "_1", Namespace.ACCUMULO);
fail();
break;
default:
// break out of infinite loop
// check test integrity
assertEquals(6, i);
// check test integrity
assertEquals(6, numRun);
break NAMESPACEEXISTS;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof NamespaceExistsException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
}
Aggregations