Search in sources :

Example 1 with Client

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

the class TableOperationsImpl method summaries.

@Override
public SummaryRetriever summaries(String 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 {
            Table.ID tableId = Tables.getTableId(context.getInstance(), tableName);
            if (Tables.getTableState(context.getInstance(), tableId) == TableState.OFFLINE)
                throw new TableOfflineException(context.getInstance(), tableId.canonicalID());
            TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
            TSummaryRequest request = new TSummaryRequest(tableId.canonicalID(), range, summariesToFetch, summarizerClassRegex);
            if (flush) {
                _flush(tableId, startRow, endRow, true);
            }
            TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
                TSummaries tsr = client.startGetSummaries(Tracer.traceInfo(), context.rpcCreds(), request);
                while (!tsr.finished) {
                    tsr = client.contiuneGetSummaries(Tracer.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 : RootTable(org.apache.accumulo.core.metadata.RootTable) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) 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.data.thrift.TSummaryRequest) TSummaries(org.apache.accumulo.core.data.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.client.impl.thrift.ClientService.Client) TRowRange(org.apache.accumulo.core.data.thrift.TRowRange) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.data.thrift.TSummarizerConfiguration)

Example 2 with Client

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

the class TableOperationsImpl method setProperty.

@Override
public void setProperty(final String tableName, final String property, final String value) throws AccumuloException, AccumuloSecurityException {
    checkArgument(tableName != null, "tableName is null");
    checkArgument(property != null, "property is null");
    checkArgument(value != null, "value is null");
    try {
        MasterClient.executeTable(context, new ClientExec<MasterClientService.Client>() {

            @Override
            public void execute(MasterClientService.Client client) throws Exception {
                client.setTableProperty(Tracer.traceInfo(), context.rpcCreds(), tableName, property, value);
            }
        });
    } catch (TableNotFoundException e) {
        throw new AccumuloException(e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) 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 3 with Client

use of org.apache.accumulo.core.client.impl.thrift.ClientService.Client in project teiid by teiid.

the class AccumuloConnectionImpl method checkTabletServerExists.

private void checkTabletServerExists(ZooKeeperInstance inst, String userName, String password) throws ResourceException {
    ClientService.Client client = null;
    try {
        Pair<String, Client> pair = ServerClient.getConnection(new ClientContext(inst, new Credentials(userName, new PasswordToken(password)), inst.getConfiguration()), true, 10);
        client = pair.getSecond();
    } catch (TTransportException e) {
        throw new ResourceException(AccumuloManagedConnectionFactory.UTIL.getString("no_tserver"), e);
    } finally {
        if (client != null) {
            ServerClient.close(client);
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TTransportException(org.apache.thrift.transport.TTransportException) ResourceException(javax.resource.ResourceException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) ServerClient(org.apache.accumulo.core.client.impl.ServerClient) Credentials(org.apache.accumulo.core.client.impl.Credentials)

Example 4 with Client

use of org.apache.accumulo.core.client.impl.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, 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, TimeUnit.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());
        }
    }
    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) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) TDiskUsage(org.apache.accumulo.core.client.impl.thrift.TDiskUsage) ThriftSecurityException(org.apache.accumulo.core.client.impl.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.client.impl.thrift.TDiskUsage) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client)

Example 5 with Client

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

the class TableOperationsImpl method testClassLoad.

@Override
public boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    checkArgument(tableName != null, "tableName is null");
    checkArgument(className != null, "className is null");
    checkArgument(asTypeName != null, "asTypeName is null");
    try {
        return ServerClient.executeRaw(context, new ClientExecReturn<Boolean, ClientService.Client>() {

            @Override
            public Boolean execute(ClientService.Client client) throws Exception {
                return client.checkTableClass(Tracer.traceInfo(), context.rpcCreds(), tableName, className, asTypeName);
            }
        });
    } catch (ThriftTableOperationException e) {
        switch(e.getType()) {
            case NOTFOUND:
                throw new TableNotFoundException(e);
            case NAMESPACE_NOTFOUND:
                throw new TableNotFoundException(tableName, new NamespaceNotFoundException(e));
            default:
                throw new AccumuloException(e.description, e);
        }
    } catch (ThriftSecurityException e) {
        throw new AccumuloSecurityException(e.user, e.code, e);
    } catch (AccumuloException e) {
        throw e;
    } catch (Exception e) {
        throw new AccumuloException(e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) ClientService(org.apache.accumulo.core.client.impl.thrift.ClientService) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) 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) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client) Client(org.apache.accumulo.core.client.impl.thrift.ClientService.Client)

Aggregations

Client (org.apache.accumulo.core.client.impl.thrift.ClientService.Client)7 TTransportException (org.apache.thrift.transport.TTransportException)6 AccumuloException (org.apache.accumulo.core.client.AccumuloException)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)4 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)4 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)4 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)4 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)4 TApplicationException (org.apache.thrift.TApplicationException)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 TableDeletedException (org.apache.accumulo.core.client.TableDeletedException)3 TableExistsException (org.apache.accumulo.core.client.TableExistsException)3 ClientService (org.apache.accumulo.core.client.impl.thrift.ClientService)3 ThriftNotActiveServiceException (org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException)3 MasterClientService (org.apache.accumulo.core.master.thrift.MasterClientService)3 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)3 TException (org.apache.thrift.TException)3