Search in sources :

Example 1 with NamespaceExistsException

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));
}
Also used : NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 2 with NamespaceExistsException

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);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 3 with NamespaceExistsException

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);
            }
    }
}
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 4 with NamespaceExistsException

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);
    }
}
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)

Aggregations

NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)4 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 TableExistsException (org.apache.accumulo.core.client.TableExistsException)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 IOException (java.io.IOException)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)2 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)2 FileNotFoundException (java.io.FileNotFoundException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)1 NamespaceNotEmptyException (org.apache.accumulo.core.client.NamespaceNotEmptyException)1 TableDeletedException (org.apache.accumulo.core.client.TableDeletedException)1 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)1 NamespaceOperations (org.apache.accumulo.core.client.admin.NamespaceOperations)1 ThriftNotActiveServiceException (org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException)1 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)1 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)1