Search in sources :

Example 16 with NamespaceNotFoundException

use of org.apache.accumulo.core.client.NamespaceNotFoundException 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);
    }
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NamespaceOperations(org.apache.accumulo.core.client.admin.NamespaceOperations) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) VersioningIterator(org.apache.accumulo.core.iterators.user.VersioningIterator) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) 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) Test(org.junit.Test)

Example 17 with NamespaceNotFoundException

use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.

the class TableOperationsImpl method getDiskUsage.

@Override
public List<DiskUsage> getDiskUsage(Set<String> tableNames) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    List<TDiskUsage> diskUsages = null;
    while (diskUsages == null) {
        Pair<String, Client> pair = null;
        try {
            // this operation may us a lot of memory... its likely that connections to tabletservers hosting metadata tablets will be cached, so do not use cached
            // connections
            pair = ServerClient.getConnection(context, false);
            diskUsages = pair.getSecond().getDiskUsage(tableNames, context.rpcCreds());
        } catch (ThriftTableOperationException e) {
            switch(e.getType()) {
                case NOTFOUND:
                    throw new TableNotFoundException(e);
                case NAMESPACE_NOTFOUND:
                    throw new TableNotFoundException(e.getTableName(), new NamespaceNotFoundException(e));
                default:
                    throw new AccumuloException(e.description, e);
            }
        } catch (ThriftSecurityException e) {
            throw new AccumuloSecurityException(e.getUser(), e.getCode());
        } catch (TTransportException e) {
            // some sort of communication error occurred, retry
            if (pair == null) {
                log.debug("Disk usage request failed.  Pair is null.  Retrying request...", e);
            } else {
                log.debug("Disk usage request failed {}, retrying ... ", pair.getFirst(), e);
            }
            sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        } catch (TException e) {
            // may be a TApplicationException which indicates error on the server side
            throw new AccumuloException(e);
        } finally {
            // must always return thrift connection
            if (pair != null)
                ServerClient.close(pair.getSecond());
        }
    }
    List<DiskUsage> finalUsages = new ArrayList<>();
    for (TDiskUsage diskUsage : diskUsages) {
        finalUsages.add(new DiskUsage(new TreeSet<>(diskUsage.getTables()), diskUsage.getUsage()));
    }
    return finalUsages;
}
Also used : TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) TDiskUsage(org.apache.accumulo.core.client.impl.thrift.TDiskUsage) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TDiskUsage(org.apache.accumulo.core.client.impl.thrift.TDiskUsage) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client)

Example 18 with NamespaceNotFoundException

use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.

the class TableOperationsImpl method testClassLoad.

@Override
public boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    checkArgument(tableName != null, "tableName is null");
    checkArgument(className != null, "className is null");
    checkArgument(asTypeName != null, "asTypeName is null");
    try {
        return ServerClient.executeRaw(context, new ClientExecReturn<Boolean, ClientService.Client>() {

            @Override
            public Boolean execute(ClientService.Client client) throws Exception {
                return client.checkTableClass(Tracer.traceInfo(), context.rpcCreds(), tableName, className, asTypeName);
            }
        });
    } catch (ThriftTableOperationException e) {
        switch(e.getType()) {
            case NOTFOUND:
                throw new TableNotFoundException(e);
            case NAMESPACE_NOTFOUND:
                throw new TableNotFoundException(tableName, new NamespaceNotFoundException(e));
            default:
                throw new AccumuloException(e.description, e);
        }
    } catch (ThriftSecurityException e) {
        throw new AccumuloSecurityException(e.user, e.code, e);
    } catch (AccumuloException e) {
        throw e;
    } catch (Exception e) {
        throw new AccumuloException(e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) 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) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client)

Example 19 with NamespaceNotFoundException

use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.

the class Tables method _getTableId.

/**
 * Lookup table ID in ZK. If not found, clears cache and tries again.
 */
public static Table.ID _getTableId(Instance instance, String tableName) throws NamespaceNotFoundException, TableNotFoundException {
    Table.ID tableId = getNameToIdMap(instance).get(tableName);
    if (tableId == null) {
        // maybe the table exist, but the cache was not updated yet... so try to clear the cache and check again
        clearCache(instance);
        tableId = getNameToIdMap(instance).get(tableName);
        if (tableId == null) {
            String namespace = qualify(tableName).getFirst();
            if (Namespaces.getNameToIdMap(instance).containsKey(namespace))
                throw new TableNotFoundException(null, tableName, null);
            else
                throw new NamespaceNotFoundException(null, namespace, null);
        }
    }
    return tableId;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 20 with NamespaceNotFoundException

use of org.apache.accumulo.core.client.NamespaceNotFoundException in project accumulo by apache.

the class NamespaceOperationsHelper method getIteratorSetting.

@Override
public IteratorSetting getIteratorSetting(String namespace, String name, IteratorScope scope) throws AccumuloSecurityException, AccumuloException, NamespaceNotFoundException {
    if (!exists(namespace))
        throw new NamespaceNotFoundException(null, namespace, null);
    int priority = -1;
    String classname = null;
    Map<String, String> settings = new HashMap<>();
    String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
    String opt = root + ".opt.";
    for (Entry<String, String> property : this.getProperties(namespace)) {
        if (property.getKey().equals(root)) {
            String[] parts = property.getValue().split(",");
            if (parts.length != 2) {
                throw new AccumuloException("Bad value for iterator setting: " + property.getValue());
            }
            priority = Integer.parseInt(parts[0]);
            classname = parts[1];
        } else if (property.getKey().startsWith(opt)) {
            settings.put(property.getKey().substring(opt.length()), property.getValue());
        }
    }
    if (priority <= 0 || classname == null) {
        return null;
    }
    return new IteratorSetting(priority, name, classname, settings);
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

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