use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithLabels method testGetScannerResultsWithAuthorizations.
@Test
public void testGetScannerResultsWithAuthorizations() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
// insert data
TColumnValue columnValue = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
for (int i = 0; i < 20; i++) {
TPut put = new TPut(wrap(("testGetScannerResults" + pad(i, (byte) 2)).getBytes()), columnValues);
if (i == 3) {
put.setCellVisibility(new TCellVisibility().setExpression(PUBLIC));
} else {
put.setCellVisibility(new TCellVisibility().setExpression("(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET));
}
handler.put(table, put);
}
// create scan instance
TScan scan = new TScan();
List<TColumn> columns = new ArrayList<>(1);
TColumn column = new TColumn();
column.setFamily(familyAname);
column.setQualifier(qualifierAname);
columns.add(column);
scan.setColumns(columns);
scan.setStartRow("testGetScannerResults".getBytes());
// get 5 rows and check the returned results
scan.setStopRow("testGetScannerResults05".getBytes());
TAuthorization tauth = new TAuthorization();
List<String> labels = new ArrayList<>(2);
labels.add(SECRET);
labels.add(PRIVATE);
tauth.setLabels(labels);
scan.setAuthorizations(tauth);
List<TResult> results = handler.getScannerResults(table, scan, 5);
assertEquals(4, results.size());
for (int i = 0; i < 4; i++) {
if (i < 3) {
assertArrayEquals(("testGetScannerResults" + pad(i, (byte) 2)).getBytes(), results.get(i).getRow());
} else if (i == 3) {
continue;
} else {
assertArrayEquals(("testGetScannerResults" + pad(i + 1, (byte) 2)).getBytes(), results.get(i).getRow());
}
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TResult in project hbase by apache.
the class DemoClient method run.
public void run() throws Exception {
int timeout = 10000;
boolean framed = false;
TTransport transport = new TSocket(host, port, timeout);
if (framed) {
transport = new TFramedTransport(transport);
} else if (secure) {
/**
* The Thrift server the DemoClient is trying to connect to
* must have a matching principal, and support authentication.
*
* The HBase cluster must be secure, allow proxy user.
*/
Map<String, String> saslProperties = new HashMap<>();
saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
transport = new TSaslClientTransport("GSSAPI", null, // Thrift server user name, should be an authorized proxy user
user != null ? user : "hbase", // Thrift server domain
host, saslProperties, null, transport);
}
TProtocol protocol = new TBinaryProtocol(transport);
// This is our thrift client.
THBaseService.Iface client = new THBaseService.Client(protocol);
// open the transport
transport.open();
ByteBuffer table = ByteBuffer.wrap("example".getBytes());
TPut put = new TPut();
put.setRow("row1".getBytes());
TColumnValue columnValue = new TColumnValue();
columnValue.setFamily("family1".getBytes());
columnValue.setQualifier("qualifier1".getBytes());
columnValue.setValue("value1".getBytes());
List<TColumnValue> columnValues = new ArrayList<>(1);
columnValues.add(columnValue);
put.setColumnValues(columnValues);
client.put(table, put);
TGet get = new TGet();
get.setRow("row1".getBytes());
TResult result = client.get(table, get);
System.out.print("row = " + new String(result.getRow()));
for (TColumnValue resultColumnValue : result.getColumnValues()) {
System.out.print("family = " + new String(resultColumnValue.getFamily()));
System.out.print("qualifier = " + new String(resultColumnValue.getFamily()));
System.out.print("value = " + new String(resultColumnValue.getValue()));
System.out.print("timestamp = " + resultColumnValue.getTimestamp());
}
transport.close();
}
Aggregations