Search in sources :

Example 6 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.

the class ServerConfigurationFactory method getNamespaceConfigurationForTable.

public NamespaceConfiguration getNamespaceConfigurationForTable(TableId tableId) {
    NamespaceConfiguration conf;
    synchronized (tableParentConfigs) {
        conf = tableParentConfigs.get(instanceID).get(tableId);
    }
    // which may result in creating multiple objects for the same id, but that's ok.
    if (conf == null) {
        NamespaceId namespaceId;
        try {
            namespaceId = context.getNamespaceId(tableId);
        } catch (TableNotFoundException e) {
            throw new RuntimeException(e);
        }
        conf = new NamespaceConfiguration(namespaceId, context, getSystemConfiguration());
        ConfigCheckUtil.validate(conf);
        synchronized (tableParentConfigs) {
            tableParentConfigs.get(instanceID).put(tableId, conf);
        }
    }
    return conf;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 7 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.

the class ImportPopulateZookeeper method call.

@Override
public Repo<Manager> call(long tid, Manager env) throws Exception {
    // reserve the table name in zookeeper or fail
    Utils.getTableNameLock().lock();
    try {
        // write tableName & tableId to zookeeper
        Utils.checkTableDoesNotExist(env.getContext(), tableInfo.tableName, tableInfo.tableId, TableOperation.CREATE);
        String namespace = TableNameUtil.qualify(tableInfo.tableName).getFirst();
        NamespaceId namespaceId = Namespaces.getNamespaceId(env.getContext(), namespace);
        env.getTableManager().addTable(tableInfo.tableId, namespaceId, tableInfo.tableName);
        env.getContext().clearTableListCache();
    } finally {
        Utils.getTableNameLock().unlock();
    }
    VolumeManager volMan = env.getVolumeManager();
    for (Entry<String, String> entry : getExportedProps(volMan).entrySet()) if (!TablePropUtil.setTableProperty(env.getContext(), tableInfo.tableId, entry.getKey(), entry.getValue())) {
        throw new AcceptableThriftTableOperationException(tableInfo.tableId.canonical(), tableInfo.tableName, TableOperation.IMPORT, TableOperationExceptionType.OTHER, "Invalid table property " + entry.getKey());
    }
    return new CreateImportDir(tableInfo);
}
Also used : VolumeManager(org.apache.accumulo.server.fs.VolumeManager) NamespaceId(org.apache.accumulo.core.data.NamespaceId) AcceptableThriftTableOperationException(org.apache.accumulo.core.clientImpl.AcceptableThriftTableOperationException)

Example 8 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.

the class CompactionDriverTest method testCancelId.

@Test
public void testCancelId() throws Exception {
    final InstanceId instance = InstanceId.of(UUID.randomUUID());
    final long compactId = 123;
    final long cancelId = 124;
    final NamespaceId namespaceId = NamespaceId.of("13");
    final TableId tableId = TableId.of("42");
    final byte[] startRow = new byte[0];
    final byte[] endRow = new byte[0];
    Manager manager = EasyMock.createNiceMock(Manager.class);
    ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
    ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
    EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
    EasyMock.expect(manager.getContext()).andReturn(ctx);
    EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
    final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
    EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
    EasyMock.replay(manager, ctx, zrw);
    final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
    final long tableIdLong = Long.parseLong(tableId.toString());
    var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
    assertTrue(e.getTableId().equals(tableId.toString()));
    assertTrue(e.getOp().equals(TableOperation.COMPACT));
    assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
    assertTrue(e.getDescription().equals(TableOperationsImpl.COMPACTION_CANCELED_MSG));
    EasyMock.verify(manager, ctx, zrw);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Example 9 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.

the class DUCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws IOException, TableNotFoundException, NamespaceNotFoundException {
    final SortedSet<String> tables = new TreeSet<>(Arrays.asList(cl.getArgs()));
    if (cl.hasOption(ShellOptions.tableOption)) {
        tables.add(cl.getOptionValue(ShellOptions.tableOption));
    }
    if (cl.hasOption(optNamespace.getOpt())) {
        NamespaceId namespaceId = Namespaces.getNamespaceId(shellState.getContext(), cl.getOptionValue(optNamespace.getOpt()));
        tables.addAll(Namespaces.getTableNames(shellState.getContext(), namespaceId));
    }
    boolean prettyPrint = cl.hasOption(optHumanReadble.getOpt());
    // Add any patterns
    if (cl.hasOption(optTablePattern.getOpt())) {
        shellState.getAccumuloClient().tableOperations().list().stream().filter(Pattern.compile(cl.getOptionValue(optTablePattern.getOpt())).asMatchPredicate()).forEach(tables::add);
    }
    // If we didn't get any tables, and we have a table selected, add the current table
    if (tables.isEmpty() && !shellState.getTableName().isEmpty()) {
        tables.add(shellState.getTableName());
    }
    // sanity check...make sure the user-specified tables exist
    for (String tableName : tables) {
        if (!shellState.getAccumuloClient().tableOperations().exists(tableName)) {
            throw new TableNotFoundException(tableName, tableName, "specified table that doesn't exist");
        }
    }
    try {
        String valueFormat = prettyPrint ? "%9s" : "%,24d";
        for (DiskUsage usage : shellState.getAccumuloClient().tableOperations().getDiskUsage(tables)) {
            Object value = prettyPrint ? NumUtil.bigNumberForSize(usage.getUsage()) : usage.getUsage();
            shellState.getWriter().println(String.format(valueFormat + " %s", value, usage.getTables()));
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return 0;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) NamespaceId(org.apache.accumulo.core.data.NamespaceId) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) IOException(java.io.IOException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 10 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.

the class CompactionCoordinator method cancel.

@Override
public void cancel(TInfo tinfo, TCredentials credentials, String externalCompactionId) throws TException {
    var runningCompaction = RUNNING.get(ExternalCompactionId.of(externalCompactionId));
    var extent = KeyExtent.fromThrift(runningCompaction.getJob().getExtent());
    try {
        NamespaceId nsId = getContext().getNamespaceId(extent.tableId());
        if (!security.canCompact(credentials, extent.tableId(), nsId)) {
            throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
        }
    } catch (TableNotFoundException e) {
        throw new ThriftTableOperationException(extent.tableId().canonical(), null, TableOperation.COMPACT_CANCEL, TableOperationExceptionType.NOTFOUND, e.getMessage());
    }
    HostAndPort address = HostAndPort.fromString(runningCompaction.getCompactorAddress());
    ExternalCompactionUtil.cancelCompaction(getContext(), address, externalCompactionId);
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Aggregations

NamespaceId (org.apache.accumulo.core.data.NamespaceId)32 TableId (org.apache.accumulo.core.data.TableId)20 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)12 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)11 TException (org.apache.thrift.TException)9 IOException (java.io.IOException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 HashSet (java.util.HashSet)6 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)5 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)5 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 Authorizations (org.apache.accumulo.core.security.Authorizations)4 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)4 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)4