Search in sources :

Example 1 with Client

use of org.apache.accumulo.core.clientImpl.thrift.ClientService.Client in project accumulo by apache.

the class ServerClient method executeRawVoid.

public static void executeRawVoid(ClientContext context, ClientExec<ClientService.Client> exec) throws Exception {
    while (true) {
        ClientService.Client client = null;
        String server = null;
        try {
            Pair<String, Client> pair = ServerClient.getConnection(context, new ClientService.Client.Factory(), true);
            server = pair.getFirst();
            client = pair.getSecond();
            exec.execute(client);
            break;
        } catch (TApplicationException tae) {
            throw new AccumuloServerException(server, tae);
        } catch (TTransportException tte) {
            log.debug("ClientService request failed " + server + ", retrying ... ", tte);
            sleepUninterruptibly(100, MILLISECONDS);
        } finally {
            if (client != null)
                ServerClient.close(client, context);
        }
    }
}
Also used : ClientService(org.apache.accumulo.core.clientImpl.thrift.ClientService) TTransportException(org.apache.thrift.transport.TTransportException) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client) TServiceClient(org.apache.thrift.TServiceClient) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client) TApplicationException(org.apache.thrift.TApplicationException)

Example 2 with Client

use of org.apache.accumulo.core.clientImpl.thrift.ClientService.Client 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)

Example 3 with Client

use of org.apache.accumulo.core.clientImpl.thrift.ClientService.Client in project accumulo by apache.

the class TableOperationsImpl method summaries.

@Override
public SummaryRetriever summaries(String tableName) {
    EXISTING_TABLE_NAME.validate(tableName);
    return new SummaryRetriever() {

        private Text startRow = null;

        private Text endRow = null;

        private List<TSummarizerConfiguration> summariesToFetch = Collections.emptyList();

        private String summarizerClassRegex;

        private boolean flush = false;

        @Override
        public SummaryRetriever startRow(Text startRow) {
            Objects.requireNonNull(startRow);
            if (endRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.startRow = startRow;
            return this;
        }

        @Override
        public SummaryRetriever startRow(CharSequence startRow) {
            return startRow(new Text(startRow.toString()));
        }

        @Override
        public List<Summary> retrieve() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
            TableId tableId = context.getTableId(tableName);
            context.requireNotOffline(tableId, tableName);
            TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
            TSummaryRequest request = new TSummaryRequest(tableId.canonical(), range, summariesToFetch, summarizerClassRegex);
            if (flush) {
                _flush(tableId, startRow, endRow, true);
            }
            TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
                TSummaries tsr = client.startGetSummaries(TraceUtil.traceInfo(), context.rpcCreds(), request);
                while (!tsr.finished) {
                    tsr = client.contiuneGetSummaries(TraceUtil.traceInfo(), tsr.sessionId);
                }
                return tsr;
            });
            return new SummaryCollection(ret).getSummaries();
        }

        @Override
        public SummaryRetriever endRow(Text endRow) {
            Objects.requireNonNull(endRow);
            if (startRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.endRow = endRow;
            return this;
        }

        @Override
        public SummaryRetriever endRow(CharSequence endRow) {
            return endRow(new Text(endRow.toString()));
        }

        @Override
        public SummaryRetriever withConfiguration(Collection<SummarizerConfiguration> configs) {
            Objects.requireNonNull(configs);
            summariesToFetch = configs.stream().map(SummarizerConfigurationUtil::toThrift).collect(Collectors.toList());
            return this;
        }

        @Override
        public SummaryRetriever withConfiguration(SummarizerConfiguration... config) {
            Objects.requireNonNull(config);
            return withConfiguration(Arrays.asList(config));
        }

        @Override
        public SummaryRetriever withMatchingConfiguration(String regex) {
            Objects.requireNonNull(regex);
            // Do a sanity check here to make sure that regex compiles, instead of having it fail on a
            // tserver.
            Pattern.compile(regex);
            this.summarizerClassRegex = regex;
            return this;
        }

        @Override
        public SummaryRetriever flush(boolean b) {
            this.flush = b;
            return this;
        }
    };
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Text(org.apache.hadoop.io.Text) SummarizerConfigurationUtil(org.apache.accumulo.core.summary.SummarizerConfigurationUtil) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) TSummaryRequest(org.apache.accumulo.core.dataImpl.thrift.TSummaryRequest) TSummaries(org.apache.accumulo.core.dataImpl.thrift.TSummaries) Summary(org.apache.accumulo.core.client.summary.Summary) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.dataImpl.thrift.TSummarizerConfiguration)

Aggregations

Client (org.apache.accumulo.core.clientImpl.thrift.ClientService.Client)3 ArrayList (java.util.ArrayList)2 ClientService (org.apache.accumulo.core.clientImpl.thrift.ClientService)2 TTransportException (org.apache.thrift.transport.TTransportException)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)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 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 DiskUsage (org.apache.accumulo.core.client.admin.DiskUsage)1 SummaryRetriever (org.apache.accumulo.core.client.admin.SummaryRetriever)1 SummarizerConfiguration (org.apache.accumulo.core.client.summary.SummarizerConfiguration)1 Summary (org.apache.accumulo.core.client.summary.Summary)1 TDiskUsage (org.apache.accumulo.core.clientImpl.thrift.TDiskUsage)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)1 TableId (org.apache.accumulo.core.data.TableId)1