Search in sources :

Example 91 with TableId

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

the class ClientServiceHandler method grantTablePermission.

@Override
public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException {
    TableId tableId = checkTableId(context, tableName, TableOperation.PERMISSION);
    NamespaceId namespaceId;
    try {
        namespaceId = context.getNamespaceId(tableId);
    } catch (TableNotFoundException e) {
        throw new TException(e);
    }
    security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 92 with TableId

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

the class ClientServiceHandler method getDiskUsage.

@Override
public List<TDiskUsage> getDiskUsage(Set<String> tables, TCredentials credentials) throws ThriftTableOperationException, ThriftSecurityException, TException {
    try {
        HashSet<TableId> tableIds = new HashSet<>();
        for (String table : tables) {
            // ensure that table table exists
            TableId tableId = checkTableId(context, table, null);
            tableIds.add(tableId);
            NamespaceId namespaceId = context.getNamespaceId(tableId);
            if (!security.canScan(credentials, tableId, namespaceId))
                throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
        }
        // use the same set of tableIds that were validated above to avoid race conditions
        Map<TreeSet<String>, Long> diskUsage = TableDiskUsage.getDiskUsage(tableIds, context.getVolumeManager(), context);
        List<TDiskUsage> retUsages = new ArrayList<>();
        for (Map.Entry<TreeSet<String>, Long> usageItem : diskUsage.entrySet()) {
            retUsages.add(new TDiskUsage(new ArrayList<>(usageItem.getKey()), usageItem.getValue()));
        }
        return retUsages;
    } catch (TableNotFoundException | IOException e) {
        throw new TException(e);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 93 with TableId

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

the class TableConfiguration method createCompactionDispatcher.

private static CompactionDispatcher createCompactionDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    CompactionDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_COMPACTION_DISPATCHER, CompactionDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_COMPACTION_DISPATCHER_OPTS);
    newDispatcher.init(new CompactionDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) CompactionDispatcher(org.apache.accumulo.core.spi.compaction.CompactionDispatcher) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 94 with TableId

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

the class TableConfiguration method createScanDispatcher.

private static ScanDispatcher createScanDispatcher(AccumuloConfiguration conf, ServerContext context, TableId tableId) {
    ScanDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf, Property.TABLE_SCAN_DISPATCHER, ScanDispatcher.class, null);
    Map<String, String> opts = conf.getAllPropertiesWithPrefixStripped(Property.TABLE_SCAN_DISPATCHER_OPTS);
    newDispatcher.init(new ScanDispatcher.InitParameters() {

        private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);

        @Override
        public TableId getTableId() {
            return tableId;
        }

        @Override
        public Map<String, String> getOptions() {
            return opts;
        }

        @Override
        public ServiceEnvironment getServiceEnv() {
            return senv;
        }
    });
    return newDispatcher;
}
Also used : ScanDispatcher(org.apache.accumulo.core.spi.scan.ScanDispatcher) TableId(org.apache.accumulo.core.data.TableId) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 95 with TableId

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

the class CheckForMetadataProblems method checkMetadataAndRootTableEntries.

private static void checkMetadataAndRootTableEntries(String tableNameToCheck, ServerUtilOpts opts) throws Exception {
    TableId tableCheckId = opts.getServerContext().getTableId(tableNameToCheck);
    System.out.println("Checking tables whose metadata is found in: " + tableNameToCheck + " (" + tableCheckId + ")");
    Map<TableId, TreeSet<KeyExtent>> tables = new HashMap<>();
    try (AccumuloClient client = Accumulo.newClient().from(opts.getClientProps()).build();
        Scanner scanner = client.createScanner(tableNameToCheck, Authorizations.EMPTY)) {
        scanner.setRange(TabletsSection.getRange());
        TabletColumnFamily.PREV_ROW_COLUMN.fetch(scanner);
        scanner.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
        Text colf = new Text();
        Text colq = new Text();
        boolean justLoc = false;
        int count = 0;
        for (Entry<Key, Value> entry : scanner) {
            colf = entry.getKey().getColumnFamily(colf);
            colq = entry.getKey().getColumnQualifier(colq);
            count++;
            TableId tableId = KeyExtent.fromMetaRow(entry.getKey().getRow()).tableId();
            TreeSet<KeyExtent> tablets = tables.get(tableId);
            if (tablets == null) {
                tables.forEach(CheckForMetadataProblems::checkTable);
                tables.clear();
                tablets = new TreeSet<>();
                tables.put(tableId, tablets);
            }
            if (TabletColumnFamily.PREV_ROW_COLUMN.equals(colf, colq)) {
                KeyExtent tabletKe = KeyExtent.fromMetaPrevRow(entry);
                tablets.add(tabletKe);
                justLoc = false;
            } else if (colf.equals(CurrentLocationColumnFamily.NAME)) {
                if (justLoc) {
                    System.out.println("Problem at key " + entry.getKey());
                    sawProblems = true;
                }
                justLoc = true;
            }
        }
        if (count == 0) {
            System.err.println("ERROR : table " + tableNameToCheck + " (" + tableCheckId + ") is empty");
            sawProblems = true;
        }
    }
    tables.forEach(CheckForMetadataProblems::checkTable);
    if (!sawProblems) {
        System.out.println("No problems found in " + tableNameToCheck + " (" + tableCheckId + ")");
    }
// end METADATA table sanity check
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Scanner(org.apache.accumulo.core.client.Scanner) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TreeSet(java.util.TreeSet) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Aggregations

TableId (org.apache.accumulo.core.data.TableId)169 Text (org.apache.hadoop.io.Text)64 HashMap (java.util.HashMap)55 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)55 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)43 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)41 Map (java.util.Map)37 Key (org.apache.accumulo.core.data.Key)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)34 HashSet (java.util.HashSet)31 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)31 Value (org.apache.accumulo.core.data.Value)31 IOException (java.io.IOException)28 Scanner (org.apache.accumulo.core.client.Scanner)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Mutation (org.apache.accumulo.core.data.Mutation)27 List (java.util.List)26 Range (org.apache.accumulo.core.data.Range)24 BatchWriter (org.apache.accumulo.core.client.BatchWriter)23