use of org.apache.accumulo.core.client.NamespaceNotFoundException 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.NamespaceNotFoundException in project accumulo by apache.
the class NamespaceOperationsHelper method checkIteratorConflicts.
@Override
public void checkIteratorConflicts(String namespace, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException {
if (!exists(namespace))
throw new NamespaceNotFoundException(null, namespace, null);
for (IteratorScope scope : scopes) {
String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
String nameStr = String.format("%s.%s", scopeStr, setting.getName());
String optStr = String.format("%s.opt.", nameStr);
Map<String, String> optionConflicts = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(namespace)) {
if (property.getKey().startsWith(scopeStr)) {
if (property.getKey().equals(nameStr))
throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "=" + property.getValue()));
if (property.getKey().startsWith(optStr))
optionConflicts.put(property.getKey(), property.getValue());
if (property.getKey().contains(".opt."))
continue;
String[] parts = property.getValue().split(",");
if (parts.length != 2)
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
try {
if (Integer.parseInt(parts[0]) == setting.getPriority())
throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
} catch (NumberFormatException e) {
throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
}
}
}
if (optionConflicts.size() > 0)
throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
}
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class NamespaceOperationsHelper method listIterators.
@Override
public Map<String, EnumSet<IteratorScope>> listIterators(String namespace) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
if (!exists(namespace))
throw new NamespaceNotFoundException(null, namespace, null);
Map<String, EnumSet<IteratorScope>> result = new TreeMap<>();
for (Entry<String, String> property : this.getProperties(namespace)) {
String name = property.getKey();
String[] parts = name.split("\\.");
if (parts.length == 4) {
if (parts[0].equals("table") && parts[1].equals("iterator")) {
IteratorScope scope = IteratorScope.valueOf(parts[2]);
if (!result.containsKey(parts[3]))
result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
result.get(parts[3]).add(scope);
}
}
}
return result;
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class MasterClient method executeGeneric.
public static void executeGeneric(ClientContext context, ClientExec<MasterClientService.Client> exec) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
MasterClientService.Client client = null;
while (true) {
try {
client = getConnectionWithRetry(context);
exec.execute(client);
break;
} catch (TTransportException tte) {
log.debug("MasterClient request failed, retrying ... ", tte);
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} catch (ThriftSecurityException e) {
throw new AccumuloSecurityException(e.user, e.code, e);
} catch (AccumuloException e) {
throw e;
} catch (ThriftTableOperationException e) {
switch(e.getType()) {
case NAMESPACE_NOTFOUND:
throw new TableNotFoundException(e.getTableName(), new NamespaceNotFoundException(e));
case NOTFOUND:
throw new TableNotFoundException(e);
default:
throw new AccumuloException(e);
}
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
log.debug("Contacted a Master which is no longer active, re-creating the connection to the active Master");
} catch (Exception e) {
throw new AccumuloException(e);
} finally {
if (client != null)
close(client);
}
}
}
use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.
the class NamespacesIT method verifyTableOperationsExceptions.
@Test
public void verifyTableOperationsExceptions() throws Exception {
String tableName = namespace + ".1";
IteratorSetting setting = new IteratorSetting(200, VersioningIterator.class);
Text a = new Text("a");
Text z = new Text("z");
TableOperations ops = c.tableOperations();
// this one doesn't throw an exception, so don't fail; just check that it works
assertFalse(ops.exists(tableName));
// table operations that should throw an AccumuloException caused by NamespaceNotFoundException
int numRun = 0;
ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND: for (int i = 0; ; ++i) try {
switch(i) {
case 0:
ops.create(tableName);
fail();
break;
case 1:
ops.create("a");
ops.clone("a", tableName, true, Collections.emptyMap(), Collections.emptySet());
fail();
break;
case 2:
ops.importTable(tableName, System.getProperty("user.dir") + "/target");
fail();
break;
default:
// break out of infinite loop
// check test integrity
assertEquals(3, i);
// check test integrity
assertEquals(3, numRun);
break ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof AccumuloException) || !(e.getCause() instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
// table operations that should throw an AccumuloException caused by a TableNotFoundException caused by a NamespaceNotFoundException
// these are here because we didn't declare TableNotFoundException in the API :(
numRun = 0;
ACCUMULOEXCEPTIONS_TABLENOTFOUND: for (int i = 0; ; ++i) try {
switch(i) {
case 0:
ops.removeConstraint(tableName, 0);
fail();
break;
case 1:
ops.removeProperty(tableName, "a");
fail();
break;
case 2:
ops.setProperty(tableName, "a", "b");
fail();
break;
default:
// break out of infinite loop
// check test integrity
assertEquals(3, i);
// check test integrity
assertEquals(3, numRun);
break ACCUMULOEXCEPTIONS_TABLENOTFOUND;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof AccumuloException) || !(e.getCause() instanceof TableNotFoundException) || !(e.getCause().getCause() instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
// table operations that should throw a TableNotFoundException caused by NamespaceNotFoundException
numRun = 0;
TABLENOTFOUNDEXCEPTIONS: for (int i = 0; ; ++i) try {
switch(i) {
case 0:
ops.addConstraint(tableName, NumericValueConstraint.class.getName());
fail();
break;
case 1:
ops.addSplits(tableName, new TreeSet<>());
fail();
break;
case 2:
ops.attachIterator(tableName, setting);
fail();
break;
case 3:
ops.cancelCompaction(tableName);
fail();
break;
case 4:
ops.checkIteratorConflicts(tableName, setting, EnumSet.allOf(IteratorScope.class));
fail();
break;
case 5:
ops.clearLocatorCache(tableName);
fail();
break;
case 6:
ops.clone(tableName, "2", true, Collections.emptyMap(), Collections.emptySet());
fail();
break;
case 7:
ops.compact(tableName, a, z, true, true);
fail();
break;
case 8:
ops.delete(tableName);
fail();
break;
case 9:
ops.deleteRows(tableName, a, z);
fail();
break;
case 10:
ops.splitRangeByTablets(tableName, new Range(), 10);
fail();
break;
case 11:
ops.exportTable(tableName, namespace + "_dir");
fail();
break;
case 12:
ops.flush(tableName, a, z, true);
fail();
break;
case 13:
ops.getDiskUsage(Collections.singleton(tableName));
fail();
break;
case 14:
ops.getIteratorSetting(tableName, "a", IteratorScope.scan);
fail();
break;
case 15:
ops.getLocalityGroups(tableName);
fail();
break;
case 16:
ops.getMaxRow(tableName, Authorizations.EMPTY, a, true, z, true);
fail();
break;
case 17:
ops.getProperties(tableName);
fail();
break;
case 18:
ops.importDirectory(tableName, "", "", false);
fail();
break;
case 19:
ops.testClassLoad(tableName, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
fail();
break;
case 20:
ops.listConstraints(tableName);
fail();
break;
case 21:
ops.listIterators(tableName);
fail();
break;
case 22:
ops.listSplits(tableName);
fail();
break;
case 23:
ops.merge(tableName, a, z);
fail();
break;
case 24:
ops.offline(tableName, true);
fail();
break;
case 25:
ops.online(tableName, true);
fail();
break;
case 26:
ops.removeIterator(tableName, "a", EnumSet.of(IteratorScope.scan));
fail();
break;
case 27:
ops.rename(tableName, tableName + "2");
fail();
break;
case 28:
ops.setLocalityGroups(tableName, Collections.emptyMap());
fail();
break;
default:
// break out of infinite loop
// check test integrity
assertEquals(29, i);
// check test integrity
assertEquals(29, numRun);
break TABLENOTFOUNDEXCEPTIONS;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof TableNotFoundException) || !(e.getCause() instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
}
Aggregations