use of org.apache.accumulo.core.dataImpl.thrift.TColumn in project accumulo by apache.
the class ColumnTest method testThriftRoundTrip.
@Test
public void testThriftRoundTrip() {
for (Column c : col) {
TColumn tc = c.toThrift();
assertEquals(c, new Column(tc));
}
}
use of org.apache.accumulo.core.dataImpl.thrift.TColumn in project accumulo by apache.
the class AuditedSecurityOperation method canScan.
@Override
public boolean canScan(TCredentials credentials, TableId tableId, NamespaceId namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
if (shouldAudit(credentials, tableId)) {
Range convertedRange = new Range(range);
List<String> convertedColumns = truncate(columns.stream().map(Column::new).collect(Collectors.toList()));
String tableName = getTableName(tableId);
try {
boolean canScan = super.canScan(credentials, tableId, namespaceId);
audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
return canScan;
} catch (ThriftSecurityException ex) {
audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
throw ex;
}
} else {
return super.canScan(credentials, tableId, namespaceId);
}
}
use of org.apache.accumulo.core.dataImpl.thrift.TColumn in project accumulo by apache.
the class VerifyTabletAssignments method checkTabletServer.
private static void checkTabletServer(ClientContext context, Entry<HostAndPort, List<KeyExtent>> entry, HashSet<KeyExtent> failures) throws ThriftSecurityException, TException, NoSuchScanIDException {
TabletClientService.Iface client = ThriftUtil.getTServerClient(entry.getKey(), context);
Map<TKeyExtent, List<TRange>> batch = new TreeMap<>();
for (KeyExtent keyExtent : entry.getValue()) {
Text row = keyExtent.endRow();
Text row2 = null;
if (row == null) {
row = keyExtent.prevEndRow();
if (row != null) {
row = new Text(row);
row.append(new byte[] { 'a' }, 0, 1);
} else {
row = new Text("1234567890");
}
row2 = new Text(row);
row2.append(new byte[] { '!' }, 0, 1);
} else {
row = new Text(row);
row2 = new Text(row);
row.getBytes()[row.getLength() - 1] = (byte) (row.getBytes()[row.getLength() - 1] - 1);
}
Range r = new Range(row, true, row2, false);
batch.put(keyExtent.toThrift(), Collections.singletonList(r.toThrift()));
}
TInfo tinfo = TraceUtil.traceInfo();
Map<String, Map<String, String>> emptyMapSMapSS = Collections.emptyMap();
List<IterInfo> emptyListIterInfo = Collections.emptyList();
List<TColumn> emptyListColumn = Collections.emptyList();
InitialMultiScan is = client.startMultiScan(tinfo, context.rpcCreds(), batch, emptyListColumn, emptyListIterInfo, emptyMapSMapSS, Authorizations.EMPTY.getAuthorizationsBB(), false, null, 0L, null, null);
if (is.result.more) {
MultiScanResult result = client.continueMultiScan(tinfo, is.scanID);
checkFailures(entry.getKey(), failures, result);
while (result.more) {
result = client.continueMultiScan(tinfo, is.scanID);
checkFailures(entry.getKey(), failures, result);
}
}
client.closeMultiScan(tinfo, is.scanID);
ThriftUtil.returnClient((TServiceClient) client, context);
}
use of org.apache.accumulo.core.dataImpl.thrift.TColumn in project accumulo by apache.
the class ThriftClientHandler method startScan.
@Override
public InitialScan startScan(TInfo tinfo, TCredentials credentials, TKeyExtent textent, TRange range, List<TColumn> columns, int batchSize, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations, boolean waitForWrites, boolean isolated, long readaheadThreshold, TSamplerConfiguration tSamplerConfig, long batchTimeOut, String contextArg, Map<String, String> executionHints) throws NotServingTabletException, ThriftSecurityException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
TableId tableId = TableId.of(new String(textent.getTable(), UTF_8));
NamespaceId namespaceId;
try {
namespaceId = server.getContext().getNamespaceId(tableId);
} catch (TableNotFoundException e1) {
throw new NotServingTabletException(textent);
}
if (!security.canScan(credentials, tableId, namespaceId, range, columns, ssiList, ssio, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
if (!security.authenticatedUserHasAuthorizations(credentials, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
}
final KeyExtent extent = KeyExtent.fromThrift(textent);
// metadata
if (waitForWrites) {
writeTracker.waitForWrites(TabletType.type(extent));
}
Tablet tablet = server.getOnlineTablet(extent);
if (tablet == null) {
throw new NotServingTabletException(textent);
}
HashSet<Column> columnSet = new HashSet<>();
for (TColumn tcolumn : columns) {
columnSet.add(new Column(tcolumn));
}
ScanParameters scanParams = new ScanParameters(batchSize, new Authorizations(authorizations), columnSet, ssiList, ssio, isolated, SamplerConfigurationImpl.fromThrift(tSamplerConfig), batchTimeOut, contextArg);
final SingleScanSession scanSession = new SingleScanSession(credentials, extent, scanParams, readaheadThreshold, executionHints);
scanSession.scanner = tablet.createScanner(new Range(range), scanParams, scanSession.interruptFlag);
long sid = server.sessionManager.createSession(scanSession, true);
ScanResult scanResult;
try {
scanResult = continueScan(tinfo, sid, scanSession);
} catch (NoSuchScanIDException e) {
log.error("The impossible happened", e);
throw new RuntimeException();
} finally {
server.sessionManager.unreserveSession(sid);
}
return new InitialScan(sid, scanResult);
}
use of org.apache.accumulo.core.dataImpl.thrift.TColumn in project accumulo by apache.
the class ThriftClientHandler method startMultiScan.
@Override
public InitialMultiScan startMultiScan(TInfo tinfo, TCredentials credentials, Map<TKeyExtent, List<TRange>> tbatch, List<TColumn> tcolumns, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations, boolean waitForWrites, TSamplerConfiguration tSamplerConfig, long batchTimeOut, String contextArg, Map<String, String> executionHints) throws ThriftSecurityException, TSampleNotPresentException {
// find all of the tables that need to be scanned
final HashSet<TableId> tables = new HashSet<>();
for (TKeyExtent keyExtent : tbatch.keySet()) {
tables.add(TableId.of(new String(keyExtent.getTable(), UTF_8)));
}
if (tables.size() != 1) {
throw new IllegalArgumentException("Cannot batch scan over multiple tables");
}
// check if user has permission to the tables
for (TableId tableId : tables) {
NamespaceId namespaceId = getNamespaceId(credentials, tableId);
if (!security.canScan(credentials, tableId, namespaceId, tbatch, tcolumns, ssiList, ssio, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
}
try {
if (!security.authenticatedUserHasAuthorizations(credentials, authorizations)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
}
} catch (ThriftSecurityException tse) {
log.error("{} is not authorized", credentials.getPrincipal(), tse);
throw tse;
}
// @formatter:off
Map<KeyExtent, List<Range>> batch = tbatch.entrySet().stream().collect(Collectors.toMap(entry -> KeyExtent.fromThrift(entry.getKey()), entry -> entry.getValue().stream().map(Range::new).collect(Collectors.toList())));
// @formatter:on
// This is used to determine which thread pool to use
KeyExtent threadPoolExtent = batch.keySet().iterator().next();
if (waitForWrites) {
writeTracker.waitForWrites(TabletType.type(batch.keySet()));
}
Set<Column> columnSet = tcolumns.isEmpty() ? Collections.emptySet() : new HashSet<>(Collections2.transform(tcolumns, Column::new));
ScanParameters scanParams = new ScanParameters(-1, new Authorizations(authorizations), columnSet, ssiList, ssio, false, SamplerConfigurationImpl.fromThrift(tSamplerConfig), batchTimeOut, contextArg);
final MultiScanSession mss = new MultiScanSession(credentials, threadPoolExtent, batch, scanParams, executionHints);
mss.numTablets = batch.size();
for (List<Range> ranges : batch.values()) {
mss.numRanges += ranges.size();
}
long sid = server.sessionManager.createSession(mss, true);
MultiScanResult result;
try {
result = continueMultiScan(sid, mss);
} finally {
server.sessionManager.unreserveSession(sid);
}
return new InitialMultiScan(sid, result);
}
Aggregations