Search in sources :

Example 1 with TDiskUsage

use of org.apache.accumulo.core.clientImpl.thrift.TDiskUsage 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 2 with TDiskUsage

use of org.apache.accumulo.core.clientImpl.thrift.TDiskUsage 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, new ClientService.Client.Factory(), 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, 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(), context);
        }
    }
    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) ClientService(org.apache.accumulo.core.clientImpl.thrift.ClientService) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) TTransportException(org.apache.thrift.transport.TTransportException) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) ThriftSecurityException(org.apache.accumulo.core.clientImpl.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.clientImpl.thrift.TDiskUsage) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client)

Aggregations

ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 TDiskUsage (org.apache.accumulo.core.clientImpl.thrift.TDiskUsage)2 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)2 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)1 DiskUsage (org.apache.accumulo.core.client.admin.DiskUsage)1 ClientService (org.apache.accumulo.core.clientImpl.thrift.ClientService)1 Client (org.apache.accumulo.core.clientImpl.thrift.ClientService.Client)1 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)1 NamespaceId (org.apache.accumulo.core.data.NamespaceId)1 TableId (org.apache.accumulo.core.data.TableId)1 ManagerClientService (org.apache.accumulo.core.manager.thrift.ManagerClientService)1