Search in sources :

Example 6 with NamespaceNotFoundException

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);
            }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 7 with NamespaceNotFoundException

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));
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TreeMap(java.util.TreeMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 8 with NamespaceNotFoundException

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;
}
Also used : EnumSet(java.util.EnumSet) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) TreeMap(java.util.TreeMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 9 with NamespaceNotFoundException

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);
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) TTransportException(org.apache.thrift.transport.TTransportException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TTransportException(org.apache.thrift.transport.TTransportException) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) UnknownHostException(java.net.UnknownHostException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)

Example 10 with NamespaceNotFoundException

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) VersioningIterator(org.apache.accumulo.core.iterators.user.VersioningIterator) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) Test(org.junit.Test)

Aggregations

NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)23 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)10 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)9 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)8 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)7 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)7 TableExistsException (org.apache.accumulo.core.client.TableExistsException)6 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)4 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)4 TTransportException (org.apache.thrift.transport.TTransportException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Entry (java.util.Map.Entry)3 NamespaceNotEmptyException (org.apache.accumulo.core.client.NamespaceNotEmptyException)3 ThriftNotActiveServiceException (org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException)3 MasterClientService (org.apache.accumulo.core.master.thrift.MasterClientService)3 FileNotFoundException (java.io.FileNotFoundException)2